Skip to content

Commit 59194bc

Browse files
committed
parser state is popped by the caller
1 parent 25e740d commit 59194bc

File tree

2 files changed

+420
-257
lines changed

2 files changed

+420
-257
lines changed

include/boost/json/basic_parser.hpp

+36-25
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,8 @@ class basic_parser
283283
val1, val2, val3
284284
};
285285

286+
using no_state = std::integral_constant< state, state(CHAR_MAX) >;
287+
286288
struct number
287289
{
288290
uint64_t mant;
@@ -292,7 +294,7 @@ class basic_parser
292294
bool neg;
293295
};
294296

295-
template< bool StackEmpty_, char First_ >
297+
template< class PrevState, char First_ >
296298
struct parse_number_helper;
297299

298300
// optimization: must come first
@@ -392,42 +394,47 @@ class basic_parser
392394
#pragma warning pop
393395
#endif
394396

395-
template<bool StackEmpty_/*, bool Terminal_*/>
397+
template<class PrevState/*, bool Terminal_*/>
396398
const char* parse_comment(const char* p,
397-
std::integral_constant<bool, StackEmpty_> stack_empty,
399+
PrevState st,
398400
/*std::integral_constant<bool, Terminal_>*/ bool terminal);
399401

400-
template<bool StackEmpty_>
401-
const char* parse_document(const char* p,
402-
std::integral_constant<bool, StackEmpty_> stack_empty);
402+
template<class PrevState>
403+
const char* parse_document(const char* p, PrevState st);
403404

404-
template<bool StackEmpty_, bool AllowComments_/*,
405+
template<class PrevState, bool AllowComments_/*,
405406
bool AllowTrailing_, bool AllowBadUTF8_*/>
406-
const char* parse_value(const char* p,
407-
std::integral_constant<bool, StackEmpty_> stack_empty,
407+
const char* parse_value(
408+
const char* p,
409+
PrevState st,
408410
std::integral_constant<bool, AllowComments_> allow_comments,
409411
/*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing,
410412
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
411413

412414
template<bool AllowComments_/*,
413415
bool AllowTrailing_, bool AllowBadUTF8_*/>
414-
const char* resume_value(const char* p,
416+
const char* resume_value(
417+
const char* p,
418+
state st,
415419
std::integral_constant<bool, AllowComments_> allow_comments,
416420
/*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing,
417421
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
418422

419-
template<bool StackEmpty_, bool AllowComments_/*,
423+
template<class PrevState, bool AllowComments_/*,
420424
bool AllowTrailing_, bool AllowBadUTF8_*/>
421-
const char* parse_object(const char* p,
422-
std::integral_constant<bool, StackEmpty_> stack_empty,
425+
const char* parse_object(
426+
const char* p,
427+
PrevState st,
428+
std::size_t size,
423429
std::integral_constant<bool, AllowComments_> allow_comments,
424430
/*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing,
425431
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
426432

427-
template<bool StackEmpty_, bool AllowComments_/*,
433+
template<class PrevState, bool AllowComments_/*,
428434
bool AllowTrailing_, bool AllowBadUTF8_*/>
429435
const char* parse_array(const char* p,
430-
std::integral_constant<bool, StackEmpty_> stack_empty,
436+
PrevState st,
437+
std::size_t size,
431438
std::integral_constant<bool, AllowComments_> allow_comments,
432439
/*std::integral_constant<bool, AllowTrailing_>*/ bool allow_trailing,
433440
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
@@ -436,32 +443,36 @@ class basic_parser
436443
const char* parse_literal(const char* p,
437444
std::integral_constant<int, Literal> literal);
438445

439-
template<bool StackEmpty_, bool IsKey_/*,
446+
template<class PrevState, bool IsKey_/*,
440447
bool AllowBadUTF8_*/>
441-
const char* parse_string(const char* p,
442-
std::integral_constant<bool, StackEmpty_> stack_empty,
448+
const char* parse_string(
449+
const char* p,
450+
PrevState st,
451+
std::size_t total,
443452
std::integral_constant<bool, IsKey_> is_key,
444453
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
445454

446-
template<bool StackEmpty_, char First_, number_precision Numbers_>
455+
template<class PrevState, char First_, number_precision Numbers_>
447456
const char* parse_number(const char* p,
448-
std::integral_constant<bool, StackEmpty_> stack_empty,
457+
PrevState st,
449458
std::integral_constant<char, First_> first,
450459
std::integral_constant<number_precision, Numbers_> numbers);
451460

452-
template<bool StackEmpty_, bool IsKey_/*,
461+
template<class PrevState, bool IsKey_/*,
453462
bool AllowBadUTF8_*/>
454-
const char* parse_unescaped(const char* p,
455-
std::integral_constant<bool, StackEmpty_> stack_empty,
463+
const char* parse_unescaped(
464+
const char* p,
465+
PrevState st,
466+
std::size_t total,
456467
std::integral_constant<bool, IsKey_> is_key,
457468
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
458469

459-
template<bool StackEmpty_/*, bool IsKey_,
470+
template<class PrevState/*, bool IsKey_,
460471
bool AllowBadUTF8_*/>
461472
const char* parse_escaped(
462473
const char* p,
474+
PrevState st,
463475
std::size_t total,
464-
std::integral_constant<bool, StackEmpty_> stack_empty,
465476
/*std::integral_constant<bool, IsKey_>*/ bool is_key,
466477
/*std::integral_constant<bool, AllowBadUTF8_>*/ bool allow_bad_utf8);
467478

0 commit comments

Comments
 (0)