UNPKG

@stordata/grammars

Version:

A collection of ANTLR grammars used at Stordata. This project exists so that we can package the grammars (and various utilities) as a CommonJS module. The `antlr4` Javascript runtime is only available as an ES module at the time of writing.

19 lines (14 loc) 501 B
import { CommonTokenStream, InputStream } from 'antlr4'; import ThrowingErrorListener from './ThrowingErrorListener.js'; export default function parse(input, Lexer, Parser) { const parser = new Parser( new CommonTokenStream( new Lexer( new InputStream(input) ) ) ); parser.removeErrorListeners(); // There's a default one parser.addErrorListener(new ThrowingErrorListener()); // Will throw on first error return parser.all(); // The "all" rule gotta exist! }