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"