This commit is contained in:
Cai Bingjun 2022-09-05 20:43:02 +08:00
parent 089b02c6ed
commit 70d2ae73ae
4 changed files with 13 additions and 7 deletions

View file

@ -1,4 +1,5 @@
# The Grammar of Erg (ver 0.1.0, provisional) # The Grammar of Erg (ver 0.1.0, provisional)
```
special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&' special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&'
separator ::= ';' | '\n' separator ::= ';' | '\n'
escape ::= '\' escape ::= '\'
@ -86,3 +87,4 @@ expr ::= accessor | literal
| call | def | lambda | call | def | lambda
line ::= expr separator+ line ::= expr separator+
program ::= expr? | (line | comment)* program ::= expr? | (line | comment)*
```

View file

@ -1,4 +1,5 @@
# The Grammar of Erg (ver 0.1.0, provisional) # The Grammar of Erg (ver 0.1.0, provisional)
```
special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&' special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&'
separator ::= ';' | '\n' separator ::= ';' | '\n'
escape ::= '\' escape ::= '\'
@ -86,3 +87,4 @@ expr ::= accessor | literal
| call | def | lambda | call | def | lambda
line ::= expr separator+ line ::= expr separator+
program ::= expr? | (line | comment)* program ::= expr? | (line | comment)*
```

View file

@ -16,13 +16,13 @@ assert a == [2, 2]
```python ```python
C = Class {i = Int!} C = Class {i = Int!}
C. get(ref self) = C. get(ref self) =
self::i # TypeError: `self::i` is `Int!` (require ownership) but `get` doesn't own `self` self::i # 类型错误:`self::i``Int!`(需要所有权)但 `get` 不拥有 `self`
C.steal(self) = C.steal(self) =
self::i self::i
#NG #NG
C.new({i = 1}).steal().inc!() # OwnershipWarning: `C.new({i = 1}).steal()` is not owned by anyone C.new({i = 1}).steal().inc!() # 所有权警告:`C.new({i = 1}).steal()` 不属于任何人
# hint: assign to a variable or use `uwn_do!` # 提示:分配给变量或使用 `uwn_do!`
# OK (assigning) # OK (分配)
c = C.new({i = 1}) c = C.new({i = 1})
i = c.steal() i = c.steal()
i.inc!() i.inc!()
@ -31,12 +31,12 @@ assert i == 2
own_do! C.new({i = 1}).steal(), i => i.inc!() own_do! C.new({i = 1}).steal(), i => i.inc!()
``` ```
Also, `[]` can be disowned, but the element is not shifted. 此外,`[]` 可以不承认,但元素不会移动
```python ```python
a = [!1, !2] a = [!1, !2]
i = a[0] i = a[0]
i.inc!() i.inc!()
assert a[1] == 2 assert a[1] == 2
a[0] # OwnershipError: `a[0]` is moved to `i` a[0] # 所有权错误:`a[0]` 被移动到 `i`
``` ```

View file

@ -1,4 +1,5 @@
# The Grammar of Erg (ver 0.1.0, provisional) # Erg 的语法(版本 0.1.0, 临时)
```
special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&' special_op ::= '=' | '->' | '=>' | '.' | ',' | ':' | '::' | '|>' | '&'
separator ::= ';' | '\n' separator ::= ';' | '\n'
escape ::= '\' escape ::= '\'
@ -86,3 +87,4 @@ expr ::= accessor | literal
| call | def | lambda | call | def | lambda
line ::= expr separator+ line ::= expr separator+
program ::= expr? | (line | comment)* program ::= expr? | (line | comment)*
```