1
Fork 0
simple-sql-parser/Syntax.lhs
Jake Wheat c29176f08e add TODO, tests and some small fixes
add TODO
add a bunch of tests
fix issue where 'order by' was being confused with the 'or' operator
  due to bad lexing
fix missing ctor in parens scalar expr parser
rename parens scalar parser to sparens and betweenParens helper to
  parrens
export the makeSelect from the syntax module
2013-12-13 14:08:33 +02:00

57 lines
1.8 KiB
Plaintext

> module Syntax (QueryExpr(..)
> ,makeSelect
> ,ScalarExpr(..)
> ,TableRef(..)
> ,JoinType(..)
> ,JoinCondition(..))
> where
> data ScalarExpr = Literal String
> | Identifier String
> | Identifier2 String String
> | Star
> | Star2 String
> | App String [ScalarExpr]
> | Op String [ScalarExpr]
> | Case (Maybe ScalarExpr) -- test value
> [(ScalarExpr,ScalarExpr)] -- when branches
> (Maybe ScalarExpr) -- else value
> | Parens ScalarExpr
> deriving (Eq,Show)
> data QueryExpr
> = Select
> {qeSelectList :: [(Maybe String,ScalarExpr)]
> ,qeFrom :: [TableRef]
> ,qeWhere :: Maybe ScalarExpr
> ,qeGroupBy :: [ScalarExpr]
> ,qeHaving :: Maybe ScalarExpr
> ,qeOrderBy :: [ScalarExpr]
> } deriving (Eq,Show)
> makeSelect :: QueryExpr
> makeSelect = Select {qeSelectList = []
> ,qeFrom = []
> ,qeWhere = Nothing
> ,qeGroupBy = []
> ,qeHaving = Nothing
> ,qeOrderBy = []}
> data TableRef = SimpleTableRef String
> | JoinTableRef JoinType TableRef TableRef (Maybe JoinCondition)
> | JoinParens TableRef
> | JoinAlias TableRef String
> | JoinQueryExpr QueryExpr
> deriving (Eq,Show)
> data JoinType = Inner | JLeft | JRight | Full | Cross
> deriving (Eq,Show)
> data JoinCondition = JoinOn ScalarExpr
> | JoinUsing [String]
> | JoinNatural
> deriving (Eq,Show)