diff options
Diffstat (limited to 'cmd/exttmpl/main.go')
-rw-r--r-- | cmd/exttmpl/main.go | 97 |
1 files changed, 61 insertions, 36 deletions
diff --git a/cmd/exttmpl/main.go b/cmd/exttmpl/main.go index 4d11488..043e493 100644 --- a/cmd/exttmpl/main.go +++ b/cmd/exttmpl/main.go @@ -155,59 +155,84 @@ func processNode(node parse.Node) { for _, m := range n.Nodes { processNode(m) } + case *parse.PipeNode: + for _, m := range n.Cmds { + processNode(m) + } + case *parse.TemplateNode: + processNode(n.Pipe) case *parse.IfNode: processBranch(n.BranchNode) case *parse.RangeNode: processBranch(n.BranchNode) case *parse.WithNode: processBranch(n.BranchNode) + case *parse.BranchNode: + processBranch(*n) case *parse.ActionNode: - for _, cmd := range n.Pipe.Cmds { - if len(cmd.Args) == 0 { - continue - } + processNode(n.Pipe) + case *parse.CommandNode: + if len(n.Args) == 0 { + break + } - f, ok := cmd.Args[0].(*parse.FieldNode) - if !ok || len(f.Ident) == 0 { - continue + var funcname string + f, ok := n.Args[0].(*parse.FieldNode) + if !ok || len(f.Ident) == 0 { + ff, ok := n.Args[0].(*parse.VariableNode) + if !ok || len(ff.Ident) == 0 { + fff, ok := n.Args[0].(*parse.IdentifierNode) + if !ok { + for _, pipe := range n.Args { + processNode(pipe) + } + break + } + funcname = fff.Ident + } else { + funcname = ff.Ident[len(ff.Ident)-1] } + } else { + funcname = f.Ident[len(f.Ident)-1] + } - cfg, ok := configs[f.Ident[len(f.Ident)-1]] - if !ok { - continue + cfg, ok := configs[funcname] + if !ok { + for _, pipe := range n.Args { + processNode(pipe) } + break + } - var ( - tl translation - linenr int - ) + var ( + tl translation + linenr int + ) - if sn, ok := cmd.Args[cfg.arg].(*parse.StringNode); ok { - tl.msgid = sn.Text - linenr = getlinenr(sn.Pos.Position()) - } else { - continue - } - if cfg.plural != -1 { - if sn, ok := cmd.Args[cfg.plural].(*parse.StringNode); ok { - tl.msgidPlural = sn.Text - } + if sn, ok := n.Args[cfg.arg].(*parse.StringNode); ok { + tl.msgid = sn.Text + linenr = getlinenr(sn.Pos.Position()) + } else { + break + } + if cfg.plural != -1 { + if sn, ok := n.Args[cfg.plural].(*parse.StringNode); ok { + tl.msgidPlural = sn.Text } - if cfg.context != -1 { - if sn, ok := cmd.Args[cfg.context].(*parse.StringNode); ok { - tl.msgctx = sn.Text - } + } + if cfg.context != -1 { + if sn, ok := n.Args[cfg.context].(*parse.StringNode); ok { + tl.msgctx = sn.Text } + } - ti := translations[tl] - if lastComment != "" { - ti.comment = lastComment - lastComment = "" - } - /* FIXME: Add filename and line number */ - ti.locs = append(ti.locs, loc{currentPath, linenr}) - translations[tl] = ti + ti := translations[tl] + if lastComment != "" { + ti.comment = lastComment + lastComment = "" } + ti.locs = append(ti.locs, loc{currentPath, linenr}) + translations[tl] = ti case *parse.CommentNode: if strings.HasPrefix(n.Text, "/* TRANSLATORS:") { lastComment = strings.TrimSpace(n.Text[2 : len(n.Text)-2]) |