X-Git-Url: https://git.martlubbers.net/?a=blobdiff_plain;f=parse.icl;fp=parse.icl;h=30a13a9b573ccf0eab06010a14d2ac18d982f9e5;hb=714af3007a284a4a9f5f820dc6f26a45034da47e;hp=e4bac8be0e6e4833d4ca9722fe489530eadec697;hpb=74b8c52b6f00b15208e55e0e6c1ed56ce888f0db;p=cc1516.git diff --git a/parse.icl b/parse.icl index e4bac8b..30a13a9 100644 --- a/parse.icl +++ b/parse.icl @@ -34,12 +34,12 @@ parseProgram = many parseLetDecl >>= \fds1-> parseLetDecl :: Parser Token FunDecl parseLetDecl = peekPos >>= \p-> satTok LetToken >>| - (optional parseFunType) >>= \mt-> + parseFunType >>= \mt-> parseIdent >>= \f-> satTok AssignmentToken >>| parseExpr >>= \e-> satTok SColonToken >>| - pure (FunDecl p f [] mt [] [ReturnStmt $ Just e]) + pure (FunDecl p f [] (Just mt) [] [ReturnStmt $ Just e]) parseFunDecl :: Parser Token FunDecl parseFunDecl = liftM6 FunDecl @@ -85,14 +85,15 @@ parseStmt = parseIfStmt <|> parseWhileStmt <|> parseOneLine = pure <$> parseStmt parseFunType :: Parser Token Type -parseFunType = parseFT +parseFunType = parseFT >>= \t -> case t of + t1 ->> t2 = pure t + simpleT = pure $ FuncType simpleT where parseFT :: Parser Token Type parseFT = (liftM2 (->>) (parseSF <* satTok ArrowToken) (parseFT)) <|> - parseSF <|> - (FuncType <$> parseType) + parseSF parseSF :: Parser Token Type - parseSF = parseBBraces parseFT + parseSF = parseBBraces parseFT <|> parseType parseVarDecl :: Parser Token VarDecl parseVarDecl = liftM4 VarDecl @@ -207,16 +208,16 @@ peekPos = fst <$> peek derive gPrint TokenValue derive gEq TokenValue satTok :: TokenValue -> Parser Token Token -satTok t = top >>= \tok=:({line,col},token) -> if (eq t token) +satTok t = top >>= \tok=:({line,col},token) -> if (tokEq t token) (pure tok) (fail PositionalError line col ("ParseError: Unexpected token: " +++ printToString token +++ "\nExpected: " +++ printToString t)) - where - eq (IdentToken _) (IdentToken _) = True - eq (NumberToken _) (NumberToken _) = True - eq (CharToken _) (CharToken _) = True - eq (StringToken _) (StringToken _) = True - eq x y = gEq {|*|} x y + +tokEq (IdentToken _) (IdentToken _) = True +tokEq (NumberToken _) (NumberToken _) = True +tokEq (CharToken _) (CharToken _) = True +tokEq (StringToken _) (StringToken _) = True +tokEq x y = gEq {|*|} x y parseSepList :: TokenValue (Parser Token a) -> Parser Token [a] parseSepList sep p =