on master help sign in
Clean up iWarn a bit more
1dc09acJason Felice
src/Idris/Output.hs+26−10
@@ -82,19 +82,35 @@ iWarn fc err =
82
82
83 layoutSource :: FC -> String -> Maybe OutputDoc
83 layoutSource :: FC -> String -> Maybe OutputDoc
84 layoutSource (FC fn (si, sj) (ei, ej)) src =
84 layoutSource (FC fn (si, sj) (ei, ej)) src =
85− if isJust sourceLine
85+ if haveSource
86− then Just . string $ top ++ "\n" ++ formattedLine ++ "\n" ++ bottom
86+ then Just (string source)
87 else Nothing
87 else Nothing
88 where
88 where
89+ sourceLine :: Maybe String
89 sourceLine = listToMaybe . drop (si - 1) . lines $ src
90 sourceLine = listToMaybe . drop (si - 1) . lines $ src
91+
92+ haveSource :: Bool
93+ haveSource = isJust sourceLine
94+
95+ line1 :: String
96+ line1 = replicate (length (show si)) ' ' ++ " |"
97+
98+ line2 :: String
90− formattedLine = show si ++ " | " ++ fromJust sourceLine
99+ line2 = show si ++ " | " ++ fromJust sourceLine
91− top = take (length (show si)) (repeat ' ') ++ " |"
100+
101+ highlight :: String
102+ highlight = replicate (end - sj + 1) ch ++ ellipsis
103+ where
92− indicator = case (si == ei, sj == ej) of
104+ (end, ch, ellipsis) = case (si == ei, sj == ej) of
93− (True , True ) -> "^"
105+ (True , True ) -> (ej, '^', "")
94− (True , False) -> squiggles (ej - sj + 1)
106+ (True , False) -> (ej, '~', "")
95− (False, _ ) -> squiggles (length (fromJust sourceLine) - sj + 1) ++ " ..."
107+ (False, _ ) -> (length (fromJust sourceLine), '~', " ...")
96− bottom = top ++ " " ++ (take (sj - 1) (repeat ' ')) ++ indicator
108+
97− squiggles n = take n (repeat '~')
109+ line3 :: String
110+ line3 = line1 ++ " " ++ replicate (sj - 1) ' ' ++ highlight
111+
112+ source :: String
113+ source = line1 ++ "\n" ++ line2 ++ "\n" ++ line3
98 layoutSource _ _ = Nothing
114 layoutSource _ _ = Nothing
99
115
100 layoutWarning :: OutputDoc -> Maybe OutputDoc -> OutputDoc -> OutputDoc
116 layoutWarning :: OutputDoc -> Maybe OutputDoc -> OutputDoc -> OutputDoc