diff --git a/Cargo.lock b/Cargo.lock index 55aff58..3e3e434 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ dependencies = [ [[package]] name = "display_source" -version = "0.3.23" +version = "0.3.24" dependencies = [ "parser", "syntax", @@ -307,7 +307,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.17.4" +version = "0.17.5" dependencies = [ "display_source", "logic_lint", @@ -364,7 +364,7 @@ dependencies = [ [[package]] name = "parser-tests" -version = "0.1.35" +version = "0.1.36" dependencies = [ "either", "parser", @@ -569,7 +569,7 @@ dependencies = [ [[package]] name = "syntax" -version = "0.2.41" +version = "0.2.42" dependencies = [ "either", "itermaps", diff --git a/Cargo.toml b/Cargo.toml index 7ac785a..571e9e6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.17.4" +version = "0.17.5" edition = "2021" authors = ["A4-Tacks "] diff --git a/examples/dexp.mdtlbl b/examples/dexp.mdtlbl index a0aa26a..88029c5 100644 --- a/examples/dexp.mdtlbl +++ b/examples/dexp.mdtlbl @@ -63,3 +63,28 @@ set x __0 # 可以看到, 此处__0就是一个自动分配的变量, # 不用管它的变量名, 只要好好用`$`就行 + + +# 简而言之, 就是可以在 DExp 中放一些逻辑语句, +# 然后使用这个 DExp 时这些语句总是会在使用之前执行, +# 并且如果需要传递值, DExp 中的语句给 $ 赋值就行, +# 表示了当前这一层 DExp 代表的句柄 + +print "core: "; +print ( + ulocate building core false @copper outx outy found $; + print "pos: " outx ", " outy; +); +printflush message1; + +# 以下为上述代码编译的结果 +#* >>> +print "core: " +ulocate building core false @copper outx outy found __0 +print "pos: " +print outx +print ", " +print outy +print __0 +printflush message1 +*# diff --git a/syntax/MT-Manager/MindustryLogicBangLang.mtsx b/syntax/MT-Manager/MindustryLogicBangLang.mtsx index d2ad334..935ed6c 100644 --- a/syntax/MT-Manager/MindustryLogicBangLang.mtsx +++ b/syntax/MT-Manager/MindustryLogicBangLang.mtsx @@ -80,7 +80,7 @@ } { // operator match: keywordsToRegex( - "abs acos add always and angle asin atan ceil" + "abs acos add always and angle angleDiff asin atan ceil" "cos div equal floor greaterThan greaterThanEq" "idiv land len lessThan lessThanEq lnot log" "max min mod mul noise not notEqual or" diff --git a/syntax/vim/mdtlbl.vim b/syntax/vim/mdtlbl.vim index ea5ba15..13f4bc6 100644 --- a/syntax/vim/mdtlbl.vim +++ b/syntax/vim/mdtlbl.vim @@ -41,7 +41,7 @@ syn keyword mdtlblOpFunKeyword \ equal notEqual land lessThan lessThanEq greaterThan greaterThanEq \ strictEqual strictNotEqual always _ \ shl shr or and xor max - \ min angle len noise not abs log log10 + \ min angle angleDiff len noise not abs log log10 \ floor ceil sqrt rand sin cos tan \ asin acos atan lnot diff --git a/tools/display_source/Cargo.toml b/tools/display_source/Cargo.toml index 1053428..925e585 100644 --- a/tools/display_source/Cargo.toml +++ b/tools/display_source/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "display_source" -version = "0.3.23" +version = "0.3.24" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/tools/display_source/src/impls.rs b/tools/display_source/src/impls.rs index 1ddb5d9..3cdbce8 100644 --- a/tools/display_source/src/impls.rs +++ b/tools/display_source/src/impls.rs @@ -349,7 +349,7 @@ impl DisplaySource for Op { Shl, Shr, Or, And, Xor, ] op2l: [ - Max, Min, Angle, Len, Noise, + Max, Min, Angle, AngleDiff, Len, Noise, ] }; meta.push(";"); diff --git a/tools/parser/src/parser.lalrpop b/tools/parser/src/parser.lalrpop index 4a2a1ed..f3c8fbb 100644 --- a/tools/parser/src/parser.lalrpop +++ b/tools/parser/src/parser.lalrpop @@ -312,6 +312,7 @@ pub Op: Op = { >> => Op::Max(<>), >> => Op::Min(<>), >> => Op::Angle(<>), + >> => Op::AngleDiff(<>), >> => Op::Len(<>), >> => Op::Noise(<>), @@ -773,6 +774,11 @@ OpExprCallOp: OpExprInfo = { op_expr_build_op( || Op::Angle(ResultHandle, a.into_value(meta), b.into_value(meta))) }, + OpExprFun2<"angleDiff"> => { + let (a, b) = <>; + op_expr_build_op( + || Op::AngleDiff(ResultHandle, a.into_value(meta), b.into_value(meta))) + }, OpExprFun2<"len"> => { let (a, b) = <>; op_expr_build_op( diff --git a/tools/parser/tests/Cargo.toml b/tools/parser/tests/Cargo.toml index f68ae6c..b538fe9 100644 --- a/tools/parser/tests/Cargo.toml +++ b/tools/parser/tests/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser-tests" -version = "0.1.35" +version = "0.1.36" 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 75d941b..01948df 100644 --- a/tools/parser/tests/src/lib.rs +++ b/tools/parser/tests/src/lib.rs @@ -644,6 +644,10 @@ fn op_generate_test() { Op::Add("x".into(), "y".into(), "z".into()).generate_args(&mut Default::default()), args!["op", "add", "x", "y", "z"], ); + assert_eq!( + Op::AngleDiff("x".into(), "y".into(), "z".into()).generate_args(&mut Default::default()), + args!["op", "angleDiff", "x", "y", "z"], + ); } #[test] diff --git a/tools/syntax/Cargo.toml b/tools/syntax/Cargo.toml index 3a04854..fb501df 100644 --- a/tools/syntax/Cargo.toml +++ b/tools/syntax/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "syntax" -version = "0.2.41" +version = "0.2.42" 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 c6950bb..aef4cfe 100644 --- a/tools/syntax/src/lib.rs +++ b/tools/syntax/src/lib.rs @@ -1785,6 +1785,7 @@ pub enum Op { Max(Value, Value, Value), Min(Value, Value, Value), Angle(Value, Value, Value), + AngleDiff(Value, Value, Value), Len(Value, Value, Value), Noise(Value, Value, Value), @@ -1889,6 +1890,7 @@ impl Op { Max => "max", Min => "min", Angle => "angle", + AngleDiff => "angleDiff", Len => "len", Noise => "noise", ] @@ -2024,6 +2026,7 @@ impl Op { // Not Impl | Op::StrictEqual(..) | Op::Angle(..) + | Op::AngleDiff(..) | Op::Len(..) | Op::Noise(..) | Op::Rand(..) => None?, @@ -2108,6 +2111,7 @@ impl FromMdtArgs<'_> for Op { Max "max", Min "min", Angle "angle", + AngleDiff "angleDiff", Len "len", Noise "noise", ],