reformat
This commit is contained in:
parent
97189fb802
commit
b6633bf73c
5 changed files with 97 additions and 102 deletions
Language/SQL/SimpleSQL
|
@ -20,99 +20,88 @@
|
|||
> ) where
|
||||
|
||||
> -- | Represents a scalar expression
|
||||
> data ScalarExpr = -- | a numeric literal optional decimal point, e+-
|
||||
> -- integral exponent, e.g
|
||||
> --
|
||||
> -- * 10
|
||||
> --
|
||||
> -- * 10.
|
||||
> --
|
||||
> -- * .1
|
||||
> --
|
||||
> -- * 10.1
|
||||
> --
|
||||
> -- * 1e5
|
||||
> --
|
||||
> -- * 12.34e-6
|
||||
> NumLit String
|
||||
|
||||
> -- | string literal, currently only basic strings
|
||||
> -- between single quotes without escapes (no
|
||||
> -- single quotes in strings then)
|
||||
> | StringLit String
|
||||
> -- | text of interval literal, units of interval
|
||||
> -- precision, e.g. interval 3 days (3)
|
||||
> | IntervalLit String
|
||||
> String
|
||||
> (Maybe Int)
|
||||
> -- | identifier without dots
|
||||
> | Iden String
|
||||
> -- | identifier with one dot
|
||||
> | Iden2 String String
|
||||
> -- | star
|
||||
> | Star
|
||||
> -- | star with qualifier, e.g t.*
|
||||
> | Star2 String
|
||||
> -- | function application (anything that looks
|
||||
> -- like c style function application syntactically)
|
||||
> | App String [ScalarExpr]
|
||||
> -- | aggregate application, which adds distinct or
|
||||
> -- all, and order by, to regular function
|
||||
> -- application
|
||||
> | AggregateApp String (Maybe Duplicates)
|
||||
> [ScalarExpr]
|
||||
> [(ScalarExpr,Direction)]
|
||||
> -- | window application, which adds over
|
||||
> -- (partition by a order by b) to regular function
|
||||
> -- application. Explicit frames are not currently
|
||||
> -- supported
|
||||
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
|
||||
> -- | Infix binary operators. This is used for
|
||||
> -- symbol operators (a + b), keyword operators (a
|
||||
> -- and b) and multiple keyword operators (a is
|
||||
> -- similar to b)
|
||||
> | BinOp ScalarExpr String ScalarExpr
|
||||
> -- | Prefix unary operators. This is used for
|
||||
> -- symbol operators, keyword operators and
|
||||
> -- multiple keyword operators
|
||||
> | PrefixOp String ScalarExpr
|
||||
> -- | Postfix unary operators. This is used for
|
||||
> -- symbol operators, keyword operators and multiple
|
||||
> -- keyword operators
|
||||
> | PostfixOp String ScalarExpr
|
||||
> -- | Used for ternary, mixfix and other non
|
||||
> -- orthodox operators, including the function
|
||||
> -- looking calls which use keywords instead of
|
||||
> -- commas to separate the arguments,
|
||||
> -- e.g. substring(t from 1 to 5)
|
||||
> | SpecialOp String [ScalarExpr]
|
||||
> -- | case expression. both flavours
|
||||
> -- supported. Multiple condition when branches not
|
||||
> -- currently supported (case when a=4,b=5 then x
|
||||
> -- end)
|
||||
> | Case (Maybe ScalarExpr) -- test value
|
||||
> [(ScalarExpr,ScalarExpr)] -- when branches
|
||||
> (Maybe ScalarExpr) -- else value
|
||||
> | Parens ScalarExpr
|
||||
> -- | cast(a as typename)
|
||||
> | Cast ScalarExpr TypeName
|
||||
> -- | prefix 'typed literal', e.g. int '42'
|
||||
> | CastOp TypeName String
|
||||
> -- | exists, all, any, some subqueries
|
||||
> | SubQueryExpr SubQueryExprType QueryExpr
|
||||
> -- | in list literal and in subquery, if the bool
|
||||
> -- is false it means not in was used ('a not in
|
||||
> -- (1,2)')
|
||||
> | In Bool -- true if in, false if not in
|
||||
> ScalarExpr InThing
|
||||
> deriving (Eq,Show,Read)
|
||||
> data ScalarExpr
|
||||
> = -- | a numeric literal optional decimal point, e+-
|
||||
> -- integral exponent, e.g
|
||||
> --
|
||||
> -- * 10
|
||||
> --
|
||||
> -- * 10.
|
||||
> --
|
||||
> -- * .1
|
||||
> --
|
||||
> -- * 10.1
|
||||
> --
|
||||
> -- * 1e5
|
||||
> --
|
||||
> -- * 12.34e-6
|
||||
> NumLit String
|
||||
> -- | string literal, currently only basic strings between
|
||||
> -- single quotes without escapes (no single quotes in strings
|
||||
> -- then)
|
||||
> | StringLit String
|
||||
> -- | text of interval literal, units of interval precision,
|
||||
> -- e.g. interval 3 days (3)
|
||||
> | IntervalLit String String (Maybe Int)
|
||||
> -- | identifier without dots
|
||||
> | Iden String
|
||||
> -- | identifier with one dot
|
||||
> | Iden2 String String
|
||||
> -- | star
|
||||
> | Star
|
||||
> -- | star with qualifier, e.g t.*
|
||||
> | Star2 String
|
||||
> -- | function application (anything that looks like c style
|
||||
> -- function application syntactically)
|
||||
> | App String [ScalarExpr]
|
||||
> -- | aggregate application, which adds distinct or all, and
|
||||
> -- order by, to regular function application
|
||||
> | AggregateApp String (Maybe Duplicates)
|
||||
> [ScalarExpr]
|
||||
> [(ScalarExpr,Direction)]
|
||||
> -- | window application, which adds over (partition by a order
|
||||
> -- by b) to regular function application. Explicit frames are
|
||||
> -- not currently supported
|
||||
> | WindowApp String [ScalarExpr] [ScalarExpr] [(ScalarExpr,Direction)]
|
||||
> -- | Infix binary operators. This is used for symbol operators
|
||||
> -- (a + b), keyword operators (a and b) and multiple keyword
|
||||
> -- operators (a is similar to b)
|
||||
> | BinOp ScalarExpr String ScalarExpr
|
||||
> -- | Prefix unary operators. This is used for symbol
|
||||
> -- operators, keyword operators and multiple keyword operators
|
||||
> | PrefixOp String ScalarExpr
|
||||
> -- | Postfix unary operators. This is used for symbol
|
||||
> -- operators, keyword operators and multiple keyword operators
|
||||
> | PostfixOp String ScalarExpr
|
||||
> -- | Used for ternary, mixfix and other non orthodox
|
||||
> -- operators, including the function looking calls which use
|
||||
> -- keywords instead of commas to separate the arguments,
|
||||
> -- e.g. substring(t from 1 to 5)
|
||||
> | SpecialOp String [ScalarExpr]
|
||||
> -- | case expression. both flavours supported. Multiple
|
||||
> -- condition when branches not currently supported (case when
|
||||
> -- a=4,b=5 then x end)
|
||||
> | Case (Maybe ScalarExpr) -- test value
|
||||
> [(ScalarExpr,ScalarExpr)] -- when branches
|
||||
> (Maybe ScalarExpr) -- else value
|
||||
> | Parens ScalarExpr
|
||||
> -- | cast(a as typename)
|
||||
> | Cast ScalarExpr TypeName
|
||||
> -- | prefix 'typed literal', e.g. int '42'
|
||||
> | CastOp TypeName String
|
||||
> -- | exists, all, any, some subqueries
|
||||
> | SubQueryExpr SubQueryExprType QueryExpr
|
||||
> -- | in list literal and in subquery, if the bool is false it
|
||||
> -- means not in was used ('a not in (1,2)')
|
||||
> | In Bool ScalarExpr InThing
|
||||
> deriving (Eq,Show,Read)
|
||||
|
||||
> -- | Represents a type name, used in casts.
|
||||
> data TypeName = TypeName String deriving (Eq,Show,Read)
|
||||
|
||||
|
||||
> -- | Used for 'expr in (scalar expression list)', and 'expr in
|
||||
> -- | (subquery)' syntax
|
||||
> -- (subquery)' syntax
|
||||
> data InThing = InList [ScalarExpr]
|
||||
> | InQueryExpr QueryExpr
|
||||
> deriving (Eq,Show,Read)
|
||||
|
@ -146,7 +135,8 @@
|
|||
> data QueryExpr
|
||||
> = Select
|
||||
> {qeDuplicates :: Duplicates
|
||||
> ,qeSelectList :: [(Maybe String,ScalarExpr)] -- ^ the column aliases and the expressions
|
||||
> ,qeSelectList :: [(Maybe String,ScalarExpr)]
|
||||
> -- ^ the column aliases and the expressions
|
||||
> ,qeFrom :: [TableRef]
|
||||
> ,qeWhere :: Maybe ScalarExpr
|
||||
> ,qeGroupBy :: [ScalarExpr]
|
||||
|
@ -167,8 +157,7 @@
|
|||
|
||||
TODO: add queryexpr parens to deal with e.g.
|
||||
(select 1 union select 2) union select 3
|
||||
I'm not sure if this is valid syntax or not
|
||||
|
||||
I'm not sure if this is valid syntax or not.
|
||||
|
||||
> -- | represents the Distinct or All keywords, which can be used
|
||||
> -- before a select list, in an aggregate/window function
|
||||
|
@ -182,7 +171,8 @@ I'm not sure if this is valid syntax or not
|
|||
> -- | Corresponding, an option for the set operators
|
||||
> data Corresponding = Corresponding | Respectively deriving (Eq,Show,Read)
|
||||
|
||||
> -- | helper/'default' value for query exprs to make creating query expr values a little easier
|
||||
> -- | helper/'default' value for query exprs to make creating query
|
||||
> -- expr values a little easier
|
||||
> makeSelect :: QueryExpr
|
||||
> makeSelect = Select {qeDuplicates = All
|
||||
> ,qeSelectList = []
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue