diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/Evaluator.hs | 13 | ||||
| -rw-r--r-- | src/Parser.hs | 2 |
2 files changed, 12 insertions, 3 deletions
diff --git a/src/Evaluator.hs b/src/Evaluator.hs index 2797fcd..4de5565 100644 --- a/src/Evaluator.hs +++ b/src/Evaluator.hs @@ -102,9 +102,16 @@ evaluateFunctionDef env asts = do | length args' < 2 -> throwL (astPos defAst) $ "\\ called with " ++ show (length args) ++ " arguments" | otherwise -> return $ (head args', tail args') + AST { astNode = ASTVector params' } <- assertIsASTVector params'' params <- mapM assertIsASTSymbol params' + let shadowingParamM = L.find (astNode .> (\(ASTSymbol sym) -> sym) .> isParamNameShadowing) params + case shadowingParamM of + Just shadowingParam -> throwL (astPos shadowingParam) + $ "parameter is shadowing already defined symbol " ++ show (astNode shadowingParam) + Nothing -> return () + let letExprs = take (length exprs - 1) exprs let nonLetExprM = L.find (not . isLetAST) letExprs case nonLetExprM of @@ -117,6 +124,7 @@ evaluateFunctionDef env asts = do where isLetAST AST { astNode = ASTFunctionCall (AST { astNode = ASTSymbol "let" }:_) } = True isLetAST _ = False + isParamNameShadowing name = M.member name env evaluateMatch :: Env -> [AST] -> LContext (Env, AST) evaluateMatch env asts = do @@ -137,8 +145,9 @@ evaluateMatch env asts = do return (env, matchAst { astNode = astNode ret }) where matchPairs :: (AST, AST) -> [(AST, AST)] -> LContext AST - matchPairs (actualExpr, evaledActual) [] = throwL (astPos actualExpr) $ "matching case not found when matching on expression: " ++ show actualExpr - ++ " (actual value: " ++ show evaledActual ++ ")" + matchPairs (actualExpr, evaledActual) [] = throwL (astPos actualExpr) + $ "matching case not found when matching on expression: " ++ show actualExpr + ++ " (actual value: " ++ show evaledActual ++ ")" matchPairs (actualExpr, evaledActual) ((matcher, branch):restPairs) = do (_, evaledMatcher) <- evaluate env matcher if evaledActual == evaledMatcher diff --git a/src/Parser.hs b/src/Parser.hs index 5089cb4..20a1454 100644 --- a/src/Parser.hs +++ b/src/Parser.hs @@ -41,7 +41,7 @@ parseToken (Token token tr tc tf) removeQuotes s = drop 1 s $> take (length s - 2) isBoolean t = t `elem` ["true", "false"] asBoolean t = t == "true" - ast astNode = AST { astNode = astNode, astRow = tr, astColumn = tc, astFileName = tf } + ast node = AST { astNode = node, astRow = tr, astColumn = tc, astFileName = tf } _parse :: [AST] -> [Token] -> LContext [AST] _parse acc' [] = do |
