Skip to content

Missing %whitespace directive definition should be an error ? #39

@mingodad

Description

@mingodad

While testing the https://meimporta.eu/lalr-playground/ I introduced a grammar for https://github.com/jplevyak/dparser but forgot to add a %whitespace directive but lalr didn't flagged that as an error.

Maybe this can fix it:

int GrammarParser::parse( const char* start, const char* finish, ErrorPolicy* error_policy, Grammar* grammar )
{
    LALR_ASSERT( start );
    LALR_ASSERT( finish );
    LALR_ASSERT( grammar );
    error_policy_ = error_policy;
    grammar_ = grammar;
    position_ = start;
    end_ = finish;
    line_ = 1;
    errors_ = 0;
    if ( !match_grammar() )
    {
        error( 1, LALR_ERROR_SYNTAX, "parsing grammar failed" );
    }
    if( grammar_->whitespace_tokens().empty() )
    {
        error( 1, PARSER_ERROR_UNDEFINED_SYMBOL, "no '%%whitespace' directive defined" );
    }
    return errors_;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions