1
Fork 0

trivial tweaks

This commit is contained in:
Jake Wheat 2024-01-10 17:05:56 +00:00
parent add2e373a0
commit 382555b060
4 changed files with 16 additions and 10 deletions

View file

@ -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.")
]

View file

@ -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

View file

@ -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

View file

@ -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