From 382555b0606f9409e827f6c262810c853bc25dee Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Wed, 10 Jan 2024 17:05:56 +0000 Subject: [PATCH] trivial tweaks --- Language/SQL/SimpleSQL/Lex.hs | 6 +++--- Language/SQL/SimpleSQL/Pretty.hs | 8 ++++---- website/RenderTestCases.hs | 10 +++++++--- website/contributing.asciidoc | 2 ++ 4 files changed, 16 insertions(+), 10 deletions(-) diff --git a/Language/SQL/SimpleSQL/Lex.hs b/Language/SQL/SimpleSQL/Lex.hs index 8cd63a7..395317f 100644 --- a/Language/SQL/SimpleSQL/Lex.hs +++ b/Language/SQL/SimpleSQL/Lex.hs @@ -281,7 +281,7 @@ prettyTokens d ts = T.concat $ map (prettyToken d) ts -- | parser for a sql token sqlToken :: Dialect -> Parser (WithPos Token) -sqlToken d = do +sqlToken d = (do -- possibly there's a more efficient way of doing the source positions? sp <- getSourcePos off <- getOffset @@ -298,7 +298,7 @@ sqlToken d = do ,sqlWhitespace d] off1 <- getOffset ep <- getSourcePos - pure $ WithPos sp ep (off1 - off) t + pure $ WithPos sp ep (off1 - off) t) "valid lexical token" -------------------------------------- @@ -486,7 +486,7 @@ sqlNumber d = -- this is for definitely avoiding possibly ambiguous source <* choice [-- special case to allow e.g. 1..2 guard (diPostgresSymbols d) - *> (void $ lookAhead $ try $ string "..") + *> (void $ lookAhead $ try $ (string ".." "")) <|> void (notFollowedBy (oneOf "eE.")) ,notFollowedBy (oneOf "eE.") ] diff --git a/Language/SQL/SimpleSQL/Pretty.hs b/Language/SQL/SimpleSQL/Pretty.hs index 93418b6..63c3f34 100644 --- a/Language/SQL/SimpleSQL/Pretty.hs +++ b/Language/SQL/SimpleSQL/Pretty.hs @@ -45,11 +45,11 @@ import Language.SQL.SimpleSQL.Syntax import Language.SQL.SimpleSQL.Dialect --- | Convert a query expr ast to concrete syntax. +-- | Convert a query expr ast to Text. prettyQueryExpr :: Dialect -> QueryExpr -> Text prettyQueryExpr d = render . queryExpr d --- | Convert a value expr ast to concrete syntax. +-- | Convert a value expr ast to Text. prettyScalarExpr :: Dialect -> ScalarExpr -> Text prettyScalarExpr d = render . scalarExpr d @@ -57,12 +57,12 @@ prettyScalarExpr d = render . scalarExpr d terminator :: Doc a terminator = pretty ";" <> line --- | Convert a statement ast to concrete syntax. +-- | Convert a statement ast to Text. prettyStatement :: Dialect -> Statement -> Text 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 Text. A semicolon -- is inserted after each statement. prettyStatements :: Dialect -> [Statement] -> Text prettyStatements d = render . vsep . map prettyStatementWithSemicolon diff --git a/website/RenderTestCases.hs b/website/RenderTestCases.hs index e53c581..5c3425a 100644 --- a/website/RenderTestCases.hs +++ b/website/RenderTestCases.hs @@ -40,13 +40,17 @@ doc _ (ParseScalarExprFails d str) = [Row str (showResult $ P.parseScalarExpr d "" Nothing str)] doc _ (LexTest d str t) = - [Row str (T.pack $ ppShow $ L.lexSQL d "" Nothing str)] + [Row str (showResultL $ L.lexSQL d "" Nothing str)] doc _ (LexFails d str) = - [Row str (T.pack $ ppShow $ L.lexSQL d "" Nothing str)] + [Row str (showResultL $ L.lexSQL d "" Nothing str)] showResult :: Show a => Either P.ParseError a -> Text -showResult = either P.prettyError (T.pack . ppShow) +showResult = either (("Left\n" <>) . P.prettyError) (T.pack . ppShow) + +showResultL :: Show a => Either L.ParseError a -> Text +showResultL = either (("Left\n" <>) . L.prettyError) (T.pack . ppShow) + -- TODO: should put the dialect in the html output diff --git a/website/contributing.asciidoc b/website/contributing.asciidoc index 4129a76..dbbfca1 100644 --- a/website/contributing.asciidoc +++ b/website/contributing.asciidoc @@ -36,6 +36,8 @@ A big tradeoff here is all code needs to be prepared to deal with the abstract s The system probably doesn't always pretty print in the right dialect from correct syntax. This might need some changes if it causes a problem. +TODO: handling of keywords, and relationship with dialect + TODO: tests overview in addition to the above TODO: how the website works, what it contains