adding predicates in search condition

This commit is contained in:
simon petit 2024-11-28 16:51:00 +00:00
parent d32580b143
commit a8efef907a
2 changed files with 33 additions and 7 deletions

View File

@ -23,6 +23,9 @@ and condition =
and predicate =
| Comparison of operator * string
| Between of string * string
| NotBetween of string * string
| In of string list
| NotIn of string list
and operator =
| Equals
| NotEquals

View File

@ -3,7 +3,8 @@
open Ast
%}
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN
%token CREATE TABLE
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN IN
%token LEFT RIGHT FULL INNER OUTER
%token CROSS NATURAL UNION JOIN
%token GREATER_THAN_OPERATOR LESS_THAN_OPERATOR EQUALS_OPERATOR
@ -22,9 +23,9 @@ open Ast
%%
main:
| select_stmt EOF { Query($1) }
| query_specification EOF { Query($1) }
select_stmt :
query_specification :
| SELECT select_list table_expression { Select($2, $3) }
| SELECT set_quantifier select_list table_expression { Select($3, $4) }
@ -162,7 +163,9 @@ boolean_primary :
predicate :
| comparison_predicate { $1 }
(* | between_predicate { $1 }*)
| between_predicate { $1 }
| in_predicate { $1 }
| like_predicate { $1 }
comparison_predicate :
| row_value_predicand comparison_predicate_part2 { Condition($1, $2) }
@ -171,17 +174,34 @@ comparison_predicate_part2:
| comp_op row_value_predicand { Comparison($1, $2) }
between_predicate :
| row_value_predicand between_predicate_part2 { }
| row_value_predicand between_predicate_part2 { Condition($1, $2) }
between_predicate_part2 :
| BETWEEN between_symetry row_value_predicand AND row_value_predicand {}
| NOT BETWEEN between_symetry row_value_predicand AND row_value_predicand {}
| BETWEEN between_symetry row_value_predicand AND row_value_predicand { Between($3, $5) }
| NOT BETWEEN between_symetry row_value_predicand AND row_value_predicand {NotBetween($4, $6) }
between_symetry :
| {}
| ASYMMETRIC {}
| SYMMETRIC {}
in_predicate :
| row_value_predicand in_predicate_part2 { Condition($1, $2) }
in_predicate_part2:
| IN in_predicate_value { In($2) }
| NOT IN in_predicate_value { NotIn($3) }
in_predicate_value:
| LEFT_PAREN in_value_list RIGHT_PAREN { $2 }
in_value_list:
| row_value_expression { [$1] }
| in_value_list COMMA row_value_expression { $3::$1 }
row_value_expression :
| row_value_special_case { $1 }
comp_op :
| EQUALS_OPERATOR { Equals }
| not_equals_operator { NotEquals }
@ -265,3 +285,6 @@ ordinary_grouping_set :
grouping_column_reference:
| column_reference {}
(*| column_reference collate_clause {}*)
table_definition :
| CREATE TABLE table_name {}