Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-05-12 09:08:10

0001 #ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0002 #define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
0003 
0004 #if defined(_MSC_VER) ||                                            \
0005     (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || \
0006      (__GNUC__ >= 4))  // GCC supports "pragma once" correctly since 3.4
0007 #pragma once
0008 #endif
0009 
0010 #include <ios>
0011 #include <string>
0012 
0013 #include "regex_yaml.h"
0014 #include "stream.h"
0015 
0016 namespace SHERPA_YAML {
0017 ////////////////////////////////////////////////////////////////////////////////
0018 // Here we store a bunch of expressions for matching different parts of the
0019 // file.
0020 
0021 namespace Exp {
0022 // misc
0023 inline const RegEx& Empty() {
0024   static const RegEx e;
0025   return e;
0026 }
0027 inline const RegEx& Space() {
0028   static const RegEx e = RegEx(' ');
0029   return e;
0030 }
0031 inline const RegEx& Tab() {
0032   static const RegEx e = RegEx('\t');
0033   return e;
0034 }
0035 inline const RegEx& Blank() {
0036   static const RegEx e = Space() | Tab();
0037   return e;
0038 }
0039 inline const RegEx& Break() {
0040   static const RegEx e = RegEx('\n') | RegEx("\r\n");
0041   return e;
0042 }
0043 inline const RegEx& BlankOrBreak() {
0044   static const RegEx e = Blank() | Break();
0045   return e;
0046 }
0047 inline const RegEx& Digit() {
0048   static const RegEx e = RegEx('0', '9');
0049   return e;
0050 }
0051 inline const RegEx& Alpha() {
0052   static const RegEx e = RegEx('a', 'z') | RegEx('A', 'Z');
0053   return e;
0054 }
0055 inline const RegEx& AlphaNumeric() {
0056   static const RegEx e = Alpha() | Digit();
0057   return e;
0058 }
0059 inline const RegEx& Word() {
0060   static const RegEx e = AlphaNumeric() | RegEx('-');
0061   return e;
0062 }
0063 inline const RegEx& Hex() {
0064   static const RegEx e = Digit() | RegEx('A', 'F') | RegEx('a', 'f');
0065   return e;
0066 }
0067 // Valid Unicode code points that are not part of c-printable (YAML 1.2, sec.
0068 // 5.1)
0069 inline const RegEx& NotPrintable() {
0070   static const RegEx e =
0071       RegEx(0) |
0072       RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) |
0073       RegEx(0x0E, 0x1F) |
0074       (RegEx('\xC2') + (RegEx('\x80', '\x84') | RegEx('\x86', '\x9F')));
0075   return e;
0076 }
0077 inline const RegEx& Utf8_ByteOrderMark() {
0078   static const RegEx e = RegEx("\xEF\xBB\xBF");
0079   return e;
0080 }
0081 
0082 // actual tags
0083 
0084 inline const RegEx& DocStart() {
0085   static const RegEx e = RegEx("---") + (BlankOrBreak() | RegEx());
0086   return e;
0087 }
0088 inline const RegEx& DocEnd() {
0089   static const RegEx e = RegEx("...") + (BlankOrBreak() | RegEx());
0090   return e;
0091 }
0092 inline const RegEx& DocIndicator() {
0093   static const RegEx e = DocStart() | DocEnd();
0094   return e;
0095 }
0096 inline const RegEx& BlockEntry() {
0097   static const RegEx e = RegEx('-') + (BlankOrBreak() | RegEx());
0098   return e;
0099 }
0100 inline const RegEx& Key() {
0101   static const RegEx e = RegEx('?') + BlankOrBreak();
0102   return e;
0103 }
0104 inline const RegEx& KeyInFlow() {
0105   static const RegEx e = RegEx('?') + BlankOrBreak();
0106   return e;
0107 }
0108 inline const RegEx& Value() {
0109   static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
0110   return e;
0111 }
0112 inline const RegEx& ValueInFlow() {
0113   static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx(",]}", REGEX_OR));
0114   return e;
0115 }
0116 inline const RegEx& ValueInJSONFlow() {
0117   static const RegEx e = RegEx(':');
0118   return e;
0119 }
0120 inline const RegEx Comment() {
0121   static const RegEx e = RegEx('#');
0122   return e;
0123 }
0124 inline const RegEx& Anchor() {
0125   static const RegEx e = !(RegEx("[]{},", REGEX_OR) | BlankOrBreak());
0126   return e;
0127 }
0128 inline const RegEx& AnchorEnd() {
0129   static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) | BlankOrBreak();
0130   return e;
0131 }
0132 inline const RegEx& URI() {
0133   static const RegEx e = Word() | RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) |
0134                          (RegEx('%') + Hex() + Hex());
0135   return e;
0136 }
0137 inline const RegEx& Tag() {
0138   static const RegEx e = Word() | RegEx("#;/?:@&=+$_.~*'()", REGEX_OR) |
0139                          (RegEx('%') + Hex() + Hex());
0140   return e;
0141 }
0142 
0143 // Plain scalar rules:
0144 // . Cannot start with a blank.
0145 // . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
0146 // . In the block context - ? : must be not be followed with a space.
0147 // . In the flow context ? is illegal and : and - must not be followed with a
0148 // space.
0149 inline const RegEx& PlainScalar() {
0150   static const RegEx e =
0151       !(BlankOrBreak() | RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) |
0152         (RegEx("-?:", REGEX_OR) + (BlankOrBreak() | RegEx())));
0153   return e;
0154 }
0155 inline const RegEx& PlainScalarInFlow() {
0156   static const RegEx e =
0157       !(BlankOrBreak() | RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) |
0158         (RegEx("-:", REGEX_OR) + (Blank() | RegEx())));
0159   return e;
0160 }
0161 inline const RegEx& EndScalar() {
0162   static const RegEx e = RegEx(':') + (BlankOrBreak() | RegEx());
0163   return e;
0164 }
0165 inline const RegEx& EndScalarInFlow() {
0166   static const RegEx e =
0167       (RegEx(':') + (BlankOrBreak() | RegEx() | RegEx(",]}", REGEX_OR))) |
0168       RegEx(",?[]{}", REGEX_OR);
0169   return e;
0170 }
0171 
0172 inline const RegEx& ScanScalarEndInFlow() {
0173   static const RegEx e = (EndScalarInFlow() | (BlankOrBreak() + Comment()));
0174   return e;
0175 }
0176 
0177 inline const RegEx& ScanScalarEnd() {
0178   static const RegEx e = EndScalar() | (BlankOrBreak() + Comment());
0179   return e;
0180 }
0181 inline const RegEx& EscSingleQuote() {
0182   static const RegEx e = RegEx("\'\'");
0183   return e;
0184 }
0185 inline const RegEx& EscBreak() {
0186   static const RegEx e = RegEx('\\') + Break();
0187   return e;
0188 }
0189 
0190 inline const RegEx& ChompIndicator() {
0191   static const RegEx e = RegEx("+-", REGEX_OR);
0192   return e;
0193 }
0194 inline const RegEx& Chomp() {
0195   static const RegEx e = (ChompIndicator() + Digit()) |
0196                          (Digit() + ChompIndicator()) | ChompIndicator() |
0197                          Digit();
0198   return e;
0199 }
0200 
0201 // and some functions
0202 std::string Escape(Stream& in);
0203 }  // namespace Exp
0204 
0205 namespace Keys {
0206 const char Directive = '%';
0207 const char FlowSeqStart = '[';
0208 const char FlowSeqEnd = ']';
0209 const char FlowMapStart = '{';
0210 const char FlowMapEnd = '}';
0211 const char FlowEntry = ',';
0212 const char Alias = '*';
0213 const char Anchor = '&';
0214 const char Tag = '!';
0215 const char LiteralScalar = '|';
0216 const char FoldedScalar = '>';
0217 const char VerbatimTagStart = '<';
0218 const char VerbatimTagEnd = '>';
0219 }  // namespace Keys
0220 }  // namespace SHERPA_YAML
0221 
0222 #endif  // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66