You have to expand your columns
rule to allow limit
:
columns
: VAL
| 'limit'
;
Question
I am using a limit token in my sql grammar. It works fine, but when I use the column name same as the token name I get into problem. I have a column name that is also the same name as of limit
. How do I solve this issue?
Output:
line 1:10 mismatched input 'limit' expecting VAL
line 1:10 mismatched input 'limit' expecting VAL
Input:
select a, limit from abc limit 55 ;
Grammar:
grammar SQLCmd;
parse : sql
;
sql : ('select' ((columns (',' columns)*)|count) 'from')
tables
('where' condition ((and|or) condition)*)* (limit)? ';'
;
num : NUM
;
count : 'count(*)'
;
columns : VAL
;
limit : 'limit' num
;
tables : VAL
;
condition : ( left '=' right )+
;
and : 'and'
;
or : 'or'
;
left : VAL
;
right : VAL
;
NUM : [0-9]+
;
VAL : [*a-z0-9A-Z~?]+
;
WS : [ \t\n\r]+ -> skip
;
Solution
You have to expand your columns
rule to allow limit
:
columns
: VAL
| 'limit'
;