-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ulysses Souza <[email protected]>
- Loading branch information
1 parent
ef5d373
commit 794dd48
Showing
24 changed files
with
800 additions
and
1,315 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,43 @@ | ||
grammar EnvLangFile; | ||
|
||
envFile: NL* (entry NL*)+ ; | ||
envFile | ||
: CRLF* (entry CRLF*)+ | ||
; | ||
|
||
entry : identifier (ASSIGN value | ASSIGN)? (NL* | EOF) ; | ||
entry | ||
: identifier (ASSIGN value | ASSIGN)? (SPACE* CRLF* | EOF) | ||
; | ||
|
||
identifier : TEXT; | ||
identifier | ||
: TEXT | ||
; | ||
|
||
value : op=(DQSTRING | SQSTRING | TEXT) ; | ||
value | ||
: str=(DQSTRING | SQSTRING | TEXT) | ||
; | ||
|
||
ASSIGN : '='; | ||
NL : '\r'? '\n'; | ||
TEXT : ~[=,\r\n"' ]~[=,\r\n"']* ; | ||
DQSTRING : '"' ('""'|~'"')* '"' ; | ||
SQSTRING : '\'' ('\'\''|~'\'')* '\'' ; | ||
ASSIGN | ||
: '=' | ||
; | ||
|
||
SPACE : ' ' -> skip; | ||
CRLF | ||
: '\r'? '\n' | ||
| '\r' | ||
; | ||
|
||
TEXT | ||
: ~[=,\r\n"' ]~[=,\r\n"']* | ||
; | ||
DQSTRING | ||
: '"' ('""' | ~'"')* '"' | ||
; | ||
SQSTRING | ||
: '\'' ('\'\'' | ~'\'')* '\'' | ||
; | ||
SPACE | ||
: | ||
' ' -> skip | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,58 @@ | ||
grammar EnvLangValue; | ||
|
||
dqstring : content* (CRLF* | EOF) ; | ||
dqstring | ||
: content* (SPACE* | CRLF* | EOF) | ||
; | ||
|
||
strictVar : '${' TEXT_NO_SPACE+ '}'; | ||
simpleVar : '$' TEXT_NO_SPACE+ ; | ||
variable | ||
: var=(STRICT_VAR | SIMPLE_VAR) | ||
; | ||
|
||
variable : strictVar | simpleVar ; | ||
content | ||
: variable | ||
| STR | ||
| SPACE | ||
| CRLF | ||
; | ||
|
||
TEXT_NO_SPACE : [a-zA-Z0-9_] ; | ||
TEXT_ANY : [a-zA-Z0-9_\n] ; | ||
STRICT_VAR | ||
: '${' SPACE* VAR_ID SPACE* '}' | ||
; | ||
|
||
text : TEXT_NO_SPACE TEXT_ANY* ; | ||
SIMPLE_VAR | ||
: '$' VAR_ID | ||
; | ||
|
||
space : ' '; | ||
STR | ||
: FIRST_CHAR REST_OF_STRING* | ||
; | ||
|
||
dQEscape : '""' ; | ||
SPACE | ||
: ' ' | ||
| '\t' | ||
; | ||
|
||
special | ||
: '{' | ||
| '}' | ||
| '$' | ||
; | ||
CRLF | ||
: '\r'? '\n' | ||
| '\r' | ||
; | ||
|
||
content | ||
: dQEscape | ||
| variable | ||
| space | ||
| special | ||
| text | ||
; | ||
fragment FIRST_CHAR | ||
: ~[,\\."'\r\n ] | ||
; | ||
fragment REST_OF_STRING | ||
: ~[\\'"$\r\n ] | ||
; | ||
|
||
fragment VAR_ID | ||
: [0-9]+ // Only numbers | ||
| [a-zA-Z_][a-zA-Z_0-9]* // Start with letters, then letters, numbers and underscores | ||
; | ||
|
||
// Catch all rule. | ||
// This is used to avoid the error message "no viable alternative at input '<EOF>'". Just for debugging. | ||
ANY | ||
: . | ||
; | ||
|
||
CRLF | ||
: '\r'? '\n' | ||
| '\r' | ||
; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,14 +2,19 @@ all: clean gen test | |
@echo "All done!" | ||
|
||
test: | ||
@gotestsum --format testname ./... | ||
@gotestsum --format testname -- -failfast ./... | ||
|
||
gen: | ||
@antlr -Dlanguage=Go -o gen/fileparser -package fileparser EnvLangFile.g4 | ||
@antlr -Dlanguage=Go -o gen/valueparser -package valueparser EnvLangValue.g4 | ||
@antlr4 -Dlanguage=Go -o gen/fileparser -package fileparser EnvLangFile.g4 | ||
@antlr4 -Dlanguage=Go -o gen/valueparser -package valueparser EnvLangValue.g4 | ||
|
||
clean: | ||
@rm -rf gen | ||
|
||
setup: | ||
go install gotest.tools/[email protected] | ||
|
||
grun: | ||
antlr4 EnvLangValue.g4 | ||
javac -cp "/usr/share/java/antlr-4.13.1-complete.jar:$CLASSPATH" EnvLangValue*.java | ||
java -Xmx500M -cp "/usr/share/java/antlr-4.13.1-complete.jar:$CLASSPATH" org.antlr.v4.gui.TestRig EnvLangValue dqstrings -tokens |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.