Skip to content

Commit dba7650

Browse files
expipiplus1Anton-Latukha
authored andcommitted
Correct location annotation for parenthesized expressions
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.
1 parent 4202bac commit dba7650

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/Nix/Parser.hs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ import Data.Char ( isAlpha
5858
, isSpace
5959
)
6060
import Data.Data ( Data(..) )
61+
import Data.Fix ( Fix(..) )
6162
import Data.Functor
6263
import Data.Functor.Identity
6364
import Data.HashSet ( HashSet )
@@ -195,8 +196,11 @@ nixBool =
195196
nixNull :: Parser NExprLoc
196197
nixNull = annotateLocation1 (mkNullF <$ reserved "null" <?> "null")
197198

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

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

0 commit comments

Comments
 (0)