From 896ef65f8c337831244efab0ac0eda3112c25600 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Fri, 8 Nov 2019 16:55:54 -0800 Subject: [PATCH] Rename error_offset to error_offset_within_token Hopefully clarify the role of this variable. --- src/fish_tests.cpp | 8 ++++---- src/parse_tree.cpp | 5 +++-- src/tokenizer.cpp | 2 +- src/tokenizer.h | 2 +- 4 files changed, 9 insertions(+), 8 deletions(-) diff --git a/src/fish_tests.cpp b/src/fish_tests.cpp index 823313264..5e67bfa3b 100644 --- a/src/fish_tests.cpp +++ b/src/fish_tests.cpp @@ -634,7 +634,7 @@ static void test_tokenizer() { do_test(token.has_value()); do_test(token->type == token_type_t::error); do_test(token->error == tokenizer_error_t::unterminated_escape); - do_test(token->error_offset == 3); + do_test(token->error_offset_within_token == 3); } { @@ -646,7 +646,7 @@ static void test_tokenizer() { do_test(token->type == token_type_t::error); do_test(token->error == tokenizer_error_t::closing_unopened_subshell); do_test(token->offset == 4); - do_test(token->error_offset == 0); + do_test(token->error_offset_within_token == 0); } { @@ -657,7 +657,7 @@ static void test_tokenizer() { do_test(token.has_value()); do_test(token->type == token_type_t::error); do_test(token->error == tokenizer_error_t::unterminated_subshell); - do_test(token->error_offset == 4); + do_test(token->error_offset_within_token == 4); } { @@ -668,7 +668,7 @@ static void test_tokenizer() { do_test(token.has_value()); do_test(token->type == token_type_t::error); do_test(token->error == tokenizer_error_t::unterminated_slice); - do_test(token->error_offset == 4); + do_test(token->error_offset_within_token == 4); } // Test some redirection parsing. diff --git a/src/parse_tree.cpp b/src/parse_tree.cpp index cef4a826a..93fc83dab 100644 --- a/src/parse_tree.cpp +++ b/src/parse_tree.cpp @@ -694,8 +694,9 @@ void parse_ll_t::parse_error_failed_production(struct parse_stack_element_t &sta void parse_ll_t::report_tokenizer_error(const tok_t &tok) { parse_error_code_t parse_error_code = parse_error_from_tokenizer_error(tok.error); - this->parse_error_at_location(tok.offset, tok.length, tok.offset + tok.error_offset, - parse_error_code, L"%ls", tokenizer_get_error_message(tok.error)); + this->parse_error_at_location(tok.offset, tok.length, + tok.offset + tok.error_offset_within_token, parse_error_code, + L"%ls", tokenizer_get_error_message(tok.error)); } void parse_ll_t::parse_error_unexpected_token(const wchar_t *expected, parse_token_t token) { diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index 48e8315fd..49c18c224 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -79,7 +79,7 @@ tok_t tokenizer_t::call_error(tokenizer_error_t error_type, const wchar_t *token result.offset = token_start - this->start; // If we are passed a token_length, then use it; otherwise infer it from the buffer. result.length = token_length ? *token_length : this->token_cursor - token_start; - result.error_offset = error_loc - token_start; + result.error_offset_within_token = error_loc - token_start; return result; } diff --git a/src/tokenizer.h b/src/tokenizer.h index 992e92f8c..b666fd245 100644 --- a/src/tokenizer.h +++ b/src/tokenizer.h @@ -83,7 +83,7 @@ struct tok_t { // If an error, this is the offset of the error within the token. A value of 0 means it occurred // at 'offset'. - size_t error_offset{size_t(-1)}; + size_t error_offset_within_token{size_t(-1)}; // Construct from a token type. explicit tok_t(token_type_t type);