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 '('.
This commit is contained in:
parent
5d6de23d8c
commit
e8e129a759
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue