Skip to content

Commit 9b9e8e2

Browse files
committed
antlr4: Implement annotations
1 parent 8e594c7 commit 9b9e8e2

11 files changed

+804
-659
lines changed

src/main/antlr4/PiccodeScript.g4

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ symbol_lift
2828
symbol_entry
2929
: ID (symbol_lift)? ;
3030

31-
declaration: ID CC (module | func | import_module);
31+
declaration: (annotations)? ID CC (module | func | import_module);
3232

3333
module:
3434
MODULE LBRACE module_stmts RBRACE;
@@ -40,6 +40,8 @@ module_stmt:
4040
declaration
4141
| var_decl;
4242

43+
annotations: HASH LBRACKET ID (',' ID)* RBRACKET;
44+
4345
func: func_args ASSIGN expr ;
4446

4547
func_args: '(' arg_list? ')' ;
@@ -166,7 +168,7 @@ COMMA: ',';
166168
SEMI: ';';
167169
ARROW: '->';
168170
TILDE: '~';
169-
171+
HASH: '#';
170172

171173
ASSIGN: '=';
172174
DASSIGN: ':=';

src/main/java/org/piccode/antlr4/PiccodeScript.interp

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

src/main/java/org/piccode/antlr4/PiccodeScript.tokens

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,28 @@ COMMA=28
2929
SEMI=29
3030
ARROW=30
3131
TILDE=31
32-
ASSIGN=32
33-
DASSIGN=33
34-
WHEN=34
35-
IMPORT=35
36-
IS=36
37-
IF=37
38-
ELSE=38
39-
MODULE=39
40-
DO=40
41-
USE=41
42-
RETURN_TOK=42
43-
CATCH_TOK=43
44-
LET=44
45-
IN=45
46-
NUMBER=46
47-
STRING=47
48-
DOT=48
49-
LINE_COMMENT=49
50-
BLOCK_COMMENT=50
51-
ID=51
52-
WS=52
32+
HASH=32
33+
ASSIGN=33
34+
DASSIGN=34
35+
WHEN=35
36+
IMPORT=36
37+
IS=37
38+
IF=38
39+
ELSE=39
40+
MODULE=40
41+
DO=41
42+
USE=42
43+
RETURN_TOK=43
44+
CATCH_TOK=44
45+
LET=45
46+
IN=46
47+
NUMBER=47
48+
STRING=48
49+
DOT=49
50+
LINE_COMMENT=50
51+
BLOCK_COMMENT=51
52+
ID=52
53+
WS=53
5354
'+'=1
5455
'-'=2
5556
'*'=3
@@ -81,18 +82,19 @@ WS=52
8182
';'=29
8283
'->'=30
8384
'~'=31
84-
'='=32
85-
':='=33
86-
'when'=34
87-
'import'=35
88-
'is'=36
89-
'if'=37
90-
'else'=38
91-
'module'=39
92-
'do'=40
93-
'use'=41
94-
'return'=42
95-
'catch'=43
96-
'let'=44
97-
'in'=45
98-
'.'=48
85+
'#'=32
86+
'='=33
87+
':='=34
88+
'when'=35
89+
'import'=36
90+
'is'=37
91+
'if'=38
92+
'else'=39
93+
'module'=40
94+
'do'=41
95+
'use'=42
96+
'return'=43
97+
'catch'=44
98+
'let'=45
99+
'in'=46
100+
'.'=49

src/main/java/org/piccode/antlr4/PiccodeScriptBaseListener.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ public class PiccodeScriptBaseListener implements PiccodeScriptListener {
133133
* <p>The default implementation does nothing.</p>
134134
*/
135135
@Override public void exitModule_stmt(PiccodeScriptParser.Module_stmtContext ctx) { }
136+
/**
137+
* {@inheritDoc}
138+
*
139+
* <p>The default implementation does nothing.</p>
140+
*/
141+
@Override public void enterAnnotations(PiccodeScriptParser.AnnotationsContext ctx) { }
142+
/**
143+
* {@inheritDoc}
144+
*
145+
* <p>The default implementation does nothing.</p>
146+
*/
147+
@Override public void exitAnnotations(PiccodeScriptParser.AnnotationsContext ctx) { }
136148
/**
137149
* {@inheritDoc}
138150
*

src/main/java/org/piccode/antlr4/PiccodeScriptBaseVisitor.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ public class PiccodeScriptBaseVisitor<T> extends AbstractParseTreeVisitor<T> imp
8383
* {@link #visitChildren} on {@code ctx}.</p>
8484
*/
8585
@Override public T visitModule_stmt(PiccodeScriptParser.Module_stmtContext ctx) { return visitChildren(ctx); }
86+
/**
87+
* {@inheritDoc}
88+
*
89+
* <p>The default implementation returns the result of calling
90+
* {@link #visitChildren} on {@code ctx}.</p>
91+
*/
92+
@Override public T visitAnnotations(PiccodeScriptParser.AnnotationsContext ctx) { return visitChildren(ctx); }
8693
/**
8794
* {@inheritDoc}
8895
*

src/main/java/org/piccode/antlr4/PiccodeScriptLexer.interp

Lines changed: 4 additions & 1 deletion
Large diffs are not rendered by default.

src/main/java/org/piccode/antlr4/PiccodeScriptLexer.java

Lines changed: 136 additions & 135 deletions
Large diffs are not rendered by default.

src/main/java/org/piccode/antlr4/PiccodeScriptLexer.tokens

Lines changed: 38 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -29,27 +29,28 @@ COMMA=28
2929
SEMI=29
3030
ARROW=30
3131
TILDE=31
32-
ASSIGN=32
33-
DASSIGN=33
34-
WHEN=34
35-
IMPORT=35
36-
IS=36
37-
IF=37
38-
ELSE=38
39-
MODULE=39
40-
DO=40
41-
USE=41
42-
RETURN_TOK=42
43-
CATCH_TOK=43
44-
LET=44
45-
IN=45
46-
NUMBER=46
47-
STRING=47
48-
DOT=48
49-
LINE_COMMENT=49
50-
BLOCK_COMMENT=50
51-
ID=51
52-
WS=52
32+
HASH=32
33+
ASSIGN=33
34+
DASSIGN=34
35+
WHEN=35
36+
IMPORT=36
37+
IS=37
38+
IF=38
39+
ELSE=39
40+
MODULE=40
41+
DO=41
42+
USE=42
43+
RETURN_TOK=43
44+
CATCH_TOK=44
45+
LET=45
46+
IN=46
47+
NUMBER=47
48+
STRING=48
49+
DOT=49
50+
LINE_COMMENT=50
51+
BLOCK_COMMENT=51
52+
ID=52
53+
WS=53
5354
'+'=1
5455
'-'=2
5556
'*'=3
@@ -81,18 +82,19 @@ WS=52
8182
';'=29
8283
'->'=30
8384
'~'=31
84-
'='=32
85-
':='=33
86-
'when'=34
87-
'import'=35
88-
'is'=36
89-
'if'=37
90-
'else'=38
91-
'module'=39
92-
'do'=40
93-
'use'=41
94-
'return'=42
95-
'catch'=43
96-
'let'=44
97-
'in'=45
98-
'.'=48
85+
'#'=32
86+
'='=33
87+
':='=34
88+
'when'=35
89+
'import'=36
90+
'is'=37
91+
'if'=38
92+
'else'=39
93+
'module'=40
94+
'do'=41
95+
'use'=42
96+
'return'=43
97+
'catch'=44
98+
'let'=45
99+
'in'=46
100+
'.'=49

src/main/java/org/piccode/antlr4/PiccodeScriptListener.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,16 @@ public interface PiccodeScriptListener extends ParseTreeListener {
109109
* @param ctx the parse tree
110110
*/
111111
void exitModule_stmt(PiccodeScriptParser.Module_stmtContext ctx);
112+
/**
113+
* Enter a parse tree produced by {@link PiccodeScriptParser#annotations}.
114+
* @param ctx the parse tree
115+
*/
116+
void enterAnnotations(PiccodeScriptParser.AnnotationsContext ctx);
117+
/**
118+
* Exit a parse tree produced by {@link PiccodeScriptParser#annotations}.
119+
* @param ctx the parse tree
120+
*/
121+
void exitAnnotations(PiccodeScriptParser.AnnotationsContext ctx);
112122
/**
113123
* Enter a parse tree produced by {@link PiccodeScriptParser#func}.
114124
* @param ctx the parse tree

0 commit comments

Comments
 (0)