[antlr-interest] Newline not recognized

Cory Isaacson cory.isaacson at compuflex.com
Mon Jan 14 10:55:36 PST 2008


Thanks, this was very helpful, I found out what I was doing wrong.

 

One follow on question:

 

My message format is name/value pairs like this:

 

\nLabel1=value

\nLabel2=value

 

However, the value can contain an entire SQL statement, which can of course
have single, double quotes, etc. What is a good way to recognize the value,
but not so broadly that the lexer token tries to recognize the whole
message?

 

Thanks,

 

Cory

 

From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Thomas Brandon
Sent: Monday, January 14, 2008 12:20 AM
To: antlr-interest at antlr.org
Subject: Re: [antlr-interest] Newline not recognized

 

Can't tell exactly what's going on without seeing the full grammar.
Do you have a lexer rule that matches newlines? Tokens and literals are not
interchangeable. i.e. given:
literalNL: '\n';
NL: '\n'; 
literalNL won't work as all newlines will have been matched by the NL rule
while the literal '\n' will generate a new lexer rule with a different token
type.

Tom.

On 1/14/08, Cory Isaacson <cory.isaacson at compuflex.com> wrote:

I have a rule like this:

 

r : MYSTARTTOKEN '\n' NEXTTOKEN ;

 

When I parse it doesn't see the '\n' char.

 

If I put the '\n' into to Lexer rule like this:

 

NEXTTOKEN : '\n' 'xyz' ;

 

It works fine, but this won't meet my needs as I need to get the text of
NEXTTOKEN (without the newline).

 

Any idea what is wrong in what I'm doing?

 

Cory

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.antlr.org/pipermail/antlr-interest/attachments/20080114/adc5c63d/attachment.html 


More information about the antlr-interest mailing list