From 3f7e0123a2450fe141da2ef7b7ffcb266037bdcc Mon Sep 17 00:00:00 2001 From: Jake Wheat Date: Mon, 22 Feb 2016 23:16:36 +0200 Subject: [PATCH] a few documentation and website tweaks --- Language/SQL/SimpleSQL/Lex.lhs | 3 ++ Language/SQL/SimpleSQL/Pretty.lhs | 2 +- TODO | 4 ++ tools/Language/SQL/SimpleSQL/LexerTests.lhs | 59 +++++++++++---------- website/RenderTestCases.lhs | 9 ++-- website/make_website.sh | 4 +- 6 files changed, 48 insertions(+), 33 deletions(-) diff --git a/Language/SQL/SimpleSQL/Lex.lhs b/Language/SQL/SimpleSQL/Lex.lhs index ee3b464..a252541 100644 --- a/Language/SQL/SimpleSQL/Lex.lhs +++ b/Language/SQL/SimpleSQL/Lex.lhs @@ -545,6 +545,9 @@ a good sanity test for this function is to change it to always return true, then check that the automated tests return the same number of successes. I don't think it succeeds this test at the moment +> -- | Utility function to tell you if a list of tokens +> -- will pretty print then lex back to the same set of tokens. +> -- Used internally, might be useful for generating SQL via lexical tokens. > tokenListWillPrintAndLex :: Dialect -> [Token] -> Bool > tokenListWillPrintAndLex _ [] = True > tokenListWillPrintAndLex _ [_] = True diff --git a/Language/SQL/SimpleSQL/Pretty.lhs b/Language/SQL/SimpleSQL/Pretty.lhs index e7270c3..bcd0e24 100644 --- a/Language/SQL/SimpleSQL/Pretty.lhs +++ b/Language/SQL/SimpleSQL/Pretty.lhs @@ -32,7 +32,7 @@ which have been changed to try to improve the layout of the output. > prettyStatement :: Dialect -> Statement -> String > prettyStatement d = render . statement d -> -- | Convert a list of statements to concrete syntax. A semi colon +> -- | Convert a list of statements to concrete syntax. A semicolon > -- is inserted after each statement. > prettyStatements :: Dialect -> [Statement] -> String > prettyStatements d = render . vcat . map ((<> text ";\n") . statement d) diff --git a/TODO b/TODO index 607dee6..f942e06 100644 --- a/TODO +++ b/TODO @@ -8,10 +8,14 @@ syntax from hssqlppp: rename combinequeryexpr add comment to statements? review simple enums to make sure they have default + use enum in sign in interval literal work on better dialect design: more basic customizability and rule / callback driven +review/fix documentation and website +fix the groups for generated tests + medium tasks next release + 1 add annotation diff --git a/tools/Language/SQL/SimpleSQL/LexerTests.lhs b/tools/Language/SQL/SimpleSQL/LexerTests.lhs index e74f746..4a65c22 100644 --- a/tools/Language/SQL/SimpleSQL/LexerTests.lhs +++ b/tools/Language/SQL/SimpleSQL/LexerTests.lhs @@ -125,28 +125,6 @@ assurance. > ++ map (\s -> (s,[Symbol s])) [">=","<=","!=","<>","||", "::","..",":="] > -- generic symbols -An operator name is a sequence of up to NAMEDATALEN-1 (63 by default) characters from the following list: - -+ - * / < > = ~ ! @ # % ^ & | ` ? - -There are a few restrictions on operator names, however: --- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment. - -A multiple-character operator name cannot end in + or -, unless the name also contains at least one of these characters: - -~ ! @ # % ^ & | ` ? - -todo: 'negative' tests -symbol then -- -symbol then /* -operators without one of the exception chars - followed by + or - without whitespace - -also: do the testing for the ansi compatibility special cases - -> ++ [ (x, [Symbol x]) | x <- someValidPostgresOperators 2] - - > ++ (let idens = ["a", "_a", "test", "table", "Stuff", "STUFF"] > -- simple identifiers > in map (\i -> (i, [Identifier Nothing i])) idens @@ -200,6 +178,30 @@ also: do the testing for the ansi compatibility special cases > ,"/* this *is/ a comment */" > ] +An operator name is a sequence of up to NAMEDATALEN-1 (63 by default) characters from the following list: + ++ - * / < > = ~ ! @ # % ^ & | ` ? + +There are a few restrictions on operator names, however: +-- and /* cannot appear anywhere in an operator name, since they will be taken as the start of a comment. + +A multiple-character operator name cannot end in + or -, unless the name also contains at least one of these characters: + +~ ! @ # % ^ & | ` ? + +todo: 'negative' tests +symbol then -- +symbol then /* +operators without one of the exception chars + followed by + or - without whitespace + +also: do the testing for the ansi compatibility special cases + +> postgresShortOperatorTable :: [(String,[Token])] +> postgresShortOperatorTable = +> [ (x, [Symbol x]) | x <- someValidPostgresOperators 2] + + > postgresExtraOperatorTable :: [(String,[Token])] > postgresExtraOperatorTable = > [ (x, [Symbol x]) | x <- someValidPostgresOperators 4] @@ -232,20 +234,23 @@ the + or -. > postgresLexerTests :: TestItem > postgresLexerTests = Group "postgresLexerTests" $ > [Group "postgres lexer token tests" $ -> [LexTest postgres s t | (s,t) <- postgresLexerTable ++ postgresExtraOperatorTable] +> [LexTest postgres s t | (s,t) <- postgresLexerTable] +> ,Group "postgres generated lexer token tests" $ +> [LexTest postgres s t | (s,t) <- postgresShortOperatorTable ++ postgresExtraOperatorTable] > ,Group "postgres generated combination lexer tests" $ > [ LexTest postgres (s ++ s1) (t ++ t1) -> | (s,t) <- postgresLexerTable -> , (s1,t1) <- postgresLexerTable +> | (s,t) <- postgresLexerTable ++ postgresShortOperatorTable +> , (s1,t1) <- postgresLexerTable ++ postgresShortOperatorTable > , tokenListWillPrintAndLex postgres $ t ++ t1 > ] -> ,Group "adhoc postgres lexertests" $ +> ,Group "generated postgres edgecase lexertests" $ > [LexTest postgres s t > | (s,t) <- edgeCaseCommentOps > ++ edgeCasePlusMinusOps > ++ edgeCasePlusMinusComments] -> ++ + +> ,Group "adhoc postgres lexertests" $ > -- need more tests for */ to make sure it is caught if it is in the middle of a > -- sequence of symbol letters > [LexFails postgres "*/" diff --git a/website/RenderTestCases.lhs b/website/RenderTestCases.lhs index c535a6e..08c1762 100644 --- a/website/RenderTestCases.lhs +++ b/website/RenderTestCases.lhs @@ -4,8 +4,8 @@ Converts the test data to asciidoc > import Language.SQL.SimpleSQL.Tests > import Text.Show.Pretty > import Control.Monad.State -> import Language.SQL.SimpleSQL.Parser -> import Language.SQL.SimpleSQL.Lexer +> import Language.SQL.SimpleSQL.Parse +> import Language.SQL.SimpleSQL.Lex > import Data.List > data TableItem = Heading Int String @@ -32,7 +32,10 @@ Converts the test data to asciidoc > doc _ (ParseValueExprFails d str) = > [Row str (ppShow $ parseValueExpr d "" Nothing str)] -> doc _ (LexerTest d str t) = +> doc _ (LexTest d str t) = +> [Row str (ppShow $ lexSQL d "" Nothing str)] + +> doc _ (LexFails d str) = > [Row str (ppShow $ lexSQL d "" Nothing str)] TODO: should put the dialect in the html output diff --git a/website/make_website.sh b/website/make_website.sh index cc1009c..5760327 100755 --- a/website/make_website.sh +++ b/website/make_website.sh @@ -22,7 +22,7 @@ asciidoctor website/supported_sql.asciidoc -o - | runhaskell website/AddLinks.lh # tpch sql file # pandoc src/tpch.sql -s --highlight-style kate -o tpch.sql.html # rendered test cases -runhaskell -package-db=.cabal-sandbox/x86_64-linux-ghc-7.10.2-packages.conf.d -i:tools website/RenderTestCases.lhs > build/test_cases.asciidoc +runhaskell -package-db=.cabal-sandbox/x86_64-linux-ghc-7.10.3-packages.conf.d -i:tools website/RenderTestCases.lhs > build/test_cases.asciidoc #pandoc --from=markdown --to=html build/test_cases.asciidoc -o build/test_cases.html -c main.css '--title=simple-sql-parser examples/test cases' --toc asciidoctor build/test_cases.asciidoc -o - | \ @@ -31,7 +31,7 @@ asciidoctor build/test_cases.asciidoc -o - | \ # TODO: reduce the text size on the test cases page # TODO: use scrollbars inside the tables # TODO: make the tables autowidth -# -e "s/(code.*)font-size:1em/\1font-size:0.8em/g" +# -e "s/(code.*)font-size:1em/\1font-size:0.8em/g" rm build/test_cases.asciidoc # haddock