From 91c190b807689e9864f63d46a1f431d4759a285d Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Wed, 22 Jan 2025 21:54:17 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=AF=94=E8=BE=83=E5=86=85?= =?UTF-8?q?=E8=81=94=E7=9A=84=20DExp=20=E4=B8=A4=E7=BA=A7=E5=81=87?= =?UTF-8?q?=E5=80=BC=E6=A3=80=E6=B5=8B=E5=AE=9E=E7=8E=B0=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 6 +-- Cargo.toml | 2 +- tools/parser/tests/Cargo.toml | 2 +- tools/parser/tests/src/lib.rs | 81 +++++++++++++++++++++++++++++++++++ tools/syntax/Cargo.toml | 2 +- tools/syntax/src/lib.rs | 15 ++++--- 6 files changed, 96 insertions(+), 12 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be4ac83..975c8ca 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -284,7 +284,7 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "mindustry_logic_bang_lang" -version = "0.17.17" +version = "0.17.18" dependencies = [ "display_source", "logic_lint", @@ -341,7 +341,7 @@ dependencies = [ [[package]] name = "parser-tests" -version = "0.1.43" +version = "0.1.44" dependencies = [ "either", "parser", @@ -530,7 +530,7 @@ dependencies = [ [[package]] name = "syntax" -version = "0.2.47" +version = "0.2.48" dependencies = [ "either", "itermaps", diff --git a/Cargo.toml b/Cargo.toml index d4927f6..bac6255 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.17.17" +version = "0.17.18" edition = "2021" authors = ["A4-Tacks "] diff --git a/tools/parser/tests/Cargo.toml b/tools/parser/tests/Cargo.toml index 99ab1d1..6ff0413 100644 --- a/tools/parser/tests/Cargo.toml +++ b/tools/parser/tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser-tests" -version = "0.1.43" +version = "0.1.44" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/parser/tests/src/lib.rs b/tools/parser/tests/src/lib.rs index 7f57ad3..56235bf 100644 --- a/tools/parser/tests/src/lib.rs +++ b/tools/parser/tests/src/lib.rs @@ -3150,6 +3150,87 @@ fn inline_cmp_op_test() { "#).unwrap()).compile().unwrap(), ); + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = goto(a < b); + do {} while Cmp != (`false`:); + "#).unwrap()).compile().unwrap(), + CompileMeta::new().compile(parse!(parser, r#" + const Cmp = goto(a < b); + do {} while Cmp != (`false`:); + "#).unwrap()).compile().unwrap(), + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?a < b); + break Cmp != (`false`:); + "#).unwrap()).compile().unwrap(), + vec![ + "jump 0 lessThan a b" + ] + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?a < b); + break Cmp != (false:); + "#).unwrap()).compile().unwrap(), + vec![ + "op lessThan __0 a b", + "jump 0 notEqual __0 2", + ] + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?m: a < b); + break Cmp != (`false`:); + "#).unwrap()).compile().unwrap(), + vec![ + "op lessThan m a b", + "jump 0 notEqual m false", + ] + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?a < b); + break Cmp != (`false`: {}); + "#).unwrap()).compile().unwrap(), + vec![ + "op lessThan __0 a b", + "jump 0 notEqual __0 false", + ] + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?a < b); + break Cmp == (`false`: {}); + "#).unwrap()).compile().unwrap(), + vec![ + "op lessThan __0 a b", + "jump 0 equal __0 false", + ] + ); + + assert_eq!( + CompileMeta::new().compile(parse!(parser, r#" + const false = 2; + const Cmp = (?a < b); + break Cmp == (`false`:); + "#).unwrap()).compile().unwrap(), + vec![ + "jump 0 greaterThanEq a b", + ] + ); } #[test] diff --git a/tools/syntax/Cargo.toml b/tools/syntax/Cargo.toml index 1a7b6a1..638a0cf 100644 --- a/tools/syntax/Cargo.toml +++ b/tools/syntax/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syntax" -version = "0.2.47" +version = "0.2.48" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/syntax/src/lib.rs b/tools/syntax/src/lib.rs index f4ba053..6610bfb 100644 --- a/tools/syntax/src/lib.rs +++ b/tools/syntax/src/lib.rs @@ -1572,9 +1572,10 @@ impl CmpTree { lines }), .. - }) => take_result.then_some(&**s) - .or_else(|| lines.is_empty() - .and_then(|| f(meta, s))), + }) if lines.is_empty() => take_result + .and_then(|| f(meta, s)) + .unwrap_or(&**s) + .into(), Some(_) => None, None => Some(&**s), } @@ -1583,15 +1584,17 @@ impl CmpTree { take_result, result: s, lines, - }) => take_result.then_some(&**s) - .or_else(|| lines.is_empty() - .and_then(|| f(meta, s))), + }) if lines.is_empty() => take_result + .and_then(|| f(meta, s)) + .unwrap_or(&**s) + .into(), | V::ReprVar(s) => Some(&**s), | V::ResultHandle => Some(&**meta.dexp_handle()), | V::Binder => Some(meta.get_dexp_expand_binder().map(|s| &**s).unwrap_or("__")), + | V::DExp(_) | V::ValueBind(_) | V::ValueBindRef(_) | V::Cmper(_)