本文整理汇总了Golang中go/scanner.ErrorList.Len方法的典型用法代码示例。如果您正苦于以下问题:Golang ErrorList.Len方法的具体用法?Golang ErrorList.Len怎么用?Golang ErrorList.Len使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类go/scanner.ErrorList
的用法示例。
在下文中一共展示了ErrorList.Len方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: HandleScannerError
func HandleScannerError(errList scanner.ErrorList) {
fmt.Fprintf(os.Stderr, "%d errors\n", errList.Len())
maxErrs := 10
errCount := 0
for _, scannerErr := range errList {
if errCount == maxErrs {
fmt.Fprint(os.Stderr, "too many errors")
break
}
errCount++
fmt.Fprintf(os.Stderr, "Error: %v\n", scannerErr)
}
os.Exit(1)
}
示例2: processFile
func processFile(filename string) ([]*prototype, error) {
info, err := os.Stat(filename)
if err != nil {
return nil, err
}
src, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
// Scan file
protos := make([]*prototype, 0)
var errorList scanner.ErrorList
var s scanner.Scanner
fset := token.NewFileSet()
file := fset.AddFile(filename, fset.Base(), int(info.Size()))
s.Init(file, src, nil, scanner.ScanComments)
for findPkg, isPkgToken := true, false; ; {
_, tok, lit := s.Scan()
if tok == token.EOF {
break
}
// package name
if findPkg {
if tok == token.PACKAGE {
isPkgToken = true
continue
}
if isPkgToken {
if PKG_NAME == "" {
PKG_NAME = lit
if PKG_NAME == "syscall" {
SYSCALL_DOT = ""
}
} else if PKG_NAME != lit {
return nil, errors.New("the files have different package name")
}
findPkg = false
continue
}
}
// scan comments
if tok != token.COMMENT || !strings.HasPrefix(lit, PREFIX) {
continue
}
lit = strings.Replace(lit, PREFIX, "", 1)
if lit[0] != ' ' && lit[0] != '\t' {
continue
}
lit = strings.TrimSpace(lit)
proto, err := scanProtype([]byte(lit))
if err != nil {
errorList.Add(err.Pos, err.Msg)
continue
}
if errorList.Len() == 0 {
protos = append(protos, proto)
}
}
if errorList.Len() != 0 {
return nil, errorList
}
return protos, nil
}
示例3: processFile
func processFile(filename string, proto *prototype) error {
info, err := os.Stat(filename)
if err != nil {
return err
}
src, err := ioutil.ReadFile(filename)
if err != nil {
return err
}
// Scan file
var errorList scanner.ErrorList
var s scanner.Scanner
fset := token.NewFileSet()
file := fset.AddFile(filename, fset.Base(), int(info.Size()))
s.Init(file, src, nil, scanner.ScanComments)
for findPkg, isPkgToken := true, false; ; {
_, tok, lit := s.Scan()
if tok == token.EOF {
break
}
// package name
if findPkg {
if tok == token.PACKAGE {
isPkgToken = true
continue
}
if isPkgToken {
if proto.pkgName == "" {
(*proto).pkgName = lit
} else if proto.pkgName != lit {
return errors.New("the files have different package name")
}
findPkg = false
continue
}
}
// scan comments
if tok != token.COMMENT || !strings.HasPrefix(lit, PREFIX) {
continue
}
lit = strings.Replace(lit, PREFIX, "", 1)
if lit[0] == '/' && lit[1] == '/' {
proto.comment = lit
continue
}
if lit[0] != ' ' && lit[0] != '\t' {
continue
}
lit_ := strings.TrimSpace(lit)
// multiple comments
for {
if lit[len(lit)-1] == ',' { // the line continues on the next one
_, tok, lit = s.Scan()
if tok == token.COMMENT {
lit = strings.Replace(lit, "//", "", 1)
lit = strings.TrimSpace(lit)
lit_ += lit
} else {
break
}
} else {
break
}
}
err := scanProtype(proto, []byte(lit_))
if err != nil {
errorList.Add(err.Pos, err.Msg)
continue
}
}
if errorList.Len() != 0 {
return errorList
}
return nil
}