From 89d64517cf95ab7844721d89edfac3d7257284d4 Mon Sep 17 00:00:00 2001 From: Dag Brattli Date: Wed, 12 May 2021 20:23:25 +0200 Subject: [PATCH] Use int64 for Integer to cover BigInt as well. Revert double Revert attempt --- src/NpgsqlFSharpParser/Parser.fs | 38 ++++--------------- src/NpgsqlFSharpParser/Types.fs | 5 +-- .../ParseSelectTests.fs | 36 +++++++++--------- 3 files changed, 27 insertions(+), 52 deletions(-) diff --git a/src/NpgsqlFSharpParser/Parser.fs b/src/NpgsqlFSharpParser/Parser.fs index 80fccb4..a5047ef 100644 --- a/src/NpgsqlFSharpParser/Parser.fs +++ b/src/NpgsqlFSharpParser/Parser.fs @@ -147,7 +147,7 @@ let text value : Parser = spaces >>. pstringCI value .>> spacesOrComment let star : Parser = - attempt (text "*" |>> fun _ -> Expr.Star) + text "*" |>> fun _ -> Expr.Star let opp = new OperatorPrecedenceParser() @@ -158,22 +158,8 @@ let parens parser = between (text "(") (text ")") parser let comma = text "," let integer : Parser = - attempt ( - spaces >>. pint32 .>> spacesOrComment - |>> Expr.Integer - ) - -let bigint : Parser = - attempt ( - spaces >>. pint64 .>> spacesOrComment - |>> Expr.BigInt - ) - -let smallint : Parser = - attempt ( - spaces >>. pint16 .>> spacesOrComment - |>> Expr.SmallInt - ) + spaces >>. pint64 .>> spacesOrComment + |>> Expr.Integer let number : Parser = spaces >>. pfloat .>> spacesOrComment @@ -190,10 +176,8 @@ let date : Parser = |>> Expr.Date let boolean : Parser = - attempt( - (text "true" |>> fun _ -> Expr.Boolean true) - <|> (text "false" |>> fun _ -> Expr.Boolean false) - ) + (text "true" |>> fun _ -> Expr.Boolean true) + <|> (text "false" |>> fun _ -> Expr.Boolean false) // Parses any string between double quotes let quotedString = @@ -201,14 +185,12 @@ let quotedString = <|> (skipChar '\'' |> anyStringBetween <| skipChar '\'') let stringLiteral : Parser = - attempt( - quotedString .>> spacesOrComment - |>> Expr.StringLiteral - ) + quotedString .>> spacesOrComment + |>> Expr.StringLiteral /// Parses 2 or more comma separated values. I.e (1, 2), but not (3) which will become an integer. let valueList = - let numeric = number <|> integer <|> bigint + let numeric = integer <|> number attempt( numeric .>> (pstring ",") >>= fun head -> sepBy1 numeric (pstring ",") >>= fun tail -> @@ -428,8 +410,6 @@ let updateQuery = let toOrEquals = text "=" <|> text "TO" - - // TODO: SET TIME ZONE value is an alias for SET timezone TO value let setQuery = text "SET" >>. @@ -506,9 +486,7 @@ opp.TermParser <- choice [ (text "(") >>. expr .>> (text ")") valueList star -// smallint integer - bigint boolean number date diff --git a/src/NpgsqlFSharpParser/Types.fs b/src/NpgsqlFSharpParser/Types.fs index a2ac4bd..5929be0 100644 --- a/src/NpgsqlFSharpParser/Types.fs +++ b/src/NpgsqlFSharpParser/Types.fs @@ -10,11 +10,8 @@ type Expr = | Parameter of string | Boolean of bool | StringLiteral of string - | Integer of int - | BigInt of int64 - | SmallInt of int16 + | Integer of int64 | Float of float - | Double of double | Date of string | Timestamp of string | Function of name:string * arguments:Expr list diff --git a/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs b/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs index d48375a..6c14a43 100644 --- a/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs +++ b/tests/NpgsqlFSharpAnalyzer.Tests/ParseSelectTests.fs @@ -39,11 +39,11 @@ let selectQueryTests = testList "Parse SELECT tests" [ } testSelect "SELECT 1" { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect "SELECT 36109712494634" { - SelectExpr.Default with Columns = [Expr.BigInt 36109712494634L] + SelectExpr.Default with Columns = [Expr.Integer 36109712494634L] } testSelect "SELECT ''" { @@ -51,7 +51,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ } testSelect "SELECT 1::text" { - SelectExpr.Default with Columns = [Expr.TypeCast(Expr.Integer 1, Expr.Ident "text")] + SelectExpr.Default with Columns = [Expr.TypeCast(Expr.Integer 1L, Expr.Ident "text")] } testSelect "SELECT @input::text, value::ltree" { @@ -121,7 +121,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [ Expr.As(Expr.StringConcat(Expr.Ident "ename", Expr.Ident "empno"), Expr.Ident "EmpDetails") - Expr.As(Expr.Function("COALESCE", [ Expr.Ident "comm"; Expr.Integer 0 ]), Expr.Ident "TOTALSAL") + Expr.As(Expr.Function("COALESCE", [ Expr.Ident "comm"; Expr.Integer 0L ]), Expr.Ident "TOTALSAL") ] From = Some (Expr.Ident "sales") @@ -143,7 +143,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [Expr.Function("COUNT", [Expr.Star]) ] From = Some (Expr.Ident "users") - Limit = Some(Expr.Integer 10) + Limit = Some(Expr.Integer 10L) } testSelect "SELECT COUNT(*) FROM users LIMIT @numberOfRows" { @@ -280,7 +280,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [Expr.Ident "username"; Expr.Ident "email"] From = Some (Expr.Ident "users") - Where = Some (Expr.In(Expr.Ident "user_id", Expr.List([Expr.Integer 1; Expr.Integer 2; Expr.Integer 3]))) + Where = Some (Expr.In(Expr.Ident "user_id", Expr.List([Expr.Integer 1L; Expr.Integer 2L; Expr.Integer 3L]))) } testSelect """ @@ -411,7 +411,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ Having = Some(Expr.GreaterThan(Expr.Function("SUM", [Expr.Ident "amount"]), Expr.Ident "users.salary")) - Limit = Some (Expr.Integer 20) + Limit = Some (Expr.Integer 20L) } testSelect """ @@ -443,9 +443,9 @@ let selectQueryTests = testList "Parse SELECT tests" [ Having = Some(Expr.GreaterThan(Expr.Function("SUM", [Expr.Ident "amount"]), Expr.Ident "users.salary")) - Limit = Some (Expr.Integer 20) + Limit = Some (Expr.Integer 20L) - Offset = Some (Expr.Integer 100) + Offset = Some (Expr.Integer 100L) } testSelect """ @@ -459,7 +459,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [Expr.Function ("NOW", [])] }, Expr.Ident "time")) - Limit = Some (Expr.Integer 1) + Limit = Some (Expr.Integer 1L) } testSelect """ @@ -474,7 +474,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [Expr.Function ("NOW", [])] }, Expr.Ident "time")) - Limit = Some (Expr.Integer 1) + Limit = Some (Expr.Integer 1L) } testSelect """ @@ -531,37 +531,37 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [ Expr.Ident("public.$Table.timestamp") ] From = Expr.As(Expr.Ident "$Table", Expr.Ident "tbl") |> Some - Limit = Some (Expr.Integer 100) + Limit = Some (Expr.Integer 100L) } testSelect "SELECT 1 -- This is a comment" { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect """ -- This is a comment SELECT 1""" { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect """ /* Comment inserted first */ SELECT 1""" { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect """ SELECT 1 /* Comment inserted last */ """ { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect """ SELECT 1; /* Comment inserted after semicolon */ """ { - SelectExpr.Default with Columns = [Expr.Integer 1] + SelectExpr.Default with Columns = [Expr.Integer 1L] } testSelect """ @@ -576,7 +576,7 @@ let selectQueryTests = testList "Parse SELECT tests" [ SelectExpr.Default with Columns = [Expr.Function ("NOW", [])] }, Expr.Ident "time")) - Limit = Some (Expr.Integer 1) + Limit = Some (Expr.Integer 1L) } testSelect """