on master help sign in
Clean up iWarn a bit more
commit1dc09ac7f122829152579bca681c8ebf1c87e12f authorJason Felice <jason.m.felice@gmail.com> dateThu 7 Dec 2017, 10:36 (9 years ago) parentf743272
1 file changed+26−10
src/Idris/Output.hs+26−10
src/Idris/Output.hs+26−10
@@ -82,19 +82,35 @@ iWarn fc err =
8282
8383 layoutSource :: FC -> String -> Maybe OutputDoc
8484 layoutSource (FC fn (si, sj) (ei, ej)) src =
85− if isJust sourceLine
86− then Just . string $ top ++ "\n" ++ formattedLine ++ "\n" ++ bottom
85+ if haveSource
86+ then Just (string source)
8787 else Nothing
8888 where
89+ sourceLine :: Maybe String
8990 sourceLine = listToMaybe . drop (si - 1) . lines $ src
90− formattedLine = show si ++ " | " ++ fromJust sourceLine
91− top = take (length (show si)) (repeat ' ') ++ " |"
92− indicator = case (si == ei, sj == ej) of
93− (True , True ) -> "^"
94− (True , False) -> squiggles (ej - sj + 1)
95− (False, _ ) -> squiggles (length (fromJust sourceLine) - sj + 1) ++ " ..."
96− bottom = top ++ " " ++ (take (sj - 1) (repeat ' ')) ++ indicator
97− squiggles n = take n (repeat '~')
91+
92+ haveSource :: Bool
93+ haveSource = isJust sourceLine
94+
95+ line1 :: String
96+ line1 = replicate (length (show si)) ' ' ++ " |"
97+
98+ line2 :: String
99+ line2 = show si ++ " | " ++ fromJust sourceLine
100+
101+ highlight :: String
102+ highlight = replicate (end - sj + 1) ch ++ ellipsis
103+ where
104+ (end, ch, ellipsis) = case (si == ei, sj == ej) of
105+ (True , True ) -> (ej, '^', "")
106+ (True , False) -> (ej, '~', "")
107+ (False, _ ) -> (length (fromJust sourceLine), '~', " ...")
108+
109+ line3 :: String
110+ line3 = line1 ++ " " ++ replicate (sj - 1) ' ' ++ highlight
111+
112+ source :: String
113+ source = line1 ++ "\n" ++ line2 ++ "\n" ++ line3
98114 layoutSource _ _ = Nothing
99115
100116 layoutWarning :: OutputDoc -> Maybe OutputDoc -> OutputDoc -> OutputDoc