From 6106003998ca7994acea7b168c1e4a3da82c7fc0 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Sat, 20 Jul 2024 02:34:05 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0`(*++i)`=E8=AF=AD=E6=B3=95,?= =?UTF-8?q?=20=E4=B8=8E`(=3F++i)`=E4=B8=8D=E5=90=8C=E7=9A=84=E6=98=AF?= =?UTF-8?q?=E5=AE=83=E7=9B=B4=E6=8E=A5=E5=8F=96=E5=BE=97=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 6 +++--- Cargo.toml | 2 +- examples/op_expr.mdtlbl | 2 ++ tools/parser/Cargo.toml | 2 +- tools/parser/src/parser.lalrpop | 6 ++++++ tools/parser/tests/Cargo.toml | 2 +- tools/parser/tests/src/lib.rs | 18 ++++++++++++++++++ 7 files changed, 32 insertions(+), 6 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5803761..197271d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,7 +301,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.16.18" +version = "0.16.19" dependencies = [ "display_source", "logic_lint", @@ -347,7 +347,7 @@ dependencies = [ [[package]] name = "parser" -version = "0.3.17" +version = "0.3.18" dependencies = [ "lalrpop", "lalrpop-util", @@ -358,7 +358,7 @@ dependencies = [ [[package]] name = "parser-tests" -version = "0.1.31" +version = "0.1.32" dependencies = [ "parser", "syntax", diff --git a/Cargo.toml b/Cargo.toml index e956170..42f6416 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.16.18" +version = "0.16.19" edition = "2021" authors = ["A4-Tacks "] diff --git a/examples/op_expr.mdtlbl b/examples/op_expr.mdtlbl index 7f644a4..86192e6 100644 --- a/examples/op_expr.mdtlbl +++ b/examples/op_expr.mdtlbl @@ -55,6 +55,8 @@ * 注意, 结果带值而非运算的三元表达式最好写在顶层, 不然可能出现不必要的赋值 * * 在0.14.21版本中, 添加了一个语法糖, 可以用 `(?x: a+b)` 来表示 `(x: $=a+b;)` +* 而在0.16.19版本中, 增加了简单的`(*a+b)`, 和`(?a+b)`区别在于它直接尝试展开成值 +* 这样在例如`++i`的时候可以不用看到不想要的set, `(*++i)`和`(?++i)` *# x = 1 + 2 * 3; diff --git a/tools/parser/Cargo.toml b/tools/parser/Cargo.toml index 55d7993..bde475f 100644 --- a/tools/parser/Cargo.toml +++ b/tools/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser" -version = "0.3.17" +version = "0.3.18" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/parser/src/parser.lalrpop b/tools/parser/src/parser.lalrpop index bad6c48..b9cee93 100644 --- a/tools/parser/src/parser.lalrpop +++ b/tools/parser/src/parser.lalrpop @@ -200,6 +200,7 @@ NonConstRangeValue: Value = { pub Value: Value = { NonConstRangeValue, DExp => <>.into(), + OpExprToValue, // consted-dexp "const" ConstStart )>> => { let tmp_name = meta.get_tmp_var(); @@ -581,7 +582,12 @@ OpExprBodySetR: Expand = OpExprBody => { ); vec![line].into() }; +#[inline] +OpExprBodyToValue: Value = OpExprBody => { + <>.into_value(meta) +}; OpExprDExp: DExp = METuple>; +OpExprToValue: Value = MTuple<("*" )>; OpExprAssignOper: OpExprAOperFun = { "+=" => { |meta, res, v| { let tres = meta.get_tmp_var(); Expand(vec![Take(tres.clone().into(), res).into(), Op::Add (tres.clone().into(), tres.into(), v.into_value(meta)).into()]).into() } }, diff --git a/tools/parser/tests/Cargo.toml b/tools/parser/tests/Cargo.toml index 5754935..a21b73a 100644 --- a/tools/parser/tests/Cargo.toml +++ b/tools/parser/tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser-tests" -version = "0.1.31" +version = "0.1.32" 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 c2aef90..3d67035 100644 --- a/tools/parser/tests/src/lib.rs +++ b/tools/parser/tests/src/lib.rs @@ -2629,6 +2629,24 @@ fn op_expr_test() { ); "#).unwrap(), ); + + assert_eq!( + parse!(parser, r#" + print (?++i); + "#).unwrap(), + parse!(parser, r#" + print ($ = (__: setres i; $ = $ + `1`;);); + "#).unwrap(), + ); + + assert_eq!( + parse!(parser, r#" + print (*++i); + "#).unwrap(), + parse!(parser, r#" + print (__: setres i; $ = $ + `1`;); + "#).unwrap(), + ); } #[test]