Skip to content

Commit

Permalink
Support signed integers and floats in the Schema SQL parser. Fixes #1309
Browse files Browse the repository at this point in the history
  • Loading branch information
mpscholten committed Jan 13, 2022
1 parent 20a74a0 commit 7509768
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions IHP/IDE/SchemaDesigner/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -421,10 +421,10 @@ varExpr :: Parser Expression
varExpr = VarExpression <$> identifier

doubleExpr :: Parser Expression
doubleExpr = DoubleExpression <$> Lexer.float
doubleExpr = DoubleExpression <$> (Lexer.signed spaceConsumer Lexer.float)

intExpr :: Parser Expression
intExpr = IntExpression <$> Lexer.decimal
intExpr = IntExpression <$> (Lexer.signed spaceConsumer Lexer.decimal)

callExpr :: Parser Expression
callExpr = do
Expand Down
18 changes: 18 additions & 0 deletions Test/IDE/SchemaDesigner/ParserSpec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,18 @@ COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UU
let sql = cs [plain|ALTER SEQUENCE public.a OWNED BY public.b.serial_number;|]
parseSql sql `shouldBe` UnknownStatement { raw = "ALTER SEQUENCE public.a OWNED BY public.b.serial_number" }

it "should parse positive IntExpression's" do
parseExpression "1" `shouldBe` (IntExpression 1)

it "should parse negative IntExpression's" do
parseExpression "-1" `shouldBe` (IntExpression (-1))

it "should parse positive DoubleExpression's" do
parseExpression "1.337" `shouldBe` (DoubleExpression 1.337)

it "should parse negative DoubleExpression's" do
parseExpression "-1.337" `shouldBe` (DoubleExpression (-1.337))

col :: Column
col = Column
{ name = ""
Expand All @@ -768,3 +780,9 @@ parseSqlStatements sql =
case Megaparsec.runParser Parser.parseDDL "input" sql of
Left parserError -> error (cs $ Megaparsec.errorBundlePretty parserError) -- For better error reporting in hspec
Right statements -> statements

parseExpression :: Text -> Expression
parseExpression sql =
case Megaparsec.runParser Parser.expression "input" sql of
Left parserError -> error (cs $ Megaparsec.errorBundlePretty parserError) -- For better error reporting in hspec
Right expression -> expression

0 comments on commit 7509768

Please sign in to comment.