本文整理匯總了Golang中golang.org/x/tools/go/loader.Config.ParserMode方法的典型用法代碼示例。如果您正苦於以下問題:Golang Config.ParserMode方法的具體用法?Golang Config.ParserMode怎麽用?Golang Config.ParserMode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類golang.org/x/tools/go/loader.Config
的用法示例。
在下文中一共展示了Config.ParserMode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: invalidProgram
func invalidProgram(name string) *loader.Program {
var ldr loader.Config
ldr.ParserMode = goparser.ParseComments
ldr.Import("../fixtures/goparsing/" + name)
prog, err := ldr.Load()
if err != nil {
log.Fatal(err)
}
return prog
}
示例2: allowErrors
// allowErrors causes type errors to be silently ignored.
// (Not suitable if SSA construction follows.)
func allowErrors(lconf *loader.Config) {
ctxt := *lconf.Build // copy
ctxt.CgoEnabled = false
lconf.Build = &ctxt
lconf.AllowErrors = true
// AllErrors makes the parser always return an AST instead of
// bailing out after 10 errors and returning an empty ast.File.
lconf.ParserMode = parser.AllErrors
lconf.TypeChecker.Error = func(err error) {}
}
示例3: classifierProgram
func classifierProgram() *loader.Program {
var ldr loader.Config
ldr.ParserMode = goparser.ParseComments
ldr.Import("../fixtures/goparsing/classification")
ldr.Import("../fixtures/goparsing/classification/models")
ldr.Import("../fixtures/goparsing/classification/operations")
prog, err := ldr.Load()
if err != nil {
log.Fatal(err)
}
return prog
}
示例4: petstoreProgram
func petstoreProgram() *loader.Program {
var ldr loader.Config
ldr.ParserMode = goparser.ParseComments
ldr.Build = &gobuild.Default
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore")
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/models")
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/petstore/rest/handlers")
prog, err := ldr.Load()
if err != nil {
log.Fatal(err)
}
return prog
}
示例5: classifierProgram
func classifierProgram() *loader.Program {
var ldr loader.Config
ldr.ParserMode = goparser.ParseComments
ldr.Build = &gobuild.Default
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification")
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification/models")
ldr.ImportWithTests("github.com/go-swagger/go-swagger/fixtures/goparsing/classification/operations")
prog, err := ldr.Load()
if err != nil {
log.Fatal(err)
}
return prog
}
示例6: ParsePathsFromArgs
// ParsePathsFromArgs parses arguments from command line and looks at import
// paths to rename objects.
func ParsePathsFromArgs() {
flag.Parse()
for _, dir := range flag.Args() {
var conf loader.Config
conf.ParserMode = parser.ParseComments
conf.ImportWithTests(dir)
prog, err := conf.Load()
if err != nil {
panic(err)
}
r := renamer{prog, map[*token.File]bool{}}
r.parse()
if !*dryRun {
r.write()
}
}
}
示例7: newAppScanner
// newAppScanner creates a new api parser
func newAppScanner(opts *Opts, includes, excludes packageFilters) (*appScanner, error) {
var ldr loader.Config
ldr.ParserMode = goparser.ParseComments
ldr.ImportWithTests(opts.BasePath)
prog, err := ldr.Load()
if err != nil {
return nil, err
}
input := opts.Input
if input == nil {
input = new(spec.Swagger)
input.Swagger = "2.0"
}
if input.Paths == nil {
input.Paths = new(spec.Paths)
}
if input.Definitions == nil {
input.Definitions = make(map[string]spec.Schema)
}
if input.Responses == nil {
input.Responses = make(map[string]spec.Response)
}
return &appScanner{
MainPackage: opts.BasePath,
prog: prog,
input: input,
loader: &ldr,
operations: collectOperationsFromInput(input),
definitions: input.Definitions,
responses: input.Responses,
scanModels: opts.ScanModels,
classifier: &programClassifier{
Includes: includes,
Excludes: excludes,
},
}, nil
}