Skip to content

Commit

Permalink
增加绑定者引用及语法, 修复一个bug
Browse files Browse the repository at this point in the history
- 修复对被const的值绑定结果进行take的bug
  • Loading branch information
A4-Tacks committed Jan 2, 2024
1 parent d3fb2f7 commit 9d0560e
Show file tree
Hide file tree
Showing 13 changed files with 353 additions and 54 deletions.
10 changes: 5 additions & 5 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.14.3"
version = "0.14.4"
edition = "2021"

authors = ["A4-Tacks <[email protected]>"]
Expand Down
1 change: 1 addition & 0 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
> [`consted_dexp.mdtlbl`](./consted_dexp.mdtlbl)<br/>
> [`quick_dexp_take.mdtlbl`](./quick_dexp_take.mdtlbl)<br/>
> [`value_bind.mdtlbl`](./value_bind.mdtlbl)<br/>
> [`dexp_binder.mdtlbl`](./dexp_binder.mdtlbl)<br/>
> [`caller.mdtlbl`](./caller.mdtlbl)<br/>
> [`match.mdtlbl`](./match.mdtlbl)<br/>
Expand Down
38 changes: 38 additions & 0 deletions examples/dexp_binder.mdtlbl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#**
* 这是0.14.4所添加的新语法, 将会尝试给每个const记录其绑定者,
* 然后可以通过`..`来引用
*
* 正如ValueBind那章所说, 不要轻易给容易混淆的非匿名量绑定
*
* 这有什么用呢? 这可以模拟'类型方法' '类型成员'等
*#

# 以下一个二维向量的例子
const Vec2 = (
take $.X=_0 $.Y=_1;
const $.Add = (
take Rhs = _0;
take ...X=...X ...Y=...Y; # take
# 为了'简单'的常量求值, 需要先take变成支持的格式
take X=...X Y=...Y;
take RX=Rhs.X RY=Rhs.Y;
# 需要绑定, 不然只是局部作用域并不是全局作用域
take ...X = ($ = X + RX;);
take ...Y = ($ = Y + RY;);
);
const $.Print = (
print ...X","...Y;
);
);

take V1 = Vec2[2 3];
take V2 = Vec2[3 4];
take V1.Add[V2];
take V1.Print;
printflush message1;
#*
print 5
print ","
print 7
printflush message1
*#
31 changes: 31 additions & 0 deletions examples/match.mdtlbl
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* 可以使用重复块, 它将在一个内联块中重复给定块, 并且每次重复迭代指定个参数,
* 此数字未指定则为1, 它不能为0, 它是构建期被指定的
*
* 需要注意的是, 在这里`Foo`和`Foo[]`有了区别, `Foo`并不会传进空的参数表
*
* match语句
* ===
* 改语句由参数输入, 并在之后的块中编写多个分支.
Expand Down Expand Up @@ -283,3 +285,32 @@ print b
print "no."
print d
*#


# 坑点排除, 空参数
const Foo = (
match @ {
{
print "empty";
}
@ {
take N = 0;
inline@{
take N = ($ = N+1;);
}
print N;
}
}
);
match a b c { @ {} }
print "a";
take Foo;
print "b";
take Foo[];
#*
print "a"
print 3
print "b"
print "empty"
*#
# 在这里, `Foo`和`Foo[]`的作用已经不同了
2 changes: 1 addition & 1 deletion tools/display_source/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "display_source"
version = "0.3.5"
version = "0.3.6"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
1 change: 1 addition & 0 deletions tools/display_source/src/impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl DisplaySource for Value {
meta.push("`");
},
Self::ResultHandle => meta.push("$"),
Self::Binder => meta.push(".."),
Self::DExp(dexp) => dexp.display_source(meta),
Self::ValueBind(value_attr) => value_attr.display_source(meta),
Self::Cmper(cmp) => {
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.2.0"
version = "0.2.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
5 changes: 3 additions & 2 deletions tools/parser/src/parser.lalrpop
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,16 @@ NonDExpValue: Value = {
<v:Var> => v.into(),
"`" <Var> "`" => ReprVar(<>), // 原始值
"$" => ResultHandle,
<name:Var> <args:MList<Args?>> => {
<name:NonDExpValue> <args:MList<Args?>> => {
// QuickDExpTake
DExp::new("__".into(), vec![
LogicLine::SetArgs(args.unwrap_or_default()),
LogicLine::SetResultHandle(name.into()),
LogicLine::SetResultHandle(name),
].into()).into()
},
ValueBind => <>.into(),
"goto" <MTuple<JumpCmpOnce>> => Value::Cmper(<>.into()),
".." => Value::Binder,
}

pub Value: Value = {
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.1"
version = "0.1.2"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Expand Down
Loading

0 comments on commit 9d0560e

Please sign in to comment.