1
Fork 0

add positional arg to the syntax and parser

This commit is contained in:
Jake Wheat 2016-02-21 23:36:47 +02:00
parent 64d3b742b4
commit d8b351472f
4 changed files with 18 additions and 3 deletions

View file

@ -586,6 +586,11 @@ select x from t where x > :param
> <$> hostParamTok > <$> hostParamTok
> <*> optionMaybe (keyword "indicator" *> hostParamTok)] > <*> optionMaybe (keyword "indicator" *> hostParamTok)]
== positional arg
> positionalArg :: Parser ValueExpr
> positionalArg = PositionalArg <$> positionalArgTok
== parens == parens
value expression parens, row ctor and scalar subquery value expression parens, row ctor and scalar subquery
@ -1238,6 +1243,7 @@ documenting/fixing.
> term :: Parser ValueExpr > term :: Parser ValueExpr
> term = choice [simpleLiteral > term = choice [simpleLiteral
> ,parameter > ,parameter
> ,positionalArg
> ,star > ,star
> ,parensExpr > ,parensExpr
> ,caseExpr > ,caseExpr
@ -2048,6 +2054,13 @@ It is only allowed when all the strings are quoted with ' atm.
> L.PrefixedVariable c p -> Just (c:p) > L.PrefixedVariable c p -> Just (c:p)
> _ -> Nothing) > _ -> Nothing)
> positionalArgTok :: Parser Int
> positionalArgTok = mytoken (\tok ->
> case tok of
> L.PositionalArg p -> Just p
> _ -> Nothing)
> sqlNumberTok :: Bool -> Parser String > sqlNumberTok :: Bool -> Parser String
> sqlNumberTok intOnly = mytoken (\tok -> > sqlNumberTok intOnly = mytoken (\tok ->
> case tok of > case tok of

View file

@ -52,6 +52,7 @@ which have been changed to try to improve the layout of the output.
> valueExpr _ (Iden i) = names i > valueExpr _ (Iden i) = names i
> valueExpr _ Star = text "*" > valueExpr _ Star = text "*"
> valueExpr _ Parameter = text "?" > valueExpr _ Parameter = text "?"
> valueExpr _ (PositionalArg n) = text $ "$" ++ show n
> valueExpr _ (HostParameter p i) = > valueExpr _ (HostParameter p i) =
> text p > text p
> <+> me (\i' -> text "indicator" <+> text i') i > <+> me (\i' -> text "indicator" <+> text i') i

View file

@ -109,6 +109,7 @@
> | Star > | Star
> | Parameter -- ^ Represents a ? in a parameterized query > | Parameter -- ^ Represents a ? in a parameterized query
> | PositionalArg Int -- ^ Represents an e.g. $1 in a parameterized query
> | HostParameter String (Maybe String) -- ^ represents a host > | HostParameter String (Maybe String) -- ^ represents a host
> -- parameter, e.g. :a. The > -- parameter, e.g. :a. The
> -- Maybe String is for the > -- Maybe String is for the

View file

@ -60,9 +60,9 @@ Tests for parsing value expressions
> ] > ]
> parameter :: TestItem > parameter :: TestItem
> parameter = Group "parameter" $ map (uncurry (TestValueExpr ansi2011)) > parameter = Group "parameter"
> [("?", Parameter) > [TestValueExpr ansi2011 "?" Parameter
> ] > ,TestValueExpr postgres "$13" $ PositionalArg 13]
> dots :: TestItem > dots :: TestItem