66module Update.Span
77 ( SpanUpdate (.. )
88 , SrcSpan (.. )
9- , SourcePos (.. )
9+ , NSourcePos (.. )
1010 , updateSpan
1111 , updateSpans
1212 , linearizeSourcePos
@@ -25,7 +25,11 @@ import Data.Text ( Text
2525 , lines
2626 , splitAt
2727 )
28- import Nix.Expr.Types.Annotated
28+ import Nix.Expr.Types ( NPos (.. )
29+ , NSourcePos (.. )
30+ , unPos
31+ )
32+ import Nix.Expr.Types.Annotated ( SrcSpan (.. ) )
2933import Prelude hiding ( length
3034 , lines
3135 , splitAt
@@ -42,7 +46,7 @@ data SpanUpdate = SpanUpdate
4246-- | Update many spans in a file. They must be non-overlapping.
4347updateSpans :: [SpanUpdate ] -> Text -> Text
4448updateSpans us t =
45- let sortedSpans = sortOn (spanBegin . spanUpdateSpan) us
49+ let sortedSpans = sortOn (getSpanBegin . spanUpdateSpan) us
4650 anyOverlap =
4751 any (uncurry overlaps) (zip <*> tail $ spanUpdateSpan <$> sortedSpans)
4852 in assert (not anyOverlap) (foldr updateSpan t sortedSpans)
@@ -60,9 +64,9 @@ overlaps :: SrcSpan -> SrcSpan -> Bool
6064overlaps (SrcSpan b1 e1) (SrcSpan b2 e2) =
6165 b2 >= b1 && b2 < e1 || e2 >= b1 && e2 < e1
6266
63- -- | Split some text at a particular 'SourcePos '
64- split :: SourcePos -> Text -> (Text , Text )
65- split (SourcePos _ row col) t = splitAt
67+ -- | Split some text at a particular 'NSourcePos '
68+ split :: NSourcePos -> Text -> (Text , Text )
69+ split (NSourcePos _ ( NPos row) ( NPos col) ) t = splitAt
6670 (fromIntegral
6771 (linearizeSourcePos t
6872 (fromIntegral (unPos row - 1 ))
@@ -84,6 +88,6 @@ linearizeSourcePos t l c = fromIntegral lineCharOffset + c
8488 where
8589 lineCharOffset = sum . fmap ((+ 1 ) . length ) . genericTake l . lines $ t
8690
87- prettyPrintSourcePos :: SourcePos -> String
88- prettyPrintSourcePos (SourcePos _ row column) =
91+ prettyPrintSourcePos :: NSourcePos -> String
92+ prettyPrintSourcePos (NSourcePos _ ( NPos row) ( NPos column) ) =
8993 show (unPos row) <> " :" <> show (unPos column)
0 commit comments