escaped {
%whitespace "[ \t\r\n]*";
ch : '\\' ;
}
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
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;
}
While testing a grammar for https://github.com/potassco/clingo/blob/master/libgringo/src/input/nongroundgrammar.yy I found that
lalrdo not handle the literal'\\'see example and possible fix bellow:Error:
Possible fix: