hako(parser): add index operator support

- ParserExprBox: support postfix [expr] and lower to Method(recv, "get", [index])
- ParserStmtBox: support index assignment IDENT [expr] = expr → Expr(Method(recv, "set", [idx, val]))
- Note: lowering uses existing Method → MIR emit path (int args). Phase‑1 canaries use int indices/values.
This commit is contained in:
nyash-codex
2025-10-31 20:22:43 +09:00
parent 5e3d9e7ae4
commit dbc285f2b1
2 changed files with 38 additions and 3 deletions

View File

@ -168,6 +168,16 @@ static box ParserExprBox {
k = ctx.skip_ws(src, k)
if src.substring(k, k+1) == ")" { k = k + 1 }
node = "{\"type\":\"Method\",\"recv\":" + node + ",\"method\":\"" + mname + "\",\"args\":" + args_json2 + "}"
} else if tch == "[" {
// Index access: node[ index ] → Method(recv=node, method="get", args=[index])
k = k + 1
k = ctx.skip_ws(src, k)
local idx_json = ctx.parse_expr2(src, k)
k = ctx.gpos_get()
k = ctx.skip_ws(src, k)
if src.substring(k, k+1) == "]" { k = k + 1 }
local args_idx = "[" + idx_json + "]"
node = "{\\\"type\\\":\\\"Method\\\",\\\"recv\\\":" + node + ",\\\"method\\\":\\\"get\\\",\\\"args\\\":" + args_idx + "}"
} else {
cont2 = 0
}
@ -352,4 +362,3 @@ static box ParserExprBox {
return out + "@" + ctx.i2s(j)
}
}