From b5e1460151451e124f5e80e0dbe670fff83899c0 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 24 Oct 2023 17:45:49 +0800 Subject: feat: use backslash at end of line for multiline text (#147) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit BREAKING CHANGE: use backslash at end of line for multiline text ``` 〉.set dry_run true 〉abc \ def \ ijk >>> The following message consumes 12 tokens. abc def ijk ``` Deprecate old {}/() multi-line editing --- src/repl/validator.rs | 47 +---------------------------------------------- 1 file changed, 1 insertion(+), 46 deletions(-) (limited to 'src/repl/validator.rs') diff --git a/src/repl/validator.rs b/src/repl/validator.rs index d829911..1a5f405 100644 --- a/src/repl/validator.rs +++ b/src/repl/validator.rs @@ -6,55 +6,10 @@ pub struct ReplValidator; impl Validator for ReplValidator { fn validate(&self, line: &str) -> ValidationResult { - if incomplete_brackets(line) { + if line.ends_with('\\') { ValidationResult::Incomplete } else { ValidationResult::Complete } } } - -fn incomplete_brackets(line: &str) -> bool { - let mut balance: Vec = Vec::new(); - let mut symbol = None; - for c in line.chars() { - match symbol { - Some(s) => match (s, c) { - ('{', '}') | ('(', ')') => { - balance.pop(); - } - _ if s == c => { - balance.push(c); - } - _ => {} - }, - None => match c { - '{' | '(' => { - balance.push(c); - symbol = Some(c); - } - _ => {} - }, - } - } - - !balance.is_empty() -} - -#[cfg(test)] -mod tests { - use super::*; - - #[test] - fn test_incomplete_brackets() { - assert!(incomplete_brackets("{")); - assert!(incomplete_brackets("(")); - assert!(!incomplete_brackets("{}")); - assert!(!incomplete_brackets("()")); - assert!(!incomplete_brackets("{ab\nc}")); - assert!(!incomplete_brackets("(ab\nc)")); - assert!(!incomplete_brackets("{[}")); - assert!(!incomplete_brackets("{{{{{}}}}}")); - assert!(incomplete_brackets("{{}")); - } -} -- cgit v1.2.3