diff options
Diffstat (limited to 'src/Parser')
| -rw-r--r-- | src/Parser/Core.hs | 18 | ||||
| -rw-r--r-- | src/Parser/Expr.hs | 4 | 
2 files changed, 15 insertions, 7 deletions
| diff --git a/src/Parser/Core.hs b/src/Parser/Core.hs index ab6079a..f40889a 100644 --- a/src/Parser/Core.hs +++ b/src/Parser/Core.hs @@ -134,11 +134,19 @@ unifyExpr off pa expr = if      | Just (Refl :: FunctionType a :~: b) <- eqT      -> do -        case exprArgs expr of -            remaining -                | anull remaining -> return (FunctionEval expr) -                | otherwise -> parseError $ FancyError off $ S.singleton $ ErrorFail $ T.unpack $ -                    "missing function arguments" +        let FunctionArguments remaining = exprArgs expr +            showType ( Nothing, SomeArgumentType atype ) = "`<" <> textExprType atype <> ">'" +            showType ( Just (ArgumentKeyword kw), SomeArgumentType atype ) = "`" <> kw <> " <" <> textExprType atype <> ">'" +            err = parseError . FancyError off . S.singleton . ErrorFail . T.unpack + +        defaults <- forM (M.toAscList remaining) $ \case +            arg@(_, SomeArgumentType NoDefault) -> err $ "missing " <> showType arg <> " argument" +            (kw, SomeArgumentType (ExprDefault def)) -> return (kw, SomeExpr def) +            (kw, SomeArgumentType atype@ContextDefault) -> do +                SomeExpr context <- gets testContext +                context' <- unifyExpr off atype context +                return (kw, SomeExpr context') +        return (FunctionEval $ ArgsApp (FunctionArguments $ M.fromAscList defaults) expr)      | Just (Refl :: DynamicType :~: b) <- eqT      , Undefined msg <- expr diff --git a/src/Parser/Expr.hs b/src/Parser/Expr.hs index 8ae0f77..4b1a89e 100644 --- a/src/Parser/Expr.hs +++ b/src/Parser/Expr.hs @@ -355,9 +355,9 @@ variable = label "variable" $ do          SomeExpr e'@(FunVariable (FunctionArguments argTypes) _ _) -> do              let check poff kw expr = do                      case M.lookup kw argTypes of -                        Just expected -> do +                        Just (SomeArgumentType (_ :: ArgumentType expected)) -> do                              withRecovery registerParseError $ do -                                void $ unify poff expected (someExprType expr) +                                void $ unify poff (ExprTypePrim (Proxy @expected)) (someExprType expr)                              return expr                          Nothing -> do                              registerParseError $ FancyError poff $ S.singleton $ ErrorFail $ T.unpack $ |