当前位置: 首页>>代码示例>>Golang>>正文


Golang scanner.ErrorList类代码示例

本文整理汇总了Golang中go/scanner.ErrorList的典型用法代码示例。如果您正苦于以下问题:Golang ErrorList类的具体用法?Golang ErrorList怎么用?Golang ErrorList使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了ErrorList类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: CompileStmtList

func (w *World) CompileStmtList(fset *token.FileSet, stmts []ast.Stmt) (Code, error) {
	if len(stmts) == 1 {
		if s, ok := stmts[0].(*ast.ExprStmt); ok {
			return w.CompileExpr(fset, s.X)
		}
	}
	errors := new(scanner.ErrorList)
	cc := &compiler{fset, errors, 0, 0}
	cb := newCodeBuf()
	fc := &funcCompiler{
		compiler:     cc,
		fnType:       nil,
		outVarsNamed: false,
		codeBuf:      cb,
		flow:         newFlowBuf(cb),
		labels:       make(map[string]*label),
	}
	bc := &blockCompiler{
		funcCompiler: fc,
		block:        w.scope.block,
	}
	nerr := cc.numError()
	for _, stmt := range stmts {
		bc.compileStmt(stmt)
	}
	fc.checkLabels()
	if nerr != cc.numError() {
		errors.Sort()
		return nil, errors.Err()
	}
	return &stmtCode{w, fc.get()}, nil
}
开发者ID:zond,项目名称:chicklet,代码行数:32,代码来源:world.go

示例2: ResolveQualifiedIdents

// ResolveQualifiedIdents resolves the selectors of qualified
// identifiers by associating the correct ast.Object with them.
// TODO(gri): Eventually, this functionality should be subsumed
//            by Check.
//
func ResolveQualifiedIdents(fset *token.FileSet, pkg *ast.Package) error {
	var errors scanner.ErrorList

	findObj := func(pkg *ast.Object, name *ast.Ident) *ast.Object {
		scope := pkg.Data.(*ast.Scope)
		obj := scope.Lookup(name.Name)
		if obj == nil {
			errors.Add(fset.Position(name.Pos()), fmt.Sprintf("no %s in package %s", name.Name, pkg.Name))
		}
		return obj
	}

	ast.Inspect(pkg, func(n ast.Node) bool {
		if s, ok := n.(*ast.SelectorExpr); ok {
			if x, ok := s.X.(*ast.Ident); ok && x.Obj != nil && x.Obj.Kind == ast.Pkg {
				// find selector in respective package
				s.Sel.Obj = findObj(x.Obj, s.Sel)
			}
			return false
		}
		return true
	})

	return errors.Err()
}
开发者ID:redcatmiss,项目名称:gcc,代码行数:30,代码来源:resolver_test.go

示例3: VisitDecl

func (c *compiler) VisitDecl(decl ast.Decl) Value {
	c.setDebugLine(decl.Pos())
	// This is temporary. We'll return errors later, rather than panicking.
	if c.Logger != nil {
		c.Logger.Println("Compile declaration:", c.fileset.Position(decl.Pos()))
	}
	defer func() {
		if e := recover(); e != nil {
			elist := new(scanner.ErrorList)
			elist.Add(c.fileset.Position(decl.Pos()), fmt.Sprint(e))
			panic(elist)
		}
	}()

	switch x := decl.(type) {
	case *ast.FuncDecl:
		return c.VisitFuncDecl(x)
	case *ast.GenDecl:
		c.VisitGenDecl(x)
		return nil
	}
	panic(fmt.Sprintf("Unhandled decl (%s) at %s\n",
		reflect.TypeOf(decl),
		c.fileset.Position(decl.Pos())))
}
开发者ID:qioixiy,项目名称:llgo,代码行数:25,代码来源:decl.go

示例4: 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)

}
开发者ID:garslo,项目名称:gogen,代码行数:17,代码来源:main.go

示例5: checkFiles

func checkFiles(t *testing.T, testname string, testfiles []string) {
	// TODO(gri) Eventually all these different phases should be
	//           subsumed into a single function call that takes
	//           a set of files and creates a fully resolved and
	//           type-checked AST.

	files, err := parseFiles(t, testname, testfiles)

	// we are expecting the following errors
	// (collect these after parsing the files so that
	// they are found in the file set)
	errors := expectedErrors(t, testname, files)

	// verify errors returned by the parser
	eliminate(t, errors, err)

	// verify errors returned after resolving identifiers
	pkg, err := ast.NewPackage(fset, files, GcImport, Universe)
	eliminate(t, errors, err)

	// verify errors returned by the typechecker
	var list scanner.ErrorList
	errh := func(pos token.Pos, msg string) {
		list.Add(fset.Position(pos), msg)
	}
	err = Check(fset, pkg, errh, nil)
	eliminate(t, errors, list)

	if *listErrors {
		scanner.PrintError(os.Stdout, err)
		return
	}

	// there should be no expected errors left
	if len(errors) > 0 {
		t.Errorf("%s: %d errors not reported:", testname, len(errors))
		for pos, msg := range errors {
			t.Errorf("%s: %s\n", fset.Position(pos), msg)
		}
	}
}
开发者ID:mm120,项目名称:gcc,代码行数:41,代码来源:check_test.go

示例6: CompileExpr

func (w *World) CompileExpr(fset *token.FileSet, e ast.Expr) (Code, error) {
	errors := new(scanner.ErrorList)
	cc := &compiler{fset, errors, 0, 0}

	ec := cc.compileExpr(w.scope.block, false, e)
	if ec == nil {
		errors.Sort()
		return nil, errors.Err()
	}
	var eval func(Value, *Thread)
	switch t := ec.t.(type) {
	case *idealIntType:
		// nothing
	case *idealFloatType:
		// nothing
	default:
		if tm, ok := t.(*MultiType); ok && len(tm.Elems) == 0 {
			return &stmtCode{w, code{ec.exec}}, nil
		}
		eval = genAssign(ec.t, ec)
	}
	return &exprCode{w, ec, eval}, nil
}
开发者ID:zond,项目名称:chicklet,代码行数:23,代码来源:world.go

示例7: Ast

func (p *Parser) Ast(fs *token.FileSet, path string, files []string, unsaved map[string]UnsavedDocument) (*ast.File, []*ast.File, error) {
	ret := make([]*ast.File, len(files))
	var retf *ast.File

	var errors scanner.ErrorList

	for i, f := range files {
		f = CanonicalPath(f)

		var v *ast.File
		var err error

		if uns, ok := unsaved[f]; ok {
			v, err = parser.ParseFile(fs, f, uns.Data, parser.AllErrors)
		} else {
			v, err = p.fromCache(fs, f)
		}

		if v == nil {
			return nil, nil, err
		}

		ret[i] = v

		if path == f {
			retf = ret[i]

			if perr, ok := err.(scanner.ErrorList); ok {
				for _, e := range perr {
					errors.Add(e.Pos, e.Msg)
				}
			}
		}
	}

	errors.RemoveMultiples()
	errors.Sort()

	var err error

	if len(errors) != 0 {
		err = errors
	}

	return retf, ret, err
}
开发者ID:GNOME,项目名称:gnome-code-assistance,代码行数:46,代码来源:parser.go

示例8: 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
}
开发者ID:postfix,项目名称:cutil,代码行数:72,代码来源:mksyscall.go

示例9: 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
}
开发者ID:kless,项目名称:goutil,代码行数:84,代码来源:mkdef.go


注:本文中的go/scanner.ErrorList类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。