Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide proper error location for antiquotations, turning big. #959

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 26 additions & 16 deletions src/Nix/Exec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import Nix.Convert
import Nix.Effects
import Nix.Eval as Eval
import Nix.Expr
import Nix.Expr.Strings ( runAntiquoted )
import Nix.Frames
import Nix.Options
import Nix.Pretty
Expand Down Expand Up @@ -190,22 +191,31 @@ instance MonadNix e t f m => MonadEval (NValue t f m) m where
span <- currentPos
pure $ nvConstantP (Provenance scope $ NConstant_ span c) c

evalString =
maybe
(nverr $ ErrorCall "Failed to assemble string")
(\ ns ->
do
scope <- currentScopes
span <- currentPos
pure $
nvStrP
(Provenance
scope
(NStr_ span $ DoubleQuoted [Plain $ stringIgnoreContext ns])
)
ns
)
<=< assembleString
evalString v =
do
scope <- currentScopes
span <- currentPos
ns <- assembleString v
pure $
nvStrP
(Provenance
scope
(NStr_ span $ DoubleQuoted [Plain $ stringIgnoreContext ns])
)
ns
where
-- XXX: A mere copy of the code from Nix.Eval
-- But this one fails properly at the right antiquotation.
assembleString =
(mconcat <$>) . traverse go . \case
Indented _ parts -> parts
DoubleQuoted parts -> parts

go =
runAntiquoted
"\n"
(pure . makeNixStringWithoutContext)
(fromValue =<<)

evalLiteralPath p = do
scope <- currentScopes
Expand Down
2 changes: 1 addition & 1 deletion src/Nix/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ nixString' = lexeme (doubleQuoted <+> indented <?> "string")

stringChar end escStart esc =
Antiquoted <$>
(antiStart *> nixToplevelForm <* char '}')
(annotateLocation1 $ NStr . DoubleQuoted . one . Antiquoted <$> lexeme (antiStart *> nixToplevelForm <* char '}'))
<+> Plain . one <$>
char '$' <+> esc <+> Plain . toText <$>
some plainChar
Expand Down