antlr4-webpack-loader
Loads an ANTLR4 grammar file (.g4
) and compiles it to JavaScript.
;
Configuration
Add the ANTLR4 JavaScript runtime as a dependency: npm install --save antlr4
.
Configure webpack.config.js
by adding antlr4-webpack-loader
:
moduleexports = module: rules: test: /\.g4/ loader: 'antlr4-webpack-loader' ;
Usage
A grammar file named MyGrammar.g4
with a rule named myStartRule
can be loaded in used in the following way:
;; { ... } ... const input = ...; // Load string contentconst lexer = input;const parser = lexer;const result = ;