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