summaryrefslogtreecommitdiff
path: root/cli/repl.rs
diff options
context:
space:
mode:
authorCasper Beyer <caspervonb@pm.me>2020-10-20 01:13:23 +0800
committerGitHub <noreply@github.com>2020-10-19 19:13:23 +0200
commit9d664f8375856be228e4f98b8381ac934d84604b (patch)
tree773b0f057671ac6ce8d5dfb89f234371fc4f8a9f /cli/repl.rs
parent08441b855d8cfbe7edd41811c8c719e5fae01f83 (diff)
fix(cli/repl): ignore pair matching inside literals (#8037)
Diffstat (limited to 'cli/repl.rs')
-rw-r--r--cli/repl.rs36
1 files changed, 27 insertions, 9 deletions
diff --git a/cli/repl.rs b/cli/repl.rs
index 3d22f8156..9d700f76d 100644
--- a/cli/repl.rs
+++ b/cli/repl.rs
@@ -33,7 +33,33 @@ impl Validator for Helper {
ctx: &mut ValidationContext,
) -> Result<ValidationResult, ReadlineError> {
let mut stack: Vec<char> = Vec::new();
+ let mut literal: Option<char> = None;
+ let mut escape: bool = false;
+
for c in ctx.input().chars() {
+ if escape {
+ escape = false;
+ continue;
+ }
+
+ if c == '\\' {
+ escape = true;
+ continue;
+ }
+
+ if let Some(v) = literal {
+ if c == v {
+ literal = None
+ }
+
+ continue;
+ } else {
+ literal = match c {
+ '`' | '"' | '/' | '\'' => Some(c),
+ _ => None,
+ };
+ }
+
match c {
'(' | '[' | '{' => stack.push(c),
')' | ']' | '}' => match (stack.pop(), c) {
@@ -51,19 +77,11 @@ impl Validator for Helper {
))))
}
},
- '`' => {
- if stack.is_empty() || stack.last().unwrap() != &c {
- stack.push(c);
- } else {
- stack.pop();
- }
- }
-
_ => {}
}
}
- if !stack.is_empty() {
+ if !stack.is_empty() || literal == Some('`') {
return Ok(ValidationResult::Incomplete);
}