Skip to content

How to disable skip whitespace within a rule individually #4420

Closed Answered by kaby76
oovm asked this question in Q&A
Discussion options

You must be logged in to vote

The parser cannot influence the lexer!

Newlines should remain on the hidden channel. Introduce a parser rule not_nl to force the parser to not allow certain alternatives for expressions, then add references to not_nl just before '++' operators. Note, since semantic predicates must be at the beginning of the alt, you have to introduce the not_nl rule rather than insert the semantic predicate directly in expr to satisfy the constraint that Antlr requires. The assumption here is that you cannot have an infix or postfix '++' operator that crosses to the next line.

grammar g;

@parser::members {
bool Check()
{
	var ct = this.InputStream as CommonTokenStream;
	var lb1 = ct.LT(-1);
	var la1 = ct…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by oovm
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants