Posted By:
Nathan_Jokel
Posted On:
Tuesday, July 6, 2004 10:51 AM
I'm having trouble getting antlr to skip whitespace where I want it to. I've defined the following rules in my Lexer: WHITESPACE : ( ' ' | ' ' | 'f' | NEWLINE )+ { $setType(Token.SKIP); } ; protected NEWLINE : ( options { generateAmbigWarnings=false; } : " " // Macintosh style | " " // MS-DOS style | " " // UNIX style ) { newline(); } ; protected LEGAL_CHAR
More>>
I'm having trouble getting antlr to skip whitespace where I want it to.
I've defined the following rules in my Lexer:
WHITESPACE
: ( ' '
| ' '
| 'f'
| NEWLINE
)+
{ $setType(Token.SKIP); }
;
protected
NEWLINE
: ( options { generateAmbigWarnings=false; }
: "
" // Macintosh style
| "
" // MS-DOS style
| "
" // UNIX style
) { newline(); }
;
protected
LEGAL_CHAR
: (~( '{' | '}' | ',' | '[' | ']' | ' ' | ' ' | 'f' | '
' | '
'));
LABEL_STRING
: '[' (LEGAL_CHAR)+ ( ',' (LEGAL_CHAR)+)* ']';
When I define LABEL_STRING in this fashion, I have trouble with Strings that include whitespace between the first '[' and the first block of LEGAL_CHARs, such as "[ a]".
If I redefine the rule as such:
LABEL_STRING
: '[' (WHITESPACE)? (LEGAL_CHAR)+ ( ',' (LEGAL_CHAR)+)* (WHITESPACE)? ']';
This circumvents the problem, but why do I need to include the additional
(WHITESPACE)?
?
Thanks,
-Nathan
<<Less