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_expression
|
||||
| CreateSchema of string
|
||||
| CreateTable of table
|
||||
| CreateTable of table_scope option * table
|
||||
| DropSchema of string
|
||||
| DropTable of table
|
||||
| DropColumn of string
|
||||
and table_scope =
|
||||
| Global
|
||||
| Local
|
||||
and column =
|
||||
| Asterisk
|
||||
(* | Column of string *)
|
||||
| Column of expression * as_clause option
|
||||
| Column of expression_primary * as_clause option
|
||||
and as_clause =
|
||||
| As of string
|
||||
and table_expression =
|
||||
@ -25,19 +28,18 @@ and join_type =
|
||||
| Union
|
||||
| Natural
|
||||
and condition =
|
||||
| Condition of predicand * predicate
|
||||
| Condition of expression_primary * predicate
|
||||
| And of condition * condition
|
||||
| Or of condition * condition
|
||||
| Not of condition
|
||||
and predicand = expression
|
||||
and predicate =
|
||||
| Comparison of operator * predicand
|
||||
| Between of predicand * predicand
|
||||
| NotBetween of predicand * predicand
|
||||
| In of predicand list
|
||||
| NotIn of predicand list
|
||||
| Like of predicand
|
||||
| NotLike of predicand
|
||||
| Comparison of operator * expression_primary
|
||||
| Between of expression_primary * expression_primary
|
||||
| NotBetween of expression_primary * expression_primary
|
||||
| In of expression_primary list
|
||||
| NotIn of expression_primary list
|
||||
| Like of expression_primary
|
||||
| NotLike of expression_primary
|
||||
and operator =
|
||||
| Equals
|
||||
| NotEquals
|
||||
@ -47,11 +49,11 @@ and operator =
|
||||
| GreaterEquals
|
||||
and filter = condition
|
||||
and group =
|
||||
| Group of quantifier option * expression list option
|
||||
| Group of quantifier option * expression_primary list option
|
||||
and aggregate =
|
||||
| Aggregate of func * filter option
|
||||
and func =
|
||||
| Function of function_type * quantifier option * expression
|
||||
| Function of function_type * quantifier option * expression_primary
|
||||
and function_type =
|
||||
| Avg
|
||||
| Max
|
||||
@ -61,11 +63,22 @@ and function_type =
|
||||
and quantifier =
|
||||
| All
|
||||
| Distinct
|
||||
and expression =
|
||||
and expression_primary =
|
||||
| Ref of string
|
||||
| StringLiteral of string
|
||||
| DateLiteral 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 =
|
||||
match ast with
|
||||
@ -86,9 +99,11 @@ and pp_column col =
|
||||
and pp_expression exp =
|
||||
match exp with
|
||||
| Ref(name) -> name
|
||||
| StringLiteral(name) -> "'"^name^"'"
|
||||
| DateLiteral(name) -> "'"^name^"'"
|
||||
| TimeLiteral(name) -> "'"^name^"'"
|
||||
| StringLiteral(s) -> "'" ^ s ^ "'"
|
||||
| DateLiteral(d) -> "'" ^ d ^ "'"
|
||||
| TimeLiteral(t) -> "'" ^ t ^ "'"
|
||||
| TimestampLiteral(ts) -> "'" ^ ts ^ "'"
|
||||
| _ -> "Expression not yet supported"
|
||||
|
||||
and pp_table_expression table_exp =
|
||||
match table_exp with
|
||||
@ -137,8 +152,8 @@ and pp_predicate pred =
|
||||
| Comparison(op, exp) -> pp_operator op ^ pp_expression exp
|
||||
| Between(exp1, exp2) -> "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
|
||||
| NotLike(exp) -> " NOT LIKE " ^ pp_expression exp
|
||||
(*| Like(exp) -> "LIKE " ^ pp_expression exp
|
||||
| NotLike(exp) -> " NOT LIKE " ^ pp_expression exp*)
|
||||
| _ -> failwith "Predicate not supported"
|
||||
|
||||
and pp_operator op =
|
||||
|
Loading…
Reference in New Issue
Block a user