Skip to content

Commit 1c8aaa6

Browse files
committed
修复switch-append-line对于填充case不生效的bug
1 parent f42b831 commit 1c8aaa6

File tree

4 files changed

+32
-3
lines changed

4 files changed

+32
-3
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "mindustry_logic_bang_lang"
3-
version = "0.7.5"
3+
version = "0.7.6"
44
edition = "2021"
55

66
authors = ["A4-Tacks <wdsjxhno1001@163.com>"]

src/syntax.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1582,6 +1582,29 @@ mod tests {
15821582
])
15831583
).into()
15841584
);
1585+
1586+
// 测试追加对于填充的效用
1587+
let ast = parse!(parser, r#"
1588+
switch 1 {
1589+
print end;
1590+
case 1: print 1;
1591+
}
1592+
"#).unwrap();
1593+
assert_eq!(
1594+
ast,
1595+
Select(
1596+
"1".into(),
1597+
Expand(vec![
1598+
Expand(vec![
1599+
LogicLine::Other(vec!["print".into(), "end".into()]),
1600+
]).into(),
1601+
Expand(vec![
1602+
LogicLine::Other(vec!["print".into(), "1".into()]),
1603+
LogicLine::Other(vec!["print".into(), "end".into()]),
1604+
]).into(),
1605+
])
1606+
).into()
1607+
);
15851608
}
15861609

15871610
#[test]

src/syntax_def.lalrpop

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,13 +347,19 @@ pub Control: LogicLine = {
347347
.max()
348348
.unwrap();
349349
let mut cases_res = Vec::with_capacity(case_num_max);
350+
351+
let fill_line = append /* 用于填充的行, 如果有追加在末尾的行则将其封装并替换填充 */
352+
.as_ref()
353+
.map(|line| Expand(vec![line.clone()]).into())
354+
.unwrap_or(LogicLine::NoOp);
355+
350356
for (nums, mut expand) in cases {
351357
if let Some(append) = &append {
352358
expand.push(append.clone())
353359
}
354360
for num in nums {
355361
for _ in cases_res.len()..=num {
356-
cases_res.push(LogicLine::NoOp)
362+
cases_res.push(fill_line.clone())
357363
}
358364
cases_res[num] = expand.clone().into()
359365
}

0 commit comments

Comments
 (0)