Torok Balint
Torok Balint

Reputation: 125

How to access hidden tokens from semantic predicates in antlr 4

In ANTLR 4 is there a way to access tokens on the hidden channel (or some other channels) in semantic predicates of the parser? I would like to send the \r\n to hidden channel since mostly I don't need the EOL characters. But in some cases in a semantic predicate I would need to see if there is an EOL after the given token.

Upvotes: 1

Views: 616

Answers (2)

Some Guy
Some Guy

Reputation: 544

Yes, this can be done. Look at this question and this question for some examples. The first one of these seems to directly address your question about handling EOL "some of the time".

Upvotes: 0

Mike Lischke
Mike Lischke

Reputation: 53407

Tbh. I have no experience with ANLTR 4 but in ANTLR 3 you can use the token source to get all tokens, regardless of the channel. Something similar is certainly possible in version 4 too. I use this feature to restore the original input for AST subtrees (i.e. from token stream start index to end index).

Upvotes: 1

Related Questions