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:
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user