diff --git a/src/generic/stage2/logger.h b/src/generic/stage2/logger.h index 85f2444a..7d6fb97a 100644 --- a/src/generic/stage2/logger.h +++ b/src/generic/stage2/logger.h @@ -30,6 +30,12 @@ namespace logger { } } + static really_inline void log_string(const char *message) { + if (LOG_ENABLED) { + printf("%s\n", message); + } + } + // Logs a single line of template static really_inline void log_line(S &structurals, const char *title_prefix, const char *title, const char *detail) { diff --git a/src/generic/stage2/structural_parser.h b/src/generic/stage2/structural_parser.h index 63dc5695..4c112b67 100644 --- a/src/generic/stage2/structural_parser.h +++ b/src/generic/stage2/structural_parser.h @@ -269,19 +269,9 @@ struct structural_parser { } } - template WARN_UNUSED really_inline error_code finish() { end_document(); - - if (STREAMING) { - parser.next_structural_index = uint32_t(structurals.next_structural_index()); - } else { - // Check if we're at the end or if there is stuff left still - if ( !structurals.at_end(parser.n_structural_indexes) ) { - log_error("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); - return parser.error = TAPE_ERROR; - } - } + parser.next_structural_index = uint32_t(structurals.next_structural_index()); if (depth != 0) { log_error("Unclosed objects or arrays!"); @@ -505,7 +495,7 @@ array_continue: } finish: - return parser.finish(); + return parser.finish(); error: return parser.error(); @@ -519,7 +509,16 @@ error: * for documentation. ***********/ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept { - return stage2::parse_structurals(*this, _doc); + error_code result = stage2::parse_structurals(*this, _doc); + if (result) { return result; } + + // If we didn't make it to the end, it's an error + if ( next_structural_index != n_structural_indexes ) { + logger::log_string("More than one JSON value at the root of the document, or extra characters at the end of the JSON!"); + return error = TAPE_ERROR; + } + + return SUCCESS; } /************