Changeset 8792 for src/Pugs/Bind.hs

Show
Ignore:
Timestamp:
01/27/06 09:59:34 (3 years ago)
Author:
audreyt
Message:

* required named parameters should be checked along

with required positional parameters.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Bind.hs

    r8298 r8792  
    2222-} 
    2323type MaybeError a = Either String a 
    24  
    25 isRequired :: Param -> Bool 
    26 isRequired prm = not $ isOptional prm 
    2724 
    2825{-| 
     
    208205            ++ (show $ subName sub) 
    209206             
    210     let (boundReq, boundOpt) = partition (isRequired . fst) bindings -- bound params which are required 
    211         (reqPrms, optPrms)   = span isRequired params -- all params which are required, and all params which are opt 
     207    let (boundOpt, boundReq) = partition (isOptional . fst) bindings -- bound params which are required 
     208        (optPrms, reqPrms)   = partition isOptional params -- all params which are required, and all params which are opt 
    212209 
    213210    -- Check length of required parameters 
    214211    when (length boundReq < length reqPrms) $ do 
    215         fail $ "Insufficient number of required parameters: " 
    216             ++ (show $ length boundReq) ++ " actual, " 
    217             ++ (show $ length reqPrms) ++ " expected" 
     212        fail $ "Missing required parameters: " 
     213            ++ unwords (map paramName $ reqPrms \\ map fst boundReq) 
    218214 
    219215    let unboundOptPrms = optPrms \\ (map fst boundOpt) -- unbound optParams are allPrms - boundPrms 
     
    250246        (namedArgs, posArgs)    = partition isNamedArg givenArgs 
    251247        (boundNamed, namedForSlurp, allPosPrms) = bindNames namedArgs argPrms -- bind pair args to params. namedForSlup = leftover pair args 
    252         (posPrms, slurpyPrms)   = break isSlurpy allPosPrms -- split any prms not yet bound, into regular and slurpy. allPosPrms = not bound by named 
     248        (itemPrms, slurpyPrms)  = break isSlurpy allPosPrms -- split any prms not yet bound, into regular and slurpy. allPosPrms = not bound by named 
     249        posPrms                 = filter (not . isNamed) itemPrms 
    253250        boundPos                = posPrms `zip` posArgs -- bind all the unbound params in positional order 
    254251        posForSlurp             = drop (length posPrms) posArgs -- and whatever's left will be slurped