mirror of
https://github.com/google/flatbuffers.git
synced 2026-06-14 16:36:55 +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
@@ -477,10 +477,28 @@ struct IDLOptions {
|
||||
|
||||
// This encapsulates where the parser is in the current source file.
|
||||
struct ParserState {
|
||||
ParserState() : cursor_(nullptr), line_(1), token_(-1) {}
|
||||
ParserState()
|
||||
: cursor_(nullptr), line_start_(nullptr), line_(0), token_(-1) {}
|
||||
|
||||
protected:
|
||||
void ResetState(const char *source) {
|
||||
cursor_ = source;
|
||||
line_ = 0;
|
||||
MarkNewLine();
|
||||
}
|
||||
|
||||
void MarkNewLine() {
|
||||
line_start_ = cursor_;
|
||||
line_ += 1;
|
||||
}
|
||||
|
||||
int64_t CursorPosition() const {
|
||||
FLATBUFFERS_ASSERT(cursor_ && line_start_ && cursor_ >= line_start_);
|
||||
return static_cast<int64_t>(cursor_ - line_start_);
|
||||
}
|
||||
|
||||
const char *cursor_;
|
||||
const char *line_start_;
|
||||
int line_; // the current line being parsed
|
||||
int token_;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user