parsing - Ignoring whitespace (in certain parts) in Antlr4 -
parsing - Ignoring whitespace (in certain parts) in Antlr4 -
i not familiar antlr. using version 4 , have grammar whitespace not of import in parts (but might in others, or rather luck).
so have next grammar
grammar foo; programme : a* ; : id '@' id '(' idlist ')' ';' ; id : [a-za-z]+ ; idlist : id (',' idlist)* ; ws : [ \t\r\n]+ -> skip ;
and test input
foo@bar(x,y); foo@baz ( z,z) ;
the first line parsed correctly whereas sec 1 not. don't want polute rules places whitespace not relevant, since actual grammar more complicated toy example. in case it's not clear part id'@'id should not have whitespace. whitespace in other position shouldn't matter @ all.
define id '@' id
lexer token rather parser token.
a : aid '(' idlist ')' ';' ; aid : [a-za-z]+ '@' [a-za-z]+;
other options
enable/disable whitespaces in token stream, e.g. here enable/disable whitespaces lexer modes (may problem because lexer modes triggered on context, not easy determine in case) parsing antlr4 removing-whitespace
Comments
Post a Comment