Skip to content

Commit

Permalink
添加(*++i)语法, 与(?++i)不同的是它直接取得值
Browse files Browse the repository at this point in the history
  • Loading branch information
A4-Tacks committed Jul 19, 2024
1 parent 5de777c commit 6106003
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 6 deletions.
6 changes: 3 additions & 3 deletions 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.16.18"
version = "0.16.19"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
2 changes: 2 additions & 0 deletions examples/op_expr.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
* 注意, 结果带值而非运算的三元表达式最好写在顶层, 不然可能出现不必要的赋值
*
* 在0.14.21版本中, 添加了一个语法糖, 可以用 `(?x: a+b)` 来表示 `(x: $=a+b;)`
* 而在0.16.19版本中, 增加了简单的`(*a+b)`, 和`(?a+b)`区别在于它直接尝试展开成值
* 这样在例如`++i`的时候可以不用看到不想要的set, `(*++i)`和`(?++i)`
*#

x = 1 + 2 * 3;
Expand Down
2 changes: 1 addition & 1 deletion tools/parser/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parser"
version = "0.3.17"
version = "0.3.18"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
6 changes: 6 additions & 0 deletions tools/parser/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ NonConstRangeValue: Value = {
pub Value: Value = {
NonConstRangeValue,
DExp => <>.into(),
OpExprToValue,
// consted-dexp
"const" ConstStart <value:Or<ValueDExp, ("!" <Value>)>> <labels:ConstStop> => {
let tmp_name = meta.get_tmp_var();
Expand Down Expand Up @@ -581,7 +582,12 @@ OpExprBodySetR: Expand = OpExprBody => {
);
vec![line].into()
};
#[inline]
OpExprBodyToValue: Value = OpExprBody => {
<>.into_value(meta)
};
OpExprDExp: DExp = METuple<MakeDExpBody<OpExprBodySetR>>;
OpExprToValue: Value = MTuple<("*" <OpExprBodyToValue>)>;

OpExprAssignOper: OpExprAOperFun = {
"+=" => { |meta, res, v| { let tres = meta.get_tmp_var(); Expand(vec![Take(tres.clone().into(), res).into(), Op::Add (tres.clone().into(), tres.into(), v.into_value(meta)).into()]).into() } },
Expand Down
2 changes: 1 addition & 1 deletion tools/parser/tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "parser-tests"
version = "0.1.31"
version = "0.1.32"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
18 changes: 18 additions & 0 deletions tools/parser/tests/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2629,6 +2629,24 @@ fn op_expr_test() {
);
"#).unwrap(),
);

assert_eq!(
parse!(parser, r#"
print (?++i);
"#).unwrap(),
parse!(parser, r#"
print ($ = (__: setres i; $ = $ + `1`;););
"#).unwrap(),
);

assert_eq!(
parse!(parser, r#"
print (*++i);
"#).unwrap(),
parse!(parser, r#"
print (__: setres i; $ = $ + `1`;);
"#).unwrap(),
);
}

#[test]
Expand Down

0 comments on commit 6106003

Please sign in to comment.