2008-09-04 02:20:39 +04:00
|
|
|
#pragma once
|
|
|
|
|
|
2009-07-30 02:27:20 +04:00
|
|
|
#ifndef EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
#define EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|
|
|
|
|
|
|
|
|
|
|
2008-09-04 02:20:39 +04:00
|
|
|
#include "regex.h"
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <ios>
|
|
|
|
|
#include "stream.h"
|
|
|
|
|
|
|
|
|
|
namespace YAML
|
|
|
|
|
{
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
// Here we store a bunch of expressions for matching different parts of the file.
|
|
|
|
|
|
|
|
|
|
namespace Exp
|
|
|
|
|
{
|
|
|
|
|
// misc
|
2009-05-23 01:52:31 +04:00
|
|
|
const RegEx Space = RegEx(' ');
|
|
|
|
|
const RegEx Tab = RegEx('\t');
|
|
|
|
|
const RegEx Blank = Space || Tab;
|
2008-09-04 02:20:39 +04:00
|
|
|
const RegEx Break = RegEx('\n') || RegEx("\r\n");
|
|
|
|
|
const RegEx BlankOrBreak = Blank || Break;
|
|
|
|
|
const RegEx Digit = RegEx('0', '9');
|
|
|
|
|
const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
|
|
|
|
|
const RegEx AlphaNumeric = Alpha || Digit;
|
|
|
|
|
const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
|
2009-10-20 03:31:11 +04:00
|
|
|
// Valid Unicode code points that are not part of c-printable (YAML 1.2, sec. 5.1)
|
|
|
|
|
const RegEx NotPrintable = RegEx(0) ||
|
|
|
|
|
RegEx("\x01\x02\x03\x04\x05\x06\x07\x08\x0B\x0C\x7F", REGEX_OR) ||
|
|
|
|
|
RegEx(0x0E, 0x1F) ||
|
|
|
|
|
(RegEx('\xC2') + (RegEx('\x80', '\x84') || RegEx('\x86', '\x9F')));
|
|
|
|
|
const RegEx Utf8_ByteOrderMark = RegEx("\xEF\xBB\xBF");
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
|
// actual tags
|
|
|
|
|
|
2009-02-01 23:48:43 +03:00
|
|
|
const RegEx DocStart = RegEx("---") + (BlankOrBreak || RegEx());
|
|
|
|
|
const RegEx DocEnd = RegEx("...") + (BlankOrBreak || RegEx());
|
2008-09-04 02:20:39 +04:00
|
|
|
const RegEx DocIndicator = DocStart || DocEnd;
|
2009-07-30 10:49:09 +04:00
|
|
|
const RegEx BlockEntry = RegEx('-') + (BlankOrBreak || RegEx());
|
2008-09-04 02:20:39 +04:00
|
|
|
const RegEx Key = RegEx('?'),
|
|
|
|
|
KeyInFlow = RegEx('?') + BlankOrBreak;
|
2009-07-30 10:49:09 +04:00
|
|
|
const RegEx Value = RegEx(':') + (BlankOrBreak || RegEx()),
|
2009-09-03 01:39:57 +04:00
|
|
|
ValueInFlow = RegEx(':') + (BlankOrBreak || RegEx(",}", REGEX_OR));
|
2008-09-04 02:20:39 +04:00
|
|
|
const RegEx Comment = RegEx('#');
|
|
|
|
|
const RegEx AnchorEnd = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak;
|
|
|
|
|
|
|
|
|
|
// Plain scalar rules:
|
|
|
|
|
// . Cannot start with a blank.
|
|
|
|
|
// . Can never start with any of , [ ] { } # & * ! | > \' \" % @ `
|
|
|
|
|
// . In the block context - ? : must be not be followed with a space.
|
|
|
|
|
// . In the flow context ? is illegal and : and - must not be followed with a space.
|
|
|
|
|
const RegEx PlainScalar = !(BlankOrBreak || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + Blank)),
|
|
|
|
|
PlainScalarInFlow = !(BlankOrBreak || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank));
|
2009-07-30 10:49:09 +04:00
|
|
|
const RegEx EndScalar = RegEx(':') + (BlankOrBreak || RegEx()),
|
2009-09-03 01:39:57 +04:00
|
|
|
EndScalarInFlow = (RegEx(':') + (BlankOrBreak || RegEx(",]}", REGEX_OR))) || RegEx(",?[]{}", REGEX_OR);
|
2008-09-04 02:20:39 +04:00
|
|
|
|
|
|
|
|
const RegEx EscSingleQuote = RegEx("\'\'");
|
|
|
|
|
const RegEx EscBreak = RegEx('\\') + Break;
|
|
|
|
|
|
|
|
|
|
const RegEx ChompIndicator = RegEx("+-", REGEX_OR);
|
|
|
|
|
const RegEx Chomp = (ChompIndicator + Digit) || (Digit + ChompIndicator) || ChompIndicator || Digit;
|
|
|
|
|
|
|
|
|
|
// and some functions
|
|
|
|
|
std::string Escape(Stream& in);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace Keys
|
|
|
|
|
{
|
|
|
|
|
const char Directive = '%';
|
|
|
|
|
const char FlowSeqStart = '[';
|
|
|
|
|
const char FlowSeqEnd = ']';
|
|
|
|
|
const char FlowMapStart = '{';
|
|
|
|
|
const char FlowMapEnd = '}';
|
|
|
|
|
const char FlowEntry = ',';
|
|
|
|
|
const char Alias = '*';
|
|
|
|
|
const char Anchor = '&';
|
|
|
|
|
const char Tag = '!';
|
|
|
|
|
const char LiteralScalar = '|';
|
|
|
|
|
const char FoldedScalar = '>';
|
|
|
|
|
}
|
|
|
|
|
}
|
2009-07-30 02:27:20 +04:00
|
|
|
|
|
|
|
|
#endif // EXP_H_62B23520_7C8E_11DE_8A39_0800200C9A66
|