38 lines
996 B
Agda
38 lines
996 B
Agda
module Lib.Error
|
|
|
|
import Prelude
|
|
import Lib.Common
|
|
|
|
-- I'll want to get Context / Val in some of these
|
|
-- and a pretty printer in the monad
|
|
data Error
|
|
= E FC String
|
|
| ENotInScope FC String
|
|
| Postpone FC QName String
|
|
|
|
|
|
instance HasFC Error where
|
|
getFC (E x str) = x
|
|
getFC (ENotInScope x _) = x
|
|
getFC (Postpone x k str) = x
|
|
|
|
errorMsg : Error -> String
|
|
errorMsg (E x str) = str
|
|
errorMsg (ENotInScope x nm) = "\{nm} not in scope"
|
|
errorMsg (Postpone x k str) = str
|
|
|
|
showError : (src : String) -> Error -> String
|
|
showError src err =
|
|
let fc = getFC err
|
|
in "ERROR at \{show $ getFC err}: \{errorMsg err}\n" ++ go fc 0 (lines src)
|
|
where
|
|
go : FC → Int → List String → String
|
|
go fc l Nil = ""
|
|
go fc l (x :: xs) =
|
|
if l == fcLine fc then
|
|
let width = fc.bnds.endCol - fc.bnds.startCol in
|
|
" \{x}\n \{padding (fcCol fc) ' '}\{padding width '^'}\n"
|
|
else if fcLine fc - 3 < l then " " ++ x ++ "\n" ++ go fc (l + 1) xs
|
|
else go fc (l + 1) xs
|
|
|