initial commit
This commit is contained in:
commit
0298a062dd
39 changed files with 2448 additions and 0 deletions
5
test/example.jn
Normal file
5
test/example.jn
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
const name: str = 'bob';
|
||||
const bob = new Person(name);
|
||||
print(bob.name);
|
||||
}
|
||||
21
test/example.ts
Normal file
21
test/example.ts
Normal 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);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue