-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
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
Labels
No labels