@@ -5,6 +5,8 @@ import Data.Aeson ((.=))
5import qualified Data.Aeson as Json
5import qualified Data.Aeson as Json
6import qualified Text.Parsec.Pos as Parsec
6import qualified Text.Parsec.Pos as Parsec
8+import Elm.Utils ((|>))
9data Region = Region
11data Region = Region
10 { start :: Position
12 { start :: Position
@@ -55,6 +57,62 @@ toPrettyString (Region start end) =
55 ++ show (column start) ++ " to " ++ show (column end)
57 ++ show (column start) ++ " to " ++ show (column end)
60+-- EXTRACT REGION from SOURCE with LINE NUMBERS
62+select :: Region -> String -> String
63+select (Region start end) source =
68+ |> take (line end - line start)
70+ case relevantLines of
72+ error "something has gone badly wrong with reporting source locations"
76+ lineNumber = show (line start) ++ "|"
81+ ++ replicate (column start + length lineNumber) ' '
82+ ++ replicate (column end - column start) '^'
88+ replicate (column start) ' ' ++ drop (column start) firstLine
91+ take (column end) (last rest)
93+ focusedRelevantLines =
94+ filteredFirstLine : init rest ++ [filteredLastLine]
97+ length (show (line end))
101+ (addLineNumber lineNumbersWidth)
102+ [line start .. line end]
103+ focusedRelevantLines
105+ unlines numberedLines
108+addLineNumber :: Int -> Int -> String -> String
109+addLineNumber width n line =
113+ replicate (width - length number) ' ' ++ number ++ "|" ++ line
60instance Json.ToJSON Region where
118instance Json.ToJSON Region where