Skip to content

Commit d462a68

Browse files
committed
fix(parser): support dotted opcode calls like tensor.matmul(x, W)
In parsePrimaryExpr, detect Ident . Ident (args) pattern and merge LHS + '.' + RHS into a single opcode name before parsing function call args. This allows kv code like 'tensor.matmul(x, W) -> tmp' to parse correctly. Scanner unchanged — dot remains a delimiter, ./path literals unaffected.
1 parent 43aea36 commit d462a68

1 file changed

Lines changed: 18 additions & 0 deletions

File tree

internal/parser/inst.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,24 @@ func (p *parser) parsePrimaryExpr() *ast.Expr {
226226
return ast.Call(name, args...)
227227
}
228228

229+
// 点号函数调用:name.name(args, ...) — e.g. tensor.matmul(x, W)
230+
// token 流:IDENT . IDENT LPAREN ... — 合并 . 两侧为操作码名
231+
if p.peek().Kind == Ident && p.peekAt(1).Kind == Dot &&
232+
p.peekAt(2).Kind == Ident && p.peekAt(3).Kind == LParen {
233+
opcode := p.advance().Value // consume LHS
234+
p.advance() // skip Dot
235+
opcode += "." + p.advance().Value // consume RHS → "tensor.matmul"
236+
p.advance() // consume (
237+
var args []*ast.Expr
238+
for p.peek().Kind != RParen && p.peek().Kind != EOF {
239+
if p.eat(Comma) { continue }
240+
arg := p.parsePratt(0)
241+
if arg != nil { args = append(args, arg) }
242+
}
243+
p.expect(RParen)
244+
return ast.Call(opcode, args...)
245+
}
246+
229247
// 叶节点:变量名、字面量、路径、裸操作码
230248
t = p.advance()
231249
// 引号字符串(非数字、非路径):加 " 前缀编码,供 resolveReadValue 识别

0 commit comments

Comments
 (0)