Skip to content

Commit

Permalink
Correct location annotation for parenthesized expressions
Browse files Browse the repository at this point in the history
At the moment parentheses are not included in the location annotation
for nix expressions. This changes the code to include any parentheses in
the SrcSpan of the underlying expression. Information which is difficult
to recover otherwise.
  • Loading branch information
expipiplus1 committed Oct 29, 2020
1 parent 4202bac commit cbe995c
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/Nix/Parser.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ import Data.Char ( isAlpha
, isSpace
)
import Data.Data ( Data(..) )
import Data.Fix ( Fix(..) )
import Data.Functor
import Data.Functor.Identity
import Data.HashSet ( HashSet )
Expand Down Expand Up @@ -195,8 +196,11 @@ nixBool =
nixNull :: Parser NExprLoc
nixNull = annotateLocation1 (mkNullF <$ reserved "null" <?> "null")

-- | 'nixTopLevelForm' returns an expression annotated with a source position,
-- however this position doesn't include the parsed parentheses, so remove the
-- "inner" location annotateion and annotate again, including the parentheses.
nixParens :: Parser NExprLoc
nixParens = parens nixToplevelForm <?> "parens"
nixParens = annotateLocation1 (stripAnn . unFix <$> (parens nixToplevelForm <?> "parens"))

nixList :: Parser NExprLoc
nixList = annotateLocation1 (brackets (NList <$> many nixTerm) <?> "list")
Expand Down

0 comments on commit cbe995c

Please sign in to comment.