Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- grammar SqlCondition;
- options {
- output = AST;
- rewrite = true;
- language = CSharp2;
- backtrack = true;
- ASTLabelType=CommonTree;
- }
- start
- :( sql_condition EOF ) -> ^(sql_condition)
- ;
- sql_condition
- : condition_or
- ;
- condition_or
- : condition_or_part_first condition_or_part_next+
- | condition_or_part_first
- ;
- condition_or_part_first
- : condition_and
- ;
- condition_or_part_next
- : OR condition_and
- ;
- condition_and
- : condition_and_part_first condition_and_part_next+
- | condition_and_part_first
- ;
- condition_and_part_first
- : condition_not
- ;
- condition_and_part_next
- : AND condition_not
- ;
- condition_not
- : NOT condition_expr
- | condition_expr
- ;
- condition_expr
- : condition_is
- | condition_comparison
- | condition_like
- | condition_paren
- ;
- condition_is
- : sql_expression 'is' NOT? 'NULL'
- ;
- condition_comparison
- : sql_expression ( EQ | NOT_EQ | GT | GEQ | LT | LEQ ) sql_expression
- ;
- condition_like
- : sql_expression 'like' sql_expression
- ;
- condition_paren
- : LPAREN sql_condition RPAREN -> sql_condition
- ;
- sql_expression
- : expr_add
- ;
- expr_add
- : expr_mul ( ( PLUS | MINUS ) expr_mul )*
- ;
- expr_mul
- : expr_expr ( ( MUL | DIVIDE ) expr_expr )*
- ;
- expr_expr
- : expr_paren
- | simple_expression
- ;
- expr_paren
- : LPAREN sql_expression RPAREN -> sql_expression
- ;
- simple_expression
- : NUMBER | FIELD | FLOAT
- ;
- LPAREN
- :'('
- ;
- RPAREN
- : ')'
- ;
- PLUS
- : '+'
- ;
- MINUS
- : '-'
- ;
- MUL
- : '*'
- ;
- DIVIDE
- : '/'
- ;
- AND
- : ('a'|'A')('n'|'N')('d'|'D')
- ;
- OR
- : ('o'|'O')('r'|'R')
- ;
- NOT
- : ('N'|'n')('O'|'o')('T'|'t')
- ;
- EQ
- : '='
- ;
- NOT_EQ
- : '<>'
- ;
- LEQ
- : '<='
- ;
- GEQ
- : '>='
- ;
- LT
- : '<'
- ;
- GT
- :'>'
- ;
- LIKE
- : ('l'|'L')('i'|'I')('k'|'K')('e'|'E')
- ;
- NUMBER
- : (DIGIT)+
- ;
- FIELD
- : LETTER ( LETTER | DIGIT)*
- ;
- FLOAT
- : NUMBER '.' NUMBER
- ;
- STRING
- : '\'' ( LETTER | DIGIT )* '\''
- ;
- fragment DIGIT
- : '0'..'9';
- fragment LETTER
- : 'a'..'z' | 'A'..'Z'
- ;
- WS : ( ' '
- | '\t'
- | '\r'
- | '\n'
- | NEWLINE
- ) {$channel=HIDDEN;} ;
- fragment NEWLINE : '\r\n';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement