add YAML parser

This commit is contained in:
MihailRis
2025-03-23 08:49:09 +03:00
parent 239181bb64
commit 2aea19febd
8 changed files with 406 additions and 25 deletions
+44 -1
View File
@@ -31,10 +31,17 @@ namespace {
}
template<typename CharT>
void BasicParser<CharT>::skipWhitespace() {
void BasicParser<CharT>::skipWhitespace(bool newline) {
if (hashComment) {
skipWhitespaceHashComment(newline);
return;
}
while (hasNext()) {
char next = source[pos];
if (next == '\n') {
if (!newline) {
break;
}
line++;
linestart = ++pos;
continue;
@@ -47,6 +54,36 @@ void BasicParser<CharT>::skipWhitespace() {
}
}
template<typename CharT>
void BasicParser<CharT>::skipWhitespaceHashComment(bool newline) {
while (hasNext()) {
char next = source[pos];
if (next == '\n') {
if (!newline) {
break;
}
line++;
linestart = ++pos;
continue;
}
if (is_whitespace(next)) {
pos++;
} else {
break;
}
}
if (hasNext() && source[pos] == '#') {
if (!newline) {
readUntilEOL();
return;
}
skipLine();
if (hasNext() && (is_whitespace(source[pos]) || source[pos] == '#')) {
skipWhitespaceHashComment(newline);
}
}
}
template<typename CharT>
void BasicParser<CharT>::skip(size_t n) {
n = std::min(n, source.length() - pos);
@@ -73,6 +110,12 @@ void BasicParser<CharT>::skipLine() {
}
}
template<typename CharT>
void BasicParser<CharT>::skipEmptyLines() {
skipWhitespace();
pos = linestart;
}
template<typename CharT>
bool BasicParser<CharT>::skipTo(const std::basic_string<CharT>& substring) {
size_t idx = source.find(substring, pos);