scide: implement selectionLength for openDocument
[supercollider.git] / external_libraries / yaml-cpp-0.3.0 / src / exp.h
blob3e12aba480c536ba9926b9699525f894e0c6e2d4
1 #ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
2 #define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
4 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
5 #pragma once
6 #endif
9 #include "regex.h"
10 #include <string>
11 #include <ios>
12 #include "stream.h"
14 namespace YAML
16 ////////////////////////////////////////////////////////////////////////////////
17 // Here we store a bunch of expressions for matching different parts of the file.
19 namespace Exp
21 // misc
22 inline const RegEx& Space() {
23 static const RegEx e = RegEx(' ');
24 return e;
26 inline const RegEx& Tab() {
27 static const RegEx e = RegEx('\t');
28 return e;
30 inline const RegEx& Blank() {
31 static const RegEx e = Space() || Tab();
32 return e;
34 inline const RegEx& Break() {
35 static const RegEx e = RegEx('\n') || RegEx("\r\n");
36 return e;
38 inline const RegEx& BlankOrBreak() {
39 static const RegEx e = Blank() || Break();
40 return e;
42 inline const RegEx& Digit() {
43 static const RegEx e = RegEx('0', '9');
44 return e;
46 inline const RegEx& Alpha() {
47 static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
48 return e;
50 inline const RegEx& AlphaNumeric() {
51 static const RegEx e = Alpha() || Digit();
52 return e;
54 inline const RegEx& Word() {
55 static const RegEx e = AlphaNumeric() || RegEx('-');
56 return e;
58 inline const RegEx& Hex() {
59 static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
60 return e;
62 // Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. 5.1)
63 inline const RegEx& NotPrintable() {
64 static const RegEx e = RegEx(0) ||
65 RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) ||
66 RegEx(0x0E, 0x1F) ||
67 (RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
68 return e;
70 inline const RegEx& Utf8_ByteOrderMark() {
71 static const RegEx e = RegEx("\xEF\xBB\xBF");
72 return e;
75 // actual tags
77 inline const RegEx& DocStart() {
78 static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
79 return e;
81 inline const RegEx& DocEnd() {
82 static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
83 return e;
85 inline const RegEx& DocIndicator() {
86 static const RegEx e = DocStart() || DocEnd();
87 return e;
89 inline const RegEx& BlockEntry() {
90 static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
91 return e;
93 inline const RegEx& Key() {
94 static const RegEx e = RegEx('?');
95 return e;
97 inline const RegEx& KeyInFlow() {
98 static const RegEx e = RegEx('?') + BlankOrBreak();
99 return e;
101 inline const RegEx& Value() {
102 static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
103 return e;
105 inline const RegEx& ValueInFlow() {
106 static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
107 return e;
109 inline const RegEx& ValueInJSONFlow() {
110 static const RegEx e = RegEx(':');
111 return e;
113 inline const RegEx Comment() {
114 static const RegEx e = RegEx('#');
115 return e;
117 inline const RegEx& Anchor() {
118 static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
119 return e;
121 inline const RegEx& AnchorEnd() {
122 static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
123 return e;
125 inline const RegEx& URI() {
126 static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) || (RegEx('%') + Hex() + Hex());
127 return e;
129 inline const RegEx& Tag() {
130 static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'", REGEX_OR) || (RegEx('%') + Hex() + Hex());
131 return e;
134 // Plain scalar rules:
135 // . Cannot start with a blank.
136 // . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
137 // . In the block context - ? : must be not be followed with a space.
138 // . In the flow context ? is illegal and : and - must not be followed with a space.
139 inline const RegEx& PlainScalar() {
140 static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
141 return e;
143 inline const RegEx& PlainScalarInFlow() {
144 static const RegEx e = !(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank()));
145 return e;
147 inline const RegEx& EndScalar() {
148 static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
149 return e;
151 inline const RegEx& EndScalarInFlow() {
152 static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
153 return e;
156 inline const RegEx& EscSingleQuote() {
157 static const RegEx e = RegEx("\'\'");
158 return e;
160 inline const RegEx& EscBreak() {
161 static const RegEx e = RegEx('\\') + Break();
162 return e;
165 inline const RegEx& ChompIndicator() {
166 static const RegEx e = RegEx("+-", REGEX_OR);
167 return e;
169 inline const RegEx& Chomp() {
170 static const RegEx e = (ChompIndicator() + Digit()) || (Digit() + ChompIndicator()) || ChompIndicator() || Digit();
171 return e;
174 // and some functions
175 std::string Escape(Stream& in);
178 namespace Keys
180 const char Directive = '%';
181 const char FlowSeqStart = '[';
182 const char FlowSeqEnd = ']';
183 const char FlowMapStart = '{';
184 const char FlowMapEnd = '}';
185 const char FlowEntry = ',';
186 const char Alias = '*';
187 const char Anchor = '&';
188 const char Tag = '!';
189 const char LiteralScalar = '|';
190 const char FoldedScalar = '>';
191 const char VerbatimTagStart = '<';
192 const char VerbatimTagEnd = '>';
196 #endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66