simple-sql-parser 0.4.3 → 0.4.4
raw patch · 5 files changed
+18/−153 lines, 5 filesdep ~base
Dependency ranges changed: base
Files
- Language/SQL/SimpleSQL/Pretty.lhs +6/−0
- changelog +2/−0
- simple-sql-parser.cabal +7/−2
- tools/Language/SQL/SimpleSQL/ErrorMessages.lhs +0/−149
- tools/SQLIndent.lhs +3/−2
Language/SQL/SimpleSQL/Pretty.lhs view
@@ -1,4 +1,6 @@ +> {-# LANGUAGE CPP #-}+> > -- | These is the pretty printing functions, which produce SQL > -- source from ASTs. The code attempts to format the output in a > -- readable way.@@ -17,6 +19,10 @@ > doubleQuotes, brackets,hcat) > import Data.Maybe (maybeToList, catMaybes) > import Data.List (intercalate)++#if MIN_VERSION_base(4,11,0)+> import Prelude hiding ((<>))+#endif > -- | Convert a query expr ast to concrete syntax. > prettyQueryExpr :: Dialect -> QueryExpr -> String
changelog view
@@ -1,6 +1,8 @@ If you need help updating to a new version of simple-sql-parser, please email jakewheatmail@gmail.com or use the github bug tracker, https://github.com/JakeWheat/simple-sql-parser/issues.+0.4.4+ tested with ghc 8.2.1 and 8.4.3 0.4.3 tested with ghc 8.0.2 and 8.2.1 0.4.1 (commit TBD)
simple-sql-parser.cabal view
@@ -1,5 +1,5 @@ name: simple-sql-parser-version: 0.4.3+version: 0.4.4 synopsis: A parser for SQL queries description: A parser for SQL queries. Parses most SQL:2011@@ -61,7 +61,7 @@ Language.SQL.SimpleSQL.Errors, Language.SQL.SimpleSQL.Combinators - Language.SQL.SimpleSQL.ErrorMessages,+ --Language.SQL.SimpleSQL.ErrorMessages, Language.SQL.SimpleSQL.FullQueries, Language.SQL.SimpleSQL.GroupBy, Language.SQL.SimpleSQL.MySQL,@@ -82,6 +82,11 @@ executable SQLIndent main-is: SQLIndent.lhs hs-source-dirs: .,tools+ Other-Modules: Language.SQL.SimpleSQL.Pretty,+ Language.SQL.SimpleSQL.Parser,+ Language.SQL.SimpleSQL.Syntax,+ Language.SQL.SimpleSQL.Errors,+ Language.SQL.SimpleSQL.Combinators Build-Depends: base >=4 && <5, parsec >=3.1 && <3.2, mtl >=2.1 && <2.3,
− tools/Language/SQL/SimpleSQL/ErrorMessages.lhs
@@ -1,149 +0,0 @@--Want to work on the error messages. Ultimately, parsec won't give the-best error message for a parser combinator library in haskell. Should-check out the alternatives such as polyparse and uu-parsing.--For now the plan is to try to get the best out of parsec. Skip heavy-work on this until the parser is more left factored?--Ideas:--1. generate large lists of invalid syntax-2. create table of the sql source and the error message-3. save these tables and compare from version to version. Want to- catch improvements and regressions and investigate. Have to do this- manually--= generating bad sql source--take good sql statements or expressions. Convert them into sequences-of tokens - want to preserve the whitespace and comments perfectly-here. Then modify these lists by either adding a token, removing a-token, or modifying a token (including creating bad tokens of raw-strings which don't represent anything than can be tokenized.--Now can see the error message for all of these bad strings. Probably-have to generate and prune this list manually in stages since there-will be too many.--Contexts:--another area to focus on is contexts: for instance, we have a set of-e.g. 1000 bad scalar expressions with error messages. Now can put-those bad scalar expressions into various contexts and see that the-error messages are still good.--plan:--1. create a list of all the value expression, with some variations for- each-2. manually create some error variations for each expression-3. create a renderer which will create a csv of the expressions and- the errors- this is to load as a spreadsheet to investigate more-4. create a renderer for the csv which will create a markdown file for- the website. this is to demonstrate the error messages in the- documentation--Then create some contexts for all of these: inside another value-expression, or inside a query expression. Do the same: render and-review the error messages.--Then, create some query expressions to focus on the non value-expression parts.---> module Language.SQL.SimpleSQL.ErrorMessages where--> import Language.SQL.SimpleSQL.Parser-> import Data.List-> import Text.Groom--> valueExpressions :: [String]-> valueExpressions =-> ["10.."-> ,"..10"-> ,"10e1e2"-> ,"10e--3"-> ,"1a"-> ,"1%"--> ,"'b'ad'"-> ,"'bad"-> ,"bad'"--> ,"interval '5' ay"-> ,"interval '5' day (4.4)"-> ,"interval '5' day (a)"-> ,"intervala '5' day"-> ,"interval 'x' day (3"-> ,"interval 'x' day 3)"--> ,"1badiden"-> ,"$"-> ,"!"-> ,"*.a"--> ,"??"-> ,"3?"-> ,"?a"--> ,"row"-> ,"row 1,2"-> ,"row(1,2"-> ,"row 1,2)"-> ,"row(1 2)"--> ,"f("-> ,"f)"--> ,"f(a"-> ,"f a)"-> ,"f(a b)"--TODO:-case-operators--> ,"a + (b + c"--casts-subqueries: + whole set of parentheses use-in list-'keyword' functions-aggregates-window functions---> ]--> queryExpressions :: [String]-> queryExpressions =-> map sl1 valueExpressions-> ++ map sl2 valueExpressions-> ++ map sl3 valueExpressions-> ++-> ["select a from t inner jin u"]-> where-> sl1 x = "select " ++ x ++ " from t"-> sl2 x = "select " ++ x ++ ", y from t"-> sl3 x = "select " ++ x ++ " fom t"--> valExprs :: [String] -> [(String,String)]-> valExprs = map parseOne-> where-> parseOne x = let p = parseValueExpr "" Nothing x-> in (x,either peFormattedError (\x -> "ERROR: parsed ok " ++ groom x) p)---> queryExprs :: [String] -> [(String,String)]-> queryExprs = map parseOne-> where-> parseOne x = let p = parseQueryExpr "" Nothing x-> in (x,either peFormattedError (\x -> "ERROR: parsed ok " ++ groom x) p)---> pExprs :: [String] -> [String] -> String-> pExprs x y =-> let l = valExprs x ++ queryExprs y-> in intercalate "\n\n\n\n" $ map (\(a,b) -> a ++ "\n" ++ b) l
tools/SQLIndent.lhs view
@@ -3,6 +3,7 @@ > import Language.SQL.SimpleSQL.Pretty > import Language.SQL.SimpleSQL.Parser+> import Language.SQL.SimpleSQL.Syntax > main :: IO () > main = do@@ -11,6 +12,6 @@ > [f] -> do > src <- readFile f > either (error . peFormattedError)-> (putStrLn . prettyQueryExprs)-> $ parseQueryExprs f Nothing src+> (putStrLn . prettyQueryExprs SQL2011)+> $ parseQueryExprs SQL2011 f Nothing src > _ -> error "please pass filename to indent"