add YAML parser
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user