Greetings,

Given a very simple grammar for a language that only has an 'if'
statement, I would like to be able to parse white space within literal
values. So far, this works (case 1):

if(value=='white space'){doThis('arg')}

But this doesn't work (case 2):

if (value == 'white space') { doThis('arg') }

Note that case 2 is spaced for readability.

Debugging case 2 in ANTLRWorks produces a MismatchedTokenException.

What is the best way to handle both cases? Here is the grammar:

grammar Lang;

statement
        :
                'if' LPAREN ID EQ literalValue RPAREN '{' action '}'
        ;

literalValue
        :
                '\'' ID '\''
        ;
        
action
        :
                ID LPAREN literalValue RPAREN
        ;
                
ID
        :
                ('a'..'z' | 'A'..'Z' | '0'..'9' | '@' | ':' | '_' | ' ' | '+')+
        ;

LPAREN
        :
                '('
        ;
        
RPAREN
        :
                ')'
        ;
        
EQ
        :
                '=='
        ;
        
WS
        :
                (' ' |'\t' |'\r' |'\n' )+ { $channel=HIDDEN; }
        ;

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