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