You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

70 lines
1.8 KiB

2 months ago
  1. #ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  2. #define TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
  3. #if defined(_MSC_VER) || \
  4. (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
  5. (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
  6. #pragma once
  7. #endif
  8. #include "yaml-cpp/mark.h"
  9. #include <iostream>
  10. #include <string>
  11. #include <vector>
  12. namespace YAML {
  13. const std::string TokenNames[] = {
  14. "DIRECTIVE", "DOC_START", "DOC_END", "BLOCK_SEQ_START",
  15. "BLOCK_MAP_START", "BLOCK_SEQ_END", "BLOCK_MAP_END", "BLOCK_ENTRY",
  16. "FLOW_SEQ_START", "FLOW_MAP_START", "FLOW_SEQ_END", "FLOW_MAP_END",
  17. "FLOW_MAP_COMPACT", "FLOW_ENTRY", "KEY", "VALUE",
  18. "ANCHOR", "ALIAS", "TAG", "SCALAR"};
  19. struct Token {
  20. // enums
  21. enum STATUS { VALID, INVALID, UNVERIFIED };
  22. enum TYPE {
  23. DIRECTIVE,
  24. DOC_START,
  25. DOC_END,
  26. BLOCK_SEQ_START,
  27. BLOCK_MAP_START,
  28. BLOCK_SEQ_END,
  29. BLOCK_MAP_END,
  30. BLOCK_ENTRY,
  31. FLOW_SEQ_START,
  32. FLOW_MAP_START,
  33. FLOW_SEQ_END,
  34. FLOW_MAP_END,
  35. FLOW_MAP_COMPACT,
  36. FLOW_ENTRY,
  37. KEY,
  38. VALUE,
  39. ANCHOR,
  40. ALIAS,
  41. TAG,
  42. PLAIN_SCALAR,
  43. NON_PLAIN_SCALAR
  44. };
  45. // data
  46. Token(TYPE type_, const Mark& mark_)
  47. : status(VALID), type(type_), mark(mark_), value{}, params{}, data(0) {}
  48. friend std::ostream& operator<<(std::ostream& out, const Token& token) {
  49. out << TokenNames[token.type] << std::string(": ") << token.value;
  50. for (const std::string& param : token.params)
  51. out << std::string(" ") << param;
  52. return out;
  53. }
  54. STATUS status;
  55. TYPE type;
  56. Mark mark;
  57. std::string value;
  58. std::vector<std::string> params;
  59. int data;
  60. };
  61. } // namespace YAML
  62. #endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66