feat: verbose error messages for parsing functions

This commit is contained in:
MihailRis 2026-07-23 19:59:31 +03:00
parent d3eb7a10be
commit 900f118f94
7 changed files with 58 additions and 16 deletions

View file

@ -57,3 +57,7 @@ std::string parsing_error::errorLog() const {
ss << "^";
return ss.str();
}
std::runtime_error parsing_error::toRuntimeError() const {
return std::runtime_error("parsing error: " + errorLog());
}

View file

@ -73,4 +73,6 @@ public:
uint linestart
);
std::string errorLog() const;
std::runtime_error toRuntimeError() const;
};

View file

@ -385,10 +385,22 @@ public:
}
if (c == '(') {
nextChar();
// TODO: replace with array parsing after moving to dv::value's
std::string value = std::string(readUntil(')'));
int depth = 1;
size_t start = pos;
while (hasNext()) {
char c = nextChar();
if (c == '(') {
depth++;
} else if (c == ')') {
depth--;
if (depth == 0) {
goBack(1);
break;
}
}
}
expect(')');
return value;
return std::string(source.substr(start, pos - start - 1));
}
return std::string(readUntilWhitespace());
}