cli: Continue on new line when missing closing group symbol

This commit is contained in:
bakk 2021-06-03 11:41:56 +02:00
parent e0bc36482c
commit dfc05bc11d
2 changed files with 18 additions and 2 deletions

View File

@ -192,7 +192,22 @@ impl Hinter for RLHelper {
impl Validator for RLHelper {
fn validate(&self, ctx: &mut ValidationContext) -> Result<ValidationResult, ReadlineError> {
self.validator.validate(ctx)
let mut group_symbol_count = vec![0i32, 0i32, 0i32];
for c in ctx.input().chars() {
match c {
'⌈' | '⌉' => group_symbol_count[0] += 1,
'⌊' | '⌋' => group_symbol_count[1] += 1,
'|' => group_symbol_count[2] += 1,
_ => (),
}
}
if !group_symbol_count.into_iter().all(|x| x % 2 == 0) {
Ok(ValidationResult::Incomplete)
} else {
self.validator.validate(ctx)
}
}
fn validate_while_typing(&self) -> bool {

View File

@ -569,7 +569,6 @@ fn parse_group_fn(context: &mut Context) -> Result<Expr, CalcError> {
};
let expr = parse_expr(context)?;
advance(context);
if peek(context).kind == TokenKind::EOF {
return Err(CalcError::Expected(String::from(
@ -577,6 +576,8 @@ fn parse_group_fn(context: &mut Context) -> Result<Expr, CalcError> {
)));
}
advance(context);
Ok(Expr::FnCall(Identifier::from_full_name(name), vec![expr]))
}