File tree Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Expand file tree Collapse file tree 2 files changed +50
-1
lines changed Original file line number Diff line number Diff line change @@ -609,9 +609,10 @@ annotateLocation :: Parser a -> Parser (Ann SrcSpan a)
609609annotateLocation p =
610610 do
611611 begin <- getSourcePos
612+ res <- p
612613 end <- get -- The state set before the last whitespace
613614
614- Ann (SrcSpan begin end) <$> p
615+ pure $ Ann (SrcSpan begin end) res
615616
616617annotateLocation1 :: Parser (NExprF NExprLoc ) -> Parser NExprLoc
617618annotateLocation1 = fmap annToAnnF . annotateLocation
Original file line number Diff line number Diff line change @@ -357,6 +357,42 @@ in null|] [text|let
357357 in (matcher.case or null).foo (v.case);
358358in null|]
359359
360+ case_simpleLoc =
361+ let
362+ mkSPos l c = SourcePos " <string>" (mkPos l) (mkPos c)
363+ mkSpan l1 c1 l2 c2 = SrcSpan (mkSPos l1 c1) (mkSPos l2 c2)
364+ in
365+ assertParseTextLoc [text |let
366+ foo = bar
367+ baz "qux";
368+ in foo
369+ |]
370+ (Fix
371+ (NLet_
372+ (mkSpan 1 1 4 7 )
373+ [ NamedVar
374+ (StaticKey " foo" :| [] )
375+ (Fix
376+ (NBinary_
377+ (mkSpan 2 7 3 15 )
378+ NApp
379+ (Fix
380+ (NBinary_ (mkSpan 2 7 3 9 )
381+ NApp
382+ (Fix (NSym_ (mkSpan 2 7 2 10 ) " bar" ))
383+ (Fix (NSym_ (mkSpan 3 6 3 9 ) " baz" ))
384+ )
385+ )
386+ (Fix (NStr_ (mkSpan 3 10 3 15 ) (DoubleQuoted [Plain " qux" ])))
387+ )
388+ )
389+ (mkSPos 2 1 )
390+ ]
391+ (Fix (NSym_ (mkSpan 4 4 4 7 ) " foo" ))
392+ )
393+ )
394+
395+
360396tests :: TestTree
361397tests = $ testGroupGenerator
362398
@@ -375,6 +411,18 @@ assertParseText str expected =
375411 )
376412 (parseNixText str)
377413
414+ assertParseTextLoc :: Text -> NExprLoc -> Assertion
415+ assertParseTextLoc str expected =
416+ either
417+ (\ err ->
418+ assertFailure $ toString $ " Unexpected fail parsing `" <> str <> " ':\n " <> show err
419+ )
420+ (assertEqual
421+ (" When parsing " <> toString str)
422+ expected
423+ )
424+ (parseNixTextLoc str)
425+
378426assertParseFile :: FilePath -> NExpr -> Assertion
379427assertParseFile file expected =
380428 do
You can’t perform that action at this time.
0 commit comments