How to disallow nested comments in antlr -


i have multiline comment lexer rule in antlr looks like:

multiline: '/*' .* '*/' {$channel=hidden;} ; 

however, allows things like:

/* /* hello */ */ 

is there possible way disable nesting comments in antlr? i've tried various things like

multiline: '/*' (~(multiline)|.*) '*/' {$channel=hidden;} ; 

but doesn't work. appreciated!

no, not correct: .* , .+ not greedy.

given parser generated following grammar:

grammar t;  parse  : (t=. {system.out.printf("\%-15s'\%s'\n", tokennames[$t.type], $t.text);} )* eof  ;  multiline  : '/*' .* '*/' {$channel=hidden;}  ;  other  : .  ; 

the input "/* /* hello */ */" produce following on command line:

other          ' ' other          '*' other          '/'

i.e., "/* /* hello */" being put on hidden channel, , 3 other tokens constructed.


Comments

Popular posts from this blog

node.js - Bad Request - node js ajax post -

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -