Replies: 2 comments
-
After losing half a day rewriting the grammar from scratch, I found some workarounds to make this dumb tool recognize the rules as I wanted. Here's the updated parser: // Document metadata
dependencies:
('.deps {' | '.dependencies {') STRING (COMMA STRING)* RBRACE;
imports:
'.imports {' STRING (COMMA STRING)* RBRACE;
// Entry Point
document:
dependencies?
imports?
root = node
EOF;
node:
IDENTIFIER (DOT IDENTIFIER)* constructor?
LBRACE
factory? (methodsChain | property | node)*
RBRACE;
constructor:
COLON COLON LPAREN args RPAREN;
factory:
('.factory:' | '.builder:') methodsChain;
property:
IDENTIFIER (COLON | EQUALS | PLUSEQUALS) type;
field:
(THIS | IDENTIFIER) (DOT IDENTIFIER)+;
method:
IDENTIFIER LPAREN args RPAREN;
methodsChain:
(THIS | (IDENTIFIER (DOT IDENTIFIER)*)) (DOT method)+;
array:
IDENTIFIER (DOT IDENTIFIER)* LBRACK args RBRACK;
collection:
ctype = ('listOf {' | 'mapOf {' | 'setOf {')
args
RBRACE;
keywords:
THIS | NULL;
type:
node
| keywords
| field
| methodsChain
| array
| collection
| BOOLEAN
| CHAR
| STRING
| INTEGER
| HEXADECIMAL
| BINARY
| OCTAL
| FLOAT
| DOUBLE
| NAN
| INFINITY;
args:
(type COMMA?)*;
|
Beta Was this translation helpful? Give feedback.
0 replies
-
UP |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm writing a little custom DSL for executing Java code with reflection and deserialize a tree structure. I'm planning on using this to build UIs from files.
I desperately need help improving it, ANTLR is very hard, and I had to make some compromises to make it work.
Here's my grammar:
Issues:
@
rather than.
because otherwise I would get the error 'no viable alternative at input' for doing something like this:This is the most confusing issue
2) I had to distinguish static fields from static methods by using either
->
or::
for fieldVal. I don't get this, either. Methods are expected to have parentheses, which distinguishes them from fields3) Both for methodsChain and fieldVal that are part of the current node/object (not static) I must specify the
this
keyword. It would be great to have it implicitBeta Was this translation helpful? Give feedback.
All reactions