package main import ( "bytes" "errors" "io" "github.com/rqlite/sql" ) type sqlVisitor struct{} func processSql(path string) { p := sql.NewParser(bytes.NewReader(currentFile)) for { stmt, err := p.ParseStatement() switch { case errors.Is(err, io.EOF): return case err != nil: die(err) } sql.Walk(sqlVisitor{}, stmt) } } func processSqlArgs(msgidExpr, msgctxtExpr sql.Expr, pos sql.Pos) { msgid, ok := msgidExpr.(*sql.StringLit) if !ok { return } msgctxt, ok := msgctxtExpr.(*sql.StringLit) if !ok { return } tl := translation{ msgid: msgid.Value, msgctxt: msgctxt.Value, } ti := translations[tl] ti.locs = append(ti.locs, loc{currentPath, pos.Line}) translations[tl] = ti } func (v sqlVisitor) Visit(n sql.Node) (sql.Visitor, sql.Node, error) { if cn, ok := n.(*sql.Call); ok && sql.IdentName(cn.Name) == "C_" { processSqlArgs(cn.Args[0], cn.Args[1], cn.Lparen) } return v, n, nil } func (v sqlVisitor) VisitEnd(n sql.Node) (sql.Node, error) { return n, nil }