[antlr-interest] Question about preserving spaces in quoted strings

John B. Brodie jbb at acm.org
Thu Jul 2 08:54:21 PDT 2009


Greetings!

On Thu, 2009-07-02 at 10:35 -0400, Penningroth, Mark wrote:
> I have the following in my grammar:
>
> sqcon
>             : '\'' ( options {greedy=false;} : .)* '\''
> ;
>
> The intent is to get a single text node with everything between the
> sing quotes.
>
> When I parse ‘Los Angeles’  I lose the space .

your sqcon rule is a Parser rule (because it begins with a lower case
letter).

have you tried making it a Lexer rule? by up-casing (at least) the first
letter.

and note that when you make it into a Lexer rule, the text of the token
will include the leading and trailing quotes, so you may need to
substring them away.

Hope this helps
   -jbb




More information about the antlr-interest mailing list