exp.h
Go to the documentation of this file.
00001 #ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00002 #define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM
00003 
00004 #if defined(_MSC_VER) || (defined(__GNUC__) && (__GNUC__ == 3 && __GNUC_MINOR__ >= 4) || (__GNUC__ >= 4)) // GCC supports "pragma once" correctly since 3.4
00005 #pragma once
00006 #endif
00007 
00008 
00009 #include "regex.h"
00010 #include <string>
00011 #include <ios>
00012 #include "stream.h"
00013 
00014 namespace YAML_PM
00015 {
00017         // Here we store a bunch of expressions for matching different parts of the file.
00018 
00019         namespace Exp
00020         {
00021                 // misc
00022                 inline const RegEx& Space() {
00023                         static const RegEx e = RegEx(' ');
00024                         return e;
00025                 }
00026                 inline const RegEx& Tab() {
00027                         static const RegEx e = RegEx('\t');
00028                         return e;
00029                 }
00030                 inline const RegEx& Blank() {
00031                         static const RegEx e = Space() || Tab();
00032                         return e;
00033                 }
00034                 inline const RegEx& Break() {
00035                         static const RegEx e = RegEx('\n') || RegEx("\r\n");
00036                         return e;
00037                 }
00038                 inline const RegEx& BlankOrBreak() {
00039                         static const RegEx e = Blank() || Break();
00040                         return e;
00041                 }
00042                 inline const RegEx& Digit() {
00043                         static const RegEx e = RegEx('0', '9');
00044                         return e;
00045                 }
00046                 inline const RegEx& Alpha() {
00047                         static const RegEx e = RegEx('a', 'z') || RegEx('A', 'Z');
00048                         return e;
00049                 }
00050                 inline const RegEx& AlphaNumeric() {
00051                         static const RegEx e = Alpha() || Digit();
00052                         return e;
00053                 }
00054                 inline const RegEx& Word() {
00055                         static const RegEx e = AlphaNumeric() || RegEx('-');
00056                         return e;
00057                 }
00058                 inline const RegEx& Hex() {
00059                         static const RegEx e = Digit() || RegEx('A', 'F') || RegEx('a', 'f');
00060                         return e;
00061                 }
00062                 // Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. 5.1)
00063                 inline const RegEx& NotPrintable() {
00064                         static const RegEx e = RegEx(0) || 
00065                                 RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) || 
00066                                 RegEx(0x0E, 0x1F) ||
00067                                 (RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
00068                         return e;
00069                 }
00070                 inline const RegEx& Utf8_ByteOrderMark() {
00071                         static const RegEx e = RegEx("\xEF\xBB\xBF");
00072                         return e;
00073                 }
00074 
00075                 // actual tags
00076 
00077                 inline const RegEx& DocStart() {
00078                         static const RegEx e = RegEx("---") + (BlankOrBreak() || RegEx());
00079                         return e;
00080                 }
00081                 inline const RegEx& DocEnd() {
00082                         static const RegEx e = RegEx("...") + (BlankOrBreak() || RegEx());
00083                         return e;
00084                 }
00085                 inline const RegEx& DocIndicator() {
00086                         static const RegEx e = DocStart() || DocEnd();
00087                         return e;
00088                 }
00089                 inline const RegEx& BlockEntry() {
00090                         static const RegEx e = RegEx('-') + (BlankOrBreak() || RegEx());
00091                         return e;
00092                 }
00093                 inline const RegEx& Key() {
00094                         static const RegEx e = RegEx('?');
00095                         return e;
00096                 }
00097                 inline const RegEx& KeyInFlow() {
00098                         static const RegEx e = RegEx('?') + BlankOrBreak();
00099                         return e;
00100                 }
00101                 inline const RegEx& Value() {
00102                         static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
00103                         return e;
00104                 }
00105                 inline const RegEx& ValueInFlow() {
00106                         static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx(",}", REGEX_OR));
00107                         return e;
00108                 }
00109                 inline const RegEx& ValueInJSONFlow() {
00110                         static const RegEx e = RegEx(':');
00111                         return e;
00112                 }
00113                 inline const RegEx Comment() {
00114                         static const RegEx e = RegEx('#');
00115                         return e;
00116                 }
00117                 inline const RegEx& Anchor() {
00118                         static const RegEx e = !(RegEx("[]{},", REGEX_OR) || BlankOrBreak());
00119                         return e;
00120                 }
00121                 inline const RegEx& AnchorEnd() {
00122                         static const RegEx e = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak();
00123                         return e;
00124                 }
00125                 inline const RegEx& URI() {
00126                         static const RegEx e = Word() || RegEx("#;/?:@&=+$,_.!~*'()[]", REGEX_OR) || (RegEx('%') + Hex() + Hex());
00127                         return e;
00128                 }
00129                 inline const RegEx& Tag() {
00130                         static const RegEx e = Word() || RegEx("#;/?:@&=+$_.~*'", REGEX_OR) || (RegEx('%') + Hex() + Hex());
00131                         return e;
00132                 }
00133 
00134                 // Plain scalar rules:
00135                 // . Cannot start with a blank.
00136                 // . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
00137                 // . In the block context - ? : must be not be followed with a space.
00138                 // . In the flow context ? is illegal and : and - must not be followed with a space.
00139                 inline const RegEx& PlainScalar() {
00140                         static const RegEx e = !(BlankOrBreak() || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + (BlankOrBreak() || RegEx())));
00141                         return e;
00142                 }
00143                 inline const RegEx& PlainScalarInFlow() {
00144                         static const RegEx e = !(BlankOrBreak() || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank()));
00145                         return e;
00146                 }
00147                 inline const RegEx& EndScalar() {
00148                         static const RegEx e = RegEx(':') + (BlankOrBreak() || RegEx());
00149                         return e;
00150                 }
00151                 inline const RegEx& EndScalarInFlow() {
00152                         static const RegEx e = (RegEx(':') + (BlankOrBreak() || RegEx() || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
00153                         return e;
00154                 }
00155 
00156                 inline const RegEx& EscSingleQuote() {
00157                         static const RegEx e = RegEx("\'\'");
00158                         return e;
00159                 }
00160                 inline const RegEx& EscBreak() {
00161                         static const RegEx e = RegEx('\\') + Break();
00162                         return e;
00163                 }
00164 
00165                 inline const RegEx& ChompIndicator() {
00166                         static const RegEx e = RegEx("+-", REGEX_OR);
00167                         return e;
00168                 }
00169                 inline const RegEx& Chomp() {
00170                         static const RegEx e = (ChompIndicator() + Digit()) || (Digit() + ChompIndicator()) || ChompIndicator() || Digit();
00171                         return e;
00172                 }
00173 
00174                 // and some functions
00175                 std::string Escape(Stream& in);
00176         }
00177 
00178         namespace Keys
00179         {
00180                 const char Directive = '%';
00181                 const char FlowSeqStart = '[';
00182                 const char FlowSeqEnd = ']';
00183                 const char FlowMapStart = '{';
00184                 const char FlowMapEnd = '}';
00185                 const char FlowEntry = ',';
00186                 const char Alias = '*';
00187                 const char Anchor = '&';
00188                 const char Tag = '!';
00189                 const char LiteralScalar = '|';
00190                 const char FoldedScalar = '>';
00191                 const char VerbatimTagStart = '<';
00192                 const char VerbatimTagEnd = '>';
00193         }
00194 }
00195 
00196 #endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66_PM


libpointmatcher
Author(s):
autogenerated on Thu Jun 20 2019 19:51:29