Commit 09cd4b9b authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

[2506] handle other rare error cases

parent 597ed99f
......@@ -203,19 +203,22 @@ optionsForTokenType(MasterToken::Type expect) {
case MasterToken::NUMBER:
return (MasterLexer::NUMBER);
default:
assert(false);
isc_throw(InvalidParameter,
"expected type for getNextToken not supported: " << expect);
}
}
}
const MasterToken&
MasterLexer::getNextToken(MasterToken::Type expect, bool eol_ok) {
// the result should be set in impl_->token_
// Get the next token, specifying an appropriate option corresponding to
// the expected type. The result should be set in impl_->token_.
getNextToken(optionsForTokenType(expect));
if (impl_->token_.getType() == MasterToken::ERROR) {
//if (impl_->token_.getErrorCode() == MasterToken::NUMBER_OUT_OF_RANGE)
ungetToken();
if (impl_->token_.getErrorCode() == MasterToken::NUMBER_OUT_OF_RANGE) {
ungetToken();
}
throw LexerError(__FILE__, __LINE__, impl_->token_);
}
......
......@@ -398,4 +398,30 @@ TEST_F(MasterLexerTest, getNextTokenNumber) {
eofCheck(lexer, MasterToken::NUMBER);
}
TEST_F(MasterLexerTest, getNextTokenErrors) {
// Check miscellaneous error cases
ss << ") "; // unbalanced parenthesis
ss << "string-after-error ";
lexer.pushSource(ss);
// Only string/qstring/number can be "expected".
EXPECT_THROW(lexer.getNextToken(MasterToken::END_OF_LINE),
isc::InvalidParameter);
EXPECT_THROW(lexer.getNextToken(MasterToken::END_OF_FILE),
isc::InvalidParameter);
EXPECT_THROW(lexer.getNextToken(MasterToken::INITIAL_WS),
isc::InvalidParameter);
EXPECT_THROW(lexer.getNextToken(MasterToken::ERROR),
isc::InvalidParameter);
// If it encounters a syntax error, it results in LexerError exception.
lexerErrorCheck(lexer, MasterToken::STRING, MasterToken::UNBALANCED_PAREN);
// Unlike the NUMBER_OUT_OF_RANGE case, the error part has been skipped
// within getNextToken(). We should be able to get the next token.
EXPECT_EQ("string-after-error",
lexer.getNextToken(MasterToken::STRING).getString());
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment