on master help sign in
Add support for `let (==>) = Lambda in …`
2609f5dEvan Czaplicki
changelog.txt+1
@@ -16,6 +16,7 @@ Syntax:
16* Record Constructors
16* Record Constructors
17* Record type aliases can be closed on the zeroth column
17* Record type aliases can be closed on the zeroth column
18* (,,) syntax in types
18* (,,) syntax in types
19+* "(+) = " is permitted
19* Unparenthesized if, let, case, and lambda in last
20* Unparenthesized if, let, case, and lambda in last
20 term of a binary expression
21 term of a binary expression
21
22
compiler/Parse/Expression.hs+18−11
@@ -195,17 +195,24 @@ expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
195 <|> binaryExpr
195 <|> binaryExpr
196 <?> "an expression"
196 <?> "an expression"
197
197
198+funcDef =
198−funcDef = try (do p1 <- try Pattern.term ; infics p1 <|> func p1)
199+ choice [ do p1 <- try Pattern.term
200+ infics p1 <|> func p1
201+ , func =<< (PVar <$> parens symOp)
199− <|> ((:[]) <$> Pattern.expr)
202+ , (:[]) <$> Pattern.expr
200− <?> "the definition of a variable (x = ...)"
203+ ] <?> "the definition of a variable (x = ...)"
204+ where
205+ func pattern =
206+ case pattern of
201− where func p@(PVar v) = (p:) <$> spacePrefix Pattern.term
207+ PVar v -> (pattern:) <$> spacePrefix Pattern.term
202− func p = do try (lookAhead (whitespace >> string "="))
208+ _ -> do try (lookAhead (whitespace >> string "="))
203− return [p]
209+ return [pattern]
210+
204− infics p1 = do
211+ infics p1 = do
205− o:p <- try (whitespace >> anyOp)
212+ o:p <- try (whitespace >> anyOp)
206− p2 <- (whitespace >> Pattern.term)
213+ p2 <- (whitespace >> Pattern.term)
207− return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ]
214+ return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ]
208− else [ PVar (o:p), p1, p2 ]
215+ else [ PVar (o:p), p1, p2 ]
209
216
210makeFunction :: [Pattern] -> LExpr t v -> LExpr t v
217makeFunction :: [Pattern] -> LExpr t v -> LExpr t v
211makeFunction args body@(L a b _) =
218makeFunction args body@(L a b _) =