Loading [MathJax]/extensions/tex2jax.js
Free Electron
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
exp.h
1 #ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define EXP_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 <ios>
11 #include <string>
12 
13 #include "regex_yaml.h"
14 #include "stream.h"
15 
16 namespace YAML {
17 ////////////////////////////////////////////////////////////////////////////////
18 // Here we store a bunch of expressions for matching different parts of the
19 // file.
20 
21 namespace Exp {
22 // misc
23 inline const RegEx& Empty() {
24  static const RegEx e;
25  return e;
26 }
27 inline const RegEx& Space() {
28  static const RegEx e = RegEx(' ');
29  return e;
30 }
31 inline const RegEx& Tab() {
32  static const RegEx e = RegEx('\t');
33  return e;
34 }
35 inline const RegEx& Blank() {
36  static const RegEx e = Space() | Tab();
37  return e;
38 }
39 inline const RegEx& Break() {
40  static const RegEx e = RegEx('\n') | RegEx("\r\n") | RegEx('\r');
41  return e;
42 }
43 inline const RegEx& BlankOrBreak() {
44  static const RegEx e = Blank() | Break();
45  return e;
46 }
47 inline const RegEx& Digit() {
48  static const RegEx e = RegEx('0', '9');
49  return e;
50 }
51 inline const RegEx& Alpha() {
52  static const RegEx e = RegEx('a', 'z') | RegEx('A', 'Z');
53  return e;
54 }
55 inline const RegEx& AlphaNumeric() {
56  static const RegEx e = Alpha() | Digit();
57  return e;
58 }
59 inline const RegEx& Word() {
60  static const RegEx e = AlphaNumeric() | RegEx('-');
61  return e;
62 }
63 inline const RegEx& Hex() {
64  static const RegEx e = Digit() | RegEx('A', 'F') | RegEx('a', 'f');
65  return e;
66 }
67 // Valid Unicode code points that are not part of c-printable (YAML 1.2, sec.
68 // 5.1)
69 inline const RegEx& NotPrintable() {
70  static const RegEx e =
71  RegEx(0) |
72  RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) |
73  RegEx(0x0E, 0x1F) |
74  (RegEx('\xC2') + (RegEx('\x80', '\x84') | RegEx('\x86', '\x9F')));
75  return e;
76 }
77 inline const RegEx& Utf8_ByteOrderMark() {
78  static const RegEx e = RegEx("\xEF\xBB\xBF");
79  return e;
80 }
81 
82 // actual tags
83 
84 inline const RegEx& DocStart() {
85  static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
86  return e;
87 }
88 inline const RegEx& DocEnd() {
89  static const RegEx e = RegEx("...") + (BlankOrBreak() | RegEx());
90  return e;
91 }
92 inline const RegEx& DocIndicator() {
93  static const RegEx e = DocStart() | DocEnd();
94  return e;
95 }
96 inline const RegEx& BlockEntry() {
97  static const RegEx e = RegEx('-') + (BlankOrBreak() | RegEx());
98  return e;
99 }
100 inline const RegEx& Key() {
101  static const RegEx e = RegEx('?') + BlankOrBreak();
102  return e;
103 }
104 inline const RegEx& KeyInFlow() {
105  static const RegEx e = RegEx('?') + BlankOrBreak();
106  return e;
107 }
108 inline const RegEx& Value() {
109  static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
110  return e;
111 }
112 inline const RegEx& ValueInFlow() {
113  static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx(",]}", REGEX_OR));
114  return e;
115 }
116 inline const RegEx& ValueInJSONFlow() {
117  static const RegEx e = RegEx(':');
118  return e;
119 }
120 inline const RegEx& Ampersand() {
121  static const RegEx e = RegEx('&');
122  return e;
123 }
124 inline const RegEx Comment() {
125  static const RegEx e = RegEx('#');
126  return e;
127 }
128 inline const RegEx& Anchor() {
129  static const RegEx e = !(RegEx("[]{},", REGEX_OR) | BlankOrBreak());
130  return e;
131 }
132 inline const RegEx& AnchorEnd() {
133  static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) | BlankOrBreak();
134  return e;
135 }
136 inline const RegEx& URI() {
137  static const RegEx e = Word() | RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) |
138  (RegEx('%') + Hex() + Hex());
139  return e;
140 }
141 inline const RegEx& Tag() {
142  static const RegEx e = Word() | RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) |
143  (RegEx('%') + Hex() + Hex());
144  return e;
145 }
146 
147 // Plain scalar rules:
148 // . Cannot start with a blank.
149 // . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
150 // . In the block context - ? : must be not be followed with a space.
151 // . In the flow context ? is illegal and : and - must not be followed with a
152 // space.
153 inline const RegEx& PlainScalar() {
154  static const RegEx e =
155  !(BlankOrBreak() | RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) |
156  (RegEx("-?:", REGEX_OR) + (BlankOrBreak() | RegEx())));
157  return e;
158 }
159 inline const RegEx& PlainScalarInFlow() {
160  static const RegEx e =
161  !(BlankOrBreak() | RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) |
162  (RegEx("-:", REGEX_OR) + (Blank() | RegEx())));
163  return e;
164 }
165 inline const RegEx& EndScalar() {
166  static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
167  return e;
168 }
169 inline const RegEx& EndScalarInFlow() {
170  static const RegEx e =
171  (RegEx(':') + (BlankOrBreak() | RegEx() | RegEx(",]}", REGEX_OR))) |
172  RegEx(",?[]{}", REGEX_OR);
173  return e;
174 }
175 
176 inline const RegEx& ScanScalarEndInFlow() {
177  static const RegEx e = (EndScalarInFlow() | (BlankOrBreak() + Comment()));
178  return e;
179 }
180 
181 inline const RegEx& ScanScalarEnd() {
182  static const RegEx e = EndScalar() | (BlankOrBreak() + Comment());
183  return e;
184 }
185 inline const RegEx& EscSingleQuote() {
186  static const RegEx e = RegEx("\'\'");
187  return e;
188 }
189 inline const RegEx& EscBreak() {
190  static const RegEx e = RegEx('\\') + Break();
191  return e;
192 }
193 
194 inline const RegEx& ChompIndicator() {
195  static const RegEx e = RegEx("+-", REGEX_OR);
196  return e;
197 }
198 inline const RegEx& Chomp() {
199  static const RegEx e = (ChompIndicator() + Digit()) |
200  (Digit() + ChompIndicator()) | ChompIndicator() |
201  Digit();
202  return e;
203 }
204 
205 // and some functions
206 std::string Escape(Stream& in);
207 } // namespace Exp
208 
209 namespace Keys {
210 const char Directive = '%';
211 const char FlowSeqStart = '[';
212 const char FlowSeqEnd = ']';
213 const char FlowMapStart = '{';
214 const char FlowMapEnd = '}';
215 const char FlowEntry = ',';
216 const char Alias = '*';
217 const char Anchor = '&';
218 const char Tag = '!';
219 const char LiteralScalar = '|';
220 const char FoldedScalar = '>';
221 const char VerbatimTagStart = '<';
222 const char VerbatimTagEnd = '>';
223 } // namespace Keys
224 } // namespace YAML
225 
226 #endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
Definition: anchor.h:12