Skip to content

Instantly share code, notes, and snippets.

View thomasvrgn's full-sized avatar
🖥️
Hard working on projects

_ thomasvrgn

🖥️
Hard working on projects
View GitHub Profile
@thomasvrgn
thomasvrgn / pattern.js
Last active August 3, 2021 07:22
haskell pattern matching in js
const _ = Symbol('_');
const chunk = (array, size) => array.length === 0
? []
: [array.splice(0, size), ...chunk(array, size)];
const variables = {};
const clear = object => {
for (const prop in object) delete object[prop];
return object;
@thomasvrgn
thomasvrgn / index.js
Created April 5, 2021 14:51
Lisp interpreter
// Based on other parser gist
const tokens = tokenize(code);
const ast = parse(tokens);
run(ast);
@thomasvrgn
thomasvrgn / index.js
Created April 5, 2021 14:20
Simple Lisp parser
const code = '(print "test" (+ 5 (- 4 2)) (print "bruh" (t "test")))';
const tokens = tokenize(code);
console.log(parse(tokens));
@thomasvrgn
thomasvrgn / index.js
Created April 5, 2021 09:00
Pattern matcher in JS
console.log(match(
[{ variable: 'x' }, 'test', ['_', 'coucou']],
['test', 'test', ['bruggh', 'coucou']]
)); // true
console.log(scope); // [ { name: 'x', value: 'test' } ]
console.log(match(
[{ variable: 'x' }, 'test', ['_', 'coucou']],
['test', 'test', ['bruggh', 'coucou']]
@thomasvrgn
thomasvrgn / index.js
Created March 6, 2021 09:48
pour itrooz
const operators = [
{
op: '!',
precedence: 5,
associativity: 'left',
function: (a) => {
let acc = 1;
for (let i = 1; i < a + 1; i++) acc *= i;
return acc;
}
@thomasvrgn
thomasvrgn / index.js
Created February 19, 2021 11:14
Svelte auto git initier
const simpleGit = require('simple-git/promise');
const path = require('path');
const fs = require('fs/promises');
const git = new simpleGit();
const capitalize = (str) => str[0].toUpperCase() + str.slice(1);
function parseProjectName(str) {
const formatted = str
.toLowerCase()
.replace(/-/g, ' ');
@thomasvrgn
thomasvrgn / code.ts
Created October 21, 2020 14:56
Parsing and compiling AST.
const tokens: Tokens = [
{
token: Token.Word,
value: 'print'
},
{
token: Token.Bracket,
value: '('
},
{
@thomasvrgn
thomasvrgn / parser.ts
Created October 11, 2020 15:26
Python like parser written in Typescript
const code: string = `
if test = "brut":
print "yay"
if message = "Hello":
print "World"
else:
print "brush"
set "test"
else:
print "hobo"
@thomasvrgn
thomasvrgn / parser.js
Created September 27, 2020 12:42
Simple recursive bracket parser written in Javascript
const test = 'test{bruh{coucou}eheh{yollo{ebeaz}}}test';
const ast = {
type: 'Program',
body: [],
};
let string = '';
function parse(chars, index, ast) {