[antlr-interest] Lines that don't match a rule ...
James Ladd
james_ladd at hotmail.com
Thu Jul 7 15:44:32 PDT 2011
Hi Jim and Others ...
The suggested grammar (which I have modified slightly) below works in most
cases except when I parse the following:
\n
+ add: value\n
^ self + value\n
\n
What I was hoping for is that line three (3) '^ self + value\n' is a seen as a line not starting with '+' | '-'
and consumed entirely - But I get a No Viable Alternative Exception.
Please can some one help ?
Rgs, James.
lines
: (line LINE_BREAK)* EOF
;
line
: ('+' | '-') (unarySelector | keywordSelector | binarySelector)
| { while (input.LA(1) != LINE_BREAK && input.LA(1) != EOF) input.consume(); }
;
unarySelector
: NAME
;
keywordSelector
: (KEYWORD NAME)+
;
binarySelector
: (BINARY_SYMBOL| '-' | '+') NAME
;
LINE_BREAK: ('\r'? '\n' | '\r');
NAME: ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9')*;
KEYWORD: NAME ':';
BINARY_SYMBOL: ('~'|'!'|'@'|'%'|'&'|'*'|'-'|'+'|'='|'\\'|'|'|'?'|'/'|'>'|'<'|',') ('~'|'!'|'@'|'%'|'&'|'*'|'-'|'+'|'='|'\\'|'|'|'?'|'/'|'>'|'<'|',')*;
>
> Message: 7
> Date: Wed, 6 Jul 2011 16:30:52 -0700
> From: Jim Idle <jimi at temporal-wave.com>
> Subject: Re: [antlr-interest] Lines that don't match a rule ...
> To: antlr-interest at antlr.org
> Message-ID: <6556c9d271c906dfb308bb73f0e8e262 at mail.gmail.com>
> Content-Type: text/plain; charset=UTF-8
>
> Try:
>
> lines
> : (messagePattern LINE_BREAK)* EOF
> ;
>
> messagePattern
> : ('+' | '-') (unarySelector | keywordSelector | binarySelector)
> | { while (input.LA(1) != LINE_BREAK && input.LA(1) != EOF)
> input.consume(); }
> ;
>
> This will just eat the lines that don't
>
>
More information about the antlr-interest
mailing list