on master help sign in
Add support for `let (==>) = Lambda in …`
commit2609f5dda7e7f2773225441ef75967445dd93225 authorEvan Czaplicki <info@elm-lang.org> dateTue 23 Jul 2013, 17:00 (13 years ago) parent7b90975
2 files changed+19−11
changelog.txt+1 compiler/Parse/Expression.hs+18−11
changelog.txt+1
@@ -16,6 +16,7 @@ Syntax:
1616* Record Constructors
1717* Record type aliases can be closed on the zeroth column
1818* (,,) syntax in types
19+* "(+) = " is permitted
1920* Unparenthesized if, let, case, and lambda in last
2021 term of a binary expression
2122
compiler/Parse/Expression.hs+18−11
@@ -195,17 +195,24 @@ expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
195195 <|> binaryExpr
196196 <?> "an expression"
197197
198−funcDef = try (do p1 <- try Pattern.term ; infics p1 <|> func p1)
199− <|> ((:[]) <$> Pattern.expr)
200− <?> "the definition of a variable (x = ...)"
201− where func p@(PVar v) = (p:) <$> spacePrefix Pattern.term
202− func p = do try (lookAhead (whitespace >> string "="))
203− return [p]
204− infics p1 = do
205− o:p <- try (whitespace >> anyOp)
206− p2 <- (whitespace >> Pattern.term)
207− return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ]
208− else [ PVar (o:p), p1, p2 ]
198+funcDef =
199+ choice [ do p1 <- try Pattern.term
200+ infics p1 <|> func p1
201+ , func =<< (PVar <$> parens symOp)
202+ , (:[]) <$> Pattern.expr
203+ ] <?> "the definition of a variable (x = ...)"
204+ where
205+ func pattern =
206+ case pattern of
207+ PVar v -> (pattern:) <$> spacePrefix Pattern.term
208+ _ -> do try (lookAhead (whitespace >> string "="))
209+ return [pattern]
210+
211+ infics p1 = do
212+ o:p <- try (whitespace >> anyOp)
213+ p2 <- (whitespace >> Pattern.term)
214+ return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ]
215+ else [ PVar (o:p), p1, p2 ]
209216
210217makeFunction :: [Pattern] -> LExpr t v -> LExpr t v
211218makeFunction args body@(L a b _) =