Remove stack, just use state machine
This commit is contained in:
@@ -64,9 +64,6 @@ public:
|
||||
// Parser state
|
||||
enum class ParseState {
|
||||
Root,
|
||||
RequestId,
|
||||
LeaderId,
|
||||
ReadVersion,
|
||||
PreconditionsArray,
|
||||
PreconditionObject,
|
||||
OperationsArray,
|
||||
@@ -82,12 +79,9 @@ public:
|
||||
struct ParserContext {
|
||||
using ArenaString = std::basic_string<char, std::char_traits<char>,
|
||||
ArenaStlAllocator<char>>;
|
||||
using ArenaStateStack =
|
||||
std::stack<ParseState,
|
||||
std::vector<ParseState, ArenaStlAllocator<ParseState>>>;
|
||||
ArenaAllocator arena;
|
||||
|
||||
ArenaStateStack state_stack;
|
||||
ParseState current_state = ParseState::Root;
|
||||
ArenaString current_key;
|
||||
ArenaString current_string;
|
||||
ArenaString current_number;
|
||||
@@ -105,8 +99,7 @@ public:
|
||||
|
||||
// Constructor to initialize arena-allocated containers
|
||||
explicit ParserContext()
|
||||
: state_stack(ArenaStateStack::container_type(
|
||||
ArenaStlAllocator<ParseState>(&arena))),
|
||||
:
|
||||
current_key(ArenaStlAllocator<char>(&arena)),
|
||||
current_string(ArenaStlAllocator<char>(&arena)),
|
||||
current_number(ArenaStlAllocator<char>(&arena)),
|
||||
@@ -122,8 +115,7 @@ public:
|
||||
current_operation = {};
|
||||
precondition_type = ArenaString{ArenaStlAllocator<char>(&arena)};
|
||||
operation_type = ArenaString{ArenaStlAllocator<char>(&arena)};
|
||||
state_stack = ArenaStateStack{ArenaStateStack::container_type(
|
||||
ArenaStlAllocator<ParseState>(&arena))};
|
||||
current_state = ParseState::Root;
|
||||
}
|
||||
};
|
||||
|
||||
@@ -313,7 +305,7 @@ public:
|
||||
WeaselJsonParser_reset(json_parser_);
|
||||
}
|
||||
parser_context_.reset_arena_memory();
|
||||
parser_context_.state_stack.push(ParseState::Root);
|
||||
parser_context_.current_state = ParseState::Root;
|
||||
parser_context_.parse_error = nullptr;
|
||||
parser_context_.parse_complete = false;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user