Changeset 3328 for src/Pugs/Bind.hs
- Timestamp:
- 05/17/05 11:33:37 (4 years ago)
- svk:copy_cache_prev:
- 4908
- Files:
-
- 1 modified
-
src/Pugs/Bind.hs (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Bind.hs
r3145 r3328 15 15 import Pugs.Types 16 16 17 -- |Contains either a valid value of @a@ (@Right@), or a @String@ error 18 -- message (@Left@). 17 {-| 18 Contains either a valid value of @a@ (@Right@), or a @String@ error 19 message (@Left@). 20 -} 19 21 type MaybeError a = Either String a 20 22 23 isRequired :: Param -> Bool 21 24 isRequired prm = not ( isOptional prm || isNamed prm ) 22 25 23 -- |Match up named arguments with named parameters, producing a list of new 24 -- bindings, and lists of remaining unbound args and params. 26 {-| 27 Match up named arguments with named parameters, producing a list of new 28 bindings, and lists of remaining unbound args and params. 29 -} 25 30 bindNames :: [Exp] -- ^ List of argument expressions to be bound 26 31 -> [Param] -- ^ List of parameters to try binding; includes both … … 94 99 prms = map (\p -> (p, (head (paramName p)))) ps 95 100 96 -- |Construct an expression representing an infinite slice of the given 97 -- array expression, beginning at element /n/ (i.e. @\@array\[\$n...\]@). 98 -- Used by 'doBindArray' to bind a slurpy array parameter to the rest of 99 -- the slurpable arguments. 101 {-| 102 Construct an expression representing an infinite slice of the given 103 array expression, beginning at element /n/ (i.e. @\@array\[\$n...\]@). 104 105 Used by 'doBindArray' to bind a slurpy array parameter to the rest of 106 the slurpable arguments. 107 -} 100 108 doSlice :: Exp -- ^ The array expression to slice 101 109 -> VInt -- ^ Index of the first element in the resulting slice (/n/) … … 104 112 105 113 -- XXX - somehow force failure 106 -- |Construct an expression representing element /n/ in the given array 107 -- expression (i.e. @\@array\[\$n\]@). Used by 'doBindArray' to bind a 108 -- particular slurpy scalar parameter to one of the slurpable arguments. 114 {-| 115 Construct an expression representing element /n/ in the given array 116 expression (i.e. @\@array\[\$n\]@). 117 118 Used by 'doBindArray' to bind a particular slurpy scalar parameter to one of 119 the slurpable arguments. 120 -} 109 121 doIndex :: Exp -> VInt -> Exp 110 122 doIndex v n = Syn "[]" [Syn "val" [v], Val $ VInt n] … … 119 131 doBindArray _ (_, _) (_, x) = internalError $ "doBindArray: unexpected char: " ++ (show x) 120 132 121 -- |(Does this even get used? It seems to be a leftover fragment of 122 -- 'doBindArray'...) 133 {-| 134 (Does this even get used? It seems to be a leftover fragment of 135 'doBindArray'...) 136 -} 123 137 bindEmpty :: Param -> MaybeError (Param, Exp) 124 138 bindEmpty p = case paramName p of … … 128 142 [] -> internalError $ "bindEmpty: empty string encountered" 129 143 130 -- |Return @True@ if the given expression represents a pair (i.e. it uses the 131 -- \"=>\" pair constructor). 144 {-| 145 Return @True@ if the given expression represents a pair (i.e. it uses the 146 \"=>\" pair constructor). 147 -} 132 148 isPair :: Exp -> Bool 133 149 isPair (Pos _ exp) = isPair exp … … 138 154 isPair _ = False 139 155 140 -- |Decompose a pair-constructor 'Exp'ression (\"=>\") into a Haskell pair 141 -- (@key :: 'String'@, @value :: 'Exp'@). 156 {-| 157 Decompose a pair-constructor 'Exp'ression (\"=>\") into a Haskell pair 158 (@key :: 'String'@, @value :: 'Exp'@). 159 -} 142 160 unPair :: Exp -> (String, Exp) 143 161 unPair (Pos _ exp) = unPair exp … … 151 169 Bind parameters to a callable, then verify that the binding is complete 152 170 (i.e. all mandatory params are bound; all unspecified params have default 153 bindings). Uses 'bindSomeParams' to perform the initial binding, then uses 171 bindings). 172 173 Uses 'bindSomeParams' to perform the initial binding, then uses 154 174 'finalizeBindings' to check all required params and give default values to 155 175 any unbound optional ones. Once this is complete, /everything/ should be
