exp.h
Go to the documentation of this file.
1 #ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
2 #define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
3 
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
7 
8 
9 #include "regex.h"
10 #include <string>
11 #include <ios>
12 #include "stream.h"
13 
14 namespace YAML_PM
15 {
17  // Here we store a bunch of expressions for matching different parts of the file.
18 
19  namespace Exp
20  {
21  // misc
22  inline const RegEx& Space() {
23  static const RegEx e = RegEx(' ');
24  return e;
25  }
26  inline const RegEx& Tab() {
27  static const RegEx e = RegEx('\t');
28  return e;
29  }
30  inline const RegEx& Blank() {
31  static const RegEx e = Space() || Tab();
32  return e;
33  }
34  inline const RegEx& Break() {
35  static const RegEx e = RegEx('\n') || RegEx("\r\n");
36  return e;
37  }
38  inline const RegEx& BlankOrBreak() {
39  static const RegEx e = Blank() || Break();
40  return e;
41  }
42  inline const RegEx& Digit() {
43  static const RegEx e = RegEx('0', '9');
44  return e;
45  }
46  inline const RegEx& Alpha() {
47  static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
48  return e;
49  }
50  inline const RegEx& AlphaNumeric() {
51  static const RegEx e = Alpha() || Digit();
52  return e;
53  }
54  inline const RegEx& Word() {
55  static const RegEx e = AlphaNumeric() || RegEx('-');
56  return e;
57  }
58  inline const RegEx& Hex() {
59  static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
60  return e;
61  }
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;
69  }
70  inline const RegEx& Utf8_ByteOrderMark() {
71  static const RegEx e = RegEx("\xEF\xBB\xBF");
72  return e;
73  }
74 
75  // actual tags
76 
77  inline const RegEx& DocStart() {
78  static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
79  return e;
80  }
81  inline const RegEx& DocEnd() {
82  static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
83  return e;
84  }
85  inline const RegEx& DocIndicator() {
86  static const RegEx e = DocStart() || DocEnd();
87  return e;
88  }
89  inline const RegEx& BlockEntry() {
90  static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
91  return e;
92  }
93  inline const RegEx& Key() {
94  static const RegEx e = RegEx('?');
95  return e;
96  }
97  inline const RegEx& KeyInFlow() {
98  static const RegEx e = RegEx('?') + BlankOrBreak();
99  return e;
100  }
101  inline const RegEx& Value() {
102  static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
103  return e;
104  }
105  inline const RegEx& ValueInFlow() {
106  static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
107  return e;
108  }
109  inline const RegEx& ValueInJSONFlow() {
110  static const RegEx e = RegEx(':');
111  return e;
112  }
113  inline const RegEx Comment() {
114  static const RegEx e = RegEx('#');
115  return e;
116  }
117  inline const RegEx& Anchor() {
118  static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
119  return e;
120  }
121  inline const RegEx& AnchorEnd() {
122  static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
123  return e;
124  }
125  inline const RegEx& URI() {
126  static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) || (RegEx('%') + Hex() + Hex());
127  return e;
128  }
129  inline const RegEx& Tag() {
130  static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'", REGEX_OR) || (RegEx('%') + Hex() + Hex());
131  return e;
132  }
133 
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;
142  }
143  inline const RegEx& PlainScalarInFlow() {
144  static const RegEx e = !(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank()));
145  return e;
146  }
147  inline const RegEx& EndScalar() {
148  static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
149  return e;
150  }
151  inline const RegEx& EndScalarInFlow() {
152  static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
153  return e;
154  }
155 
156  inline const RegEx& EscSingleQuote() {
157  static const RegEx e = RegEx("\'\'");
158  return e;
159  }
160  inline const RegEx& EscBreak() {
161  static const RegEx e = RegEx('\\') + Break();
162  return e;
163  }
164 
165  inline const RegEx& ChompIndicator() {
166  static const RegEx e = RegEx("+-", REGEX_OR);
167  return e;
168  }
169  inline const RegEx& Chomp() {
170  static const RegEx e = (ChompIndicator() + Digit()) || (Digit() + ChompIndicator()) || ChompIndicator() || Digit();
171  return e;
172  }
173 
174  // and some functions
176  }
177 
178  namespace Keys
179  {
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 = '>';
193  }
194 }
195 
196 #endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
const char FoldedScalar
Definition: exp.h:190
const char VerbatimTagEnd
Definition: exp.h:192
const RegEx & BlockEntry()
Definition: exp.h:89
const RegEx & Chomp()
Definition: exp.h:169
const RegEx & Key()
Definition: exp.h:93
const RegEx & NotPrintable()
Definition: exp.h:63
const char FlowMapEnd
Definition: exp.h:184
const RegEx & Anchor()
Definition: exp.h:117
::std::string string
Definition: gtest.h:1979
const RegEx & AlphaNumeric()
Definition: exp.h:50
const RegEx & BlankOrBreak()
Definition: exp.h:38
const RegEx & EscBreak()
Definition: exp.h:160
_Alias Alias(const std::string content)
Definition: emittermanip.h:79
const RegEx & Digit()
Definition: exp.h:42
const RegEx & KeyInFlow()
Definition: exp.h:97
const RegEx & ChompIndicator()
Definition: exp.h:165
const RegEx & Break()
Definition: exp.h:34
const RegEx & Value()
Definition: exp.h:101
const char FlowSeqEnd
Definition: exp.h:182
const RegEx & Tab()
Definition: exp.h:26
const RegEx & ValueInJSONFlow()
Definition: exp.h:109
const RegEx & PlainScalarInFlow()
Definition: exp.h:143
const RegEx & EndScalarInFlow()
Definition: exp.h:151
const RegEx & Alpha()
Definition: exp.h:46
const RegEx & Utf8_ByteOrderMark()
Definition: exp.h:70
const RegEx & DocEnd()
Definition: exp.h:81
const RegEx & PlainScalar()
Definition: exp.h:139
const RegEx & AnchorEnd()
Definition: exp.h:121
const RegEx & Blank()
Definition: exp.h:30
const RegEx & EndScalar()
Definition: exp.h:147
const char FlowEntry
Definition: exp.h:185
const RegEx & Word()
Definition: exp.h:54
const RegEx & Tag()
Definition: exp.h:129
const RegEx & Hex()
Definition: exp.h:58
const RegEx & EscSingleQuote()
Definition: exp.h:156
const char Directive
Definition: exp.h:180
const RegEx & DocIndicator()
Definition: exp.h:85
const RegEx & URI()
Definition: exp.h:125
const char FlowSeqStart
Definition: exp.h:181
std::string Escape(Stream &in, int codeLength)
Definition: exp.cpp:38
const char VerbatimTagStart
Definition: exp.h:191
const RegEx & DocStart()
Definition: exp.h:77
const char FlowMapStart
Definition: exp.h:183
const char LiteralScalar
Definition: exp.h:189
const RegEx Comment()
Definition: exp.h:113
const RegEx & Space()
Definition: exp.h:22
const RegEx & ValueInFlow()
Definition: exp.h:105


libpointmatcher
Author(s):
autogenerated on Sat May 27 2023 02:36:30