Parse if then else

This commit is contained in:
Luca Bruno 2014-07-04 14:39:11 +02:00
parent f5ab0e5be4
commit 051e8fffc2
1 changed files with 8 additions and 1 deletions

View File

@ -18,7 +18,7 @@ import Prelude hiding (elem)
nixApp :: Parser NExpr
nixApp = go <$>
someTill (whiteSpace *> nixExpr True)
(try (lookAhead (() <$ oneOf "=,;])}" <|> eof)))
(try (lookAhead (() <$ oneOf "=,;])}" <|> reserved "then" <|> reserved "else" <|> eof)))
where
go [] = error "some has failed us"
go [x] = x
@ -57,6 +57,7 @@ nixTerm allowLambdas = choice
, nixList
, nixPath
, nixLet
, nixIf
, setLambdaStringOrSym allowLambdas
]
@ -83,6 +84,12 @@ nixLet = (Fix .) . NLet
<$> (reserved "let" *> nixBinders)
<*> (whiteSpace *> reserved "in" *> nixApp)
nixIf :: Parser NExpr
nixIf = Fix <$> (NIf
<$> (reserved "if" *> nixApp)
<*> (reserved "then" *> nixApp)
<*> (reserved "else" *> nixApp))
-- | This is a bit tricky because we don't know whether we're looking at a set
-- or a lambda until we've looked ahead a bit. And then it may be neither,
-- in which case we fall back to expected a plain string or identifier.