[antlr-interest] Value passed to String based rule parameter has spaces inserted after commas.

Sam Ellis sam.ellis at arm.com
Fri Jul 20 12:15:02 PDT 2007


I've using ANTLR Version 3.0 (May 17, 2007). I have found that quoted
strings passed to String-based rules in my grammar are having extra spaces
inserted into the string when it appears in the generated parser code.
Specifically, if the string in my grammar contains a comma, then a space is
inserted after the comma in the resulting code. Here is an example:

grammar Fruit;

options {
    language=Java;
}

fruit[String allowedFruit]
    :    NAME { System.out.println(allowedFruit);}
    ;

bowl
    : fruit["apple,orange"]
    ;

NAME    :    ('a' .. 'z')+
    ;

The code that is generated contains:

            // /Users/samellis/Fruit.g:12:7: ( fruit[\"apple,orange\"] )
            // /Users/samellis/Fruit.g:12:7: fruit[\"apple,orange\"]
...
            fruit("apple, orange");

So you can see that a space has appeared in the generated code (not in the
comments though). Bug in ANTLR perhaps?


-- 
Sam Ellis, RVDK Team Leader,
DevSys Product Engineering Group,          Tel: +44 (0) 1223 400516
ARM Ltd., 110 Fulbourn Road,               Fax: +44 (0) 1223 400887
Cambridge, CB1 9NJ                         mailto:Sam.Ellis at arm.com



-- 
IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium.  Thank you.




More information about the antlr-interest mailing list