8000 message/pipeline: copy over files from cmd/gotext · golang/text@bbb8cca · GitHub
[go: up one dir, main page]

Skip to content

Commit bbb8cca

Browse files
committed
message/pipeline: copy over files from cmd/gotext
Most of the code will be turned into a package. Change-Id: I47609e5afb176e42d3b0b29bfa04cca23ab6867f Reviewed-on: https://go-review.googlesource.com/82235 Run-TryBot: Marcel van Lohuizen <mpvl@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Nigel Tao <nigeltao@golang.org>
1 parent 576e5cf commit bbb8cca

File tree

7 files changed

+1642
-0
lines changed

7 files changed

+1642
-0
lines changed

message/pipeline/common.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package main
6+
7+
import (
8+
"fmt"
9+
"go/build"
10+
"go/parser"
11+
12+
"golang.org/x/tools/go/loader"
13+
)
14+
15+
const (
16+
extractFile = "extracted.gotext.json"
17+
outFile = "out.gotext.json"
18+
gotextSuffix = ".gotext.json"
19+
)
20+
21+
// NOTE: The command line tool already prefixes with "gotext:".
22+
var (
23+
wrap = func(err error, msg string) error {
24+
return fmt.Errorf("%s: %v", msg, err)
25+
}
26+
wrapf = func(err error, msg string, args ...interface{}) error {
27+
return wrap(err, fmt.Sprintf(msg, args...))
28+
}
29+
errorf = fmt.Errorf
30+
)
31+
32+
func loadPackages(conf *loader.Config, args []string) (*loader.Program, error) {
33+
if len(args) == 0 {
34+
args = []string{"."}
35+
}
36+
37+
conf.Build = &build.Default
38+
conf.ParserMode = parser.ParseComments
39+
40+
// Use the initial packages from the command line.
41+
args, err := conf.FromArgs(args, false)
42+
if err != nil {
43+
return nil, wrap(err, "loading packages failed")
44+
}
45+
46+
// Load, parse and type-check the whole program.
47+
return conf.Load()
48+
}

message/pipeline/doc.go

Lines changed: 53 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0