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,
|
> -- | Used to set the dialect used for parsing and pretty printing,
|
||||||
> -- very unfinished at the moment.
|
> -- very unfinished at the moment.
|
||||||
> data Dialect = Dialect {diSyntaxFlavour :: SyntaxFlavour}
|
> data Dialect = Dialect {diSyntaxFlavour :: SyntaxFlavour
|
||||||
|
> ,allowOdbc :: Bool}
|
||||||
> deriving (Eq,Show,Read,Data,Typeable)
|
> deriving (Eq,Show,Read,Data,Typeable)
|
||||||
|
|
||||||
> -- | ansi sql 2011 dialect
|
> -- | ansi sql 2011 dialect
|
||||||
> ansi2011 :: Dialect
|
> ansi2011 :: Dialect
|
||||||
> ansi2011 = Dialect ANSI2011
|
> ansi2011 = Dialect ANSI2011 False
|
||||||
|
|
||||||
> -- | mysql dialect
|
> -- | mysql dialect
|
||||||
> mysql :: Dialect
|
> mysql :: Dialect
|
||||||
> mysql = Dialect MySQL
|
> mysql = Dialect MySQL False
|
||||||
|
|
||||||
> -- | postgresql dialect
|
> -- | postgresql dialect
|
||||||
> postgres :: Dialect
|
> postgres :: Dialect
|
||||||
> postgres = Dialect Postgres
|
> postgres = Dialect Postgres False
|
||||||
|
|
||||||
> -- | oracle dialect
|
> -- | oracle dialect
|
||||||
> oracle :: Dialect
|
> oracle :: Dialect
|
||||||
> oracle = Dialect Oracle
|
> oracle = Dialect Oracle False
|
||||||
|
|
||||||
> -- | microsoft sql server dialect
|
> -- | microsoft sql server dialect
|
||||||
> sqlserver :: 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
|
> -- symbol because this is the least complex way to do it
|
||||||
> otherSymbol = many1 (char '.') :
|
> otherSymbol = many1 (char '.') :
|
||||||
> (map (try . string) ["::", ":="]
|
> (map (try . string) ["::", ":="]
|
||||||
> ++ map (string . (:[])) "[],;():")
|
> ++ map (string . (:[])) "[],;():"
|
||||||
|
> ++ if allowOdbc d
|
||||||
|
> then [string "{", string "}"]
|
||||||
|
> else []
|
||||||
|
> )
|
||||||
|
|
||||||
exception char is one of:
|
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)
|
> Symbol <$> choice (otherSymbol ++ regularOp)
|
||||||
> where
|
> where
|
||||||
> otherSymbol = many1 (char '.') :
|
> 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
|
try is used because most of the first characters of the two character
|
||||||
symbols can also be part of a single character symbol
|
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 '|')
|
> choice ["||" <$ char '|' <* notFollowedBy (char '|')
|
||||||
> ,return "|"]]
|
> ,return "|"]]
|
||||||
|
|
||||||
> symbol _ =
|
> symbol d =
|
||||||
> Symbol <$> choice (otherSymbol ++ regularOp)
|
> Symbol <$> choice (otherSymbol ++ regularOp)
|
||||||
> where
|
> where
|
||||||
> otherSymbol = many1 (char '.') :
|
> 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
|
try is used because most of the first characters of the two character
|
||||||
symbols can also be part of a single character symbol
|
symbols can also be part of a single character symbol
|
||||||
|
|
|
@ -56,7 +56,7 @@
|
||||||
> ,AdminOptionFor(..)
|
> ,AdminOptionFor(..)
|
||||||
> ,GrantOptionFor(..)
|
> ,GrantOptionFor(..)
|
||||||
> -- * Dialects
|
> -- * Dialects
|
||||||
> ,Dialect
|
> ,Dialect(allowOdbc)
|
||||||
> ,ansi2011
|
> ,ansi2011
|
||||||
> ,mysql
|
> ,mysql
|
||||||
> ,postgres
|
> ,postgres
|
||||||
|
|
|
@ -303,10 +303,11 @@ the + or -.
|
||||||
|
|
||||||
> odbcLexerTests :: TestItem
|
> odbcLexerTests :: TestItem
|
||||||
> odbcLexerTests = Group "odbcLexTests" $
|
> odbcLexerTests = Group "odbcLexTests" $
|
||||||
> [ LexTest sqlserver {- {odbc = True} -} s t | (s,t) <-
|
> [ LexTest sqlserver {allowOdbc = True} s t | (s,t) <-
|
||||||
> [--("{}", [Symbol "{", Symbol "}"])
|
> [("{}", [Symbol "{", Symbol "}"])
|
||||||
> ]
|
> ]]
|
||||||
> ]
|
> ++ [LexFails sqlserver "{"
|
||||||
|
> ,LexFails sqlserver "}"]
|
||||||
|
|
||||||
> combos :: [a] -> Int -> [[a]]
|
> combos :: [a] -> Int -> [[a]]
|
||||||
> combos _ 0 = [[]]
|
> combos _ 0 = [[]]
|
||||||
|
|
|
@ -4,7 +4,8 @@ Tests.lhs module for the 'interpreter'.
|
||||||
|
|
||||||
> module Language.SQL.SimpleSQL.TestTypes
|
> module Language.SQL.SimpleSQL.TestTypes
|
||||||
> (TestItem(..)
|
> (TestItem(..)
|
||||||
> ,ansi2011,mysql,postgres,oracle,sqlserver) where
|
> ,ansi2011,mysql,postgres,oracle,sqlserver
|
||||||
|
> ,allowOdbc) where
|
||||||
|
|
||||||
> import Language.SQL.SimpleSQL.Syntax
|
> import Language.SQL.SimpleSQL.Syntax
|
||||||
> import Language.SQL.SimpleSQL.Lex (Token)
|
> import Language.SQL.SimpleSQL.Lex (Token)
|
||||||
|
|
Loading…
Reference in a new issue