Skip to content

Latest commit

 

History

History
40 lines (27 loc) · 1.38 KB

ANTLR.md

File metadata and controls

40 lines (27 loc) · 1.38 KB

ANTLR

grule-rule-engine is heavily using ANTLR4 lexer/parser to parse GRL rules. The parser .go files were generated by ANTLR4 tools program.

Download ANTLR4 tools

The version currently used can be downloaded here (antlr-4.13.1-complete.jar). Or you can always go to ANTLR4 download page.

Download the .jar file and place it somewhere a directory.

Yes, you need Java for this. You can download java from Oracle's Java Download Page. Install java and you're ready to work with ANTLR4.

Making ANTLR alias.

alias antlr='java -jar /path/to/downloaded/antlr-4.13.1-complete.jar'

Executing ANTLR

To build ANTLR4's golang listener or visitor, go to the directory where you have your antlr4 grammar .g4 file. And then execute the following command.

antlr -Dlanguage=Go -o parser -package grulev3 -lib . -listener -visitor grulev3.g4

With GNU Make installed, it is also possible to use the Makefile in the antlr directory.

The command make clean can be used to remove the generated content of the antlr/parser/grulev3 directory. Then, it is possible to generate the parser code with:

make ANTLR="java -jar /path/to/downloaded/antlr-4.13.1-complete.jar"