Parse if then else
This commit is contained in:
parent
f5ab0e5be4
commit
051e8fffc2
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue