This is only a Deno-compatible version of nearley
In order to compile your .ne
files, you'll have to install the nearley
npm package, and follow instructions as if you were running node.
npm install nearley -D
nearleyc my-grammar.ne -o my-compiled-grammar.ts
β You grammar MUST compile to Typescript. To do so, include @preprocessor typescript
on top of it.
nb: If you use Moo as a lexer, do it like that:
@{%
import * as moo from "https://deno.land/x/moo@0.5.1-deno.2/mod.ts";
// unfortunately, there will be a typescript error if you dont cast it to any :(
let lexer: any = moo.compile({
// you lexer
})
%}
@lexer lexer
import { Parser, Grammar } from "https://deno.land/x/nearley@2.19.7-deno/mod.ts";
import myCompiledGrammar from './my-compiled-grammar.ts';
const grammar = Grammar.fromCompiled(myCompiledGrammar);
const parser = new Parser(grammar);
// use it as you would with node
parser.feed('some valid text');