BNF Parser
Migrating from v3.0
If you are looking for the documentation for the older version of the api go here
Overwise if you are attempting to migrate from 3.0
->4.0
we recommend reading this migration guide
Built to not be a dependency
If you use the included cli tool to generate your syntax parser you don't need to include this library as your dependency, you can just import those artifacts.
Compile your bnfs down to WebAssembly for maximum parsing speed; with generated type definitions to make using the syntax tree outputs a breeze. The compiled output from this library is platform agnostic, so it can run anywhere new WebAssembly.Instance()
is a valid function. It bundles the WebAssembly module inside of a single js file so it can be easily incorporated into any bundler. The type definitions for a given bnf are just that, a definitions file - so if you don't want to use typescript or type hints you can go wild by ignoring it.
program ::= chunk+ ;
chunk ::= "a"+ "b"+ ;
import * as syntax from "./bnf/example.js";
const tree /*(1)!*/ = syntax.Parse_Program("abbaabab").root;
const chunk /*(2)!*/ = program.value[0];
const firstBs = program.value[1];
const bCount: number = firstBs.value.length; // (3)!
- Inferred type
Term_Program
- Inferred type
Term_Chunk
- No Errors Here! Typescript knows this will be a
number
thanks to the type definitions generated bybnf-parser
for the bnf
Try it in your browser here