aboutsummaryrefslogtreecommitdiff
path: root/parser
diff options
context:
space:
mode:
Diffstat (limited to 'parser')
-rw-r--r--parser/CC/Parser.hs24
1 files changed, 22 insertions, 2 deletions
diff --git a/parser/CC/Parser.hs b/parser/CC/Parser.hs
index 856a7b9..a097f98 100644
--- a/parser/CC/Parser.hs
+++ b/parser/CC/Parser.hs
@@ -51,7 +51,16 @@ pType :: Parser Type
pType = chainr1 pTypeAtom (symbol "->" >> return TFun)
pTypeAtom :: Parser Type
-pTypeAtom = (wordToken "Int" >> return TInt) <|> between (token "(") (token ")") pType
+pTypeAtom = (wordToken "Int" >> return TInt) <|> pParenType
+
+pParenType :: Parser Type
+pParenType = do
+ token "("
+ tys <- pType `sepBy` token ","
+ token ")"
+ case tys of
+ [ty] -> return ty
+ _ -> return (TTup tys)
pExpr :: Parser Expr
pExpr = label (pCall <|> pLam) "expression"
@@ -84,7 +93,18 @@ pExprAtom :: Parser Expr
pExprAtom =
choice [ uncurry (flip Int) <$> pInt
, uncurry (flip Var) <$> pName
- , between (token "(") (token ")") pExpr ]
+ , pParenExpr ]
+
+pParenExpr :: Parser Expr
+pParenExpr = do
+ p1 <- getPosition
+ token "("
+ exprs <- pExpr `sepBy` token ","
+ token ")"
+ p2 <- getPosition
+ case exprs of
+ [expr] -> return expr
+ _ -> return (Tup (SourceRange p1 p2) exprs)
pInt :: Parser (Int, SourceRange)
pInt = try (whitespace >> pInt0)