work on array constructors and expressions
This commit is contained in:
parent
4cf84eba7b
commit
211174cfb4
4 changed files with 71 additions and 17 deletions
Language/SQL/SimpleSQL
|
@ -462,6 +462,17 @@ a match (select a from t)
|
|||
> return $ \v -> Match v u q
|
||||
|
||||
|
||||
> arrayPostfix :: Parser (ValueExpr -> ValueExpr)
|
||||
> arrayPostfix = do
|
||||
> es <- brackets (commaSep valueExpr)
|
||||
> return $ \v -> Array v es
|
||||
|
||||
> arrayCtor :: Parser ValueExpr
|
||||
> arrayCtor = keyword_ "array" >>
|
||||
> choice
|
||||
> [ArrayCtor <$> parens queryExpr
|
||||
> ,Array (Iden (Name "array")) <$> brackets (commaSep valueExpr)]
|
||||
|
||||
typename: used in casts. Special cases for the multi keyword typenames
|
||||
that SQL supports.
|
||||
|
||||
|
@ -529,6 +540,7 @@ TODO: carefully review the precedences and associativities.
|
|||
> [E.Postfix $ try quantifiedComparison
|
||||
> ,E.Postfix matchPredicate]
|
||||
> ,[binarySym "." E.AssocLeft]
|
||||
> ,[postfix' arrayPostfix]
|
||||
> ,[prefixSym "+", prefixSym "-"]
|
||||
> ,[binarySym "^" E.AssocLeft]
|
||||
> ,[binarySym "*" E.AssocLeft
|
||||
|
@ -618,6 +630,7 @@ fragile and could at least do with some heavy explanation.
|
|||
> ,hostParameter
|
||||
> ,caseValue
|
||||
> ,cast
|
||||
> ,arrayCtor
|
||||
> ,specialOpKs
|
||||
> ,parensTerm
|
||||
> ,subquery
|
||||
|
@ -961,6 +974,13 @@ todo: work out the symbol parsing better
|
|||
> closeParen :: Parser Char
|
||||
> closeParen = lexeme $ char ')'
|
||||
|
||||
> openBracket :: Parser Char
|
||||
> openBracket = lexeme $ char '['
|
||||
|
||||
> closeBracket :: Parser Char
|
||||
> closeBracket = lexeme $ char ']'
|
||||
|
||||
|
||||
> comma :: Parser Char
|
||||
> comma = lexeme $ char ','
|
||||
|
||||
|
@ -1005,6 +1025,9 @@ todo: work out the symbol parsing better
|
|||
> parens :: Parser a -> Parser a
|
||||
> parens = between openParen closeParen
|
||||
|
||||
> brackets :: Parser a -> Parser a
|
||||
> brackets = between openBracket closeBracket
|
||||
|
||||
> commaSep :: Parser a -> Parser [a]
|
||||
> commaSep = (`sepBy` comma)
|
||||
|
||||
|
|
|
@ -14,7 +14,7 @@ which have been changed to try to improve the layout of the output.
|
|||
> import Language.SQL.SimpleSQL.Syntax
|
||||
> import Text.PrettyPrint (render, vcat, text, (<>), (<+>), empty, parens,
|
||||
> nest, Doc, punctuate, comma, sep, quotes,
|
||||
> doubleQuotes)
|
||||
> doubleQuotes, brackets)
|
||||
> import Data.Maybe (maybeToList, catMaybes)
|
||||
|
||||
> -- | Convert a query expr ast to concrete syntax.
|
||||
|
@ -162,7 +162,6 @@ which have been changed to try to improve the layout of the output.
|
|||
> <+> (if u then text "unique" else empty)
|
||||
> <+> parens (queryExpr sq)
|
||||
|
||||
|
||||
> valueExpr (In b se x) =
|
||||
> valueExpr se <+>
|
||||
> (if b then empty else text "not")
|
||||
|
@ -172,6 +171,13 @@ which have been changed to try to improve the layout of the output.
|
|||
> InList es -> commaSep $ map valueExpr es
|
||||
> InQueryExpr qe -> queryExpr qe)
|
||||
|
||||
> valueExpr (Array v es) =
|
||||
> valueExpr v <> brackets (commaSep $ map valueExpr es)
|
||||
|
||||
> valueExpr (ArrayCtor q) =
|
||||
> text "array" <> parens (queryExpr q)
|
||||
|
||||
|
||||
> unname :: Name -> String
|
||||
> unname (QName n) = "\"" ++ n ++ "\""
|
||||
> unname (Name n) = n
|
||||
|
|
|
@ -134,6 +134,12 @@
|
|||
> QueryExpr
|
||||
> | Match ValueExpr Bool -- true if unique
|
||||
> QueryExpr
|
||||
> | Array ValueExpr [ValueExpr] -- ^ represents an array
|
||||
> -- access expression, or an array ctor
|
||||
> -- e.g. a[3]. The first
|
||||
> -- valueExpr is the array, the
|
||||
> -- second is the subscripts/ctor args
|
||||
> | ArrayCtor QueryExpr -- ^ this is used for the query expression version of array constructors, e.g. array(select * from t)> deriving (Eq,Show,Read,Data,Typeable)
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
> -- | Represents an identifier name, which can be quoted or unquoted.
|
||||
|
@ -154,7 +160,7 @@
|
|||
> | InQueryExpr QueryExpr
|
||||
> deriving (Eq,Show,Read,Data,Typeable)
|
||||
|
||||
not sure if scalar subquery and aexists and unique should be represented like this
|
||||
not sure if scalar subquery, exists and unique should be represented like this
|
||||
|
||||
> -- | A subquery in a value expression.
|
||||
> data SubQueryExprType
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue