Dave Jarvis' Repositories

git clone https://repo.autonoma.ca/repo/rxm.git

Parsable grammar for where clause.

AuthorDave Jarvis <email>
Date2015-03-15 16:00:46 GMT-0700
Commitccc8d285ef897b1b6f886b52bf0fb6117e802731
Parent9f60917
source/grammar/Query.g
T_NULL : 'null' ;
-/* Define the symbols. */
+/* Define skippable tokens. */
+T_WS: [ \t\r\n]+ -> skip ;
+
+/* Define digits and numbers. */
+T_DIGIT: [0-9] ;
+T_SIGN : '+' | '-' ;
+
+T_FLOAT : T_SIGN? (T_NUMBER | T_FRACTION) ;
+T_NUMBER : T_DIGIT | T_DIGIT T_NUMBER ;
+T_FRACTION: T_NUMBER? '.' T_NUMBER ;
+
+/* Define map symbols; exclude '>', which is defined as T_GT. */
T_POP : '^' ;
T_GLOB : '.*' ;
-T_MAP : '>' ;
T_INNER: '+>' ;
T_OUTER: '->' ;
T_EOL : ',' ;
T_WHERE: ';' ;
-/* Define the table and path symbols. */
+/* Define table and path symbols. */
T_AT : '@' ;
T_PERIOD: '.' ;
T_SLASH : '/' ;
-/* Define the identifier. */
+/* Define an identifier. */
T_ID: [A-Za-z0-9_]+ ;
-
-/* Define digits. */
-T_DIGIT: [0-9] ;
-
-/* Define skippable tokens. */
-T_WS: [ \t\r\n]+ -> skip ;
-/* Define the WHERE clause comparitor operator tokens. */
-T_COMP_EQ : '=' ;
-T_COMP_INEQ : '<>' ;
-T_COMP_LT : '<' ;
-T_COMP_GT : '>' ;
-T_COMP_LTE : '<=' ;
-T_COMP_GTE : '>=' ;
+/* Define WHERE clause comparitor operator tokens. */
+T_EQ : '=' ;
+T_INEQ : '<>' ;
+T_LT : '<' ;
+T_GT : '>' ;
+T_LTE : '<=' ;
+T_GTE : '>=' ;
/* Define the WHERE clause logical operator tokens. */
*/
start : (root | module) T_EOL ;
-root : T_ROOT T_MAP element ;
+root : T_ROOT T_GT element ;
module: T_MODULE T_ID ;
statement: (pop | glob | map | include) T_EOL ;
pop : T_POP ;
glob : T_GLOB ;
/* Map lines affect the tree depth differently.
*/
map : tableMap | columnMap | attributeMap | innerMap | outerMap ;
-tableMap : table T_MAP path ;
-columnMap : column T_MAP path ;
-attributeMap: column T_MAP attribute ;
+tableMap : table T_GT path ;
+columnMap : column T_GT path ;
+attributeMap: column T_GT attribute ;
innerMap : tableColumn T_INNER tableColumn ;
outerMap : tableColumn T_OUTER tableColumn ;
path : element | elementPath;
-/* Define the WHERE clause.
- */
+/* Define the WHERE clause. */
where : T_WHERE expression? ;
-exprParen : T_EXPR_OPEN expression T_EXPR_CLOSE ;
-expression : tableColumn exprRelational exprValue ;
+expression :
+ tableColumn exprRelational exprValueOrSet
+ | tableColumn exprEquality exprValueOrSet
+ | T_EXPR_OPEN expression T_EXPR_CLOSE
+ | expression (T_LOGIC_AND | T_LOGIC_OR) expression ;
-exprRelational: T_COMP_LT | T_COMP_GT | T_COMP_LTE | T_COMP_GTE ;
-exprEquality : T_COMP_EQ | T_COMP_INEQ ;
-exprLogicAnd : T_LOGIC_AND ;
-exprLogicOr : T_LOGIC_OR ;
-exprParameter : T_EXPR_PARAMETER T_ID ;
+exprRelational: T_LT | T_GT | T_LTE | T_GTE ;
+exprEquality : T_EQ | T_INEQ ;
-exprSet : T_EXPR_SET_OPEN exprValues T_EXPR_SET_CLOSE ;
-exprValues : exprValue (',' exprValue)* ;
+exprValueOrSet: exprValue | exprSet ;
exprValue : exprParameter | literal ;
+exprList : exprValue (',' exprValue)* ;
+exprSet : T_EXPR_SET_OPEN exprList T_EXPR_SET_CLOSE ;
-literal : literalString | literalNumber | literalNull ;
+exprParameter : T_EXPR_PARAMETER T_ID ;
+literal : literalNull | literalString | literalFloat ;
-literalString : '\'' (~'\'' | '\'\'')* '\'' ;
-literalNumber : (T_DIGIT)* ('.' T_DIGIT+)*;
literalNull : T_NULL ;
-
-/*
-WEq. Where : TableColumn ComparatorOperatorEquality AllValues ;
-WParen. Where : "(" Where ")" ;
-
-*/
+literalString : '\'' (~'\'' | '\'\'')* '\'' ;
+literalFloat : T_FLOAT ;
test/people.rxm
address > address,
street > street,
-;
test/where.rxm
+root > people,
+person > person,
+.id > @pk,
+;
+(person.id = $id) ||
+(person.id <> $id) ||
+(person.id = {$id, 12}) ||
+(person.id <> {$id, 42}) ||
+(person.id = null) ||
+(person.id <> null) ||
+(person.id = 'text') ||
+(person.id = -42.0) ||
+(person.id < 42) ||
+(person.id > 42) ||
+(person.id <= 42) ||
+(person.id >= 42)
+
Delta57 lines added, 42 lines removed, 15-line increase