Merge branch 'fix-empty-statement'
This commit is contained in:
commit
ff25dbb880
|
@ -1450,14 +1450,14 @@ TODO: change style
|
||||||
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
||||||
|
|
||||||
> topLevelStatement :: Parser Statement
|
> topLevelStatement :: Parser Statement
|
||||||
> topLevelStatement = statement <??> (id <$ semi)
|
> topLevelStatement = statement
|
||||||
|
|
||||||
-------------------------
|
-------------------------
|
||||||
|
|
||||||
= Statements
|
= Statements
|
||||||
|
|
||||||
> statement :: Parser Statement
|
> statementWithoutSemicolon :: Parser Statement
|
||||||
> statement = choice
|
> statementWithoutSemicolon = choice
|
||||||
> [keyword_ "create" *> choice [createSchema
|
> [keyword_ "create" *> choice [createSchema
|
||||||
> ,createTable
|
> ,createTable
|
||||||
> ,createView
|
> ,createView
|
||||||
|
@ -1488,6 +1488,9 @@ TODO: change style
|
||||||
> ,revoke
|
> ,revoke
|
||||||
> ,SelectStatement <$> queryExpr
|
> ,SelectStatement <$> queryExpr
|
||||||
> ]
|
> ]
|
||||||
|
>
|
||||||
|
> statement :: Parser Statement
|
||||||
|
> statement = statementWithoutSemicolon <* optional semi <|> semi *> pure EmptyStatement
|
||||||
|
|
||||||
> createSchema :: Parser Statement
|
> createSchema :: Parser Statement
|
||||||
> createSchema = keyword_ "schema" >>
|
> createSchema = keyword_ "schema" >>
|
||||||
|
@ -1895,12 +1898,8 @@ wrapper to parse a series of statements. They must be separated by
|
||||||
semicolon, but for the last statement, the trailing semicolon is
|
semicolon, but for the last statement, the trailing semicolon is
|
||||||
optional.
|
optional.
|
||||||
|
|
||||||
TODO: change style
|
|
||||||
|
|
||||||
> statements :: Parser [Statement]
|
> statements :: Parser [Statement]
|
||||||
> statements = (:[]) <$> statement
|
> statements = many statement
|
||||||
> >>= optionSuffix ((semi *>) . pure)
|
|
||||||
> >>= optionSuffix (\p -> (p++) <$> statements)
|
|
||||||
|
|
||||||
----------------------------------------------
|
----------------------------------------------
|
||||||
|
|
||||||
|
|
|
@ -35,14 +35,22 @@ Try to do this when this code is ported to a modern pretty printing lib.
|
||||||
> prettyScalarExpr :: Dialect -> ScalarExpr -> String
|
> prettyScalarExpr :: Dialect -> ScalarExpr -> String
|
||||||
> prettyScalarExpr d = render . scalarExpr d
|
> prettyScalarExpr d = render . scalarExpr d
|
||||||
|
|
||||||
|
> -- | A terminating semicolon.
|
||||||
|
> terminator :: Doc
|
||||||
|
> terminator = text ";\n"
|
||||||
|
|
||||||
> -- | Convert a statement ast to concrete syntax.
|
> -- | Convert a statement ast to concrete syntax.
|
||||||
> prettyStatement :: Dialect -> Statement -> String
|
> prettyStatement :: Dialect -> Statement -> String
|
||||||
> prettyStatement d = render . statement d
|
> prettyStatement _ EmptyStatement = render terminator
|
||||||
|
> prettyStatement d s = render (statement d s)
|
||||||
|
|
||||||
> -- | Convert a list of statements to concrete syntax. A semicolon
|
> -- | Convert a list of statements to concrete syntax. A semicolon
|
||||||
> -- is inserted after each statement.
|
> -- is inserted after each statement.
|
||||||
> prettyStatements :: Dialect -> [Statement] -> String
|
> prettyStatements :: Dialect -> [Statement] -> String
|
||||||
> prettyStatements d = render . vcat . map ((<> text ";\n") . statement d)
|
> prettyStatements d = render . vcat . map prettyStatementWithSemicolon
|
||||||
|
> where
|
||||||
|
> prettyStatementWithSemicolon :: Statement -> Doc
|
||||||
|
> prettyStatementWithSemicolon s = statement d s <> terminator
|
||||||
|
|
||||||
= scalar expressions
|
= scalar expressions
|
||||||
|
|
||||||
|
@ -641,6 +649,7 @@ Try to do this when this code is ported to a modern pretty printing lib.
|
||||||
|
|
||||||
|
|
||||||
> statement _ (StatementComment cs) = vcat $ map comment cs
|
> statement _ (StatementComment cs) = vcat $ map comment cs
|
||||||
|
> statement _ EmptyStatement = empty
|
||||||
|
|
||||||
|
|
||||||
== sessions
|
== sessions
|
||||||
|
|
|
@ -530,6 +530,7 @@ I'm not sure if this is valid syntax or not.
|
||||||
> | SetTransform
|
> | SetTransform
|
||||||
> | SetCollation -}
|
> | SetCollation -}
|
||||||
> | StatementComment [Comment]
|
> | StatementComment [Comment]
|
||||||
|
> | EmptyStatement
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
> data DropBehaviour =
|
> data DropBehaviour =
|
||||||
|
|
|
@ -85,7 +85,8 @@ Test-Suite Tests
|
||||||
Language.SQL.SimpleSQL.Tpch,
|
Language.SQL.SimpleSQL.Tpch,
|
||||||
Language.SQL.SimpleSQL.ScalarExprs,
|
Language.SQL.SimpleSQL.ScalarExprs,
|
||||||
Language.SQL.SimpleSQL.LexerTests,
|
Language.SQL.SimpleSQL.LexerTests,
|
||||||
Language.SQL.SimpleSQL.CustomDialect
|
Language.SQL.SimpleSQL.CustomDialect,
|
||||||
|
Language.SQL.SimpleSQL.EmptyStatement
|
||||||
ghc-options: -threaded
|
ghc-options: -threaded
|
||||||
|
|
||||||
executable SimpleSqlParserTool
|
executable SimpleSqlParserTool
|
||||||
|
|
18
tools/Language/SQL/SimpleSQL/EmptyStatement.lhs
Normal file
18
tools/Language/SQL/SimpleSQL/EmptyStatement.lhs
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
> module Language.SQL.SimpleSQL.EmptyStatement where
|
||||||
|
>
|
||||||
|
> import Language.SQL.SimpleSQL.Syntax
|
||||||
|
> import Language.SQL.SimpleSQL.TestTypes
|
||||||
|
>
|
||||||
|
> emptyStatementTests :: TestItem
|
||||||
|
> emptyStatementTests = Group "empty statement"
|
||||||
|
> [ TestStatement ansi2011 ";" EmptyStatement
|
||||||
|
> , TestStatements ansi2011 ";" [EmptyStatement]
|
||||||
|
> , TestStatements ansi2011 ";;" [EmptyStatement, EmptyStatement]
|
||||||
|
> , TestStatements ansi2011 ";;;" [EmptyStatement, EmptyStatement, EmptyStatement]
|
||||||
|
> , TestStatement ansi2011 "/* comment */ ;" EmptyStatement
|
||||||
|
> , TestStatements ansi2011 "/* comment */ ;" [EmptyStatement]
|
||||||
|
> , TestStatements ansi2011 "/* comment */ ; /* comment */ ;"
|
||||||
|
> [EmptyStatement, EmptyStatement]
|
||||||
|
> , TestStatements ansi2011 "/* comment */ ; /* comment */ ; /* comment */ ;"
|
||||||
|
> [EmptyStatement, EmptyStatement, EmptyStatement]
|
||||||
|
> ]
|
|
@ -29,6 +29,7 @@ test data to the Test.Framework tests.
|
||||||
> import Language.SQL.SimpleSQL.Odbc
|
> import Language.SQL.SimpleSQL.Odbc
|
||||||
> import Language.SQL.SimpleSQL.Tpch
|
> import Language.SQL.SimpleSQL.Tpch
|
||||||
> import Language.SQL.SimpleSQL.LexerTests
|
> import Language.SQL.SimpleSQL.LexerTests
|
||||||
|
> import Language.SQL.SimpleSQL.EmptyStatement
|
||||||
|
|
||||||
> import Language.SQL.SimpleSQL.SQL2011Queries
|
> import Language.SQL.SimpleSQL.SQL2011Queries
|
||||||
> import Language.SQL.SimpleSQL.SQL2011AccessControl
|
> import Language.SQL.SimpleSQL.SQL2011AccessControl
|
||||||
|
@ -64,6 +65,7 @@ order on the generated documentation.
|
||||||
> ,mySQLTests
|
> ,mySQLTests
|
||||||
> ,oracleTests
|
> ,oracleTests
|
||||||
> ,customDialectTests
|
> ,customDialectTests
|
||||||
|
> ,emptyStatementTests
|
||||||
> ]
|
> ]
|
||||||
|
|
||||||
> tests :: T.TestTree
|
> tests :: T.TestTree
|
||||||
|
|
Loading…
Reference in a new issue