Handle `let { body = ... }` expressions

This commit is contained in:
Guillaume Maudoux 2018-02-09 15:29:47 +01:00
parent ad18c62566
commit 0914047115
2 changed files with 21 additions and 4 deletions

View File

@ -140,10 +140,20 @@ nixPath = annotateLocation1 $ token $ fmap (mkPathF False) $ ((++)
<?> "path"
nixLet :: Parser NExprLoc
nixLet = annotateLocation1 $ NLet
<$> (reserved "let" *> nixBinders)
<*> (whiteSpace *> reserved "in" *> nixExprLoc)
<?> "let"
nixLet = annotateLocation1 $ reserved "let"
*> whiteSpace
*> (letBody <|> letBinders)
<?> "let block"
where
letBinders = NLet
<$> nixBinders
<*> (whiteSpace *> reserved "in" *> nixExprLoc)
-- Let expressions `let {..., body = ...}' are just desugared
-- into `(rec {..., body = ...}).body'.
letBody = (\x -> NSelect x ([StaticKey "body"]) Nothing) <$> aset
aset = annotateLocation1 $ NRecSet
<$> (braces nixBinders)
nixIf :: Parser NExprLoc
nixIf = annotateLocation1 $ NIf

View File

@ -184,6 +184,13 @@ case_simple_let = do
where
binds = [NamedVar (mkSelector "a") $ mkInt 4]
case_let_body :: Assertion
case_let_body = do
assertParseString "let { body = 1; }" letBody
where
letBody = Fix $ NSelect aset (mkSelector "body") Nothing
aset = Fix $ NRecSet [NamedVar (mkSelector "body") (mkInt 1)]
case_nested_let :: Assertion
case_nested_let = do
assertParseString "let a = 4; in let b = 5; in a" $ Fix $ NLet