From 2609f5dda7e7f2773225441ef75967445dd93225 Mon Sep 17 00:00:00 2001 From: Evan Czaplicki Date: Tue, 23 Jul 2013 17:00:05 +0200 Subject: [PATCH] =?UTF-8?q?Add=20support=20for=20`let=20(=3D=3D>)=20=3D=20?= =?UTF-8?q?Lambda=20in=20=E2=80=A6`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- changelog.txt | 1 + compiler/Parse/Expression.hs | 29 ++++++++++++++++++----------- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/changelog.txt b/changelog.txt index 4dcb004..0aafb43 100644 --- a/changelog.txt +++ b/changelog.txt @@ -16,6 +16,7 @@ Syntax: * Record Constructors * Record type aliases can be closed on the zeroth column * (,,) syntax in types +* "(+) = " is permitted * Unparenthesized if, let, case, and lambda in last term of a binary expression diff --git a/compiler/Parse/Expression.hs b/compiler/Parse/Expression.hs index 13f81b5..5583499 100644 --- a/compiler/Parse/Expression.hs +++ b/compiler/Parse/Expression.hs @@ -195,17 +195,24 @@ expr = addLocation (choice [ ifExpr, letExpr, caseExpr ]) <|> binaryExpr "an expression" -funcDef = try (do p1 <- try Pattern.term ; infics p1 <|> func p1) - <|> ((:[]) <$> Pattern.expr) - "the definition of a variable (x = ...)" - where func p@(PVar v) = (p:) <$> spacePrefix Pattern.term - func p = do try (lookAhead (whitespace >> string "=")) - return [p] - infics p1 = do - o:p <- try (whitespace >> anyOp) - p2 <- (whitespace >> Pattern.term) - return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ] - else [ PVar (o:p), p1, p2 ] +funcDef = + choice [ do p1 <- try Pattern.term + infics p1 <|> func p1 + , func =<< (PVar <$> parens symOp) + , (:[]) <$> Pattern.expr + ] "the definition of a variable (x = ...)" + where + func pattern = + case pattern of + PVar v -> (pattern:) <$> spacePrefix Pattern.term + _ -> do try (lookAhead (whitespace >> string "=")) + return [pattern] + + infics p1 = do + o:p <- try (whitespace >> anyOp) + p2 <- (whitespace >> Pattern.term) + return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ] + else [ PVar (o:p), p1, p2 ] makeFunction :: [Pattern] -> LExpr t v -> LExpr t v makeFunction args body@(L a b _) =