token.h 1.52 KB
Newer Older
1
2
#pragma once

jbeder's avatar
jbeder committed
3
4
5
6
#ifndef TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66
#define TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66


7
#include "mark.h"
jbeder's avatar
jbeder committed
8
#include <iostream>
9
10
11
12
13
14
15
16
17
18
19
#include <string>
#include <vector>

namespace YAML
{
	const std::string TokenNames[] = {
		"DIRECTIVE",
		"DOC_START",
		"DOC_END",
		"BLOCK_SEQ_START",
		"BLOCK_MAP_START",
20
21
		"BLOCK_SEQ_END",
		"BLOCK_MAP_END",
22
23
24
25
26
		"BLOCK_ENTRY",
		"FLOW_SEQ_START",
		"FLOW_MAP_START",
		"FLOW_SEQ_END",
		"FLOW_MAP_END",
27
		"FLOW_MAP_COMPACT",
28
29
30
31
32
33
		"FLOW_ENTRY",
		"KEY",
		"VALUE",
		"ANCHOR",
		"ALIAS",
		"TAG",
jbeder's avatar
jbeder committed
34
		"SCALAR"
35
36
37
	};

	struct Token {
jbeder's avatar
jbeder committed
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
		// enums
		enum STATUS { VALID, INVALID, UNVERIFIED };
		enum TYPE {
			DIRECTIVE,
			DOC_START,
			DOC_END,
			BLOCK_SEQ_START,
			BLOCK_MAP_START,
			BLOCK_SEQ_END,
			BLOCK_MAP_END,
			BLOCK_ENTRY,
			FLOW_SEQ_START,
			FLOW_MAP_START,
			FLOW_SEQ_END,
			FLOW_MAP_END,
53
			FLOW_MAP_COMPACT,
jbeder's avatar
jbeder committed
54
55
56
57
58
59
60
61
			FLOW_ENTRY,
			KEY,
			VALUE,
			ANCHOR,
			ALIAS,
			TAG,
			SCALAR
		};
62
63
		
		static const std::string PLAIN_SCALAR;
jbeder's avatar
jbeder committed
64
65
				
		// data
66
		Token(TYPE type_, const Mark& mark_): status(VALID), type(type_), mark(mark_), data(0) {}
67
68
69

		friend std::ostream& operator << (std::ostream& out, const Token& token) {
			out << TokenNames[token.type] << std::string(": ") << token.value;
70
			for(std::size_t i=0;i<token.params.size();i++)
71
72
73
74
				out << std::string(" ") << token.params[i];
			return out;
		}

jbeder's avatar
jbeder committed
75
76
		STATUS status;
		TYPE type;
77
		Mark mark;
78
79
		std::string value;
		std::vector <std::string> params;
80
		int data;
81
82
	};
}
jbeder's avatar
jbeder committed
83
84

#endif // TOKEN_H_62B23520_7C8E_11DE_8A39_0800200C9A66