zhifu gao
2024-05-28 ba3a3bf4e67e861b833092d05d7c3842ea670cbc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#include "exp.h"
#include "regex_yaml.h"
#include "regeximpl.h"
#include "stream.h"
#include "yaml-cpp/exceptions.h"  // IWYU pragma: keep
#include "yaml-cpp/mark.h"
 
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;
    }
 
    int n = Exp::URI().Match(INPUT);
    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) {
      n = Exp::Word().Match(INPUT);
      if (n <= 0) {
        canBeHandle = false;
        firstNonWordChar = INPUT.mark();
      }
    }
 
    if (!canBeHandle)
      n = Exp::Tag().Match(INPUT);
 
    if (n <= 0)
      break;
 
    tag += INPUT.get(n);
  }
 
  return tag;
}
 
const std::string ScanTagSuffix(Stream& INPUT) {
  std::string tag;
 
  while (INPUT) {
    int n = Exp::Tag().Match(INPUT);
    if (n <= 0)
      break;
 
    tag += INPUT.get(n);
  }
 
  if (tag.empty())
    throw ParserException(INPUT.mark(), ErrorMsg::TAG_WITH_NO_SUFFIX);
 
  return tag;
}
}