1
Fork 0

work on documentation for new release

This commit is contained in:
Jake Wheat 2019-07-07 12:54:22 +01:00
parent 8555650583
commit e54cfee62b
4 changed files with 169 additions and 30 deletions

View file

@ -0,0 +1,43 @@
-- Simple example to show parsing some SQL then pretty printing the AST
import System.Environment
import Text.Show.Pretty
import System.IO
import Language.SQL.SimpleSQL.Parse (parseStatements,peFormattedError)
import Language.SQL.SimpleSQL.Syntax (ansi2011)
main :: IO ()
main = do
args <- getArgs
case args of
[] -> do
-- read from stdin
c <- getContents
doIt c
["-s", sql] -> do
-- parse arg given
doIt sql
[f] ->
-- read file
withFile f ReadMode (\h -> do
x <- hGetContents h
doIt x)
_ -> do
putStrLn "use no arguments to stream sql from stdin, e.g.:\n\
\ cat some.sql | SimpleSQLParserExample\n\
\n\
\use -s to parse sql on command line, e.g.:\n\
\ SimpleSQLParserExample -s \"select * from t\"\n\
\use a single arg to parse a file, e.g.\n\
\ SimpleSQLParserExample some.sql"
doIt :: String -> IO ()
doIt src = do
let parsed = parseStatements ansi2011 "" Nothing src
either (error . peFormattedError)
(putStrLn . ppShow)
parsed