exp.h 2.6 KB
Newer Older
1
2
3
#pragma once

#include "regex.h"
4
5
#include <string>
#include <ios>
6
#include "stream.h"
7
8
9
10
11
12
13
14
15
16

namespace YAML
{
	////////////////////////////////////////////////////////////////////////////////
	// Here we store a bunch of expressions for matching different parts of the file.

	namespace Exp
	{
		// misc
		const RegEx Blank = RegEx(' ') || RegEx('\t');
17
		const RegEx Break = RegEx('\n') || RegEx("\r\n");
18
		const RegEx BlankOrBreak = Blank || Break;
19
		const RegEx Digit = RegEx('0', '9');
Jesse Beder's avatar
Jesse Beder committed
20
21
		const RegEx Alpha = RegEx('a', 'z') || RegEx('A', 'Z');
		const RegEx AlphaNumeric = Alpha || Digit;
22
		const RegEx Hex = Digit || RegEx('A', 'F') || RegEx('a', 'f');
23
24
25
26
27

		// actual tags

		const RegEx DocStart = RegEx("---") + (BlankOrBreak || RegEx(EOF) || RegEx());
		const RegEx DocEnd = RegEx("...") + (BlankOrBreak || RegEx(EOF) || RegEx());
28
		const RegEx DocIndicator = DocStart || DocEnd;
29
30
31
		const RegEx BlockEntry = RegEx('-') + (BlankOrBreak || RegEx(EOF));
		const RegEx Key = RegEx('?'),
		            KeyInFlow = RegEx('?') + BlankOrBreak;
32
		const RegEx Value = RegEx(':') + BlankOrBreak,
33
34
		            ValueInFlow = RegEx(':') + BlankOrBreak;
		const RegEx Comment = RegEx('#');
Jesse Beder's avatar
Jesse Beder committed
35
		const RegEx AnchorEnd = RegEx("?:,]}%@`", REGEX_OR) || BlankOrBreak;
36
37
38
39
40

		// 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.
41
		// . In the flow context ? is illegal and : and - must not be followed with a space.
42
		const RegEx PlainScalar = !(BlankOrBreak || RegEx(",[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-?:", REGEX_OR) + Blank)),
43
		            PlainScalarInFlow = !(BlankOrBreak || RegEx("?,[]{}#&*!|>\'\"%@`", REGEX_OR) || (RegEx("-:", REGEX_OR) + Blank));
44
		const RegEx EndScalar = RegEx(':') + BlankOrBreak,
45
		            EndScalarInFlow = (RegEx(':') + BlankOrBreak) || RegEx(",?[]{}", REGEX_OR);
46
47
48
49

		const RegEx EscSingleQuote = RegEx("\'\'");
		const RegEx EscBreak = RegEx('\\') + Break;

50
51
52
		const RegEx ChompIndicator = RegEx("+-", REGEX_OR);
		const RegEx Chomp = (ChompIndicator + Digit) || (Digit + ChompIndicator) || ChompIndicator || Digit;

53
		// and some functions
54
		std::string Escape(Stream& in);
55
56
57
58
	}

	namespace Keys
	{
Jesse Beder's avatar
Jesse Beder committed
59
		const char Directive = '%';
60
61
62
63
64
65
66
67
68
69
70
71
		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 = '>';
	}
}