few small fixes
untested fix for case insensitive keywords add partial support for interval literals fix bug in prefix operator cast parsing
This commit is contained in:
parent
9c4719bda3
commit
f08f4eb13b
5 changed files with 27 additions and 13 deletions
Language/SQL/SimpleSQL
|
@ -14,6 +14,7 @@
|
|||
> import qualified Language.Haskell.Exts.Fixity as HSE
|
||||
> import Data.Maybe
|
||||
> import Data.List
|
||||
> import Data.Char
|
||||
|
||||
> import Language.SQL.SimpleSQL.Syntax
|
||||
|
||||
|
@ -112,9 +113,15 @@ digitse[+-]digits
|
|||
> i <- int
|
||||
> return (p ++ "e" ++ s ++ i)
|
||||
|
||||
> interval :: P ScalarExpr
|
||||
> interval = try (keyword_ "interval") >>
|
||||
> IntervalLit
|
||||
> <$> stringLiteral
|
||||
> <*> identifierString
|
||||
> <*> optionMaybe (try $ parens (read <$> many1 digit))
|
||||
|
||||
> literal :: P ScalarExpr
|
||||
> literal = number <|> estring
|
||||
> literal = number <|> estring <|> interval
|
||||
|
||||
> identifierString :: P String
|
||||
> identifierString = do
|
||||
|
@ -242,9 +249,9 @@ to be.
|
|||
> typeName :: P TypeName
|
||||
> typeName = choice
|
||||
> [TypeName "double precision"
|
||||
> <$ keyword_ "double" <* keyword_ "precision"
|
||||
> <$ try (keyword_ "double" <* keyword_ "precision")
|
||||
> ,TypeName "character varying"
|
||||
> <$ keyword_ "character" <* keyword_ "varying"
|
||||
> <$ try (keyword_ "character" <* keyword_ "varying")
|
||||
> ,TypeName <$> identifierString]
|
||||
|
||||
> binOpSymbolNames :: [String]
|
||||
|
@ -579,7 +586,7 @@ attempt to fix the precedence and associativity. Doesn't work
|
|||
> symbol_ s = symbol s *> return ()
|
||||
|
||||
> keyword :: String -> P String
|
||||
> keyword s = string s
|
||||
> keyword s = ((map toLower) <$> string s)
|
||||
> <* notFollowedBy (char '_' <|> alphaNum)
|
||||
> <* whiteSpace
|
||||
|
||||
|
|
|
@ -23,6 +23,10 @@ back into SQL source text. It attempts to format the output nicely.
|
|||
> scalarExpr :: ScalarExpr -> Doc
|
||||
> scalarExpr (StringLit s) = quotes $ text s
|
||||
> scalarExpr (NumLit s) = text s
|
||||
> scalarExpr (IntervalLit v u p) =
|
||||
> text "interval" <+> quotes (text v)
|
||||
> <+> text u
|
||||
> <+> maybe empty (parens . text . show ) p
|
||||
> scalarExpr (Iden i) = text i
|
||||
> scalarExpr (Iden2 q i) = text q <> text "." <> text i
|
||||
> scalarExpr Star = text "*"
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
> data ScalarExpr = NumLit String
|
||||
> | StringLit String
|
||||
> | IntervalLit String -- text of interval
|
||||
> String -- units of interval
|
||||
> (Maybe Int) -- precision
|
||||
> | Iden String
|
||||
> | Iden2 String String
|
||||
> | Star
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue