aboutsummaryrefslogtreecommitdiff
path: root/src/parser.cpp
diff options
context:
space:
mode:
authorgingerBill <gingerBill@users.noreply.github.com>2024-07-01 11:03:29 +0100
committerGitHub <noreply@github.com>2024-07-01 11:03:29 +0100
commitfb0b95bcadeb60555920c9f3c8ecd2467c71bf83 (patch)
treee14eb158c33e7b9d088dc8d3cb797a840df5ec12 /src/parser.cpp
parent1a4edad63e45f91e8ef45836868ba8285a4e8f09 (diff)
parent8ed5cb283b5039693e96d6f47eea6213194d6cbe (diff)
Merge pull request #3760 from Feoramund/refactor-show-error-on-line
Refactor `show_error_on_line`
Diffstat (limited to 'src/parser.cpp')
-rw-r--r--src/parser.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/src/parser.cpp b/src/parser.cpp
index 583f4a57d..93889d1b2 100644
--- a/src/parser.cpp
+++ b/src/parser.cpp
@@ -71,6 +71,12 @@ gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_)
u8 *line_start = pos_offset;
u8 *line_end = pos_offset;
+
+ if (offset > 0 && *line_start == '\n') {
+ // Prevent an error token that starts at the boundary of a line that
+ // leads to an empty line from advancing off its line.
+ line_start -= 1;
+ }
while (line_start >= start) {
if (*line_start == '\n') {
line_start += 1;
@@ -78,6 +84,11 @@ gb_internal gbString get_file_line_as_string(TokenPos const &pos, i32 *offset_)
}
line_start -= 1;
}
+ if (line_start == start - 1) {
+ // Prevent an error on the first line from stepping behind the boundary
+ // of the text.
+ line_start += 1;
+ }
while (line_end < end) {
if (*line_end == '\n') {