Merge branch 'fix-empty-statement'
This commit is contained in:
commit
ff25dbb880
|
@ -1450,14 +1450,14 @@ TODO: change style
|
|||
> topLevelQueryExpr = queryExpr <??> (id <$ semi)
|
||||
|
||||
> topLevelStatement :: Parser Statement
|
||||
> topLevelStatement = statement <??> (id <$ semi)
|
||||
> topLevelStatement = statement
|
||||
|
||||
-------------------------
|
||||
|
||||
= Statements
|
||||
|
||||
> statement :: Parser Statement
|
||||
> statement = choice
|
||||
> statementWithoutSemicolon :: Parser Statement
|
||||
> statementWithoutSemicolon = choice
|
||||
> [keyword_ "create" *> choice [createSchema
|
||||
> ,createTable
|
||||
> ,createView
|
||||
|
@ -1488,6 +1488,9 @@ TODO: change style
|
|||
> ,revoke
|
||||
> ,SelectStatement <$> queryExpr
|
||||
> ]
|
||||
>
|
||||
> statement :: Parser Statement
|
||||
> statement = statementWithoutSemicolon <* optional semi <|> semi *> pure EmptyStatement
|
||||
|
||||
> createSchema :: Parser Statement
|
||||
> 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
|
||||
optional.
|
||||
|
||||
TODO: change style
|
||||
|
||||
> statements :: Parser [Statement]
|
||||
> statements = (:[]) <$> statement
|
||||
> >>= optionSuffix ((semi *>) . pure)
|
||||
> >>= optionSuffix (\p -> (p++) <$> statements)
|
||||
> statements = many statement
|
||||
|
||||
----------------------------------------------
|
||||
|
||||
|
|
|
@ -35,14 +35,22 @@ Try to do this when this code is ported to a modern pretty printing lib.
|
|||
> prettyScalarExpr :: Dialect -> ScalarExpr -> String
|
||||
> prettyScalarExpr d = render . scalarExpr d
|
||||
|
||||
> -- | A terminating semicolon.
|
||||
> terminator :: Doc
|
||||
> terminator = text ";\n"
|
||||
|
||||
> -- | Convert a statement ast to concrete syntax.
|
||||
> 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
|
||||
> -- is inserted after each statement.
|
||||
> 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
|
||||
|
||||
|
@ -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 _ EmptyStatement = empty
|
||||
|
||||
|
||||
== sessions
|
||||
|
|
|
@ -530,6 +530,7 @@ I'm not sure if this is valid syntax or not.
|
|||
> | SetTransform
|
||||
> | SetCollation -}
|
||||
> | StatementComment [Comment]
|
||||
> | EmptyStatement
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
> data DropBehaviour =
|
||||
|
|
|
@ -85,7 +85,8 @@ Test-Suite Tests
|
|||
Language.SQL.SimpleSQL.Tpch,
|
||||
Language.SQL.SimpleSQL.ScalarExprs,
|
||||
Language.SQL.SimpleSQL.LexerTests,
|
||||
Language.SQL.SimpleSQL.CustomDialect
|
||||
Language.SQL.SimpleSQL.CustomDialect,
|
||||
Language.SQL.SimpleSQL.EmptyStatement
|
||||
ghc-options: -threaded
|
||||
|
||||
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.Tpch
|
||||
> import Language.SQL.SimpleSQL.LexerTests
|
||||
> import Language.SQL.SimpleSQL.EmptyStatement
|
||||
|
||||
> import Language.SQL.SimpleSQL.SQL2011Queries
|
||||
> import Language.SQL.SimpleSQL.SQL2011AccessControl
|
||||
|
@ -64,6 +65,7 @@ order on the generated documentation.
|
|||
> ,mySQLTests
|
||||
> ,oracleTests
|
||||
> ,customDialectTests
|
||||
> ,emptyStatementTests
|
||||
> ]
|
||||
|
||||
> tests :: T.TestTree
|
||||
|
|
Loading…
Reference in a new issue