diff --git a/Cargo.lock b/Cargo.lock index 44abf0d..b906da4 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -301,7 +301,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.16.1" +version = "0.16.2" dependencies = [ "display_source", "logic_lint", @@ -347,7 +347,7 @@ dependencies = [ [[package]] name = "parser" -version = "0.3.8" +version = "0.3.9" dependencies = [ "lalrpop", "lalrpop-util", diff --git a/Cargo.toml b/Cargo.toml index 51af004..dd8d41a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.16.1" +version = "0.16.2" edition = "2021" authors = ["A4-Tacks "] diff --git a/examples/cmp_deps.mdtlbl b/examples/cmp_deps.mdtlbl index d435893..8710238 100644 --- a/examples/cmp_deps.mdtlbl +++ b/examples/cmp_deps.mdtlbl @@ -3,6 +3,9 @@ * 它的优先级是溢出的, 大部分情况需要在括号内使用, 其优先级高于`||` * * 它为自身左右运算成员构建了一层作用域 +* +* 在0.16.2版本中, 添加了一个语法糖, +* 可在箭头后面添加方括号进行正常的参数设置, 并且此时可以省略前面的代码体 *# const X = ($ = 1 + 2;); @@ -11,3 +14,11 @@ while ({take N = X;} => N > 10 && N < 30) { noop; } # 不用这个语法来解决这个问题的话, 总是不那么美观, 或者只能是看着X被take多次 + + +# 利用参数设置语法糖 +# 这里用到了cmper +const Cmper = goto(_0 > 0 && _0 < _1); +while (=>[a b] Cmper) { + noop; +} diff --git a/examples/match.mdtlbl b/examples/match.mdtlbl index 4365f9b..d699a2c 100644 --- a/examples/match.mdtlbl +++ b/examples/match.mdtlbl @@ -5,6 +5,11 @@ * 简单概述为凭借对句柄的模式匹配完成分支条件编译 * * 同时还增加了重复块, 可以对参数进行重复 +* 需要注意的是, 重复块中的被跳转标签并没有被处理, 这是需要注意的 +* 也就是说很可能你在重复块中编写被跳转标签如控制语句就会引起错误 +* 并且排查可能还需要一番功夫 +* 所以你只应该在其中进行较简单的语句, 或者使用拥有子标签域的方式 +* 例如 直接take一个consted-DExp * * 修改了参数方式, 由构建期展开为编号参数改为编译期展开特定语句 * diff --git a/src/main.rs b/src/main.rs index b5a05dd..d2ec745 100644 --- a/src/main.rs +++ b/src/main.rs @@ -247,9 +247,9 @@ fn build_tag_down(meta: &mut CompileMeta) { {}\n\ TagsMap:\n\ {}", + tag_str, tag_codes.join("\n"), tags_map.join("\n"), - tag_str, ); exit(4) }) diff --git a/tools/display_source/src/impls.rs b/tools/display_source/src/impls.rs index 5c1f8b4..b436fd8 100644 --- a/tools/display_source/src/impls.rs +++ b/tools/display_source/src/impls.rs @@ -392,7 +392,12 @@ impl DisplaySource for LogicLine { Self::SetArgs(args) => { meta.do_insert_first("# ".into(), |meta| { meta.push("setArgs"); - meta.add_space(); + if !args.as_normal() + .map(Vec::is_empty) + .unwrap_or_default() + { + meta.add_space(); + } args.display_source(meta); meta.push(";"); @@ -742,6 +747,24 @@ fn display_source_test() { .display_source_and_get(&mut meta), "({\n take X = A;\n take Y = B;\n} => ((X > 10 && Y > 20) && X < Y))" ); + assert_eq!( + parse!(jumpcmp_parser, "(=>[A B] X == 2)") + .unwrap() + .display_source_and_get(&mut meta), + "({\n inline {}\n # setArgs A B;\n} => X == 2)" + ); + assert_eq!( + parse!(jumpcmp_parser, "(=>[] X == 2)") + .unwrap() + .display_source_and_get(&mut meta), + "({\n inline {}\n # setArgs;\n} => X == 2)" + ); + assert_eq!( + parse!(jumpcmp_parser, "(=>[@] X == 2)") + .unwrap() + .display_source_and_get(&mut meta), + "({\n inline {}\n # setArgs @;\n} => X == 2)" + ); assert_eq!( parse!(line_parser, r#"set a "\n\\\[hi]\\n";"#) .unwrap() diff --git a/tools/parser/Cargo.toml b/tools/parser/Cargo.toml index 400c8cc..87d62c1 100644 --- a/tools/parser/Cargo.toml +++ b/tools/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser" -version = "0.3.8" +version = "0.3.9" 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 5a36bf9..b4bbeb1 100644 --- a/tools/parser/src/parser.lalrpop +++ b/tools/parser/src/parser.lalrpop @@ -227,7 +227,14 @@ pub JumpCmpOnce: CmpTree = CmpTree1; AlwaysJumpCmp: CmpTree = JumpCmp? => <>.unwrap_or(JumpCmp::Always.into()); CmpTree1: CmpTree = { - > "=>" => CmpTree::Deps(deps.into(), cmp.into()), + > "=>" + => CmpTree::Deps(deps.into(), cmp.into()), + ?> "=>" > => { + CmpTree::Deps(vec![ + InlineBlock::from(deps.unwrap_or_default()).into(), + LogicLine::SetArgs(args.unwrap_or_default()), + ].into(), cmp.into()) + }, CmpTree2, }