-
Notifications
You must be signed in to change notification settings - Fork 14
/
hnix.patch
82 lines (77 loc) · 2.21 KB
/
hnix.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
diff --git a/src/Nix/Parser.hs b/src/Nix/Parser.hs
index 0a820b8..7e0a4d2 100644
--- a/src/Nix/Parser.hs
+++ b/src/Nix/Parser.hs
@@ -609,9 +609,10 @@ annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
annotateLocation p =
do
begin <- getSourcePos
+ res <- p
end <- get -- The state set before the last whitespace
- Ann (SrcSpan begin end) <$> p
+ pure $ Ann (SrcSpan begin end) res
annotateLocation1 :: Parser (NExprF NExprLoc) -> Parser NExprLoc
annotateLocation1 = fmap annToAnnF . annotateLocation
diff --git a/tests/ParserTests.hs b/tests/ParserTests.hs
index 0b50cf6..5720999 100644
--- a/tests/ParserTests.hs
+++ b/tests/ParserTests.hs
@@ -357,6 +357,42 @@ in null|] [text|let
in (matcher.case or null).foo (v.case);
in null|]
+case_simpleLoc =
+ let
+ mkSPos l c = SourcePos "<string>" (mkPos l) (mkPos c)
+ mkSpan l1 c1 l2 c2 = SrcSpan (mkSPos l1 c1) (mkSPos l2 c2)
+ in
+ assertParseTextLoc [text|let
+ foo = bar
+ baz "qux";
+ in foo
+ |]
+ (Fix
+ (NLet_
+ (mkSpan 1 1 4 7)
+ [ NamedVar
+ (StaticKey "foo" :| [])
+ (Fix
+ (NBinary_
+ (mkSpan 2 7 3 15)
+ NApp
+ (Fix
+ (NBinary_ (mkSpan 2 7 3 9)
+ NApp
+ (Fix (NSym_ (mkSpan 2 7 2 10) "bar"))
+ (Fix (NSym_ (mkSpan 3 6 3 9) "baz"))
+ )
+ )
+ (Fix (NStr_ (mkSpan 3 10 3 15) (DoubleQuoted [Plain "qux"])))
+ )
+ )
+ (mkSPos 2 1)
+ ]
+ (Fix (NSym_ (mkSpan 4 4 4 7) "foo"))
+ )
+ )
+
+
tests :: TestTree
tests = $testGroupGenerator
@@ -375,6 +411,18 @@ assertParseText str expected =
)
(parseNixText str)
+assertParseTextLoc :: Text -> NExprLoc -> Assertion
+assertParseTextLoc str expected =
+ either
+ (\ err ->
+ assertFailure $ toString $ "Unexpected fail parsing `" <> str <> "':\n" <> show err
+ )
+ (assertEqual
+ ("When parsing " <> toString str)
+ expected
+ )
+ (parseNixTextLoc str)
+
assertParseFile :: FilePath -> NExpr -> Assertion
assertParseFile file expected =
do