Skip to content

Commit 5e69fb7

Browse files
committed
Call a function to parse structurals
1 parent a5beffd commit 5e69fb7

1 file changed

Lines changed: 16 additions & 12 deletions

File tree

src/generic/stage2/structural_parser.h

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -368,23 +368,17 @@ struct structural_parser {
368368
really_inline void log_error(const char *error) {
369369
logger::log_line(structurals, "", "ERROR", error);
370370
}
371-
};
371+
}; // struct structural_parser
372372

373373
// Redefine FAIL_IF to use goto since it'll be used inside the function now
374374
#undef FAIL_IF
375375
#define FAIL_IF(EXPR) { if (EXPR) { goto error; } }
376376

377-
} // namespace stage2
378-
379-
/************
380-
* The JSON is parsed to a tape, see the accompanying tape.md file
381-
* for documentation.
382-
***********/
383-
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
384-
this->doc = &_doc;
377+
WARN_UNUSED static error_code parse_structurals(dom_parser_implementation &dom_parser, dom::document &doc) noexcept {
378+
dom_parser.doc = &doc;
385379
static constexpr stage2::unified_machine_addresses addresses = INIT_ADDRESSES();
386-
stage2::structural_parser parser(*this);
387-
error_code result = parser.start(len, addresses.finish);
380+
stage2::structural_parser parser(dom_parser);
381+
error_code result = parser.start(dom_parser.len, addresses.finish);
388382
if (result) { return result; }
389383

390384
//
@@ -398,7 +392,7 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
398392
FAIL_IF( parser.start_array(addresses.finish) );
399393
// Make sure the outer array is closed before continuing; otherwise, there are ways we could get
400394
// into memory corruption. See https://github.com/simdjson/simdjson/issues/906
401-
if (buf[structural_indexes[n_structural_indexes - 1]] != ']') {
395+
if (parser.structurals.buf[parser.structurals.structural_indexes[dom_parser.n_structural_indexes - 1]] != ']') {
402396
goto error;
403397
}
404398
goto array_begin;
@@ -505,6 +499,16 @@ WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) no
505499
return parser.error();
506500
}
507501

502+
} // namespace stage2
503+
504+
/************
505+
* The JSON is parsed to a tape, see the accompanying tape.md file
506+
* for documentation.
507+
***********/
508+
WARN_UNUSED error_code dom_parser_implementation::stage2(dom::document &_doc) noexcept {
509+
return stage2::parse_structurals(*this, _doc);
510+
}
511+
508512
namespace stage2 {
509513

510514
struct streaming_structural_parser: structural_parser {

0 commit comments

Comments
 (0)