From e8e129a7592adb6164b051d84238a31059207fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benno=20F=C3=BCnfst=C3=BCck?= Date: Wed, 13 Aug 2014 22:35:51 +0200 Subject: [PATCH] factor out "inherit" keyword in binding parser When parsing '{ inherit a; }' without this fix, the `scopedInherit` parser would be tried first. Because this parser already consumes the `inherit` keyword, it won't backtrack anymore and the non-scoped `inherit` parser will never be tried, so we get a parse failure which is of course not correct. The solution is to first parse `inherit` (in both cases) and then decide whether it is a scoped import or not by looking for a following '('. --- Nix/Parser.hs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Nix/Parser.hs b/Nix/Parser.hs index af11e38..15bfb46 100644 --- a/Nix/Parser.hs +++ b/Nix/Parser.hs @@ -133,10 +133,14 @@ argExpr = (try (Fix . NArgs . FormalSet <$> paramSet) <*> optional (symbolic '?' *> nixExpr False) nixBinders :: Parser [Binding NExpr] -nixBinders = (scopedInherit <|> inherit <|> namedVar) `endBy` symbolic ';' where - scopedInherit = (reserved "inherit" *> whiteSpace *> symbolic '(') *> +nixBinders = choice + [ reserved "inherit" *> whiteSpace *> (scopedInherit <|> inherit) "inherited binding" + , namedVar + ] `endBy` symbolic ';' + where + scopedInherit = try (symbolic '(') *> (ScopedInherit <$> nixExpr False <* symbolic ')' <*> many keyName) "scoped inherit binding" - inherit = Inherit <$> (reserved "inherit" *> many keyName) "inherited binding" + inherit = Inherit <$> many keyName namedVar = NamedVar <$> keyName <*> (symbolic '=' *> nixApp) "variable binding" keyName :: Parser NExpr