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

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -