summaryrefslogtreecommitdiffstats
path: root/src/repl/validator.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/repl/validator.rs')
-rw-r--r--src/repl/validator.rs47
1 files changed, 1 insertions, 46 deletions
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<char> = 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("{{}"));
- }
-}