Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify SOQL grammar #300

Merged
merged 9 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
131 changes: 66 additions & 65 deletions jopa-impl/src/main/antlr4/cz/cvut/kbss/jopa/query/soql/Soql.g4
Original file line number Diff line number Diff line change
@@ -1,48 +1,30 @@
grammar Soql;

start: querySentence EOF ;

querySentence : selectStatement whereClauseWrapper? groupByClause? orderByClause? ;
querySentence: selectStatement ;

selectStatement: typeDef params FROM tables ;
selectStatement: selectClause fromClause whereClause? groupByClause? orderByClause? ;

typeDef: SELECT ;
singleValuedObjectPathExpression: simpleSubpath DOT singleValuedObjectField ;

params: paramComma* distinctParam ;
simpleSubpath: singleValuedObjectField (DOT simpleSubpath)* ;

paramComma: distinctParam ',' ;
singleValuedObjectField: IDENTIFICATION_VARIABLE ;

distinctParam: distinct? selectedParam ;
selectClause: SELECT (DISTINCT)? selectItem (',' selectItem)* ;

selectedParam: param | count;
selectItem: selectExpression;

count: COUNT '(' param ')' ;
selectExpression: simpleSubpath | aggregateExpression ;

param: objWithAttr | objWithOutAttr ;
aggregateExpression: COUNT '(' (DISTINCT)? simpleSubpath ')';

objWithAttr: object DOT attribute;
fromClause: FROM entityName IDENTIFICATION_VARIABLE;

objWithOutAttr: object ;
entityName: IDENTIFICATION_VARIABLE ;

distinct: DISTINCT ;

object: IDENTIFICATION_VARIABLE ;

attribute: IDENTIFICATION_VARIABLE ;

joinedParams: object DOT attribute (DOT attribute)+ ;



tables: tableWithName ;

table: IDENTIFICATION_VARIABLE ;

tableName: IDENTIFICATION_VARIABLE ;

tableWithName: table tableName ;


whereClauseWrapper
whereClause
: WHERE conditionalExpression
;

Expand All @@ -66,38 +48,44 @@ simpleConditionalExpression
;

inExpression
: whereClauseParam (NOT)? IN '('? (inItem (',' inItem)*) ')'?
: simpleSubpath (NOT)? IN '('? (inItem (',' inItem)*) ')'?
;

inItem
: literal
| whereClauseValue
| inputParameter
;

literal
:
: STRING_LITERAL
| INT_LITERAL
| FLOAT_LITERAL
| BOOLEAN_LITERAL
| IDENTIFICATION_VARIABLE
;

likeExpression
: stringExpression (NOT)? LIKE whereClauseValue
: stringExpression (NOT)? LIKE stringExpression
;

memberOfExpression
: inItem (NOT)? MEMBEROF whereClauseParam
: inItem (NOT)? MEMBER OF simpleSubpath
;

entityExpression
: IDENTIFICATION_VARIABLE
| inputParameter
;

comparisonExpression
: stringExpression COMPARISON_OPERATOR stringExpression
| simpleArithmeticExpression COMPARISON_OPERATOR simpleArithmeticExpression
| whereClauseParam COMPARISON_OPERATOR ( whereClauseParam | whereClauseValue )
: stringExpression comparisonOperator stringExpression
| simpleArithmeticExpression comparisonOperator simpleArithmeticExpression
| entityExpression op=(EQUAL | NOT_EQUAL) ( entityExpression )
;

whereClauseValue: (QMARK TEXT QMARK) | inputParameter ;

whereClauseParam: param | joinedParams ;

stringExpression
: whereClauseParam
: simpleSubpath
| STRING_LITERAL
| inputParameter
| functionsReturningStrings
;
Expand All @@ -107,7 +95,7 @@ functionsReturningStrings
| 'SUBSTRING' '(' stringExpression ',' simpleArithmeticExpression ',' simpleArithmeticExpression ')'
| 'LOWER' '(' stringExpression ')'
| 'UPPER' '(' stringExpression ')'
| 'LANG' '(' whereClauseParam ')'
| 'LANG' '(' simpleSubpath ')'
;

simpleArithmeticExpression
Expand All @@ -123,7 +111,7 @@ arithmeticFactor
;

arithmeticPrimary
: param
: simpleSubpath
| literal
| '(' simpleArithmeticExpression ')'
| inputParameter
Expand All @@ -138,22 +126,24 @@ functionsReturningNumerics
| 'FLOOR' '(' simpleArithmeticExpression ')'
;

orderByClause: ORDERBY orderByFullFormComma orderByFullFormComma* ;

orderByFullFormComma: orderByFullForm ','? ;

orderByFullForm: orderByParam ORDERING? ;

orderByParam: object DOT attribute (DOT attribute)* ;
orderByClause: ORDER BY orderByItem (',' orderByItem)* ;

groupByClause: GROUPBY groupByParamComma groupByParamComma* ;
orderByItem: singleValuedObjectPathExpression (ASC | DESC) ;

groupByParamComma: groupByParam ','? ;
groupByClause: GROUP BY groupByItem (',' groupByItem)* ;

groupByParam: object DOT attribute (DOT attribute)* ;
groupByItem: singleValuedObjectPathExpression ;

inputParameter: COLON IDENTIFICATION_VARIABLE ;

comparisonOperator
: op=EQUAL
| op='>'
| op='>='
| op='<'
| op='<='
| op=NOT_EQUAL
;

SELECT: 'SELECT' ;

Expand All @@ -169,11 +159,13 @@ AND: 'AND' ;

OR: 'OR' ;

ORDERBY: 'ORDER BY' ;
BY: 'BY' ;

OF: 'OF' ;

ORDERING: ASC | DESC ;
ORDER: 'ORDER' ;

GROUPBY: 'GROUP BY' ;
GROUP: 'GROUP' ;

ASC: 'ASC' ;

Expand All @@ -187,18 +179,31 @@ LIKE: 'LIKE' ;

IN: 'IN' ;

MEMBEROF: 'MEMBER OF' ;
MEMBER: 'MEMBER' ;

COMPARISON_OPERATOR: '>' | '<' | '>=' | '<=' | '=' | '<>' | '!=' ;
EQUAL: '=' ;
NOT_EQUAL: '<>' | '!=' ;

DOT: '.' ;

QMARK: '"' ;

COLON: ':' ;

TRUE: 'TRUE';

FALSE: 'FALSE';

IDENTIFICATION_VARIABLE: (LOWERCASE | UPPERCASE | '_') (LOWERCASE | UPPERCASE | DIGIT | '_')* ;

STRING_LITERAL: QMARK TEXT QMARK ;

INT_LITERAL: DIGIT+;

FLOAT_LITERAL: DIGIT* '.' DIGIT;

BOOLEAN_LITERAL: TRUE | FALSE;

TEXT: (LOWERCASE | UPPERCASE | DIGIT)+ ;

UPPERCASE: ('A'..'Z');
Expand All @@ -207,8 +212,4 @@ LOWERCASE: ('a'..'z');

DIGIT: ('0'..'9');

NUMBER: DIGIT+ ;

VALUE: NUMBER ;

WHITESPACE: (' ')+ -> skip;
Loading
Loading