I'm quite new to ANTLR and looking at other examples, I used the following lexer rule to skip whitespaces:
WHITESPACE: [ \t\r\n]-> skip;
This is my complete grammar file:
grammar CoreQueries;
// Parser Rules
orExpression : andExpression (orOp andExpression)*;
andExpression : notExpression (andOp notExpression)*;
notExpression : (notOp)? atom ;
atom : coreQuery | lp orExpression rp;
coreQuery : noLabels | noDueDate | overdue | nDays | priority | all | toMe | toOthers | project | label | user ;
orOp: '|';
andOp: '&';
notOp: '!';
lp: LP;
rp: RP;
noLabels : NO_LABELS;
noDueDate: NO_DUE_DATE;
overdue : OVERDUE;
nDays : N_DAYS;
priority : PRIORITY;
all : ALL;
toMe : TO_ME;
toOthers : TO_OTHERS;
project : PROJECT;
label : LABEL;
user : USER;
stringOrDate : STRING_OR_DATE;
// Lexer Rules
// Tokens
LP : '(';
RP : ')';
NO_LABELS : NO LABELS;
NO_DUE_DATE : NO DUE DATE;
OVERDUE : O V E R D U E;
N_DAYS : ANY_INTEGER_EXCEPT_ZERO DAYS;
PRIORITY : PRIORITY_QUERY_TITLE ONE_TO_FOUR;
ALL : A L L;
TO_ME : TO ME;
TO_OTHERS : TO OTHERS ;
PROJECT: PROJECT_QUERY_TITLE COLON ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS | PROJECT_QUERY_TITLE COLON ANY_INTEGER | HASH ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS | HASH ANY_INTEGER;
LABEL : AT ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS;
USER : U COLON ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS ;
STRING_OR_DATE: Q COLON ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS | ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS;
WHITESPACE: [ \t\r\n]-> skip;
//Fragments
fragment A : ('a'|'A');
fragment B : ('b'|'B');
fragment C : ('c'|'C');
fragment D : ('d'|'D');
fragment E : ('e'|'E');
fragment F : ('f'|'F');
fragment G : ('g'|'G');
fragment H : ('h'|'H');
fragment I : ('i'|'I');
fragment J : ('j'|'J');
fragment K : ('k'|'K');
fragment L : ('l'|'L');
fragment M : ('m'|'M');
fragment N : ('n'|'N');
fragment O : ('o'|'O');
fragment P : ('p'|'P');
fragment Q : ('q'|'Q');
fragment R : ('r'|'R');
fragment S : ('s'|'S');
fragment T : ('t'|'T');
fragment U : ('u'|'U');
fragment V : ('v'|'V');
fragment W : ('w'|'W');
fragment X : ('x'|'X');
fragment Y : ('y'|'Y');
fragment Z : ('z'|'Z');
fragment COLON : ':';
fragment HASH : '#';
fragment AT : '@';
fragment PROJECT_QUERY_TITLE : P R O J E C T | P;
fragment PRIORITY_QUERY_TITLE: P R I O R I T Y | P;
fragment ONE_TO_FOUR : [1-4];
fragment NO : N O;
fragment LABELS : L A B E L S;
fragment DUE : D U E;
fragment DATE : D A T E;
fragment DAYS : D A Y S;
fragment TO : T O;
fragment ME : M E;
fragment OTHERS : O T H E R S;
fragment ANY_INTEGER :('0'|'1'..'9''0'..'9'*);
fragment ANY_INTEGER_EXCEPT_ZERO :('1'..'9''0'..'9'*);
fragment ANY_TEXT_EXCEPT_OPERATORS_AND_PARENS: ~[<>#=&|!()]*;
I can't quite figure out why whitespaces are not being ignored here.
for example: nolabels
is recognised correctly but no labels
is not.
What am I doing wrong?
--
You received this message because you are subscribed to the Google Groups "antlr-discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to antlr-discussi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.