From 62b4780e07e152e037e29823bfd7d911b9767f2e Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Tue, 24 Dec 2019 08:34:24 +1100 Subject: [PATCH] Fix command error line/column reporting --- src/command_manager.cc | 20 +++++++++++++++++--- src/command_manager.hh | 1 + 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/command_manager.cc b/src/command_manager.cc index 3a3654f8..82985b5d 100644 --- a/src/command_manager.cc +++ b/src/command_manager.cc @@ -92,11 +92,25 @@ Reader& Reader::operator++() { kak_assert(pos < str.end()); if (*pos == '\n') + { ++line; + line_start = ++pos; + return *this; + } utf8::to_next(pos, str.end()); return *this; } +void Reader::next_byte() +{ + kak_assert(pos < str.end()); + if (*pos++ == '\n') + { + ++line; + line_start = pos; + } +} + namespace { @@ -152,10 +166,10 @@ QuotedResult parse_quoted_balanced(Reader& reader, char opening_delimiter, else if (c == closing_delimiter and level-- == 0) { auto content = reader.substr_from(start); - ++reader.pos; + reader.next_byte(); return {String{String::NoCopy{}, content}, true}; } - ++reader.pos; + reader.next_byte(); } return {String{String::NoCopy{}, reader.substr_from(start)}, false}; } @@ -179,7 +193,7 @@ String parse_unquoted(Reader& reader) else return str; } - ++reader.pos; + reader.next_byte(); } if (beg < reader.str.end()) str += reader.substr_from(beg); diff --git a/src/command_manager.hh b/src/command_manager.hh index 0545a27c..affec4e3 100644 --- a/src/command_manager.hh +++ b/src/command_manager.hh @@ -69,6 +69,7 @@ public: Codepoint operator*() const; Codepoint peek_next() const; Reader& operator++(); + void next_byte(); explicit operator bool() const { return pos < str.end(); } StringView substr_from(const char* start) const { return {start, pos}; }