From 9cd5aeaf47ae4ab3069d37057bcdfa0b939f565a Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Tue, 3 Oct 2023 22:25:13 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=BA`do=5Fwhile`=20`goto`=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E6=9C=AA=E5=A1=AB=E5=86=99=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E6=97=B6=E7=9A=84=E9=BB=98=E8=AE=A4=E5=80=BC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Cargo.lock | 2 +- Cargo.toml | 2 +- src/syntax.rs | 32 +++++++++++++++++++++++++++++++- src/syntax_def.lalrpop | 23 +++++++++++------------ syntax/vim/mdtlbl.snippets | 2 +- 5 files changed, 45 insertions(+), 16 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index d85be06..9a7e783 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -265,7 +265,7 @@ checksum = "2dffe52ecf27772e601905b7522cb4ef790d2cc203488bbd0e2fe85fcb74566d" [[package]] name = "mindustry_logic_bang_lang" -version = "0.12.0" +version = "0.12.1" dependencies = [ "display_source", "lalrpop", diff --git a/Cargo.toml b/Cargo.toml index 0e6da13..33f2070 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mindustry_logic_bang_lang" -version = "0.12.0" +version = "0.12.1" edition = "2021" authors = ["A4-Tacks "] diff --git a/src/syntax.rs b/src/syntax.rs index 69b708b..d9f2c99 100644 --- a/src/syntax.rs +++ b/src/syntax.rs @@ -5484,7 +5484,7 @@ mod tests { } #[test] - fn test_op_expr_if_else() { + fn op_expr_if_else_test() { let parser = TopLevelParser::new(); assert_eq!( @@ -5564,4 +5564,34 @@ mod tests { ); } + + #[test] + fn optional_jumpcmp_test() { + let parser = TopLevelParser::new(); + + assert_eq!( + parse!(parser, r#" + :x + goto :x; + "#).unwrap(), + parse!(parser, r#" + :x + goto :x _; + "#).unwrap() + ); + + assert_eq!( + parse!(parser, r#" + do { + foo; + } while; + "#).unwrap(), + parse!(parser, r#" + do { + foo; + } while _; + "#).unwrap() + ); + + } } diff --git a/src/syntax_def.lalrpop b/src/syntax_def.lalrpop index 6d11542..3b4e188 100644 --- a/src/syntax_def.lalrpop +++ b/src/syntax_def.lalrpop @@ -166,6 +166,9 @@ JumpCmpBody: JumpCmp = { pub JumpCmp: CmpTree = CmpTree1; +// 可空的, 空时为总是的条件 +AlwaysJumpCmp: CmpTree = JumpCmp? => <>.unwrap_or(JumpCmp::Always.into()); + pub CmpTree1: CmpTree = { "||" => CmpTree::Or(Box::new(a.into()), b.into()), CmpTree2, @@ -586,20 +589,16 @@ SwitchCatchFlag: SwitchCatch = { } pub Control: LogicLine = { - "goto"