gulp-antlr4
Gulp plugin running ANTLR 4
Background
First you should get familiar with ANTLR4 and how to write grammars. This plugin won't save you from getting fluent with that powerhouse of a tool.
But once you've done that, you will be able to make excitingly complex transforms of your files.
ANTLR4 comes with a Javascript runtime, but the documentation on the web is almost exclusively in a JAVA context. This Gulp plugin aims at eliminating all frictions in the Javascript context between your grammars and your intents.
The normal Gulp way is to source your data files and get downstream your translations or your interpretations. Just point the plugin to your custom translator or your custom visitor and it will do the rest.
But the plugin can also recognize your grammar files and generate for you the base parser/lexer files from which you will derive your translator/visitor. You need for that Java installed and the ANTLR4 Jar installed. The plugin will refuse to work if your environment is not properly set up, since if you can't generate anew from your updated grammars, you can't develop any ANTLR4 application anyway.
Usage
Generating a listener parser
Convenience usage, but not the Gulp way. See Using a listener parser for the Gulp way.
;; gulp; // Streams down the unchanged grammars
Generating a visitor parser
Convenience usage, but not the Gulp way. See Using a visitor parser for the Gulp way.
;; gulp;
Using a listener parser
;; gulp;
Using a visitor parser
;; gulp;
Real life Gulpfile example
;; const grammarGlob = 'src/static/antlr4/grammars/**/*.g4';const parserDir = 'src/static/antlr4/parsers';const dataGlob = 'src/static/data/**/*.*';const grammar = 'Calc';const rule = 'prog';const listener = 'Translator';const listenerDir = 'build/src/static/antlr4/custom';const visitor = 'Interpreter';const visitorDir = 'build/src/static/antlr4/custom';const outputDir = 'src/static/results'; const makeParser = { if require && requirecache // Remove parser files from require cache Object; return gulp ;}; const translate = { return gulp ;}; gulp; const calculate = { return gulp ;}; gulp;
License
gulp-antlr4 is MIT licensed.
© 2017-2019 Jason Lenoble