Changeset 7622 for src/Pugs/Bind.hs
- Timestamp:
- 10/15/05 09:08:18 (3 years ago)
- Files:
-
- 1 modified
-
src/Pugs/Bind.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Bind.hs
r7593 r7622 39 39 where 40 40 prms' = prms \\ (map fst bound) 41 (bound, exps') = foldr doBind ([], []) (map un Pairexps)41 (bound, exps') = foldr doBind ([], []) (map unwrapNamedArg exps) 42 42 doBind (name, exp) (bound, exps) 43 43 | Just prm <- find ((matchNamedAttribute name) . paramName) prms … … 148 148 -- doBindArray _ (_, _) (_, x) = internalError $ "doBindArray: unexpected char: " ++ (show x) 149 149 150 {-| 151 Return @True@ if the given expression represents a pair (i.e. it uses the 152 \"=>\" pair constructor). 153 -} 154 isPair :: Exp -> Bool 155 isPair (Pos _ exp) = isPair exp 156 isPair (Cxt _ exp) = isPair exp 157 isPair (Syn "=>" [(Cxt _ (Val _)), _]) = True 158 isPair (Syn "=>" [(Val _), _]) = True 159 isPair _ = False 160 161 {-| 162 Decompose a pair-constructor 'Exp'ression (\"=>\") into a Haskell pair 163 (@key :: 'String'@, @value :: 'Exp'@). 164 -} 165 unPair :: Exp -> (String, Exp) 166 unPair (Pos _ exp) = unPair exp 167 unPair (Cxt _ exp) = unPair exp 168 unPair (Syn "=>" [key, exp]) 169 | Val (VStr k) <- unwrap key = (k, exp) 170 unPair x = error ("Not a pair: " ++ show x) 150 151 isNamedArg :: Exp -> Bool 152 isNamedArg (Syn "named" [(Val (VStr _)), _]) = True 153 isNamedArg arg@(Syn "named" _) = error $ "malformed named arg: " ++ show arg 154 isNamedArg _ = False 155 156 unwrapNamedArg :: Exp -> (String, Exp) 157 unwrapNamedArg (Syn "named" [(Val (VStr key)), val]) = (key, val) 158 unwrapNamedArg x = error $ "not a well-formed named arg: " ++ show x 171 159 172 160 {-| … … 210 198 211 199 -- Check that we have enough invocants bound 212 unless (nullinvocants) $ do200 when (not . null $ invocants) $ do 213 201 let cnt = length invocants 214 202 act = length boundInvs … … 218 206 ++ (show $ subName sub) 219 207 220 let (boundReq, boundOpt) = partition ( \x -> isRequired (fst x)) bindings -- bound params which are required208 let (boundReq, boundOpt) = partition (isRequired . fst) bindings -- bound params which are required 221 209 (reqPrms, optPrms) = span isRequired params -- all params which are required, and all params which are opt 222 210 … … 258 246 259 247 let boundInv = invPrms `zip` givenInvs -- invocants are just bound, params to given 260 (namedArgs, posArgs) = partition is Pair givenArgs -- pairs are named arguments, they go elsewhere248 (namedArgs, posArgs) = partition isNamedArg givenArgs 261 249 (boundNamed, namedForSlurp, allPosPrms) = bindNames namedArgs argPrms -- bind pair args to params. namedForSlup = leftover pair args 262 250 (posPrms, slurpyPrms) = break isSlurpy allPosPrms -- split any prms not yet bound, into regular and slurpy. allPosPrms = not bound by named
