Improved Let syntax and improvements to type system
[cc1516.git] / parse.icl
index e4bac8b..30a13a9 100644 (file)
--- 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 =