From 0cd340a196fd89ba30f0243303e75c387e1208a6 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Wed, 8 May 2024 08:14:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0gswitch=E7=9A=84append?= =?UTF-8?q?=E5=BF=BD=E7=95=A5=E8=AF=AD=E6=B3=95,=20=E5=B9=B6=E6=94=B9?= =?UTF-8?q?=E5=96=84=E4=B8=80=E7=82=B9=E7=82=B9=E6=8A=A5=E9=94=99?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 10 +++---- Cargo.toml | 2 +- README-en_US.md | 2 +- README.md | 2 +- examples/gswitch.mdtlbl | 3 +++ syntax/vim/mdtlbl.vim | 5 +++- tools/display_source/Cargo.toml | 2 +- tools/display_source/src/impls.rs | 18 ++++++++++--- tools/parser/Cargo.toml | 2 +- tools/parser/src/parser.lalrpop | 18 ++++++------- tools/parser/tests/Cargo.toml | 2 +- tools/parser/tests/src/lib.rs | 44 +++++++++++++++++++++++++++++++ tools/syntax/Cargo.toml | 2 +- tools/syntax/src/lib.rs | 24 ++++++++++++----- 14 files changed, 102 insertions(+), 34 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 8cf96b2..2612f8e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -100,7 +100,7 @@ dependencies = [ [[package]] name = "display_source" -version = "0.3.13" +version = "0.3.14" dependencies = [ "parser", "syntax", @@ -301,7 +301,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.16.3" +version = "0.16.4" dependencies = [ "display_source", "logic_lint", @@ -347,7 +347,7 @@ dependencies = [ [[package]] name = "parser" -version = "0.3.10" +version = "0.3.11" dependencies = [ "lalrpop", "lalrpop-util", @@ -358,7 +358,7 @@ dependencies = [ [[package]] name = "parser-tests" -version = "0.1.22" +version = "0.1.23" dependencies = [ "parser", "syntax", @@ -535,7 +535,7 @@ dependencies = [ [[package]] name = "syntax" -version = "0.2.22" +version = "0.2.23" dependencies = [ "either", "tag_code", diff --git a/Cargo.toml b/Cargo.toml index 8e3ee08..71f78e1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.16.3" +version = "0.16.4" edition = "2021" authors = ["A4-Tacks "] diff --git a/README-en_US.md b/README-en_US.md index 4f8b417..af2ff1f 100644 --- a/README-en_US.md +++ b/README-en_US.md @@ -179,7 +179,7 @@ printflush message1 # Project Build Building this project will be relatively slow due to the following reasons: 1. Compile using `rustc`, which is slightly slower compared to `gcc` and `clang` -2. Using the large syntax analysis framework 'lalrpop', which generates over 400000 lines of code and works together with 'rustc' to make compilation slower +2. Using the large syntax analysis framework 'lalrpop', which generates over 500000 lines of code and works together with 'rustc' to make compilation slower You can first check the Releases to see if there is a built program, and if it does not exist or cannot be used, try building it yourself diff --git a/README.md b/README.md index c8a49c2..d274d8c 100644 --- a/README.md +++ b/README.md @@ -154,7 +154,7 @@ printflush message1 # 项目构建 构建这个项目将会比较慢, 原因如下: 1. 使用`rustc`进行编译, 而它略慢, 相对于`gcc` `clang` -2. 使用了大型语法分析框架`lalrpop`, 它会生成四十多万行代码, 再叠加上`rustc`编译更慢 +2. 使用了大型语法分析框架`lalrpop`, 它会生成五十多万行代码, 再叠加上`rustc`编译更慢 你可以先翻一翻Releases, 看一看有没有已构建的程序, 如果没有或无法使用再尝试自己构建. diff --git a/examples/gswitch.mdtlbl b/examples/gswitch.mdtlbl index a8bfdc7..3bea2e8 100644 --- a/examples/gswitch.mdtlbl +++ b/examples/gswitch.mdtlbl @@ -19,6 +19,9 @@ * 将仅在成立时执行这个case. * 当然不设计为为同一个case中每个匹配使用不同的守卫支持, 也是类似上面的原因. * 实在要使用也可以使用类似上面的解决方法 +* +* 在0.16.4新增了一个便捷语法, 在case后面加上星号可以忽略append, +* 这可以既享受append的便利, 又为一些特化场景做优化 *# # 一个例子 diff --git a/syntax/vim/mdtlbl.vim b/syntax/vim/mdtlbl.vim index 0c28ff8..d83db17 100644 --- a/syntax/vim/mdtlbl.vim +++ b/syntax/vim/mdtlbl.vim @@ -25,10 +25,12 @@ syn case match " 一些关键字 {{{1 syn keyword mdtlblKeyword - \ while gwhile do skip goto if elif else switch gswitch case break continue + \ while gwhile do skip goto if elif else switch gswitch break continue \ const take setres select match \ inline \ op set noop print +syn keyword mdtlblKeyword case nextgroup=mdtlblStar skipwhite +syn match mdtlblStar /\*/ contained syn keyword mdtlblOpFunKeyword \ add sub mul div idiv mod pow @@ -133,6 +135,7 @@ setlocal indentkeys+==: " END And Color Links {{{1 hi def link mdtlblKeyword Keyword +hi def link mdtlblStar Keyword hi def link mdtlblOpFunKeyword Operator hi def link mdtlblCmpTreeOper Operator hi def link mdtlblComment Comment diff --git a/tools/display_source/Cargo.toml b/tools/display_source/Cargo.toml index 8ee50d5..8ede4df 100644 --- a/tools/display_source/Cargo.toml +++ b/tools/display_source/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "display_source" -version = "0.3.13" +version = "0.3.14" 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 dcf94c4..5909da1 100644 --- a/tools/display_source/src/impls.rs +++ b/tools/display_source/src/impls.rs @@ -635,13 +635,17 @@ impl DisplaySource for ConstMatch { } impl DisplaySource for GSwitchCase { fn display_source(&self, meta: &mut DisplaySourceMeta) { - match self { - &Self::Catch { + match *self { + Self::Catch { + skip_extra, underflow, missed, overflow, ref to, } => { + if skip_extra { + meta.push("*"); + } meta.add_space(); if underflow { meta.push("<"); @@ -657,7 +661,14 @@ impl DisplaySource for GSwitchCase { key.display_source(meta); } }, - Self::Normal { ids, guard } => { + Self::Normal { + skip_extra, + ref ids, + ref guard + } => { + if skip_extra { + meta.push("*"); + } if !ids.as_normal().map(Vec::is_empty).unwrap_or_default() { meta.add_space(); ids.display_source(meta); @@ -682,7 +693,6 @@ impl DisplaySource for GSwitch { meta.add_lf(); meta.do_block(|meta| { self.extra.display_source(meta); - meta.add_lf(); }); for (case, expand) in &self.cases { meta.push("case"); diff --git a/tools/parser/Cargo.toml b/tools/parser/Cargo.toml index 0ac3385..8ded57f 100644 --- a/tools/parser/Cargo.toml +++ b/tools/parser/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "parser" -version = "0.3.10" +version = "0.3.11" 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 882a9ad..5ed64ba 100644 --- a/tools/parser/src/parser.lalrpop +++ b/tools/parser/src/parser.lalrpop @@ -915,16 +915,14 @@ ControlBody: LogicLine = { Block, } GSwitchCase: GSwitchCase = { - )?> => { - GSwitchCase::Normal { ids: ids.unwrap_or_default(), guard } - }, - "<" => GSwitchCase::Catch { underflow: true, missed: false, overflow: false, to }, - "!" => GSwitchCase::Catch { underflow: false, missed: true, overflow: false, to }, - ">" => GSwitchCase::Catch { underflow: false, missed: false, overflow: true, to }, - "<" "!" => GSwitchCase::Catch { underflow: true, missed: true, overflow: false, to }, - "!" ">" => GSwitchCase::Catch { underflow: false, missed: true, overflow: true, to }, - "<" ">" => GSwitchCase::Catch { underflow: true, missed: false, overflow: true, to }, - "<" "!" ">" => GSwitchCase::Catch { underflow: true, missed: true, overflow: true, to }, + > )?> => GSwitchCase::Normal { skip_extra, ids: ids.unwrap_or_default(), guard }, + > "<" => GSwitchCase::Catch { skip_extra, underflow: true, missed: false, overflow: false, to }, + > "!" => GSwitchCase::Catch { skip_extra, underflow: false, missed: true, overflow: false, to }, + > ">" => GSwitchCase::Catch { skip_extra, underflow: false, missed: false, overflow: true, to }, + > "<" "!" => GSwitchCase::Catch { skip_extra, underflow: true, missed: true, overflow: false, to }, + > "!" ">" => GSwitchCase::Catch { skip_extra, underflow: false, missed: true, overflow: true, to }, + > "<" ">" => GSwitchCase::Catch { skip_extra, underflow: true, missed: false, overflow: true, to }, + > "<" "!" ">" => GSwitchCase::Catch { skip_extra, underflow: true, missed: true, overflow: true, to }, } ControlWithoutOptionalEnd: LogicLine = { "goto"