1
Fork 0

work on the semicolon handling

This commit is contained in:
Jake Wheat 2013-12-14 11:59:29 +02:00
parent cd7a15c193
commit 3f08adb4c5
3 changed files with 22 additions and 6 deletions

View file

@ -612,7 +612,7 @@ wrapper for query expr which ignores optional trailing semicolon.
> topLevelQueryExpr :: P QueryExpr > topLevelQueryExpr :: P QueryExpr
> topLevelQueryExpr = > topLevelQueryExpr =
> queryExpr <* (choice [try $ symbol_ ";", return()]) > queryExpr >>= optionSuffix ((symbol ";" *>) . return)
wrapper to parse a series of query exprs from a single source. They wrapper to parse a series of query exprs from a single source. They
must be separated by semicolon, but for the last expression, the must be separated by semicolon, but for the last expression, the
@ -620,11 +620,9 @@ trailing semicolon is optional.
> queryExprs :: P [QueryExpr] > queryExprs :: P [QueryExpr]
> queryExprs = do > queryExprs = do
> qe <- queryExpr > ((:[]) <$> queryExpr)
> choice [[qe] <$ eof > >>= optionSuffix ((symbol ";" *>) . return)
> ,symbol_ ";" *> > >>= optionSuffix (\p -> (p++) <$> queryExprs)
> choice [[qe] <$ eof
> ,(:) qe <$> queryExprs]]
------------------------------------------------ ------------------------------------------------

View file

@ -5,6 +5,7 @@ back into SQL source text. It attempts to format the output nicely.
> module Language.SQL.SimpleSQL.Pretty > module Language.SQL.SimpleSQL.Pretty
> (prettyQueryExpr > (prettyQueryExpr
> ,prettyScalarExpr > ,prettyScalarExpr
> ,prettyQueryExprs
> ) where > ) where
> import Language.SQL.SimpleSQL.Syntax > import Language.SQL.SimpleSQL.Syntax
@ -17,6 +18,8 @@ back into SQL source text. It attempts to format the output nicely.
> prettyScalarExpr :: ScalarExpr -> String > prettyScalarExpr :: ScalarExpr -> String
> prettyScalarExpr = render . scalarExpr > prettyScalarExpr = render . scalarExpr
> prettyQueryExprs :: [QueryExpr] -> String
> prettyQueryExprs = render . vcat . map ((<> text ";") . queryExpr)
= scalar expressions = scalar expressions

View file

@ -11,6 +11,7 @@
> data TestItem = Group String [TestItem] > data TestItem = Group String [TestItem]
> | TestScalarExpr String ScalarExpr > | TestScalarExpr String ScalarExpr
> | TestQueryExpr String QueryExpr > | TestQueryExpr String QueryExpr
> | TestQueryExprs String [QueryExpr]
> | ParseQueryExpr String > | ParseQueryExpr String
> deriving (Eq,Show) > deriving (Eq,Show)
@ -440,6 +441,17 @@
> ) > )
> ] > ]
> queryExprsParserTests :: TestItem
> queryExprsParserTests = Group "query exprs" $ map (uncurry TestQueryExprs)
> [("select 1",[ms])
> ,("select 1;",[ms])
> ,("select 1;select 1",[ms,ms])
> ,("select 1;select 1;",[ms,ms])
> ,(" select 1;select 1; ",[ms,ms])
> ]
> where
> ms = makeSelect {qeSelectList = [(Nothing,NumLit "1")]}
> tpchTests :: TestItem > tpchTests :: TestItem
> tpchTests = > tpchTests =
> Group "parse tpch" > Group "parse tpch"
@ -450,6 +462,7 @@
> Group "parserTest" > Group "parserTest"
> [scalarExprParserTests > [scalarExprParserTests
> ,queryExprParserTests > ,queryExprParserTests
> ,queryExprsParserTests
> ,tpchTests > ,tpchTests
> ] > ]
@ -464,6 +477,8 @@
> toTest parseScalarExpr prettyScalarExpr str expected > toTest parseScalarExpr prettyScalarExpr str expected
> itemToTest (TestQueryExpr str expected) = > itemToTest (TestQueryExpr str expected) =
> toTest parseQueryExpr prettyQueryExpr str expected > toTest parseQueryExpr prettyQueryExpr str expected
> itemToTest (TestQueryExprs str expected) =
> toTest parseQueryExprs prettyQueryExprs str expected
> itemToTest (ParseQueryExpr str) = > itemToTest (ParseQueryExpr str) =
> toPTest parseQueryExpr prettyQueryExpr str > toPTest parseQueryExpr prettyQueryExpr str