17 lines
328 B
TypeScript
17 lines
328 B
TypeScript
import { Parser, Grammar } from "nearley"
|
|
import compiledGrammar from "./grammar.out"
|
|
|
|
const parser = new Parser(Grammar.fromCompiled(compiledGrammar));
|
|
|
|
const input = "1 + 2";
|
|
|
|
if (input === null)
|
|
throw new Error("input fucked")
|
|
|
|
parser.feed(input);
|
|
|
|
const ast = parser.results;
|
|
|
|
console.log(JSON.stringify(ast, null, 4))
|
|
|