scantag.cpp 1.4 KB
Newer Older
1
2
3
#include "scanner.h"
#include "regex.h"
#include "exp.h"
4
#include "yaml-cpp/exceptions.h"
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21

namespace YAML
{
	const std::string ScanVerbatimTag(Stream& INPUT)
	{
		std::string tag;
		
		// eat the start character
		INPUT.get();
		
		while(INPUT) {
			if(INPUT.peek() == Keys::VerbatimTagEnd) {
				// eat the end character
				INPUT.get();
				return tag;
			}
		
22
			int n = Exp::URI().Match(INPUT);
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
			if(n <= 0)
				break;
			
			tag += INPUT.get(n);
		}

		throw ParserException(INPUT.mark(), ErrorMsg::END_OF_VERBATIM_TAG);
	}
	
	const std::string ScanTagHandle(Stream& INPUT, bool& canBeHandle)
	{
		std::string tag;
		canBeHandle = true;
		Mark firstNonWordChar;
		
		while(INPUT) {
			if(INPUT.peek() == Keys::Tag) {
				if(!canBeHandle)
					throw ParserException(firstNonWordChar, ErrorMsg::CHAR_IN_TAG_HANDLE);
				break;
			}

			int n = 0;
			if(canBeHandle) {
47
				n = Exp::Word().Match(INPUT);
48
49
50
51
52
53
54
				if(n <= 0) {
					canBeHandle = false;
					firstNonWordChar = INPUT.mark();
				}
			}
			
			if(!canBeHandle)
55
				n = Exp::Tag().Match(INPUT);
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70

			if(n <= 0)
				break;
			
			tag += INPUT.get(n);
		}

		return tag;
	}
	
	const std::string ScanTagSuffix(Stream& INPUT)
	{
		std::string tag;
		
		while(INPUT) {
71
			int n = Exp::Tag().Match(INPUT);
72
73
74
75
76
77
78
79
80
81
82
83
84
			if(n <= 0)
				break;
			
			tag += INPUT.get(n);
		}
		
		if(tag.empty())
			throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
		
		return tag;
	}
}