From: "Kevin J. Cummings" <[email protected]>
> On 09/23/2010 09:50 AM, Daniel Lidström wrote:
>> How do I "capture" the dash and colon? Here's my grammar:
>
> If the "-" and ":" are a part of your format string, then they are not a
> part of your input, are they?  I would think that outputting them would
> be a function of how you handle your format string (which you included
> above).  It looks like you are outputting just the "variable" part of
> your format string and not the "constant" part....
>
> When you parse your format string, you will need to save the constant
> parts verbatim.
>
> Perhaps you can use the "dot notation" (of the lexer) to save anything
> that isn't one of your tokens listed below, and output them verbatim.
> So, you need another token type to catch "anything else".

Thanks for the suggestion. I have taken a step back and my grammar now looks 
like this:

program
        : statement*
        ;

statement
        : TEXT
        | variable
        ;

variable
        : '[' LETTERS ']'
        ;

fragment LETTER : 'a'..'z' | 'A'..'Z' ;
LETTERS : LETTER+ ;
TEXT : ~('[' | ']')+ ;


Using Antlr IDE within Eclipse I can see that this parses something like 
"set status [yyyy]-[M]-[d] [H]:[m]"
correctly (all [...] are treated like variables, the rest are statements). 
My TEXT lexer seems to be working fine. If I try to use the dot, I get an 
error:

TEXT : .+ ;

error(201): /TemplateCommand/src/com/gpsgate/TemplateCommand.g:31:8: The 
following alternatives can never be matched: 1
 |---> TEXT : .+ ;

Is there a way to use dot or should I just be fine with the TEXT lexer as 
is?

Daniel 


List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to