Hi All,

I hope I can get a little help on the grammar I have below.
It works to a degree but I'm having trouble with some edge cases and that is
stressing me a little.

When I write something like the following I get the right response - sequence 
of tokens.

Im putting '\n' where I would have new lines.

\n
+ foo\n
\n

What I can't seem to do is put in a rule that matches a line that doesn't start 
with '+' or '-'
I get a no viable Alt Exception with all that I try.


My goal is to be able to detect lines starting with a '+' or a '-' followed by 
a messagePattern.
And lines NOT starting with a '+' or a '-'.  The grammar below does not contain 
any rules
for this, because I can't get them to work.

Please help

Rgs, James.


grammar Preprocessor;

options {
  language = Java;
}

@header {
  package compiler;

}

@lexer::header {
  package compiler;
}

lines
  : (lineBreak | messagePattern)* EOF
  ;

messagePattern
  : ('+' | '-') (unarySelector | keywordSelector | binarySelector)

  ;

unarySelector
  : NAME
  ;

keywordSelector
  : (KEYWORD NAME)+
  ;
  
binarySelector
  : BINARY_SYMBOL NAME
  ;

lineBreak
  : LINE_BREAK  ;

LINE_BREAK: ('\r'? '\n' | '\r');

NAME: ('a'..'z' | 'A'..'Z')('a'..'z' | 'A'..'Z' | '0'..'9')*;
KEYWORD: NAME':';
BINARY_SYMBOL: 
('~'|'!'|'@'|'%'|'&'|'*'|'-'|'+'|'='|'\\'|'|'|'?'|'/'|'>'|'<'|',') 
('~'|'!'|'@'|'%'|'&'|'*'|'-'|'+'|'='|'\\'|'|'|'?'|'/'|'>'|'<'|',')*;

                                          

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