add support for odbc symbols: {} in lexer
This commit is contained in:
parent
9adce162e5
commit
a4d91b3e44
|
@ -27,25 +27,28 @@ hack for now, later will expand to flags on a feature by feature basis
|
|||
|
||||
> -- | Used to set the dialect used for parsing and pretty printing,
|
||||
> -- very unfinished at the moment.
|
||||
> data Dialect = Dialect {diSyntaxFlavour :: SyntaxFlavour}
|
||||
> data Dialect = Dialect {diSyntaxFlavour :: SyntaxFlavour
|
||||
> ,allowOdbc :: Bool}
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
> -- | ansi sql 2011 dialect
|
||||
> ansi2011 :: Dialect
|
||||
> ansi2011 = Dialect ANSI2011
|
||||
> ansi2011 = Dialect ANSI2011 False
|
||||
|
||||
> -- | mysql dialect
|
||||
> mysql :: Dialect
|
||||
> mysql = Dialect MySQL
|
||||
> mysql = Dialect MySQL False
|
||||
|
||||
> -- | postgresql dialect
|
||||
> postgres :: Dialect
|
||||
> postgres = Dialect Postgres
|
||||
> postgres = Dialect Postgres False
|
||||
|
||||
> -- | oracle dialect
|
||||
> oracle :: Dialect
|
||||
> oracle = Dialect Oracle
|
||||
> oracle = Dialect Oracle False
|
||||
|
||||
> -- | microsoft sql server dialect
|
||||
> sqlserver :: Dialect
|
||||
> sqlserver = Dialect SQLServer
|
||||
> sqlserver = Dialect SQLServer False
|
||||
|
||||
|
||||
|
|
|
@ -375,7 +375,11 @@ A multiple-character operator name cannot end in + or -, unless the name also co
|
|||
> -- symbol because this is the least complex way to do it
|
||||
> otherSymbol = many1 (char '.') :
|
||||
> (map (try . string) ["::", ":="]
|
||||
> ++ map (string . (:[])) "[],;():")
|
||||
> ++ map (string . (:[])) "[],;():"
|
||||
> ++ if allowOdbc d
|
||||
> then [string "{", string "}"]
|
||||
> else []
|
||||
> )
|
||||
|
||||
exception char is one of:
|
||||
~ ! @ # % ^ & | ` ?
|
||||
|
@ -433,7 +437,10 @@ which allows the last character of a multi character symbol to be + or
|
|||
> Symbol <$> choice (otherSymbol ++ regularOp)
|
||||
> where
|
||||
> otherSymbol = many1 (char '.') :
|
||||
> map (string . (:[])) ",;():?"
|
||||
> (map (string . (:[])) ",;():?"
|
||||
> ++ if allowOdbc d
|
||||
> then [string "{", string "}"]
|
||||
> else [])
|
||||
|
||||
try is used because most of the first characters of the two character
|
||||
symbols can also be part of a single character symbol
|
||||
|
@ -444,11 +451,14 @@ symbols can also be part of a single character symbol
|
|||
> choice ["||" <$ char '|' <* notFollowedBy (char '|')
|
||||
> ,return "|"]]
|
||||
|
||||
> symbol _ =
|
||||
> symbol d =
|
||||
> Symbol <$> choice (otherSymbol ++ regularOp)
|
||||
> where
|
||||
> otherSymbol = many1 (char '.') :
|
||||
> map (string . (:[])) "[],;():?"
|
||||
> (map (string . (:[])) "[],;():?"
|
||||
> ++ if allowOdbc d
|
||||
> then [string "{", string "}"]
|
||||
> else [])
|
||||
|
||||
try is used because most of the first characters of the two character
|
||||
symbols can also be part of a single character symbol
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
> ,AdminOptionFor(..)
|
||||
> ,GrantOptionFor(..)
|
||||
> -- * Dialects
|
||||
> ,Dialect
|
||||
> ,Dialect(allowOdbc)
|
||||
> ,ansi2011
|
||||
> ,mysql
|
||||
> ,postgres
|
||||
|
|
|
@ -303,10 +303,11 @@ the + or -.
|
|||
|
||||
> odbcLexerTests :: TestItem
|
||||
> odbcLexerTests = Group "odbcLexTests" $
|
||||
> [ LexTest sqlserver {- {odbc = True} -} s t | (s,t) <-
|
||||
> [--("{}", [Symbol "{", Symbol "}"])
|
||||
> ]
|
||||
> ]
|
||||
> [ LexTest sqlserver {allowOdbc = True} s t | (s,t) <-
|
||||
> [("{}", [Symbol "{", Symbol "}"])
|
||||
> ]]
|
||||
> ++ [LexFails sqlserver "{"
|
||||
> ,LexFails sqlserver "}"]
|
||||
|
||||
> combos :: [a] -> Int -> [[a]]
|
||||
> combos _ 0 = [[]]
|
||||
|
|
|
@ -4,7 +4,8 @@ Tests.lhs module for the 'interpreter'.
|
|||
|
||||
> module Language.SQL.SimpleSQL.TestTypes
|
||||
> (TestItem(..)
|
||||
> ,ansi2011,mysql,postgres,oracle,sqlserver) where
|
||||
> ,ansi2011,mysql,postgres,oracle,sqlserver
|
||||
> ,allowOdbc) where
|
||||
|
||||
> import Language.SQL.SimpleSQL.Syntax
|
||||
> import Language.SQL.SimpleSQL.Lex (Token)
|
||||
|
|
Loading…
Reference in a new issue