Changeset 7622 for src/Pugs/Bind.hs

Show
Ignore:
Timestamp:
10/15/05 09:08:18 (3 years ago)
Author:
scook0
Message:

* Abracadabra, shalakazam, demagicalize pairs!
(This will probably break all the other backends.)
* A few minor style/readability tweaks

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Bind.hs

    r7593 r7622  
    3939    where 
    4040    prms' = prms \\ (map fst bound) 
    41     (bound, exps') = foldr doBind ([], []) (map unPair exps) 
     41    (bound, exps') = foldr doBind ([], []) (map unwrapNamedArg exps) 
    4242    doBind (name, exp) (bound, exps)  
    4343        | Just prm <- find ((matchNamedAttribute name) . paramName) prms 
     
    148148-- doBindArray _ (_, _)  (_, x) = internalError $ "doBindArray: unexpected char: " ++ (show x) 
    149149 
    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 
     151isNamedArg :: Exp -> Bool 
     152isNamedArg (Syn "named" [(Val (VStr _)), _]) = True 
     153isNamedArg arg@(Syn "named" _)               = error $ "malformed named arg: " ++ show arg 
     154isNamedArg _                                 = False 
     155 
     156unwrapNamedArg :: Exp -> (String, Exp) 
     157unwrapNamedArg (Syn "named" [(Val (VStr key)), val]) = (key, val) 
     158unwrapNamedArg x = error $ "not a well-formed named arg: " ++ show x 
    171159 
    172160{-| 
     
    210198 
    211199    -- Check that we have enough invocants bound 
    212     unless (null invocants) $ do 
     200    when (not . null $ invocants) $ do 
    213201        let cnt = length invocants 
    214202            act = length boundInvs 
     
    218206            ++ (show $ subName sub) 
    219207             
    220     let (boundReq, boundOpt) = partition (\x -> isRequired (fst x)) bindings -- bound params which are required 
     208    let (boundReq, boundOpt) = partition (isRequired . fst) bindings -- bound params which are required 
    221209        (reqPrms, optPrms)   = span isRequired params -- all params which are required, and all params which are opt 
    222210 
     
    258246 
    259247    let boundInv                = invPrms `zip` givenInvs -- invocants are just bound, params to given 
    260         (namedArgs, posArgs)    = partition isPair givenArgs -- pairs are named arguments, they go elsewhere 
     248        (namedArgs, posArgs)    = partition isNamedArg givenArgs 
    261249        (boundNamed, namedForSlurp, allPosPrms) = bindNames namedArgs argPrms -- bind pair args to params. namedForSlup = leftover pair args 
    262250        (posPrms, slurpyPrms)   = break isSlurpy allPosPrms -- split any prms not yet bound, into regular and slurpy. allPosPrms = not bound by named