initial commit

This commit is contained in:
rus07tam 2025-12-25 13:16:15 +00:00
commit 0298a062dd
39 changed files with 2448 additions and 0 deletions

21
test/example.ts Normal file
View file

@ -0,0 +1,21 @@
import { readFileSync } from 'fs';
import { Parser, Tokenizer } from '@/compiler';
import * as grammars from '@/grammars';
const grammar = grammars.v1;
const tokenizer = new Tokenizer(grammar);
const parser = new Parser(tokenizer, grammar);
const source = readFileSync(__dirname + '/example.jn', 'utf-8');
const maxLength = Math.max(...source.split('\n').map((line) => line.length));
const padding = Math.floor((maxLength - ' Parsing: '.length) / 2);
try {
console.log('='.repeat(padding) + ' Parsing: ' + '='.repeat(padding));
console.log(source);
console.log('='.repeat(maxLength));
console.log(JSON.stringify(parser.parse(source), null, 2));
} catch (error) {
console.error(`Error parsing "${source}":`, error);
}