1
Fork 0

all tests passing, switch to megaparsec provisionally complete

This commit is contained in:
Jake Wheat 2024-01-10 11:41:38 +00:00
parent 4e09fe9f45
commit e76aa2818b
3 changed files with 22 additions and 31 deletions

View file

@ -1175,13 +1175,13 @@ opTable bExpr =
[-- parse match and quantified comparisons as postfix ops [-- parse match and quantified comparisons as postfix ops
-- todo: left factor the quantified comparison with regular -- todo: left factor the quantified comparison with regular
-- binary comparison, somehow -- binary comparison, somehow
[E.Postfix $ try quantifiedComparisonSuffix [postfix $ try quantifiedComparisonSuffix
,E.Postfix matchPredicateSuffix] ,postfix matchPredicateSuffix]
,[binarySymL "."] ,[binarySymL "."]
,[E.Postfix arraySuffix ,[postfix arraySuffix
,E.Postfix collateSuffix] ,postfix collateSuffix]
,[prefixSym "+", prefixSym "-"] ,[prefixSym "+", prefixSym "-"]
@ -1206,8 +1206,8 @@ opTable bExpr =
-- with 'in' in position function, and not between -- with 'in' in position function, and not between
-- between also has a try in it to deal with 'not' -- between also has a try in it to deal with 'not'
-- ambiguity -- ambiguity
,E.Postfix $ try inSuffix ,postfix $ try inSuffix
,E.Postfix betweenSuffix] ,postfix betweenSuffix]
-- todo: figure out where to put the try? -- todo: figure out where to put the try?
++ [binaryKeywordsN $ makeKeywordTree ++ [binaryKeywordsN $ makeKeywordTree
["not like" ["not like"
@ -1250,8 +1250,8 @@ opTable bExpr =
binaryKeywordN nm = E.InfixN (mkBinOp nm <$ keyword_ nm) binaryKeywordN nm = E.InfixN (mkBinOp nm <$ keyword_ nm)
binaryKeywordL nm = E.InfixL (mkBinOp nm <$ keyword_ nm) binaryKeywordL nm = E.InfixL (mkBinOp nm <$ keyword_ nm)
mkBinOp nm a b = BinOp a (mkNm nm) b mkBinOp nm a b = BinOp a (mkNm nm) b
prefixSym nm = E.Prefix (PrefixOp (mkNm nm) <$ symbol_ nm) prefixSym nm = prefix (PrefixOp (mkNm nm) <$ symbol_ nm)
prefixKeyword nm = E.Prefix (PrefixOp (mkNm nm) <$ keyword_ nm) prefixKeyword nm = prefix (PrefixOp (mkNm nm) <$ keyword_ nm)
mkNm nm = [Name Nothing nm] mkNm nm = [Name Nothing nm]
binaryKeywordsN p = binaryKeywordsN p =
E.InfixN (do E.InfixN (do
@ -1265,20 +1265,12 @@ opTable bExpr =
d <- option SQDefault duplicates d <- option SQDefault duplicates
pure (\a b -> MultisetBinOp a o d b)) pure (\a b -> MultisetBinOp a o d b))
postfixKeywords p = postfixKeywords p =
E.Postfix $ do postfix $ do
o <- try p o <- try p
pure $ PostfixOp [Name Nothing $ T.unwords o] pure $ PostfixOp [Name Nothing $ T.unwords o]
-- parse repeated prefix or postfix operators
{- postfix p = E.Postfix $ foldr1 (flip (.)) <$> some p
-- hack from here prefix p = E.Prefix $ foldr1 (.) <$> some p
-- http://stackoverflow.com/questions/10475337/parsec-expr-repeated-prefix-postfix-operator-not-supported
-- not implemented properly yet
-- I don't think this will be enough for all cases
-- at least it works for 'not not a'
-- ok: "x is not true is not true"
-- no work: "x is not true is not null"
prefix' p = E.Prefix . chainl1 p $ pure (.)
postfix' p = E.Postfix . chainl1 p $ pure (flip (.))-}
{- {-
== scalar expression top level == scalar expression top level

View file

@ -3,6 +3,8 @@
support table constraints without separating comma for sqlite support table constraints without separating comma for sqlite
switch source from literate to regular haskell switch source from literate to regular haskell
use prettyprinter lib instead of pretty use prettyprinter lib instead of pretty
nested block comments regressed - post a bug if you need this
fixed fixity parsing of union, except and intersect (matches postgres docs now)
0.6.1 added odbc handling to sqlsqerver dialect 0.6.1 added odbc handling to sqlsqerver dialect
added sqlserver dialect case for convert function added sqlserver dialect case for convert function
0.6.0 0.6.0

View file

@ -147,30 +147,27 @@ offsetFetch = Group "offsetFetch" $ map (uncurry (TestQueryExpr ansi2011))
combos :: TestItem combos :: TestItem
combos = Group "combos" $ map (uncurry (TestQueryExpr ansi2011)) combos = Group "combos" $ map (uncurry (TestQueryExpr ansi2011))
[("select a from t union select b from u" [("select a from t union select b from u"
,QueryExprSetOp ms1 Union SQDefault Respectively ms2) ,QueryExprSetOp mst Union SQDefault Respectively msu)
,("select a from t intersect select b from u" ,("select a from t intersect select b from u"
,QueryExprSetOp ms1 Intersect SQDefault Respectively ms2) ,QueryExprSetOp mst Intersect SQDefault Respectively msu)
,("select a from t except all select b from u" ,("select a from t except all select b from u"
,QueryExprSetOp ms1 Except All Respectively ms2) ,QueryExprSetOp mst Except All Respectively msu)
,("select a from t union distinct corresponding \ ,("select a from t union distinct corresponding \
\select b from u" \select b from u"
,QueryExprSetOp ms1 Union Distinct Corresponding ms2) ,QueryExprSetOp mst Union Distinct Corresponding msu)
,("select a from t union select a from t union select a from t" ,("select a from t union select a from t union select a from t"
-- TODO: union should be left associative. I think the others also ,QueryExprSetOp (QueryExprSetOp mst Union SQDefault Respectively mst)
-- so this needs to be fixed (new optionSuffix variation which Union SQDefault Respectively mst)
-- handles this)
,QueryExprSetOp ms1 Union SQDefault Respectively
(QueryExprSetOp ms1 Union SQDefault Respectively ms1))
] ]
where where
ms1 = makeSelect mst = makeSelect
{qeSelectList = [(Iden [Name Nothing "a"],Nothing)] {qeSelectList = [(Iden [Name Nothing "a"],Nothing)]
,qeFrom = [TRSimple [Name Nothing "t"]]} ,qeFrom = [TRSimple [Name Nothing "t"]]}
ms2 = makeSelect msu = makeSelect
{qeSelectList = [(Iden [Name Nothing "b"],Nothing)] {qeSelectList = [(Iden [Name Nothing "b"],Nothing)]
,qeFrom = [TRSimple [Name Nothing "u"]]} ,qeFrom = [TRSimple [Name Nothing "u"]]}