2023-03-31 13:27:38 -04:00
|
|
|
module Quox.Parser.FromParser.Error
|
|
|
|
|
|
|
|
import Quox.Parser.Parser
|
|
|
|
import Quox.Typing
|
|
|
|
import System.File
|
|
|
|
|
|
|
|
import Quox.Pretty
|
|
|
|
|
|
|
|
|
2023-04-24 17:19:15 -04:00
|
|
|
public export
|
|
|
|
TypeError, LexError, ParseError : Type
|
|
|
|
TypeError = Typing.Error
|
|
|
|
LexError = Lexer.Error
|
|
|
|
ParseError = Parser.Error
|
|
|
|
%hide Typing.Error
|
|
|
|
%hide Lexer.Error
|
|
|
|
%hide Parser.Error
|
|
|
|
|
2023-03-31 13:27:38 -04:00
|
|
|
public export
|
|
|
|
data Error =
|
2023-05-01 21:06:25 -04:00
|
|
|
AnnotationNeeded Loc (NameContexts d n) (Term d n)
|
|
|
|
| DuplicatesInEnum Loc (List TagVal)
|
|
|
|
| TermNotInScope Loc Name
|
|
|
|
| DimNotInScope Loc PBaseName
|
|
|
|
| QtyNotGlobal Loc Qty
|
|
|
|
| DimNameInTerm Loc PBaseName
|
2023-04-24 17:19:15 -04:00
|
|
|
| WrapTypeError TypeError
|
2023-05-01 21:06:25 -04:00
|
|
|
| LoadError Loc String FileError
|
2023-04-24 17:19:15 -04:00
|
|
|
| WrapParseError String ParseError
|
2023-03-31 13:27:38 -04:00
|
|
|
|
|
|
|
|
|
|
|
parameters (unicode, showContext : Bool)
|
2023-04-24 17:19:15 -04:00
|
|
|
export
|
|
|
|
prettyParseError1 : String -> ParsingError _ -> Doc HL
|
|
|
|
prettyParseError1 file (Error msg Nothing) =
|
|
|
|
pretty msg
|
|
|
|
prettyParseError1 file (Error msg (Just bounds)) =
|
2023-05-01 21:06:25 -04:00
|
|
|
hsep [prettyLoc $ makeLoc file bounds, pretty msg]
|
2023-04-24 17:19:15 -04:00
|
|
|
|
|
|
|
export
|
|
|
|
prettyParseError : String -> ParseError -> Doc HL
|
|
|
|
prettyParseError file (LexError err) =
|
|
|
|
vsep ["lexical error:", nest 2 $ pretty $ show err]
|
|
|
|
prettyParseError file (ParseError errs) =
|
|
|
|
vsep $ "parse error:" ::
|
|
|
|
map (("-" <++>) . prettyParseError1 file) (toList errs)
|
|
|
|
|
2023-03-31 13:27:38 -04:00
|
|
|
export
|
|
|
|
prettyError : Error -> Doc HL
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (AnnotationNeeded loc ctx tm) =
|
|
|
|
sep [prettyLoc loc <++> "the term",
|
|
|
|
prettyTerm unicode ctx.dnames ctx.tnames tm,
|
2023-03-31 13:27:38 -04:00
|
|
|
"needs a type annotation"]
|
2023-04-18 16:55:23 -04:00
|
|
|
-- [todo] print the original PTerm instead
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (DuplicatesInEnum loc tags) =
|
|
|
|
sep [prettyLoc loc <++> "duplicate tags in enum type",
|
|
|
|
braces $ fillSep $ map pretty tags]
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (DimNotInScope loc i) =
|
|
|
|
sep [prettyLoc loc <++> "dimension",
|
|
|
|
pretty0 unicode $ DV $ fromString i, "not in scope"]
|
2023-04-18 16:55:23 -04:00
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (TermNotInScope loc x) =
|
|
|
|
sep [prettyLoc loc <++> "term variable",
|
|
|
|
hl Free $ pretty0 unicode x, "not in scope"]
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (QtyNotGlobal loc pi) =
|
|
|
|
sep [prettyLoc loc <++> "quantity", pretty0 unicode pi,
|
2023-03-31 13:27:38 -04:00
|
|
|
"can't be used on a top level declaration"]
|
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (DimNameInTerm loc i) =
|
|
|
|
sep [prettyLoc loc <++> "dimension variable",
|
|
|
|
pretty0 unicode $ DV $ fromString i, "used in a term context"]
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-04-24 17:19:15 -04:00
|
|
|
prettyError (WrapTypeError err) =
|
2023-04-18 16:55:23 -04:00
|
|
|
Typing.prettyError unicode showContext $ trimContext 2 err
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-05-01 21:06:25 -04:00
|
|
|
prettyError (LoadError loc str err) =
|
|
|
|
vsep [hsep [prettyLoc loc, "couldn't load file", pretty str],
|
|
|
|
fromString $ show err]
|
2023-03-31 13:27:38 -04:00
|
|
|
|
2023-04-24 17:19:15 -04:00
|
|
|
prettyError (WrapParseError file err) =
|
|
|
|
prettyParseError file err
|