adding expression_primary type + new tokens
This commit is contained in:
parent
58b13cdd52
commit
323b17e4a9
55
lib/ast.ml
55
lib/ast.ml
@ -2,13 +2,16 @@ type query =
|
|||||||
(*| Select of column list * table list option * filter option*)
|
(*| Select of column list * table list option * filter option*)
|
||||||
| Select of column list * table_expression
|
| Select of column list * table_expression
|
||||||
| CreateSchema of string
|
| CreateSchema of string
|
||||||
| CreateTable of table
|
| CreateTable of table_scope option * table
|
||||||
| DropSchema of string
|
| DropSchema of string
|
||||||
| DropTable of table
|
| DropTable of table
|
||||||
|
| DropColumn of string
|
||||||
|
and table_scope =
|
||||||
|
| Global
|
||||||
|
| Local
|
||||||
and column =
|
and column =
|
||||||
| Asterisk
|
| Asterisk
|
||||||
(* | Column of string *)
|
| Column of expression_primary * as_clause option
|
||||||
| Column of expression * as_clause option
|
|
||||||
and as_clause =
|
and as_clause =
|
||||||
| As of string
|
| As of string
|
||||||
and table_expression =
|
and table_expression =
|
||||||
@ -25,19 +28,18 @@ and join_type =
|
|||||||
| Union
|
| Union
|
||||||
| Natural
|
| Natural
|
||||||
and condition =
|
and condition =
|
||||||
| Condition of predicand * predicate
|
| Condition of expression_primary * predicate
|
||||||
| And of condition * condition
|
| And of condition * condition
|
||||||
| Or of condition * condition
|
| Or of condition * condition
|
||||||
| Not of condition
|
| Not of condition
|
||||||
and predicand = expression
|
|
||||||
and predicate =
|
and predicate =
|
||||||
| Comparison of operator * predicand
|
| Comparison of operator * expression_primary
|
||||||
| Between of predicand * predicand
|
| Between of expression_primary * expression_primary
|
||||||
| NotBetween of predicand * predicand
|
| NotBetween of expression_primary * expression_primary
|
||||||
| In of predicand list
|
| In of expression_primary list
|
||||||
| NotIn of predicand list
|
| NotIn of expression_primary list
|
||||||
| Like of predicand
|
| Like of expression_primary
|
||||||
| NotLike of predicand
|
| NotLike of expression_primary
|
||||||
and operator =
|
and operator =
|
||||||
| Equals
|
| Equals
|
||||||
| NotEquals
|
| NotEquals
|
||||||
@ -47,11 +49,11 @@ and operator =
|
|||||||
| GreaterEquals
|
| GreaterEquals
|
||||||
and filter = condition
|
and filter = condition
|
||||||
and group =
|
and group =
|
||||||
| Group of quantifier option * expression list option
|
| Group of quantifier option * expression_primary list option
|
||||||
and aggregate =
|
and aggregate =
|
||||||
| Aggregate of func * filter option
|
| Aggregate of func * filter option
|
||||||
and func =
|
and func =
|
||||||
| Function of function_type * quantifier option * expression
|
| Function of function_type * quantifier option * expression_primary
|
||||||
and function_type =
|
and function_type =
|
||||||
| Avg
|
| Avg
|
||||||
| Max
|
| Max
|
||||||
@ -61,11 +63,22 @@ and function_type =
|
|||||||
and quantifier =
|
and quantifier =
|
||||||
| All
|
| All
|
||||||
| Distinct
|
| Distinct
|
||||||
and expression =
|
and expression_primary =
|
||||||
| Ref of string
|
| Ref of string
|
||||||
| StringLiteral of string
|
| StringLiteral of string
|
||||||
| DateLiteral of string
|
| DateLiteral of string
|
||||||
| TimeLiteral of string
|
| TimeLiteral of string
|
||||||
|
| TimestampLiteral of string
|
||||||
|
| Concatenation of expression_primary * expression_primary
|
||||||
|
| Numeric of expression_primary * sign * expression_primary
|
||||||
|
| Signed of sign * expression_primary
|
||||||
|
| Substring of expression_primary * expression_primary
|
||||||
|
and sign =
|
||||||
|
| Plus
|
||||||
|
| Minus
|
||||||
|
| Times
|
||||||
|
| Divide
|
||||||
|
|
||||||
|
|
||||||
let rec pp_query fmt ast =
|
let rec pp_query fmt ast =
|
||||||
match ast with
|
match ast with
|
||||||
@ -86,9 +99,11 @@ and pp_column col =
|
|||||||
and pp_expression exp =
|
and pp_expression exp =
|
||||||
match exp with
|
match exp with
|
||||||
| Ref(name) -> name
|
| Ref(name) -> name
|
||||||
| StringLiteral(name) -> "'"^name^"'"
|
| StringLiteral(s) -> "'" ^ s ^ "'"
|
||||||
| DateLiteral(name) -> "'"^name^"'"
|
| DateLiteral(d) -> "'" ^ d ^ "'"
|
||||||
| TimeLiteral(name) -> "'"^name^"'"
|
| TimeLiteral(t) -> "'" ^ t ^ "'"
|
||||||
|
| TimestampLiteral(ts) -> "'" ^ ts ^ "'"
|
||||||
|
| _ -> "Expression not yet supported"
|
||||||
|
|
||||||
and pp_table_expression table_exp =
|
and pp_table_expression table_exp =
|
||||||
match table_exp with
|
match table_exp with
|
||||||
@ -137,8 +152,8 @@ and pp_predicate pred =
|
|||||||
| Comparison(op, exp) -> pp_operator op ^ pp_expression exp
|
| Comparison(op, exp) -> pp_operator op ^ pp_expression exp
|
||||||
| Between(exp1, exp2) -> "BETWEEN " ^ pp_expression exp1 ^ " AND " ^pp_expression exp2
|
| Between(exp1, exp2) -> "BETWEEN " ^ pp_expression exp1 ^ " AND " ^pp_expression exp2
|
||||||
| NotBetween(exp1, exp2) -> "NOT BETWEEN " ^ pp_expression exp1 ^ " AND " ^pp_expression exp2
|
| NotBetween(exp1, exp2) -> "NOT BETWEEN " ^ pp_expression exp1 ^ " AND " ^pp_expression exp2
|
||||||
| Like(exp) -> "LIKE " ^ pp_expression exp
|
(*| Like(exp) -> "LIKE " ^ pp_expression exp
|
||||||
| NotLike(exp) -> " NOT LIKE " ^ pp_expression exp
|
| NotLike(exp) -> " NOT LIKE " ^ pp_expression exp*)
|
||||||
| _ -> failwith "Predicate not supported"
|
| _ -> failwith "Predicate not supported"
|
||||||
|
|
||||||
and pp_operator op =
|
and pp_operator op =
|
||||||
|
Loading…
Reference in New Issue
Block a user