[antlr-interest] Is it possible to capture the input of a wildcard for tree construction inside a block of multiple occurrences?

Jim Idle jimi at temporal-wave.com
Wed Dec 19 08:38:51 PST 2007


This sounds more like something you should do in the lexer to be honest 
(assuming it does not cause a context issue). The use of '.' in a parser 
is a bit tricky as it just matches any token of course and in the 
construct you have will match to EOF I think.

Also note that you cannot use both '!' and AST rewrites. If you are 
using rewrites, then just don't mention the APOSTROPHE tokens ;-).

You would have more surety by creating a parser rule that contains all 
the tokens other than APOSTROPHE. Then you could do:

rule:
	APOSTROPHE
		(stuff += notanapostrophe)*
	APOSTROPHE

	-> ^(APOSTROPHE $stuff*)
;

Jim

> -----Original Message-----
> From: Ralf Cremerius [mailto:ralf_c at web.de]
> Sent: Wednesday, December 19, 2007 6:10 AM
> To: antlr-interest at antlr.org
> Subject: [antlr-interest] Is it possible to capture the input of a
> wildcard for tree construction inside a block of multiple occurrences?
> 
> Hi,
> 
> I just have a question about some detail in ANTLR v3:
> 
> I'm writing a parser grammar generating an AST. In one specific rule, 
I
> need to use the wildcard (.) inside some block of multiple 
occurrences,
> but I also need the matched input to construct a tree from it. Can 
this be
> done somehow? I tried to use a label but this didn't work.
> 
> rule:	     (
> 	       APOSTROPHE!
> 	       (options {greedy=false;} : .  )*
> 	       APOSTROPHE!
> 	       )+
> 	       -> ^( ----?---- );
> 
> Or am I just asking for too much and this is conceptually forbidden?
> 
> Thanks in advance for reading,
>   Ralf Cremerius
> 
________________________________________________________________________
_
> In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und 
gestalten!
> Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114
> 




More information about the antlr-interest mailing list