From 9dd70f20047d2712cb5f905e2f7d0b7eac1ea921 Mon Sep 17 00:00:00 2001 From: "NGnius (Graham)" Date: Fri, 4 Mar 2022 11:00:24 -0500 Subject: [PATCH] Fix filters syntax parsing matching tokens after end of filter --- mps-interpreter/src/lang/filter.rs | 10 +++++++--- mps-interpreter/tests/single_line.rs | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mps-interpreter/src/lang/filter.rs b/mps-interpreter/src/lang/filter.rs index 0e99b58..378245b 100644 --- a/mps-interpreter/src/lang/filter.rs +++ b/mps-interpreter/src/lang/filter.rs @@ -474,7 +474,7 @@ impl + 'static> BoxedMps { fn is_op_boxed(&self, tokens: &VecDeque) -> bool { let tokens_len = tokens.len(); - if last_open_bracket_is_after_dot(tokens) { + if is_correct_format(tokens) { let start_of_predicate = last_dot_before_open_bracket(tokens) + 2; // .(predicate) if start_of_predicate > tokens_len - 1 { false @@ -615,11 +615,15 @@ impl + 'static> BoxedMps } } -fn last_open_bracket_is_after_dot(tokens: &VecDeque) -> bool { +fn is_correct_format(tokens: &VecDeque) -> bool { let mut inside_brackets = 0; let mut open_bracket_found = false; + let mut close_bracket = 0; for i in (0..tokens.len()).rev() { if tokens[i].is_close_bracket() { + if inside_brackets == 0 { + close_bracket = i; + } inside_brackets += 1; } else if tokens[i].is_open_bracket() { if inside_brackets == 1 { @@ -628,7 +632,7 @@ fn last_open_bracket_is_after_dot(tokens: &VecDeque) -> bool { inside_brackets -= 1; } } else if open_bracket_found { - return tokens[i].is_dot(); + return tokens[i].is_dot() && (close_bracket == 0 || close_bracket == tokens.len() - 1); } } false diff --git a/mps-interpreter/tests/single_line.rs b/mps-interpreter/tests/single_line.rs index 42a25fe..54b713c 100644 --- a/mps-interpreter/tests/single_line.rs +++ b/mps-interpreter/tests/single_line.rs @@ -677,7 +677,7 @@ fn execute_compareitemop_line() -> Result<(), Box> { #[test] fn execute_computeitemop_line() -> Result<(), Box> { execute_single_line( - "files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{ + "files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(artist? like `Bruno`).{ let count = 1, item.track = count, item.title = ~`Song #{track}` item,