Add support for let (==>) = Lambda in …

This commit is contained in:
Evan Czaplicki 2013-07-23 17:00:05 +02:00
parent 7b90975dad
commit 2609f5dda7
2 changed files with 19 additions and 11 deletions

View file

@ -16,6 +16,7 @@ Syntax:
* Record Constructors * Record Constructors
* Record type aliases can be closed on the zeroth column * Record type aliases can be closed on the zeroth column
* (,,) syntax in types * (,,) syntax in types
* "(+) = " is permitted
* Unparenthesized if, let, case, and lambda in last * Unparenthesized if, let, case, and lambda in last
term of a binary expression term of a binary expression

View file

@ -195,17 +195,24 @@ expr = addLocation (choice [ ifExpr, letExpr, caseExpr ])
<|> binaryExpr <|> binaryExpr
<?> "an expression" <?> "an expression"
funcDef = try (do p1 <- try Pattern.term ; infics p1 <|> func p1) funcDef =
<|> ((:[]) <$> Pattern.expr) choice [ do p1 <- try Pattern.term
<?> "the definition of a variable (x = ...)" infics p1 <|> func p1
where func p@(PVar v) = (p:) <$> spacePrefix Pattern.term , func =<< (PVar <$> parens symOp)
func p = do try (lookAhead (whitespace >> string "=")) , (:[]) <$> Pattern.expr
return [p] ] <?> "the definition of a variable (x = ...)"
infics p1 = do where
o:p <- try (whitespace >> anyOp) func pattern =
p2 <- (whitespace >> Pattern.term) case pattern of
return $ if o == '`' then [ PVar $ takeWhile (/='`') p, p1, p2 ] PVar v -> (pattern:) <$> spacePrefix Pattern.term
else [ PVar (o:p), p1, p2 ] _ -> 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 :: [Pattern] -> LExpr t v -> LExpr t v
makeFunction args body@(L a b _) = makeFunction args body@(L a b _) =