From 0620cdf7114a772e961a8574cd3a5ec20446cbec Mon Sep 17 00:00:00 2001 From: Mahmoud Al-Qudsi Date: Sun, 11 Mar 2018 20:06:45 -0500 Subject: [PATCH] Fix tokenizer errors for nested, alternating {} and () --- src/tokenizer.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/tokenizer.cpp b/src/tokenizer.cpp index ae804bb59..65e262204 100644 --- a/src/tokenizer.cpp +++ b/src/tokenizer.cpp @@ -109,6 +109,7 @@ ENUM_FLAGS(tok_mode) { tok_t tokenizer_t::read_string() { tok_mode mode { tok_mode::regular_text }; std::vector paran_offsets; + std::vector brace_offsets; std::vector expecting; int slice_offset = 0; const wchar_t *const buff_start = this->buff; @@ -146,7 +147,7 @@ tok_t tokenizer_t::read_string() { mode |= tok_mode::subshell; } else if (c == L'{') { - paran_offsets.push_back(this->buff - this->start); + brace_offsets.push_back(this->buff - this->start); expecting.push_back(L'}'); mode |= tok_mode::curly_braces; } @@ -162,19 +163,21 @@ tok_t tokenizer_t::read_string() { default: paran_offsets.pop_back(); } + expecting.pop_back(); } else if (c == L'}') { if (expecting.size() > 0 && expecting.back() == L')') { return this->call_error(TOK_EXPECTED_PCLOSE_FOUND_BCLOSE, this->start, this->buff); } - switch (paran_offsets.size()) { + switch (brace_offsets.size()) { case 0: return this->call_error(TOK_CLOSING_UNOPENED_BRACE, this->start, this->buff); case 1: mode &= ~(tok_mode::curly_braces); default: - paran_offsets.pop_back(); + brace_offsets.pop_back(); } + expecting.pop_back(); } else if (c == L'[') { if (this->buff != buff_start) { @@ -247,8 +250,8 @@ tok_t tokenizer_t::read_string() { this->start + offset_of_open_paran); } else if ((mode & tok_mode::curly_braces) == tok_mode::curly_braces) { - assert(paran_offsets.size() > 0); - size_t offset_of_open_brace = paran_offsets.back(); + assert(brace_offsets.size() > 0); + size_t offset_of_open_brace = brace_offsets.back(); error = this->call_error(TOK_UNTERMINATED_BRACE, buff_start, this->start + offset_of_open_brace);