[antlr-interest] Occasionally match hidden channel
Jim Idle
jimi at temporal-wave.com
Thu Dec 18 10:40:41 PST 2008
On Thu, 2008-12-18 at 18:04 +0000, Zenzike wrote:
> I'm trying to make it so that input only occasionally matches tokens
> that are sent to the hidden channel.
> My grammar has something along the following:
>
> SLASHSLASH : '\\\\' {$channel=HIDDEN}; // For the symbols "\\"
>
> This is regarded as whitespace in the language I'm trying to define,
> and should be able to
> appear between any two tokens. However, occasionally, I want to make
> sure that there is definitely
> a SLASHSLASH token between two other tokens.
>
> As far as I can tell, the way to do this is to hide the SLASHSLASH
> (which I have done),
> and in places where it is needed, I should query the hidden channel --
> but I can't find
> any documentation about how this done (although there seems to be
> plenty saying that it is possible!)
>
> Something like this would be ideal:
>
> rule : TOKEN1 {channel.hidden.match(SLASHSLASH)} TOKEN2 ;
>
> What is the right syntax?
This will do it:
((TokenStream)input ).get( input.index()-1 ).sometokenmethodsuchasgetType() == SLASHSLASH
Jim
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20081218/1fa8081d/attachment.html
More information about the antlr-interest
mailing list