Give start_*/end_* error codes
This commit is contained in:
parent
d8974d53b2
commit
1b56211a70
|
@ -91,7 +91,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
|
|||
// Start the document
|
||||
//
|
||||
if (at_end()) { return EMPTY; }
|
||||
visitor.start_document(*this);
|
||||
SIMDJSON_TRY( visitor.start_document(*this) );
|
||||
|
||||
//
|
||||
// Read first value
|
||||
|
@ -127,7 +127,7 @@ SIMDJSON_WARN_UNUSED simdjson_really_inline error_code json_iterator::walk_docum
|
|||
object_begin:
|
||||
depth++;
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
visitor.start_object(*this);
|
||||
SIMDJSON_TRY( visitor.start_object(*this) );
|
||||
|
||||
if (advance() != '"') { log_error("Object does not start with a key"); return TAPE_ERROR; }
|
||||
visitor.increment_count(*this);
|
||||
|
@ -149,7 +149,7 @@ object_continue:
|
|||
if (simdjson_unlikely( advance() != '"' )) { log_error("Key string missing at beginning of field in object"); return TAPE_ERROR; }
|
||||
SIMDJSON_TRY( visitor.key(*this, value) );
|
||||
goto object_field;
|
||||
case '}': visitor.end_object(*this); goto scope_end;
|
||||
case '}': SIMDJSON_TRY( visitor.end_object(*this) ); goto scope_end;
|
||||
default: log_error("No comma between object fields"); return TAPE_ERROR;
|
||||
}
|
||||
|
||||
|
@ -165,7 +165,7 @@ scope_end:
|
|||
array_begin:
|
||||
depth++;
|
||||
if (depth >= dom_parser.max_depth()) { log_error("Exceeded max depth!"); return DEPTH_ERROR; }
|
||||
visitor.start_array(*this);
|
||||
SIMDJSON_TRY( visitor.start_array(*this) );
|
||||
visitor.increment_count(*this);
|
||||
|
||||
array_value:
|
||||
|
@ -178,12 +178,12 @@ array_value:
|
|||
array_continue:
|
||||
switch (advance()) {
|
||||
case ',': visitor.increment_count(*this); goto array_value;
|
||||
case ']': visitor.end_array(*this); goto scope_end;
|
||||
case ']': SIMDJSON_TRY( visitor.end_array(*this) ); goto scope_end;
|
||||
default: log_error("Missing comma between array values"); return TAPE_ERROR;
|
||||
}
|
||||
|
||||
document_end:
|
||||
visitor.end_document(*this);
|
||||
SIMDJSON_TRY( visitor.end_document(*this) );
|
||||
|
||||
dom_parser.next_structural_index = uint32_t(next_structural - &dom_parser.structural_indexes[0]);
|
||||
|
||||
|
|
|
@ -56,50 +56,44 @@ struct tape_builder {
|
|||
empty_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
|
||||
}
|
||||
|
||||
simdjson_really_inline void start_document(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_document(json_iterator &iter) {
|
||||
iter.log_start_value("document");
|
||||
start_container(iter);
|
||||
iter.dom_parser.is_array[iter.depth] = false;
|
||||
return SUCCESS;
|
||||
}
|
||||
simdjson_really_inline void start_object(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_object(json_iterator &iter) {
|
||||
iter.log_start_value("object");
|
||||
start_container(iter);
|
||||
iter.dom_parser.is_array[iter.depth] = false;
|
||||
return SUCCESS;
|
||||
}
|
||||
simdjson_really_inline void start_array(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code start_array(json_iterator &iter) {
|
||||
iter.log_start_value("array");
|
||||
start_container(iter);
|
||||
iter.dom_parser.is_array[iter.depth] = true;
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
simdjson_really_inline void end_object(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_object(json_iterator &iter) {
|
||||
iter.log_end_value("object");
|
||||
end_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
|
||||
return end_container(iter, internal::tape_type::START_OBJECT, internal::tape_type::END_OBJECT);
|
||||
}
|
||||
simdjson_really_inline void end_array(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_array(json_iterator &iter) {
|
||||
iter.log_end_value("array");
|
||||
end_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
|
||||
return end_container(iter, internal::tape_type::START_ARRAY, internal::tape_type::END_ARRAY);
|
||||
}
|
||||
simdjson_really_inline void end_document(json_iterator &iter) {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_document(json_iterator &iter) {
|
||||
iter.log_end_value("document");
|
||||
constexpr uint32_t start_tape_index = 0;
|
||||
tape.append(start_tape_index, internal::tape_type::ROOT);
|
||||
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter), internal::tape_type::ROOT);
|
||||
return SUCCESS;
|
||||
}
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code key(json_iterator &iter, const uint8_t *key) {
|
||||
return parse_string(iter, key, true);
|
||||
}
|
||||
|
||||
// Called after end_object/end_array. Not called after empty_object/empty_array,
|
||||
// as the parent is already known in those cases.
|
||||
//
|
||||
// The object returned from end_container() should support the in_container(),
|
||||
// in_array() and in_object() methods, allowing the iterator to branch to the
|
||||
// correct place.
|
||||
simdjson_really_inline tape_builder &end_container(json_iterator &iter) {
|
||||
iter.depth--;
|
||||
return *this;
|
||||
}
|
||||
// increment_count increments the count of keys in an object or values in an array.
|
||||
simdjson_really_inline void increment_count(json_iterator &iter) {
|
||||
iter.dom_parser.open_containers[iter.depth].count++; // we have a key value pair in the object at parser.dom_parser.depth - 1
|
||||
|
@ -219,7 +213,7 @@ private:
|
|||
tape.skip(); // We don't actually *write* the start element until the end.
|
||||
}
|
||||
|
||||
simdjson_really_inline void end_container(json_iterator &iter, internal::tape_type start, internal::tape_type end) noexcept {
|
||||
SIMDJSON_WARN_UNUSED simdjson_really_inline error_code end_container(json_iterator &iter, internal::tape_type start, internal::tape_type end) noexcept {
|
||||
// Write the ending tape element, pointing at the start location
|
||||
const uint32_t start_tape_index = iter.dom_parser.open_containers[iter.depth].tape_index;
|
||||
tape.append(start_tape_index, end);
|
||||
|
@ -229,6 +223,7 @@ private:
|
|||
const uint32_t count = iter.dom_parser.open_containers[iter.depth].count;
|
||||
const uint32_t cntsat = count > 0xFFFFFF ? 0xFFFFFF : count;
|
||||
tape_writer::write(iter.dom_parser.doc->tape[start_tape_index], next_tape_index(iter) | (uint64_t(cntsat) << 32), start);
|
||||
return SUCCESS;
|
||||
}
|
||||
|
||||
simdjson_really_inline uint8_t *on_start_string(json_iterator &iter) noexcept {
|
||||
|
|
Loading…
Reference in New Issue