yaml-cpp

FORK: A YAML parser and emitter in C++
git clone https://git.neptards.moe/neptards/yaml-cpp.git
Log | Files | Refs | README | LICENSE

token.h (1858B)


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