// finer.
fromtextError(error_issued, lexer, callbacks, NULL, ex.what());
}
- // Other exceptions mean a serious implementation bug; it doesn't make
- // sense to catch and try to recover from them here. Just propagate.
+ // Other exceptions mean a serious implementation bug or fatal system
+ // error; it doesn't make sense to catch and try to recover from them
+ // here. Just propagate.
// Consume to end of line / file.
// If not at end of line initially set error code.
// Call callback via fromtextError once if there was an error.
do {
const MasterToken& token = lexer.getNextToken();
- if (token.getType() != MasterToken::END_OF_LINE &&
- token.getType() != MasterToken::END_OF_FILE) {
+ switch (token.getType()) {
+ case MasterToken::END_OF_LINE:
+ return (rdata);
+ case MasterToken::END_OF_FILE:
+ callbacks.warning(lexer.getSourceName(), lexer.getSourceLine(),
+ "file does not end with newline");
+ return (rdata);
+ default:
rdata.reset(); // we'll return NULL
- if (!error_issued) {
- fromtextError(error_issued, lexer, callbacks, &token,
- "extra input text");
- }
- } else { // reached EOL or EOF
- break;
+ fromtextError(error_issued, lexer, callbacks, &token,
+ "extra input text");
+ // Continue until we see EOL or EOF
}
} while (true);
- return (rdata);
+ // We shouldn't reach here
+ assert(false);
+ return (RdataPtr()); // add explicit return to silence some compilers
}
int
ss << aaaa_rdata.toText() << " extra token\n"; // 2 extra tokens
ss << ")\n"; // causing lexer error in parsing the RDATA text
ss << "192.0.2.1\n"; // semantics error: IPv4 address is given for AAAA
+ ss << aaaa_rdata.toText(); // valid, but end with EOF, not EOL
lexer.pushSource(ss);
CreateRdataCallback callback;
callback.check(src_name, 5, CreateRdataCallback::ERROR,
"createRdata from text failed: Failed to convert "
"'192.0.2.1' to IN/AAAA RDATA");
+
+ // Input is valid and parse will succeed, but with a warning that the
+ // file is not ended with a newline.
+ callback.clear();
+ rdata = createRdata(RRType::AAAA(), RRClass::IN(), lexer, NULL,
+ MasterLoader::MANY_ERRORS, callbacks);
+ EXPECT_EQ(0, aaaa_rdata.compare(*rdata));
+ callback.check(src_name, 6, CreateRdataCallback::WARN,
+ "file does not end with newline");
}
}