Compare commits
No commits in common. "82460a22fd75e6969eca3a6535467dbc6b8f8015" and "323b17e4a926d0c24d44071497922acb7a80bd3b" have entirely different histories.
82460a22fd
...
323b17e4a9
12
lib/ast.ml
12
lib/ast.ml
@ -69,8 +69,6 @@ and expression_primary =
|
|||||||
| DateLiteral of string
|
| DateLiteral of string
|
||||||
| TimeLiteral of string
|
| TimeLiteral of string
|
||||||
| TimestampLiteral of string
|
| TimestampLiteral of string
|
||||||
| IntegerLiteral of int
|
|
||||||
| FloatLiteral of float
|
|
||||||
| Concatenation of expression_primary * expression_primary
|
| Concatenation of expression_primary * expression_primary
|
||||||
| Numeric of expression_primary * sign * expression_primary
|
| Numeric of expression_primary * sign * expression_primary
|
||||||
| Signed of sign * expression_primary
|
| Signed of sign * expression_primary
|
||||||
@ -105,18 +103,8 @@ and pp_expression exp =
|
|||||||
| DateLiteral(d) -> "'" ^ d ^ "'"
|
| DateLiteral(d) -> "'" ^ d ^ "'"
|
||||||
| TimeLiteral(t) -> "'" ^ t ^ "'"
|
| TimeLiteral(t) -> "'" ^ t ^ "'"
|
||||||
| TimestampLiteral(ts) -> "'" ^ ts ^ "'"
|
| TimestampLiteral(ts) -> "'" ^ ts ^ "'"
|
||||||
| IntegerLiteral(i) -> string_of_int i
|
|
||||||
| FloatLiteral(f) -> string_of_float f
|
|
||||||
| Numeric(n1, s, n2) -> pp_expression n1 ^ pp_sign s ^ pp_expression n2
|
|
||||||
| _ -> "Expression not yet supported"
|
| _ -> "Expression not yet supported"
|
||||||
|
|
||||||
and pp_sign sign =
|
|
||||||
match sign with
|
|
||||||
| Plus -> "+"
|
|
||||||
| Minus -> "-"
|
|
||||||
| Times -> "*"
|
|
||||||
| Divide -> "/"
|
|
||||||
|
|
||||||
and pp_table_expression table_exp =
|
and pp_table_expression table_exp =
|
||||||
match table_exp with
|
match table_exp with
|
||||||
| TableExpression(tables, filter, _) -> pp_tables tables ^ pp_filter filter
|
| TableExpression(tables, filter, _) -> pp_tables tables ^ pp_filter filter
|
||||||
|
@ -24,7 +24,7 @@ open Ast
|
|||||||
%token DATE TIME TIMESTAMP
|
%token DATE TIME TIMESTAMP
|
||||||
%token <int> INTEGER
|
%token <int> INTEGER
|
||||||
%token <float> FLOAT
|
%token <float> FLOAT
|
||||||
%token QUOTE COLON
|
%token UNDERSCORE QUOTE COLON
|
||||||
%token EOF
|
%token EOF
|
||||||
%start main
|
%start main
|
||||||
%type <query> main
|
%type <query> main
|
||||||
@ -61,7 +61,7 @@ literal :
|
|||||||
| general_literal { $1 }
|
| general_literal { $1 }
|
||||||
|
|
||||||
unsigned_literal:
|
unsigned_literal:
|
||||||
| unsigned_numeric_literal { $1 }
|
(* | unsigned_numeric_literal { $1 }*)
|
||||||
| general_literal { $1 }
|
| general_literal { $1 }
|
||||||
|
|
||||||
general_literal:
|
general_literal:
|
||||||
@ -71,17 +71,19 @@ general_literal:
|
|||||||
character_string_literal:
|
character_string_literal:
|
||||||
| QUOTE IDENT QUOTE { StringLiteral($2) }
|
| QUOTE IDENT QUOTE { StringLiteral($2) }
|
||||||
|
|
||||||
|
introducer:
|
||||||
|
| UNDERSCORE { }
|
||||||
|
|
||||||
signed_numeric_literal:
|
signed_numeric_literal:
|
||||||
| sign unsigned_numeric_literal { Signed($1,$2) }
|
| sign unsigned_numeric_literal {}
|
||||||
| unsigned_numeric_literal { $1 }
|
| unsigned_numeric_literal {}
|
||||||
|
|
||||||
unsigned_numeric_literal :
|
unsigned_numeric_literal :
|
||||||
| exact_numeric_literal { $1 }
|
| exact_numeric_literal { $1 }
|
||||||
|
|
||||||
exact_numeric_literal:
|
exact_numeric_literal:
|
||||||
| FLOAT { FloatLiteral($1) }
|
| FLOAT { }
|
||||||
| INTEGER { IntegerLiteral($1) }
|
| INTEGER {}
|
||||||
|
|
||||||
sign:
|
sign:
|
||||||
| PLUS_SIGN { Plus }
|
| PLUS_SIGN { Plus }
|
||||||
@ -188,6 +190,10 @@ nonparenthesized_value_expression_primary:
|
|||||||
|
|
||||||
unsigned_value_specification:
|
unsigned_value_specification:
|
||||||
| unsigned_literal { $1 }
|
| unsigned_literal { $1 }
|
||||||
|
(*| general_value_specification {}*)
|
||||||
|
|
||||||
|
general_value_specification:
|
||||||
|
| {}
|
||||||
|
|
||||||
(*********************************************)
|
(*********************************************)
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@ let test_simple_select () =
|
|||||||
in
|
in
|
||||||
Alcotest.(check query_testable) query q2 ast2 ;
|
Alcotest.(check query_testable) query q2 ast2 ;
|
||||||
|
|
||||||
let query = "SELECT 1+1, 1, 'b', 'a', DATE '2024-12-25' AS date" in
|
let query = "SELECT 'b', 'a', DATE '2024-12-25' AS date" in
|
||||||
let q3 = parse query in
|
let q3 = parse query in
|
||||||
let ast3 =
|
let ast3 =
|
||||||
Select(
|
Select(
|
||||||
@ -76,18 +76,6 @@ let test_simple_select () =
|
|||||||
Column(
|
Column(
|
||||||
StringLiteral("b"),
|
StringLiteral("b"),
|
||||||
None
|
None
|
||||||
);
|
|
||||||
Column(
|
|
||||||
IntegerLiteral(1),
|
|
||||||
None
|
|
||||||
);
|
|
||||||
Column(
|
|
||||||
Numeric(
|
|
||||||
IntegerLiteral(1),
|
|
||||||
Plus,
|
|
||||||
IntegerLiteral(1)
|
|
||||||
),
|
|
||||||
None
|
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
TableExpression(
|
TableExpression(
|
||||||
|
Loading…
Reference in New Issue
Block a user