Compare commits

...

3 Commits

Author SHA1 Message Date
82460a22fd testing numric literals 2024-12-13 09:34:40 +00:00
bacc8b4ddb adding numeric literals 2024-12-13 09:34:23 +00:00
9f345489ae adding literals + pretty printing 2024-12-13 09:33:56 +00:00
3 changed files with 31 additions and 13 deletions

View File

@ -69,6 +69,8 @@ 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
@ -103,8 +105,18 @@ 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

View File

@ -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 UNDERSCORE QUOTE COLON %token 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,19 +71,17 @@ 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 {} | sign unsigned_numeric_literal { Signed($1,$2) }
| unsigned_numeric_literal {} | unsigned_numeric_literal { $1 }
unsigned_numeric_literal : unsigned_numeric_literal :
| exact_numeric_literal { $1 } | exact_numeric_literal { $1 }
exact_numeric_literal: exact_numeric_literal:
| FLOAT { } | FLOAT { FloatLiteral($1) }
| INTEGER {} | INTEGER { IntegerLiteral($1) }
sign: sign:
| PLUS_SIGN { Plus } | PLUS_SIGN { Plus }
@ -190,10 +188,6 @@ nonparenthesized_value_expression_primary:
unsigned_value_specification: unsigned_value_specification:
| unsigned_literal { $1 } | unsigned_literal { $1 }
(*| general_value_specification {}*)
general_value_specification:
| {}
(*********************************************) (*********************************************)

View File

@ -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 'b', 'a', DATE '2024-12-25' AS date" in let query = "SELECT 1+1, 1, '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,6 +76,18 @@ 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(