From dba7650bc571360521b8d6729a0c85702afe1807 Mon Sep 17 00:00:00 2001 From: Joe Hermaszewski Date: Fri, 16 Oct 2020 19:13:03 +0800 Subject: [PATCH] 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. --- src/Nix/Parser.hs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Nix/Parser.hs b/src/Nix/Parser.hs index a3b43cc..1ef4d3d 100644 --- a/src/Nix/Parser.hs +++ b/src/Nix/Parser.hs @@ -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 ) @@ -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")