Skip to content

Upgrade ANTLR4 to 4.13.0 #470

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 14 additions & 4 deletions ANTLR.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# ANTLR

*grule-rule-engine* is heavily using ANTLR4 lexer/parser to parse GRL rule. The parser
*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 latest version can be downloaded [here (antlr-4.9.2-complete.jar)](https://www.antlr.org/download/antlr-4.9.2-complete.jar)
Or you can always go to [ANTLR4 download page](https://www.antlr.org/download.html)
The version currently used can be downloaded [here (antlr-4.13.0-complete.jar)](https://github.com/antlr/website-antlr4/blob/gh-pages/download/antlr-4.13.0-complete.jar).
Or you can always go to [ANTLR4 download page](https://www.antlr.org/download.html).

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

Expand All @@ -16,7 +16,7 @@ Install java and you're ready to work with ANTLR4.
## Making ANTLR alias.

```bash
alias antlr='java -jar /path/to/downloaded/antlr-4.9.2-complete.jar'
alias antlr='java -jar /path/to/downloaded/antlr-4.13.0-complete.jar'
```

## Executing ANTLR
Expand All @@ -28,3 +28,13 @@ 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:
```bash
make ANTLR="java -jar /path/to/downloaded/antlr-4.13.0-complete.jar"
```

4 changes: 2 additions & 2 deletions antlr/GruleParserV3Listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import (
"strconv"
"strings"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr4-go/antlr/v4"
"github.com/hyperjumptech/grule-rule-engine/antlr/parser/grulev3"
"github.com/hyperjumptech/grule-rule-engine/ast"
"github.com/hyperjumptech/grule-rule-engine/logger"
Expand All @@ -35,7 +35,7 @@ var (
"struct": "GruleParserV3Listener",
}

// LoggerV3 is a logger instance twith default fields for grule
// LoggerV3 is a logger instance with default fields for grule
LoggerV3 = logger.Log.WithFields(loggerV3Fields)
)

Expand Down
2 changes: 1 addition & 1 deletion antlr/GruleParserV3_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
"reflect"
"testing"

"github.com/antlr/antlr4/runtime/Go/antlr"
"github.com/antlr4-go/antlr/v4"
parser "github.com/hyperjumptech/grule-rule-engine/antlr/parser/grulev3"
"github.com/hyperjumptech/grule-rule-engine/ast"
"github.com/hyperjumptech/grule-rule-engine/pkg"
Expand Down
30 changes: 30 additions & 0 deletions antlr/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# GNU Make >= 4.3

## Configuration (See ../ANTLR.md)

OUTPUT_DIR = parser/grulev3

ANTLR = antlr4
ANTLRFLAGS = -Dlanguage=Go -o '${OUTPUT_DIR}' -package '$(notdir ${OUTPUT_DIR})'

GRAMMAR = grulev3.g4

## Rules

PREFIX = ${OUTPUT_DIR}/$(basename ${GRAMMAR})
tokens = $(addsuffix .interp,$(1)) $(addsuffix .tokens,$(1))

TOKENS = $(call tokens,${PREFIX}Lexer) $(call tokens,${PREFIX})
LEXER = ${PREFIX}_lexer.go
PARSER = ${PREFIX}_parser.go ${PREFIX}_listener.go ${PREFIX}_base_listener.go ${PREFIX}_visitor.go ${PREFIX}_base_visitor.go

.PHONY: clean all
.DELETE_ON_ERROR:

all: ${TOKENS} ${LEXER} ${PARSER}

${TOKENS} ${LEXER} ${PARSER} &: ${GRAMMAR}
$(ANTLR) ${ANTLRFLAGS} -visitor $^

clean:
rm -f ${TOKENS} ${LEXER} ${PARSER}
Empty file modified antlr/parser/grulev3/grulev3.interp
100755 → 100644
Empty file.
160 changes: 80 additions & 80 deletions antlr/parser/grulev3/grulev3.tokens
100755 → 100644
Original file line number Diff line number Diff line change
@@ -1,80 +1,80 @@
T__0=1
PLUS=2
MINUS=3
DIV=4
MUL=5
MOD=6
DOT=7
SEMICOLON=8
LR_BRACE=9
RR_BRACE=10
LR_BRACKET=11
RR_BRACKET=12
LS_BRACKET=13
RS_BRACKET=14
RULE=15
WHEN=16
THEN=17
AND=18
OR=19
TRUE=20
FALSE=21
NIL_LITERAL=22
NEGATION=23
SALIENCE=24
EQUALS=25
ASSIGN=26
PLUS_ASIGN=27
MINUS_ASIGN=28
DIV_ASIGN=29
MUL_ASIGN=30
GT=31
LT=32
GTE=33
LTE=34
NOTEQUALS=35
BITAND=36
BITOR=37
SIMPLENAME=38
DQUOTA_STRING=39
SQUOTA_STRING=40
DECIMAL_FLOAT_LIT=41
DECIMAL_EXPONENT=42
HEX_FLOAT_LIT=43
HEX_EXPONENT=44
DEC_LIT=45
HEX_LIT=46
OCT_LIT=47
SPACE=48
COMMENT=49
LINE_COMMENT=50
','=1
'+'=2
'-'=3
'/'=4
'*'=5
'%'=6
'.'=7
';'=8
'{'=9
'}'=10
'('=11
')'=12
'['=13
']'=14
'&&'=18
'||'=19
'!'=23
'=='=25
'='=26
'+='=27
'-='=28
'/='=29
'*='=30
'>'=31
'<'=32
'>='=33
'<='=34
'!='=35
'&'=36
'|'=37
T__0=1
PLUS=2
MINUS=3
DIV=4
MUL=5
MOD=6
DOT=7
SEMICOLON=8
LR_BRACE=9
RR_BRACE=10
LR_BRACKET=11
RR_BRACKET=12
LS_BRACKET=13
RS_BRACKET=14
RULE=15
WHEN=16
THEN=17
AND=18
OR=19
TRUE=20
FALSE=21
NIL_LITERAL=22
NEGATION=23
SALIENCE=24
EQUALS=25
ASSIGN=26
PLUS_ASIGN=27
MINUS_ASIGN=28
DIV_ASIGN=29
MUL_ASIGN=30
GT=31
LT=32
GTE=33
LTE=34
NOTEQUALS=35
BITAND=36
BITOR=37
SIMPLENAME=38
DQUOTA_STRING=39
SQUOTA_STRING=40
DECIMAL_FLOAT_LIT=41
DECIMAL_EXPONENT=42
HEX_FLOAT_LIT=43
HEX_EXPONENT=44
DEC_LIT=45
HEX_LIT=46
OCT_LIT=47
SPACE=48
COMMENT=49
LINE_COMMENT=50
','=1
'+'=2
'-'=3
'/'=4
'*'=5
'%'=6
'.'=7
';'=8
'{'=9
'}'=10
'('=11
')'=12
'['=13
']'=14
'&&'=18
'||'=19
'!'=23
'=='=25
'='=26
'+='=27
'-='=28
'/='=29
'*='=30
'>'=31
'<'=32
'>='=33
'<='=34
'!='=35
'&'=36
'|'=37
Empty file modified antlr/parser/grulev3/grulev3Lexer.interp
100755 → 100644
Empty file.
Loading