From a3d1ba7e5c2f467cf659889a62a7b528b26488fb Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Thu, 11 Jan 2024 14:01:04 +0000 Subject: [PATCH] attempt to improve some parse errors, change some imports to be explicit --- Language/SQL/SimpleSQL/Dialect.hs | 2 +- Language/SQL/SimpleSQL/Parse.hs | 30 +++++++++++++++--------------- Language/SQL/SimpleSQL/Syntax.hs | 2 +- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/Language/SQL/SimpleSQL/Dialect.hs b/Language/SQL/SimpleSQL/Dialect.hs index 8d3d5c5..6d9566d 100644 --- a/Language/SQL/SimpleSQL/Dialect.hs +++ b/Language/SQL/SimpleSQL/Dialect.hs @@ -14,7 +14,7 @@ module Language.SQL.SimpleSQL.Dialect ) where import Data.Text (Text) -import Data.Data +import Data.Data (Data,Typeable) -- | Used to set the dialect used for parsing and pretty printing, -- very unfinished at the moment. diff --git a/Language/SQL/SimpleSQL/Parse.hs b/Language/SQL/SimpleSQL/Parse.hs index d44de80..73500c5 100644 --- a/Language/SQL/SimpleSQL/Parse.hs +++ b/Language/SQL/SimpleSQL/Parse.hs @@ -392,7 +392,7 @@ names = reverse <$> (((:[]) <$> name) anotherName) -- this will change when this is left factored where anotherName :: Parser ([Name] -> [Name]) - anotherName = try ((:) <$> (symbol "." *> name)) + anotherName = try ((:) <$> ((symbol "." *> name) "")) {- = Type Names @@ -1369,7 +1369,7 @@ from = keyword_ "from" *> commaSep1 tref where -- TODO: use P (a->) for the join tref suffix -- chainl or buildexpressionparser - tref = nonJoinTref >>= optionSuffix joinTrefSuffix + tref = (nonJoinTref "table ref") >>= optionSuffix (joinTrefSuffix) nonJoinTref = choice [parens $ choice [TRQueryExpr <$> queryExpr @@ -1387,11 +1387,11 @@ from = keyword_ "from" *> commaSep1 tref ] aliasSuffix aliasSuffix = fromAlias <$$> TRAlias joinTrefSuffix t = - (TRJoin t <$> option False (True <$ keyword_ "natural") + ((TRJoin t <$> option False (True <$ keyword_ "natural") <*> joinType <*> nonJoinTref <*> optional joinCondition) - >>= optionSuffix joinTrefSuffix + >>= optionSuffix joinTrefSuffix) "" {- TODO: factor the join stuff to produce better error messages (and make @@ -1520,7 +1520,7 @@ queryExpr = E.makeExprParser qeterm qeOpTable mkSelect <$> option SQDefault duplicates <*> selectList - <*> optional tableExpression + <*> (optional tableExpression) "table expression" mkSelect d sl Nothing = makeSelect{qeSetQuantifier = d, qeSelectList = sl} mkSelect d sl (Just (TableExpression f w g h od ofs fe)) = @@ -1534,10 +1534,10 @@ queryExpr = E.makeExprParser qeterm qeOpTable ,[E.InfixL $ setOp Except "except" ,E.InfixL $ setOp Union "union"]] setOp :: SetOperatorName -> Text -> Parser (QueryExpr -> QueryExpr -> QueryExpr) - setOp ctor opName = cq + setOp ctor opName = (cq <$> (ctor <$ keyword_ opName) <*> option SQDefault duplicates - <*> corr + <*> corr) "" cq o d c q0 q1 = QueryExprSetOp q0 o d c q1 corr = option Respectively (Corresponding <$ keyword_ "corresponding") @@ -1559,12 +1559,12 @@ data TableExpression ,_teFetchFirst :: Maybe ScalarExpr} tableExpression :: Parser TableExpression -tableExpression = mkTe <$> from - <*> optional whereClause - <*> option [] groupByClause - <*> optional having - <*> option [] orderBy - <*> offsetFetch +tableExpression = mkTe <$> (from "from clause") + <*> (optional whereClause "where clause") + <*> (option [] groupByClause "group by clause") + <*> (optional having "having clause") + <*> (option [] orderBy "order by clause") + <*> (offsetFetch "") where mkTe f w g h od (ofs,fe) = TableExpression f w g h od ofs fe @@ -2198,10 +2198,10 @@ closeBracket = singleCharSymbol ']' comma :: Parser Char -comma = singleCharSymbol ',' +comma = singleCharSymbol ',' "" semi :: Parser Char -semi = singleCharSymbol ';' +semi = singleCharSymbol ';' "" -- = helper functions diff --git a/Language/SQL/SimpleSQL/Syntax.hs b/Language/SQL/SimpleSQL/Syntax.hs index 708f555..da624ad 100644 --- a/Language/SQL/SimpleSQL/Syntax.hs +++ b/Language/SQL/SimpleSQL/Syntax.hs @@ -64,7 +64,7 @@ module Language.SQL.SimpleSQL.Syntax import Data.Text (Text) -import Data.Data +import Data.Data (Data, Typeable) -- | Represents a value expression. This is used for the expressions -- in select lists. It is also used for expressions in where, group