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
YAML_PM::Exp::Tab
const RegEx & Tab()
Definition: exp.h:26
YAML_PM::Exp::EscSingleQuote
const RegEx & EscSingleQuote()
Definition: exp.h:156
YAML_PM::Exp::Alpha
const RegEx & Alpha()
Definition: exp.h:46
YAML_PM::Exp::BlockEntry
const RegEx & BlockEntry()
Definition: exp.h:89
YAML_PM::Exp::EndScalarInFlow
const RegEx & EndScalarInFlow()
Definition: exp.h:151
YAML_PM::Exp::Break
const RegEx & Break()
Definition: exp.h:34
YAML_PM::Keys::Alias
const char Alias
Definition: exp.h:186
YAML_PM::Exp::AnchorEnd
const RegEx & AnchorEnd()
Definition: exp.h:121
YAML_PM::Keys::Anchor
const char Anchor
Definition: exp.h:187
YAML_PM::Keys::FlowSeqStart
const char FlowSeqStart
Definition: exp.h:181
YAML_PM
Definition: aliasmanager.h:11
YAML_PM::Keys::VerbatimTagStart
const char VerbatimTagStart
Definition: exp.h:191
YAML_PM::Tag
Definition: tag.h:15
YAML_PM::Exp::Anchor
const RegEx & Anchor()
Definition: exp.h:117
YAML_PM::Exp::ValueInFlow
const RegEx & ValueInFlow()
Definition: exp.h:105
YAML_PM::Exp::Hex
const RegEx & Hex()
Definition: exp.h:58
YAML_PM::Keys::FlowSeqEnd
const char FlowSeqEnd
Definition: exp.h:182
YAML_PM::Exp::Tag
const RegEx & Tag()
Definition: exp.h:129
YAML_PM::Exp::Value
const RegEx & Value()
Definition: exp.h:101
YAML_PM::Exp::BlankOrBreak
const RegEx & BlankOrBreak()
Definition: exp.h:38
testing::internal::string
::std::string string
Definition: gtest.h:1979
YAML_PM::Exp::Utf8_ByteOrderMark
const RegEx & Utf8_ByteOrderMark()
Definition: exp.h:70
YAML_PM::Keys::FlowMapEnd
const char FlowMapEnd
Definition: exp.h:184
YAML_PM::Exp::DocEnd
const RegEx & DocEnd()
Definition: exp.h:81
YAML_PM::Exp::PlainScalarInFlow
const RegEx & PlainScalarInFlow()
Definition: exp.h:143
YAML_PM::Exp::Key
const RegEx & Key()
Definition: exp.h:93
YAML_PM::Exp::DocIndicator
const RegEx & DocIndicator()
Definition: exp.h:85
YAML_PM::Exp::URI
const RegEx & URI()
Definition: exp.h:125
YAML_PM::Keys::FoldedScalar
const char FoldedScalar
Definition: exp.h:190
stream.h
YAML_PM::Keys::VerbatimTagEnd
const char VerbatimTagEnd
Definition: exp.h:192
regex.h
YAML_PM::Keys::LiteralScalar
const char LiteralScalar
Definition: exp.h:189
YAML_PM::Exp::EndScalar
const RegEx & EndScalar()
Definition: exp.h:147
YAML_PM::RegEx
Definition: regex.h:21
YAML_PM::Keys::FlowMapStart
const char FlowMapStart
Definition: exp.h:183
YAML_PM::Exp::Space
const RegEx & Space()
Definition: exp.h:22
YAML_PM::Exp::PlainScalar
const RegEx & PlainScalar()
Definition: exp.h:139
YAML_PM::Exp::Escape
std::string Escape(Stream &in, int codeLength)
Definition: exp.cpp:38
YAML_PM::Exp::AlphaNumeric
const RegEx & AlphaNumeric()
Definition: exp.h:50
YAML_PM::Keys::FlowEntry
const char FlowEntry
Definition: exp.h:185
YAML_PM::Stream
Definition: stream.h:20
YAML_PM::Exp::Digit
const RegEx & Digit()
Definition: exp.h:42
YAML_PM::REGEX_OR
@ REGEX_OR
Definition: regex.h:16
YAML_PM::Exp::NotPrintable
const RegEx & NotPrintable()
Definition: exp.h:63
YAML_PM::Exp::ValueInJSONFlow
const RegEx & ValueInJSONFlow()
Definition: exp.h:109
YAML_PM::Exp::Word
const RegEx & Word()
Definition: exp.h:54
YAML_PM::Exp::EscBreak
const RegEx & EscBreak()
Definition: exp.h:160
YAML_PM::Keys::Directive
const char Directive
Definition: exp.h:180
YAML_PM::Exp::Comment
const RegEx Comment()
Definition: exp.h:113
YAML_PM::Exp::KeyInFlow
const RegEx & KeyInFlow()
Definition: exp.h:97
YAML_PM::Exp::DocStart
const RegEx & DocStart()
Definition: exp.h:77
YAML_PM::Exp::Chomp
const RegEx & Chomp()
Definition: exp.h:169
YAML_PM::Exp::Blank
const RegEx & Blank()
Definition: exp.h:30
YAML_PM::Exp::ChompIndicator
const RegEx & ChompIndicator()
Definition: exp.h:165


mp2p_icp
Author(s):
autogenerated on Fri Dec 20 2024 03:45:57