Fix handling of invalid conversion/split within parser, update parser tests

This commit is contained in:
ado
2023-08-05 18:11:13 +02:00
parent 7c9ba953ad
commit 2e1c4c97ec
3 changed files with 90 additions and 18 deletions

View File

@@ -88,14 +88,26 @@ public:
return to_object<T>(get_next<Ts...>());
}
// TODO make the method work with if valid() returns false
size_t line() const {
return valid() ? reader_.line_number_ - 1 : 0;
}
template <typename T, typename... Ts>
no_void_validator_tup_t<T, Ts...> get_next() {
std::optional<std::string> error;
if (!eof_) {
reader_.parse();
if constexpr (throw_on_error) {
try {
reader_.parse();
} catch (...) {
read_line();
throw;
}
} else {
reader_.parse();
}
}
reader_.update();
@@ -112,6 +124,17 @@ public:
return {};
}
if constexpr (throw_on_error) {
try {
auto value = reader_.converter_.template convert<T, Ts...>();
read_line();
return value;
} catch (...) {
read_line();
throw;
}
}
auto value = reader_.converter_.template convert<T, Ts...>();
if (!reader_.converter_.valid()) {

View File

@@ -162,7 +162,6 @@ private:
}
}
// TODO handle this efficiently (if multiline is enabled)
void handle_error_unterminated_quote() {
constexpr static auto error_msg = "unterminated quote";