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:
Selfhosting Dev
2025-09-19 08:34:29 +09:00
parent f4e340da08
commit 9142476484
348 changed files with 2539 additions and 281 deletions

View File

@ -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) # OKcomputed
b.name = "A" # OKstored
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
# ❌ 使えない