diagnostic.hh 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #ifndef RUBY_PARSER_DIAGNOSTIC_HH
  2. #define RUBY_PARSER_DIAGNOSTIC_HH
  3. #include <cstddef>
  4. #include <string>
  5. #include <vector>
  6. #include "token.hh"
  7. #include "diagnostic_class.hh"
  8. namespace ruby_parser {
  9. enum class dlevel {
  10. NOTE = 1,
  11. WARNING = 2,
  12. ERROR = 3,
  13. FATAL = 4,
  14. };
  15. class diagnostic {
  16. public:
  17. struct range {
  18. const size_t beginPos;
  19. const size_t endPos;
  20. range(size_t beginPos, size_t endPos)
  21. : beginPos(beginPos)
  22. , endPos(endPos)
  23. {}
  24. };
  25. private:
  26. dlevel level_;
  27. dclass type_;
  28. range location_;
  29. std::string data_;
  30. public:
  31. diagnostic(dlevel lvl, dclass type, range location, const std::string& data = "")
  32. : level_(lvl)
  33. , type_(type)
  34. , location_(location)
  35. , data_(data)
  36. {}
  37. diagnostic(dlevel lvl, dclass type, const token *token, const std::string& data = "")
  38. : level_(lvl)
  39. , type_(type)
  40. , location_(token->start(), token->end())
  41. , data_(data)
  42. {}
  43. dlevel level() const {
  44. return level_;
  45. }
  46. dclass error_class() const {
  47. return type_;
  48. }
  49. const std::string& data() const {
  50. return data_;
  51. }
  52. const range& location() const {
  53. return location_;
  54. }
  55. };
  56. using diagnostics_t = std::vector<diagnostic>;
  57. }
  58. #endif