parser(match): add MVP type patterns (IntegerBox(x)/StringBox(s)) via AST If-chain; keep literal-only path using PeekExpr; add smoke app (apps/tests/match_type_pattern_basic.nyash); build + stage-2 smokes green
This commit is contained in:
@ -37,6 +37,30 @@ static box Main {
|
||||
}
|
||||
```
|
||||
|
||||
### プロパティ(stored / computed / once / birth_once)
|
||||
```nyash
|
||||
box MyBox {
|
||||
# stored(格納・読み書き可)
|
||||
name: StringBox
|
||||
id: IntegerBox = 42 # 初期値は生成時に一度だけ評価
|
||||
|
||||
# computed(計算・読み専用)
|
||||
greeting: StringBox { return "Hello, " + me.name }
|
||||
|
||||
# once(初回アクセス時に一度だけ計算→以降は保存値)
|
||||
once cache: ResultBox { return heavyWork() }
|
||||
|
||||
# birth_once(生成時に一度だけ計算→以降は保存値)
|
||||
birth_once token: StringBox { return readEnv("TOKEN") }
|
||||
}
|
||||
|
||||
# 読みは共通、書きは stored のみ可能
|
||||
local b = new MyBox()
|
||||
print(b.greeting) # OK(computed)
|
||||
b.name = "A" # OK(stored)
|
||||
b.greeting = "x" # エラー(computed には代入不可)
|
||||
```
|
||||
|
||||
## 🔄 制御構文
|
||||
|
||||
### 条件分岐
|
||||
@ -167,6 +191,16 @@ local x
|
||||
x = 42
|
||||
```
|
||||
|
||||
### ❌ 計算プロパティへの代入
|
||||
```nyash
|
||||
box B {
|
||||
value: IntegerBox { return 1 } # computed
|
||||
}
|
||||
|
||||
local b = new B()
|
||||
b.value = 2 # ❌ エラー: 計算プロパティには代入できません(setter を定義するか stored にしてください)
|
||||
```
|
||||
|
||||
### ❌ 削除された構文
|
||||
```nyash
|
||||
# ❌ 使えない
|
||||
|
||||
Reference in New Issue
Block a user