Fix some string syntax syncing issues in REPL

This commit is contained in:
NGnius (Graham) 2022-03-16 11:56:59 -04:00
parent 9f37a6558a
commit 2e75abd893
2 changed files with 51 additions and 32 deletions

58
Cargo.lock generated
View file

@ -70,9 +70,9 @@ dependencies = [
[[package]] [[package]]
name = "anyhow" name = "anyhow"
version = "1.0.55" version = "1.0.56"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "159bb86af3a200e19a068f4224eae4c8bb2d0fa054c7e5d1cacd5cef95e684cd" checksum = "4361135be9122e0870de935d7c439aef945b9f9ddd4199a553b5270b49c82a27"
[[package]] [[package]]
name = "arrayvec" name = "arrayvec"
@ -111,7 +111,7 @@ dependencies = [
"peeking_take_while", "peeking_take_while",
"proc-macro2", "proc-macro2",
"quote", "quote",
"regex 1.5.4", "regex 1.5.5",
"rustc-hash", "rustc-hash",
"shlex", "shlex",
] ]
@ -214,9 +214,9 @@ checksum = "e3b5ca7a04898ad4bcd41c90c5285445ff5b791899bb1b0abdd2a2aa791211d7"
[[package]] [[package]]
name = "bytemuck" name = "bytemuck"
version = "1.7.3" version = "1.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "439989e6b8c38d1b6570a384ef1e49c8848128f5a97f3914baef02920842712f" checksum = "0e851ca7c24871e7336801608a4797d7376545b6928a10d32d75685687141ead"
[[package]] [[package]]
name = "byteorder" name = "byteorder"
@ -319,9 +319,9 @@ dependencies = [
[[package]] [[package]]
name = "clap" name = "clap"
version = "3.1.2" version = "3.1.6"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5177fac1ab67102d8989464efd043c6ff44191b1557ec1ddd489b4f7e1447e77" checksum = "d8c93436c21e4698bacadf42917db28b23017027a4deccb35dbe47a7e7840123"
dependencies = [ dependencies = [
"atty", "atty",
"bitflags", "bitflags",
@ -331,14 +331,14 @@ dependencies = [
"os_str_bytes", "os_str_bytes",
"strsim 0.10.0", "strsim 0.10.0",
"termcolor", "termcolor",
"textwrap 0.14.2", "textwrap 0.15.0",
] ]
[[package]] [[package]]
name = "clap_derive" name = "clap_derive"
version = "3.1.2" version = "3.1.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "01d42c94ce7c2252681b5fed4d3627cc807b13dfc033246bd05d5b252399000e" checksum = "da95d038ede1a964ce99f49cbe27a7fb538d1da595e4b4f70b8c8f338d17bf16"
dependencies = [ dependencies = [
"heck 0.4.0", "heck 0.4.0",
"proc-macro-error", "proc-macro-error",
@ -372,7 +372,7 @@ dependencies = [
"encode_unicode", "encode_unicode",
"libc", "libc",
"once_cell", "once_cell",
"regex 1.5.4", "regex 1.5.5",
"terminal_size", "terminal_size",
"unicode-width", "unicode-width",
"winapi 0.3.9", "winapi 0.3.9",
@ -639,7 +639,7 @@ dependencies = [
"atty", "atty",
"humantime", "humantime",
"log", "log",
"regex 1.5.4", "regex 1.5.5",
"termcolor", "termcolor",
] ]
@ -1101,7 +1101,7 @@ dependencies = [
name = "mps" name = "mps"
version = "0.6.0" version = "0.6.0"
dependencies = [ dependencies = [
"clap 3.1.2", "clap 3.1.6",
"console", "console",
"mps-interpreter", "mps-interpreter",
"mps-player", "mps-player",
@ -1114,7 +1114,7 @@ dependencies = [
"bliss-audio", "bliss-audio",
"dirs", "dirs",
"rand", "rand",
"regex 1.5.4", "regex 1.5.5",
"rusqlite", "rusqlite",
"shellexpand", "shellexpand",
"symphonia 0.5.0", "symphonia 0.5.0",
@ -1124,7 +1124,7 @@ dependencies = [
name = "mps-m3u8" name = "mps-m3u8"
version = "0.6.0" version = "0.6.0"
dependencies = [ dependencies = [
"clap 3.1.2", "clap 3.1.6",
"m3u8-rs", "m3u8-rs",
"mps-interpreter", "mps-interpreter",
] ]
@ -1374,18 +1374,18 @@ dependencies = [
[[package]] [[package]]
name = "num_enum" name = "num_enum"
version = "0.5.6" version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "720d3ea1055e4e4574c0c0b0f8c3fd4f24c4cdaf465948206dea090b57b526ad" checksum = "cf5395665662ef45796a4ff5486c5d41d29e0c09640af4c5f17fd94ee2c119c9"
dependencies = [ dependencies = [
"num_enum_derive", "num_enum_derive",
] ]
[[package]] [[package]]
name = "num_enum_derive" name = "num_enum_derive"
version = "0.5.6" version = "0.5.7"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0d992b768490d7fe0d8586d9b5745f6c49f557da6d81dc982b1d167ad4edbb21" checksum = "3b0498641e53dd6ac1a4f22547548caa6864cc4933784319cd1775271c5a46ce"
dependencies = [ dependencies = [
"proc-macro-crate", "proc-macro-crate",
"proc-macro2", "proc-macro2",
@ -1427,9 +1427,9 @@ dependencies = [
[[package]] [[package]]
name = "once_cell" name = "once_cell"
version = "1.9.0" version = "1.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "da32515d9f6e6e489d7bc9d84c71b060db7247dc035bbe44eac88cf87486d8d5" checksum = "87f3e037eac156d1775da914196f0f37741a274155e34a0b7e427c35d2a2ecb9"
[[package]] [[package]]
name = "opaque-debug" name = "opaque-debug"
@ -1675,9 +1675,9 @@ dependencies = [
[[package]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.2.10" version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8383f39639269cde97d255a32bdb68c047337295414940c68bdd30c2e13203ff" checksum = "8380fe0152551244f0747b1bf41737e0f8a74f97a14ccefd1148187271634f3c"
dependencies = [ dependencies = [
"bitflags", "bitflags",
] ]
@ -1707,9 +1707,9 @@ dependencies = [
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.5.4" version = "1.5.5"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461" checksum = "1a11647b6b25ff05a515cb92c365cec08801e83423a235b51e231e1808747286"
dependencies = [ dependencies = [
"aho-corasick 0.7.18", "aho-corasick 0.7.18",
"memchr 2.4.1", "memchr 2.4.1",
@ -2257,9 +2257,9 @@ dependencies = [
[[package]] [[package]]
name = "termcolor" name = "termcolor"
version = "1.1.2" version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2dfed899f0eb03f32ee8c6a0aabdb8a7949659e3466561fc0adf54e26d88c5f4" checksum = "bab24d30b911b2376f3a13cc2cd443142f0c81dda04c118693e35b3835757755"
dependencies = [ dependencies = [
"winapi-util", "winapi-util",
] ]
@ -2285,9 +2285,9 @@ dependencies = [
[[package]] [[package]]
name = "textwrap" name = "textwrap"
version = "0.14.2" version = "0.15.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0066c8d12af8b5acd21e00547c3797fde4e8677254a7ee429176ccebbe93dd80" checksum = "b1141d4d61095b28419e22cb0bbf02755f5e54e0526f97f1e3d1d160e60885fb"
[[package]] [[package]]
name = "thiserror" name = "thiserror"

View file

@ -170,11 +170,28 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
Key::Backspace => { Key::Backspace => {
if state.cursor_rightward_position == 0 { if state.cursor_rightward_position == 0 {
if let Some(c) = state.statement_buf.pop() { if let Some(c) = state.statement_buf.pop() {
// re-sync syntax tracking
match c {
'"' | '`' => {
if let Some(c2) = state.in_literal {
if c == c2 {
state.in_literal = None;
}
} else {
state.in_literal = Some(c);
}
},
'(' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },
')' => state.bracket_depth += 1,
'{' => if state.curly_depth != 0 { state.curly_depth -= 1 },
'}' => state.curly_depth += 1,
_ => {},
}
match c { match c {
'\n' | '\r' => { '\n' | '\r' => {
// another line, cannot backspace that far // another line, cannot backspace that far
state.statement_buf.push(c); state.statement_buf.push(c);
} },
_ => { _ => {
state.current_line.pop(); state.current_line.pop();
state.terminal.move_cursor_left(1).expect("Failed to write to terminal output"); state.terminal.move_cursor_left(1).expect("Failed to write to terminal output");
@ -192,10 +209,12 @@ fn read_loop<F: FnMut()>(args: &CliArgs, state: &mut ReplState, mut execute: F)
// re-sync unclosed syntax tracking // re-sync unclosed syntax tracking
match removed_char { match removed_char {
'"' | '`' => { '"' | '`' => {
if let Some(c) = state.in_literal { if let Some(c2) = state.in_literal {
if c == removed_char { if removed_char == c2 {
state.in_literal = None; state.in_literal = None;
} }
} else {
state.in_literal = Some(removed_char);
} }
}, },
'(' => if state.bracket_depth != 0 { state.bracket_depth -= 1 }, '(' => if state.bracket_depth != 0 { state.bracket_depth -= 1 },