at15 / reika

[WIP] A DSL for query and benchmark TSDB
MIT License
1 stars 0 forks source link

[antlr] Grammar rule for record is wrong: extraneous input ' ' #16

Closed at15 closed 6 years ago

at15 commented 6 years ago
literal
    : BOOL # BoolLiteral
    | INT # IntLiteral
    | DOUBLE # DoubleLiteral
    | STRING # StringLiteral
    ;

// TODO: [0:123]
list
    : '[' literal (' ' literal)* ']'
    ;

term
    : literal # LiteralTerm
    | list # ListTerm
    // FIXME: the record rule is wrong
    | '{' ID ':' literal (',' ID ':' literal)* '}' # RecordTerm // TODO: allow record to have non-literal types? nested record etc.
    | '(' term ')' # BracketsTerm
    ;
java -cp ./third_party/antlr-4.7-complete.jar:./build/libs/reika-0.0.1-SNAPSHOT.jar org.antlr.v4.gui.TestRig me.at15.reika.parser.Reika prog -gui
{a: 123, b: 124};
line 1:3 extraneous input ' ' expecting {BOOL, INT, DOUBLE, STRING}
line 1:8 extraneous input ' ' expecting ID
line 1:11 extraneous input ' ' expecting {BOOL, INT, DOUBLE, STRING}
at15 commented 6 years ago

this is because I specify ' ' in list's rule .... https://stackoverflow.com/questions/44293377/how-to-fix-extraneous-input-expecting-in-antlr4, since we already have WS in token, we don't need to add that space in rule anymore

wrong

list
    : '[' literal (' ' literal)* ']'
    ;

correct

list
    : '[' literal* ']'
    ;