Skip to content

Commit

Permalink
Avoid initializing Parser with invalid ParserStateMachine
Browse files Browse the repository at this point in the history
When a grammar fails to generate a parser the ParserStateMachine has a
null start state.  When this is passed to construct a Parser quietly
avoid creating any parser specific state, esp. ParserNode which will
assert if passed a null state.
  • Loading branch information
Charles Baker committed Jul 16, 2023
1 parent 4ba3456 commit 4881754
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/lalr/Parser.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,13 @@ Parser<Iterator, UserData, Char, Traits, Allocator>::Parser( const ParserStateMa
++action;
}

nodes_.reserve( 64 );
user_data_.reserve( 64 );
nodes_.push_back( ParserNode(state_machine_->start_state, nullptr, 0, 1) );
user_data_.push_back( UserData() );
if ( state_machine_->start_state )
{
nodes_.reserve( 64 );
user_data_.reserve( 64 );
nodes_.push_back( ParserNode(state_machine_->start_state, nullptr, 0, 1) );
user_data_.push_back( UserData() );
}
}

/**
Expand Down

0 comments on commit 4881754

Please sign in to comment.