1
Fork 0

change set quantifier and sort direction to represent default separately

This commit is contained in:
Jake Wheat 2014-04-18 11:18:21 +03:00
parent c814cc9437
commit 3df87a3cf9
8 changed files with 55 additions and 49 deletions
Language/SQL/SimpleSQL

View file

@ -184,11 +184,11 @@ aggregate([all|distinct] args [order by orderitems])
> aggOrApp :: Name -> Parser ValueExpr
> aggOrApp n =
> makeApp n
> <$> parens ((,,) <$> duplicates
> <$> parens ((,,) <$> (fromMaybe SQDefault <$> duplicates)
> <*> choice [commaSep valueExpr]
> <*> (optionMaybe orderBy))
> where
> makeApp i (Nothing,es,Nothing) = App i es
> makeApp i (SQDefault,es,Nothing) = App i es
> makeApp i (d,es,od) = AggregateApp i d es (fromMaybe [] od)
> duplicates :: Parser (Maybe SetQuantifier)
@ -602,7 +602,7 @@ TODO: carefully review the precedences and associativities.
> ,"is unknown"
> ,"is not unknown"]
> -- have to use try with inSuffix because of a conflict
> -- with 'in' in position function
> -- with 'in' in position function, and not between
> -- between also has a try in it to deal with 'not'
> -- ambiguity
> ++ [E.Postfix $ try inSuffix,E.Postfix betweenSuffix]
@ -780,8 +780,8 @@ pretty trivial.
> where
> ob = SortSpec
> <$> valueExpr
> <*> option Asc (choice [Asc <$ keyword_ "asc"
> ,Desc <$ keyword_ "desc"])
> <*> option DirDefault (choice [Asc <$ keyword_ "asc"
> ,Desc <$ keyword_ "desc"])
> <*> option NullsOrderDefault
> (keyword_ "nulls" >>
> choice [NullsFirst <$ keyword "first"
@ -833,7 +833,7 @@ and union, etc..
> where
> select = keyword_ "select" >>
> mkSelect
> <$> (fromMaybe All <$> duplicates)
> <$> (fromMaybe SQDefault <$> duplicates)
> <*> selectList
> <*> optionMaybe tableExpression
> mkSelect d sl Nothing =
@ -877,7 +877,7 @@ be in the public syntax?
> [Union <$ keyword_ "union"
> ,Intersect <$ keyword_ "intersect"
> ,Except <$ keyword_ "except"] <?> "set operator")
> <*> (fromMaybe Distinct <$> duplicates)
> <*> (fromMaybe SQDefault <$> duplicates)
> <*> option Respectively
> (Corresponding <$ keyword_ "corresponding")
> <*> queryExpr)

View file

@ -54,9 +54,9 @@ which have been changed to try to improve the layout of the output.
> valueExpr (AggregateApp f d es od) =
> name f
> <> parens ((case d of
> Just Distinct -> text "distinct"
> Just All -> text "all"
> Nothing -> empty)
> Distinct -> text "distinct"
> All -> text "all"
> SQDefault -> empty)
> <+> commaSep (map valueExpr es)
> <+> orderBy od)
@ -214,7 +214,8 @@ which have been changed to try to improve the layout of the output.
> queryExpr (Select d sl fr wh gb hv od off fe) =
> sep [text "select"
> ,case d of
> All -> empty
> SQDefault -> empty
> All -> text "all"
> Distinct -> text "distinct"
> ,nest 7 $ sep [selectList sl]
> ,from fr
@ -233,8 +234,9 @@ which have been changed to try to improve the layout of the output.
> Intersect -> "intersect"
> Except -> "except")
> <+> case d of
> SQDefault -> empty
> All -> text "all"
> Distinct -> empty -- text "distinct"
> Distinct -> text "distinct"
> <+> case c of
> Corresponding -> text "corresponding"
> Respectively -> empty
@ -320,7 +322,10 @@ which have been changed to try to improve the layout of the output.
> where
> f (SortSpec e d n) =
> valueExpr e
> <+> (if d == Asc then empty else text "desc")
> <+> (case d of
> Asc -> text "asc"
> Desc -> text "desc"
> DirDefault -> empty)
> <+> (case n of
> NullsOrderDefault -> empty
> NullsFirst -> text "nulls" <+> text "first"

View file

@ -71,7 +71,7 @@
> -- order by, to regular function application
> | AggregateApp
> {aggName :: Name -- ^ aggregate function name
> ,aggDistinct :: Maybe SetQuantifier -- ^ distinct
> ,aggDistinct :: SetQuantifier -- ^ distinct
> ,aggArgs :: [ValueExpr]-- ^ args
> ,aggOrderBy :: [SortSpec] -- ^ order by
> }
@ -265,7 +265,7 @@ I'm not sure if this is valid syntax or not.
> -- expr values a little easier. It is defined like this:
> --
> -- > makeSelect :: QueryExpr
> -- > makeSelect = Select {qeSetQuantifier = All
> -- > makeSelect = Select {qeSetQuantifier = SQDefault
> -- > ,qeSelectList = []
> -- > ,qeFrom = []
> -- > ,qeWhere = Nothing
@ -276,7 +276,7 @@ I'm not sure if this is valid syntax or not.
> -- > ,qeFetchFirst = Nothing}
> makeSelect :: QueryExpr
> makeSelect = Select {qeSetQuantifier = All
> makeSelect = Select {qeSetQuantifier = SQDefault
> ,qeSelectList = []
> ,qeFrom = []
> ,qeWhere = Nothing
@ -290,10 +290,10 @@ 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
> -- application, or in a query expression set operator.
> data SetQuantifier = Distinct | All deriving (Eq,Show,Read,Data,Typeable)
> data SetQuantifier = SQDefault | Distinct | All deriving (Eq,Show,Read,Data,Typeable)
> -- | The direction for a column in order by.
> data Direction = Asc | Desc deriving (Eq,Show,Read,Data,Typeable)
> data Direction = DirDefault | Asc | Desc deriving (Eq,Show,Read,Data,Typeable)
> -- | Query expression set operators.
> data CombineOp = Union | Except | Intersect deriving (Eq,Show,Read,Data,Typeable)
> -- | Corresponding, an option for the set operators.