error.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #pragma once
  2. #include "namedict.h"
  3. #include "str.h"
  4. #include "tuplelist.h"
  5. namespace pkpy{
  6. struct NeedMoreLines {
  7. NeedMoreLines(bool is_compiling_class) : is_compiling_class(is_compiling_class) {}
  8. bool is_compiling_class;
  9. };
  10. struct HandledException {};
  11. struct UnhandledException {};
  12. struct ToBeRaisedException {};
  13. enum CompileMode {
  14. EXEC_MODE,
  15. EVAL_MODE,
  16. REPL_MODE,
  17. JSON_MODE,
  18. CELL_MODE
  19. };
  20. struct SourceData {
  21. std::string source;
  22. Str filename;
  23. std::vector<const char*> line_starts;
  24. CompileMode mode;
  25. SourceData(const SourceData&) = delete;
  26. SourceData& operator=(const SourceData&) = delete;
  27. SourceData(const Str& source, const Str& filename, CompileMode mode);
  28. std::pair<const char*,const char*> get_line(int lineno) const;
  29. Str snapshot(int lineno, const char* cursor=nullptr, std::string_view name="");
  30. };
  31. struct Exception {
  32. StrName type;
  33. Str msg;
  34. bool is_re;
  35. stack<Str> stacktrace;
  36. int _ip_on_error;
  37. void* _code_on_error;
  38. Exception(StrName type, Str msg): type(type), msg(msg), is_re(true), _ip_on_error(-1), _code_on_error(nullptr) {}
  39. bool match_type(StrName t) const { return this->type == t;}
  40. void st_push(Str&& snapshot);
  41. Str summary() const;
  42. };
  43. } // namespace pkpy