aboutsummaryrefslogtreecommitdiff
path: root/boot
diff options
context:
space:
mode:
Diffstat (limited to 'boot')
-rw-r--r--boot/parse.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/boot/parse.c b/boot/parse.c
index 2891a0f..aeb4d88 100644
--- a/boot/parse.c
+++ b/boot/parse.c
@@ -100,17 +100,12 @@ parser_error_is_none(const struct Parser_Error* error)
struct Span
token_span_to_line_span(struct Span span, struct String source)
{
- Pos line_start = span.start + 1, line_end = span.end - 1;
- // expand `line_start` to start from the beginning of the line,
- // and `line_end` to end at the end of the line.
- while (line_start > 0) {
- if (string_at(source, line_start - 1) == '\n') break;
- line_start--;
- }
- while (line_end < string_length(source)) {
- if (string_at(source, line_end) == '\n') break;
- line_end++;
- }
+ Pos line_start = span.start, line_end = span.start;
+
+ // go backwards from the start of the token's span to find line start.
+ while (line_start > 0 && string_at(source, line_start - 1) != '\n') line_start--;
+ // go forwards from the end of the token's span to find line end.
+ while (line_end < string_length(source) && string_at(source, line_end) != '\n') line_end++;
return span_new(line_start, line_end);
}