+
Skip to content

Unable to accept the literal '\\'  #40

@mingodad

Description

@mingodad

While testing a grammar for https://github.com/potassco/clingo/blob/master/libgringo/src/input/nongroundgrammar.yy I found that lalr do not handle the literal '\\' see example and possible fix bellow:

escaped {

%whitespace "[ \t\r\n]*";

	ch : '\\' ;
}

Error:

lalr (5:0): ERROR: unterminated literal
lalr (5:0): ERROR: expected ';' not found
lalr (5:0): ERROR: expected '}' not found
Error compiling grammar. Error count = 3

Possible fix:

bool GrammarParser::match_literal()
{
    match_whitespace_and_comments();
    if ( match("'") )
    {
        bool escaped = false;
        const char* position = position_;
        while ( position != end_ && (*position != '\'' || escaped) && !is_new_line(position) )
        {
            escaped = *position == '\\';
            ++position;
            if(*position == '\\' && escaped) //!!!<<<<< this new block seems to fix this issue
            {
                ++position;
                escaped = false;
            }
	}
        if ( position == end_ || !is_new_line(position) )
        {
            lexeme_.assign( position_, position );
            position_ = position;
            expect( "'" );
            return true;
        }
        error( line_, LALR_ERROR_UNTERMINATED_LITERAL, "unterminated literal" );
        return false;
    }
    return false;
}

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

      点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载