Skip to content

Commit

Permalink
do_while goto添加了未填写条件时的默认值
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Oct 3, 2023
1 parent f6a24b6 commit 9cd5aea
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "mindustry_logic_bang_lang"
version = "0.12.0"
version = "0.12.1"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
32 changes: 31 additions & 1 deletion src/syntax.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down Expand Up @@ -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()
);

}
}
23 changes: 11 additions & 12 deletions src/syntax_def.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,9 @@ JumpCmpBody: JumpCmp = {

pub JumpCmp: CmpTree = CmpTree1;

// 可空的, 空时为总是的条件
AlwaysJumpCmp: CmpTree = JumpCmp? => <>.unwrap_or(JumpCmp::Always.into());

pub CmpTree1: CmpTree = {
<a:CmpTree1> "||" <b:CmpTree2> => CmpTree::Or(Box::new(a.into()), b.into()),
CmpTree2,
Expand Down Expand Up @@ -586,20 +589,16 @@ SwitchCatchFlag: SwitchCatch = {
}

pub Control: LogicLine = {
"goto" <Label> <JumpCmp> LEnd => Goto(<>).into(),
"goto" <Label> <AlwaysJumpCmp> LEnd => {
Goto(<>).into()
},

"break" <JumpCmp?> LEnd => {
Goto(
meta.get_break().clone(),
<>.unwrap_or(JumpCmp::Always.into()),
).into()
"break" <AlwaysJumpCmp> LEnd => {
Goto(meta.get_break().clone(), <>).into()
},

"continue" <JumpCmp?> LEnd => {
Goto(
meta.get_continue().clone(),
<>.unwrap_or(JumpCmp::Always.into()),
).into()
"continue" <AlwaysJumpCmp> LEnd => {
Goto(meta.get_continue().clone(), <>).into()
},

"skip" <cmp:JumpCmp> <body:LogicLine> => {
Expand Down Expand Up @@ -632,7 +631,7 @@ pub Control: LogicLine = {
Expand(res).into()
},

"do" CtrlStart <body:Block> <ctrl:CtrlStop> "while" <cmp:JumpCmp> LEnd => {
"do" CtrlStart <body:Block> <ctrl:CtrlStop> "while" <cmp:AlwaysJumpCmp> LEnd => {
let (break_lab, continue_lab) = ctrl;
let head = meta.get_tag();
let mut res = Vec::with_capacity(5);
Expand Down
2 changes: 1 addition & 1 deletion syntax/vim/mdtlbl.snippets
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ do {
} while ${1};
endsnippet
snippet goto "goto" w
goto :${1:tag} ${2:_};$0
goto :${1:tag} ${2};$0
endsnippet
snippet skip "skip" w
skip ${1} {
Expand Down

0 comments on commit 9cd5aea

Please sign in to comment.