Advertisement
Guest User

Untitled

a guest
Jun 23rd, 2017
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. grammar SqlCondition;
  2.  
  3.  
  4. options {
  5.  
  6. output = AST;
  7. rewrite = true;
  8. language = CSharp2;
  9. backtrack = true;
  10. ASTLabelType=CommonTree;
  11.  
  12. }
  13.  
  14. start
  15. :( sql_condition EOF ) -> ^(sql_condition)
  16. ;
  17.  
  18. sql_condition
  19. : condition_or
  20. ;
  21.  
  22. condition_or
  23. : condition_or_part_first condition_or_part_next+
  24. | condition_or_part_first
  25. ;
  26.  
  27. condition_or_part_first
  28. : condition_and
  29. ;
  30.  
  31. condition_or_part_next
  32. : OR condition_and
  33. ;
  34.  
  35. condition_and
  36. : condition_and_part_first condition_and_part_next+
  37. | condition_and_part_first
  38. ;
  39.  
  40. condition_and_part_first
  41. : condition_not
  42. ;
  43.  
  44. condition_and_part_next
  45. : AND condition_not
  46. ;
  47.  
  48. condition_not
  49. : NOT condition_expr
  50. | condition_expr
  51. ;
  52.  
  53. condition_expr
  54. : condition_is
  55. | condition_comparison
  56. | condition_like
  57. | condition_paren
  58. ;
  59.  
  60. condition_is
  61. : sql_expression 'is' NOT? 'NULL'
  62.  
  63. ;
  64.  
  65. condition_comparison
  66. : sql_expression ( EQ | NOT_EQ | GT | GEQ | LT | LEQ ) sql_expression
  67. ;
  68.  
  69.  
  70. condition_like
  71. : sql_expression 'like' sql_expression
  72. ;
  73.  
  74. condition_paren
  75. : LPAREN sql_condition RPAREN -> sql_condition
  76. ;
  77.  
  78.  
  79. sql_expression
  80. : expr_add
  81. ;
  82.  
  83.  
  84. expr_add
  85. : expr_mul ( ( PLUS | MINUS ) expr_mul )*
  86. ;
  87.  
  88. expr_mul
  89. : expr_expr ( ( MUL | DIVIDE ) expr_expr )*
  90. ;
  91.  
  92. expr_expr
  93. : expr_paren
  94. | simple_expression
  95. ;
  96.  
  97. expr_paren
  98. : LPAREN sql_expression RPAREN -> sql_expression
  99. ;
  100.  
  101.  
  102. simple_expression
  103. : NUMBER | FIELD | FLOAT
  104. ;
  105.  
  106.  
  107. LPAREN
  108. :'('
  109. ;
  110. RPAREN
  111. : ')'
  112. ;
  113.  
  114. PLUS
  115. : '+'
  116. ;
  117. MINUS
  118. : '-'
  119. ;
  120. MUL
  121. : '*'
  122. ;
  123. DIVIDE
  124. : '/'
  125. ;
  126.  
  127. AND
  128. : ('a'|'A')('n'|'N')('d'|'D')
  129. ;
  130.  
  131. OR
  132. : ('o'|'O')('r'|'R')
  133. ;
  134.  
  135. NOT
  136. : ('N'|'n')('O'|'o')('T'|'t')
  137. ;
  138.  
  139. EQ
  140. : '='
  141. ;
  142.  
  143. NOT_EQ
  144. : '<>'
  145. ;
  146.  
  147. LEQ
  148. : '<='
  149. ;
  150.  
  151. GEQ
  152. : '>='
  153. ;
  154. LT
  155. : '<'
  156. ;
  157.  
  158. GT
  159. :'>'
  160. ;
  161.  
  162. LIKE
  163. : ('l'|'L')('i'|'I')('k'|'K')('e'|'E')
  164. ;
  165.  
  166. NUMBER
  167. : (DIGIT)+
  168. ;
  169.  
  170. FIELD
  171. : LETTER ( LETTER | DIGIT)*
  172. ;
  173.  
  174. FLOAT
  175. : NUMBER '.' NUMBER
  176. ;
  177.  
  178. STRING
  179. : '\'' ( LETTER | DIGIT )* '\''
  180. ;
  181.  
  182. fragment DIGIT
  183. : '0'..'9';
  184.  
  185. fragment LETTER
  186. : 'a'..'z' | 'A'..'Z'
  187. ;
  188.  
  189.  
  190. WS : ( ' '
  191. | '\t'
  192. | '\r'
  193. | '\n'
  194. | NEWLINE
  195. ) {$channel=HIDDEN;} ;
  196.  
  197. fragment NEWLINE : '\r\n';
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement