mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-05 04:58:57 +00:00
Parser error message reports both the line number and the cursor position. (#4954)
This commit is contained in:
committed by
Wouter van Oortmerssen
parent
bf871ffd7f
commit
7e711f80d7
@@ -94,11 +94,12 @@ std::string MakeCamel(const std::string &in, bool first) {
|
||||
void Parser::Message(const std::string &msg) {
|
||||
error_ = file_being_parsed_.length() ? AbsolutePath(file_being_parsed_) : "";
|
||||
// clang-format off
|
||||
#ifdef _WIN32
|
||||
error_ += "(" + NumToString(line_) + ")"; // MSVC alike
|
||||
#else
|
||||
#ifdef _WIN32 // MSVC alike
|
||||
error_ +=
|
||||
"(" + NumToString(line_) + ", " + NumToString(CursorPosition()) + ")";
|
||||
#else // gcc alike
|
||||
if (file_being_parsed_.length()) error_ += ":";
|
||||
error_ += NumToString(line_) + ":0"; // gcc alike
|
||||
error_ += NumToString(line_) + ": " + NumToString(CursorPosition());
|
||||
#endif
|
||||
// clang-format on
|
||||
error_ += ": " + msg;
|
||||
@@ -280,7 +281,7 @@ CheckedError Parser::Next() {
|
||||
case '\r':
|
||||
case '\t': break;
|
||||
case '\n':
|
||||
line_++;
|
||||
MarkNewLine();
|
||||
seen_newline = true;
|
||||
break;
|
||||
case '{':
|
||||
@@ -420,7 +421,7 @@ CheckedError Parser::Next() {
|
||||
cursor_++;
|
||||
// TODO: make nested.
|
||||
while (*cursor_ != '*' || cursor_[1] != '/') {
|
||||
if (*cursor_ == '\n') line_++;
|
||||
if (*cursor_ == '\n') MarkNewLine();
|
||||
if (!*cursor_) return Error("end of file in comment");
|
||||
cursor_++;
|
||||
}
|
||||
@@ -2259,8 +2260,8 @@ bool Parser::Parse(const char *source, const char **include_paths,
|
||||
CheckedError Parser::StartParseFile(const char *source,
|
||||
const char *source_filename) {
|
||||
file_being_parsed_ = source_filename ? source_filename : "";
|
||||
source_ = cursor_ = source;
|
||||
line_ = 1;
|
||||
source_ = source;
|
||||
ResetState(source_);
|
||||
error_.clear();
|
||||
ECHECK(SkipByteOrderMark());
|
||||
NEXT();
|
||||
|
||||
Reference in New Issue
Block a user