Skip to content

Commit

Permalink
Fix to only match fully words, because before it was matching a subst…
Browse files Browse the repository at this point in the history
…ring like 'error' inside 'errors'
  • Loading branch information
mingodad committed Jul 18, 2023
1 parent 51ab70e commit 208eda6
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions src/lalr/GrammarParser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ bool GrammarParser::match_associativity_statement()

bool GrammarParser::match_whitespace_statement()
{
if ( match("%whitespace") )
if ( match_word("%whitespace") )
{
grammar_->whitespace();
if ( match_regex() )
Expand All @@ -109,7 +109,7 @@ bool GrammarParser::match_whitespace_statement()

bool GrammarParser::match_case_insensitive_statement()
{
if ( match("%case_insensitive") )
if ( match_word("%case_insensitive") )
{
grammar_->case_insensitive();
expect( ";" );
Expand Down Expand Up @@ -167,22 +167,22 @@ bool GrammarParser::match_symbol()

bool GrammarParser::match_associativity()
{
if ( match("%left") )
if ( match_word("%left") )
{
grammar_->left( line_ );
return true;
}
else if ( match("%right") )
else if ( match_word("%right") )
{
grammar_->right( line_ );
return true;
}
else if ( match("%none") || match("%nonassoc"))
else if ( match_word("%none") || match_word("%nonassoc"))
{
grammar_->none( line_ );
return true;
}
else if ( match("%precedence") )
else if ( match_word("%precedence") )
{
grammar_->assoc_prec( line_ );
return true;
Expand All @@ -209,7 +209,7 @@ bool GrammarParser::match_expression()

bool GrammarParser::match_precedence()
{
if ( match("%precedence") || match("%prec") )
if ( match_word("%precedence") || match_word("%prec") )
{
grammar_->precedence();
match_symbol();
Expand All @@ -235,7 +235,7 @@ bool GrammarParser::match_action()

bool GrammarParser::match_error()
{
return match( "error" );
return match_word( "error" );
}

bool GrammarParser::match_literal()
Expand Down Expand Up @@ -408,6 +408,21 @@ bool GrammarParser::match( const char* keyword )
return match_without_skipping_whitespace( keyword );
}

bool GrammarParser::match_word( const char* keyword )
{
match_whitespace_and_comments();
const char *saved_position = position_;
bool result = match_without_skipping_whitespace( keyword );
//check for fully word match
if(result && position_ != end_ && (isalnum(*position_) || isdigit(*position_) || *position_ == '_'))
{
position_ = saved_position;
return false;
}

return result;
}

bool GrammarParser::match_without_skipping_whitespace( const char* lexeme )
{
const char* position = position_;
Expand Down

0 comments on commit 208eda6

Please sign in to comment.