Fix curly bracket syntax error spam and REPL bracket curly handling
This commit is contained in:
parent
f05e57ba54
commit
ec03746b41
2 changed files with 7 additions and 3 deletions
|
@ -274,7 +274,7 @@ impl BoxedMpsOpFactory for MpsItemBlockFactory {
|
||||||
Err(SyntaxError {
|
Err(SyntaxError {
|
||||||
line: 0,
|
line: 0,
|
||||||
token: MpsToken::OpenCurly,
|
token: MpsToken::OpenCurly,
|
||||||
got: None,
|
got: tokens.pop_front(),
|
||||||
})
|
})
|
||||||
}?;
|
}?;
|
||||||
let block_tokens = tokens.split_off(open_curly_pos - 1); // . always before {
|
let block_tokens = tokens.split_off(open_curly_pos - 1); // . always before {
|
||||||
|
|
|
@ -15,6 +15,7 @@ struct ReplState {
|
||||||
writer: ChannelWriter,
|
writer: ChannelWriter,
|
||||||
in_literal: Option<char>,
|
in_literal: Option<char>,
|
||||||
bracket_depth: usize,
|
bracket_depth: usize,
|
||||||
|
curly_depth: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ReplState {
|
impl ReplState {
|
||||||
|
@ -26,6 +27,7 @@ impl ReplState {
|
||||||
writer: chan_writer,
|
writer: chan_writer,
|
||||||
in_literal: None,
|
in_literal: None,
|
||||||
bracket_depth: 0,
|
bracket_depth: 0,
|
||||||
|
curly_depth: 0,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -119,7 +121,9 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
'(' => state.bracket_depth += 1,
|
'(' => state.bracket_depth += 1,
|
||||||
')' => state.bracket_depth -= 1,
|
')' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },
|
||||||
|
'{' => state.curly_depth += 1,
|
||||||
|
'}' => if state.curly_depth != 0 { state.curly_depth -= 1 },
|
||||||
';' => {
|
';' => {
|
||||||
if state.in_literal.is_none() {
|
if state.in_literal.is_none() {
|
||||||
state
|
state
|
||||||
|
@ -136,7 +140,7 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
|
||||||
//println!("Got {}", statement_result.unwrap());
|
//println!("Got {}", statement_result.unwrap());
|
||||||
repl_commands(statement_result.unwrap().trim());
|
repl_commands(statement_result.unwrap().trim());
|
||||||
state.statement_buf.clear();
|
state.statement_buf.clear();
|
||||||
} else if state.bracket_depth == 0 && state.in_literal.is_none() {
|
} else if state.bracket_depth == 0 && state.in_literal.is_none() && state.curly_depth == 0 {
|
||||||
state.statement_buf.push(b';');
|
state.statement_buf.push(b';');
|
||||||
state
|
state
|
||||||
.writer
|
.writer
|
||||||
|
|
Loading…
Reference in a new issue