Я пишу ANTLR для создания синтаксиса моего запроса, поэтому сценарий должен быть правильным и передавать:
select * from Person
select name,age from Person
select _id,name,age from Person
select name,age,adress.age from Person
select name , age from Person
select name, age ,adress.age from Person
select name, age ,adress.age from Person order by name
select name, age ,adress.age from Person order by name asc
select name, age ,adress.age from Person order by name desc
select name, age ,adress.age from Person order by name asc age asc
select name, age ,adress.age from Person order by name desc age
select name, age ,adress.age from Person order by name desc age desc
select name, age ,adress.age from Person
select * from Person start 10
select name, age ,adress.age from Person start 20 order by name desc
age desc
select name, age ,adress.age from Person start 20 limit 10 order by
name desc age desc
select name, age ,adress.age from Person limit 10 order by name desc
age desc
И они должны возвращать синтаксическую ошибку:
* from Person
select *, name from Person
select name, *
select name,
select name from *
select * from Person order by
select * from Person order by asc
select * from Person order by asc age
select * from Person start
select name, age ,adress.age from Person order by name desc age desc
start 20
select name, age ,adress.age from Person limit qwe start 12 order by
name desc age desc
select name, age ,adress.age from Person start -20 limit 5 order by
name desc age desc
select name, age ,adress.age from Person limit order by name desc age
desc
Итак, я создаю свой Select.g4
grammar Select;
query : 'select' fields 'from' entity start? limit? order_clause?;
fields: star | name (',' name)*;
star: '*';
order_clause: 'order by' order_name (',' order_name)*;
order_name: name | name 'asc' | name 'desc';
start: 'start at' INT;
limit: 'limit' INT;
name: ANY_NAME;
entity: ANY_NAME;
INT: [0-9]+;
ANY_NAME: [a-zA-Z_.] [a-zA-Z._0-9]*;
WS : [ \t\r\n]+ -> skip ;
Все, что должно пройти, работает, однако есть три, которые должны вернуть ошибку, но это не так.
select * from Person start
select name, age ,adress.age from Person order by name desc age desc
start 20
select name, age ,adress.age from Person start -20 limit 5 order by
name desc age desc//cannot be a negative number