mirror of
https://github.com/MihailRis/voxelcore.git
synced 2026-10-05 19:11:50 +00:00
add YAML parser
This commit is contained in:
parent
239181bb64
commit
2aea19febd
8 changed files with 406 additions and 25 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue