diff --git a/src/lalr/ErrorCode.hpp b/src/lalr/ErrorCode.hpp index 4ed44c3..0fcab63 100644 --- a/src/lalr/ErrorCode.hpp +++ b/src/lalr/ErrorCode.hpp @@ -12,6 +12,7 @@ enum ErrorCode PARSER_ERROR_NONE, ///< No %error. LALR_ERROR_SYNTAX, ///< Syntax %error occured while parsing input. LALR_ERROR_UNTERMINATED_LITERAL, ///< Unterminated literal in an lalr grammar. + LALR_ERROR_EMPTY_LITERAL, ///< Empty literal in an lalr grammar. LEXER_ERROR_MISSING_ACTION_HANDLER, ///< A lexer action hasn't been bound to a function. LEXER_ERROR_SYNTAX, ///< Syntax %error occured while parsing some input. LEXER_ERROR_SYMBOL_CONFLICT, ///< A lexer state matches more than one symbol. diff --git a/src/lalr/GrammarParser.cpp b/src/lalr/GrammarParser.cpp index 7c369f3..6564190 100644 --- a/src/lalr/GrammarParser.cpp +++ b/src/lalr/GrammarParser.cpp @@ -228,12 +228,21 @@ bool GrammarParser::match_literal() { escaped = *position == '\\'; ++position; + if ( *position == '\\' && escaped ) + { + ++position; + escaped = false; + } } if ( position == end_ || !is_new_line(position) ) { lexeme_.assign( position_, position ); position_ = position; expect( "'" ); + if ( lexeme_.empty() ) + { + error( LALR_ERROR_EMPTY_LITERAL, "empty literal" ); + } return true; } error( LALR_ERROR_UNTERMINATED_LITERAL, "unterminated literal" ); @@ -253,10 +262,19 @@ bool GrammarParser::match_regex() { escaped = *position == '\\'; ++position; + if (*position == '\\' && escaped) + { + ++position; + escaped = false; + } } lexeme_.assign( position_, position ); position_ = position; expect( "\"" ); + if ( lexeme_.empty() ) + { + error( LALR_ERROR_EMPTY_LITERAL, "empty regex" ); + } return true; } return false;