completing grammar

This commit is contained in:
simon petit 2024-11-29 15:47:22 +00:00
parent a8efef907a
commit 34ccc51b79
3 changed files with 80 additions and 4 deletions

View File

@ -24,6 +24,9 @@ rule read_token = parse
| "ON" { ON }
| "WHERE" { WHERE }
| "HAVING" { HAVING }
| "BETWEEN" { BETWEEN }
| "IN" { IN }
| "LIKE" { LIKE }
| "GROUP" { GROUP }
| "BY" { BY }
| "*" { ASTERISK }
@ -32,6 +35,7 @@ rule read_token = parse
| "(" { LEFT_PAREN }
| ")" { RIGHT_PAREN }
| "," { COMMA }
| "|" { PIPE }
| whitespace { read_token lexbuf }
| alpha alphanumeric* as ident { IDENT ident }
| eof { EOF }

View File

@ -26,6 +26,7 @@ and predicate =
| NotBetween of string * string
| In of string list
| NotIn of string list
| Like of string
and operator =
| Equals
| NotEquals
@ -37,3 +38,44 @@ and filter =
| Filter of string
and search_condition =
| Search of string
let rec pp_query ast =
match ast with
| Query(s) -> pp_select s
and pp_select s =
match s with
| Select(cols, _) -> pp_columns cols
and pp_columns cols =
match cols with
| [] -> ""
| [col] -> pp_column col
| col::l -> pp_column col ^ ";" ^ pp_columns l
and pp_column col =
match col with
| Column(name) -> name
| Asterisk -> "*"
and pp_tables tables =
match tables with
| [] -> ""
| [table] -> pp_table table
| table::l -> pp_table table ^ ";" ^ pp_tables l
and pp_table table =
match table with
| Table(table) -> table
| Join(t1, j, t2, _) -> pp_table t1 ^ pp_join_type j ^ pp_table t2
and pp_join_type j =
match j with
| Inner -> "inner"
| Left -> "left"
| Right -> "right"
| Full -> "full"
| Cross -> "cross"
| Union -> "union"
| Natural -> "natural"

View File

@ -4,14 +4,14 @@ open Ast
%}
%token CREATE TABLE
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN IN
%token SELECT ALL DISTINCT FROM WHERE HAVING BETWEEN IN LIKE
%token LEFT RIGHT FULL INNER OUTER
%token CROSS NATURAL UNION JOIN
%token CROSS NATURAL UNION JOIN
%token GREATER_THAN_OPERATOR LESS_THAN_OPERATOR EQUALS_OPERATOR
%token MAX MIN SUM COUNT AVG
%token ASYMMETRIC SYMMETRIC
%token <string> IDENT
%token COMMA DOT
%token COMMA DOT PIPE
%token LEFT_PAREN RIGHT_PAREN
%token ASTERISK
%token AS ON GROUP BY FILTER
@ -165,7 +165,7 @@ predicate :
| comparison_predicate { $1 }
| between_predicate { $1 }
| in_predicate { $1 }
| like_predicate { $1 }
(* | like_predicate { $1 } *)
comparison_predicate :
| row_value_predicand comparison_predicate_part2 { Condition($1, $2) }
@ -199,6 +199,36 @@ in_value_list:
| row_value_expression { [$1] }
| in_value_list COMMA row_value_expression { $3::$1 }
like_predicate :
| character_like_predicate { $1 }
character_like_predicate :
| row_value_predicand character_like_predicate_part2 { }
character_like_predicate_part2:
| LIKE character_pattern {}
| NOT LIKE character_pattern {}
character_pattern :
| character_value_expression {}
character_value_expression:
| concatenation {}
| character_factor {}
concatenation:
| character_value_expression concatenation_operator character_factor {}
character_factor :
| character_primary {}
character_primary:
| value_expression_primary {}
(* | string_value_function {} *)
concatenation_operator:
| PIPE PIPE {}
row_value_expression :
| row_value_special_case { $1 }