• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang scanner.PrintError函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: main

func main() {
	flag.Parse()

	var filename string
	switch flag.NArg() {
	case 0:
		filename = "/dev/stdin"
	case 1:
		filename = flag.Arg(0)
	default:
		usage()
	}

	src, err := ioutil.ReadFile(filename)
	if err != nil {
		scanner.PrintError(os.Stderr, err)
	}

	if path.Ext(filename) == ".html" {
		src = extractEBNF(src)
	}

	grammar, err := ebnf.Parse(filename, src)
	if err != nil {
		scanner.PrintError(os.Stderr, err)
	}

	if err = ebnf.Verify(grammar, *start); err != nil {
		scanner.PrintError(os.Stderr, err)
	}
}
开发者ID:ivanwyc,项目名称:google-go,代码行数:31,代码来源:ebnflint.go


示例2: main

func main() {
	flag.Parse()
	log.SetFlags(0)

	// If no paths are provided then use the present working directory.
	roots := flag.Args()
	if len(roots) == 0 {
		roots = []string{"."}
	}

	// Recursively retrieve all ego templates
	var v visitor
	for _, root := range roots {
		if err := filepath.Walk(root, v.visit); err != nil {
			scanner.PrintError(os.Stderr, err)
			os.Exit(1)
		}
	}

	// Parse every *.ego file.
	for _, path := range v.paths {
		template, err := egon.ParseFile(path)
		if err != nil {
			log.Fatal("parse file: ", err)
		}

		pkg := &egon.Package{Template: template}
		err = pkg.Write()
		if err != nil {
			log.Fatal("write: ", err)
		}
	}
}
开发者ID:commondream,项目名称:egon,代码行数:33,代码来源:main.go


示例3: FormatCode

// FormatCode runs "goimports -w" on the source file.
func (f *SourceFile) FormatCode() error {
	if NoFormat {
		return nil
	}
	// Parse file into AST
	fset := token.NewFileSet()
	file, err := parser.ParseFile(fset, f.Abs(), nil, parser.ParseComments)
	if err != nil {
		content, _ := ioutil.ReadFile(f.Abs())
		var buf bytes.Buffer
		scanner.PrintError(&buf, err)
		return fmt.Errorf("%s\n========\nContent:\n%s", buf.String(), content)
	}
	// Clean unused imports
	imports := astutil.Imports(fset, file)
	for _, group := range imports {
		for _, imp := range group {
			path := strings.Trim(imp.Path.Value, `"`)
			if !astutil.UsesImport(file, path) {
				astutil.DeleteImport(fset, file, path)
			}
		}
	}
	ast.SortImports(fset, file)
	// Open file to be written
	w, err := os.OpenFile(f.Abs(), os.O_WRONLY|os.O_CREATE|os.O_TRUNC, os.ModePerm)
	if err != nil {
		return err
	}
	defer w.Close()
	// Write formatted code without unused imports
	return format.Node(w, fset, file)
}
开发者ID:jim-slattery-rs,项目名称:goa,代码行数:34,代码来源:workspace.go


示例4: ErrPosition

// ErrPosition reports an error at position.
func (c *Report) ErrPosition(position token.Position, format string, arg ...interface{}) {
	if c.TraceErrors {
		fmt.Fprintf(os.Stderr, "%v: %s\n", position, fmt.Sprintf(format, arg...))
	}

	if c.IgnoreErrors {
		return
	}

	c.errorsMu.Lock()         // X+
	defer c.errorsMu.Unlock() // X-

	if c.PanicOnError {
		panic(fmt.Errorf("%s: %v", position, fmt.Sprintf(format, arg...)))
	}

	c.errors.Add(position, fmt.Sprintf(format, arg...))

	if c.ErrLimit > 0 {
		c.ErrLimit--
		if c.ErrLimit == 0 {
			scanner.PrintError(os.Stderr, c.errors)
			log.Fatalf("too many errors")
		}
	}

}
开发者ID:cznic,项目名称:xc,代码行数:28,代码来源:global.go


示例5: main

func main() {
	log.SetFlags(0)
	kingpin.CommandLine.Help = "Generate native Go code from ERB-style Templates"
	kingpin.Parse()

	if len(egon.Config.Folders) == 0 {
		egon.Config.Folders = []string{"."}
	}

	// Recursively retrieve all templates
	var v visitor
	for _, root := range egon.Config.Folders {
		log.Printf("scanning folder [%s]", root)
		if err := filepath.Walk(root, v.visit); err != nil {
			scanner.PrintError(os.Stderr, err)
			os.Exit(1)
		}
	}

	// Parse every *.ego file.
	for _, path := range v.paths {
		template, err := egon.ParseFile(path)
		if err != nil {
			log.Fatal("parse file: ", err)
		}

		pkg := &egon.Package{Template: template}
		err = pkg.Write()
		if err != nil {
			log.Fatal("write: ", err)
		}
	}
}
开发者ID:SlinSo,项目名称:egon,代码行数:33,代码来源:main.go


示例6: main

func main() {
	log.SetFlags(0)
	list := flag.Bool("l", false, "List assembly code and exit.")
	trace := flag.Bool("t", false, "Trace execution.")
	stack := flag.Bool("s", false, "Trace execution and stack.")
	flag.Parse()
	if n := flag.NArg(); n != 1 {
		log.Fatalf("expected 1 argument, got %v", n)
	}

	prog, err := pl0.Parse(flag.Arg(0))
	if err != nil {
		scanner.PrintError(os.Stderr, err)
		os.Stderr.Sync()
		os.Exit(1)
	}

	if *list {
		prog.List(os.Stdout)
		return
	}

	switch {
	case *stack:
		err = prog.Run(pl0.TraceStack())
	case *trace:
		err = prog.Run(pl0.Trace())
	default:
		err = prog.Run()
	}
	if err != nil {
		log.Fatal(err)
	}
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:34,代码来源:pl0.go


示例7: Example_undeclared

func Example_undeclared() {
	_, err := ParseString("",
		`
	CONST a = 42;
	
	VAR b;
	
	PROCEDURE c;
	BEGIN
		CALL aa;
		CALL c;
	END;
	
	BEGIN
		b := a;
		b := d;
		e := 10;
		CALL c;
		CALL f;
		? b;
		? g;
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 8:8: undeclared identifier aa
	// 14:8: undeclared identifier d
	// 15:3: undeclared identifier e
	// 17:8: undeclared identifier f
	// 19:5: undeclared identifier g
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:32,代码来源:all_test.go


示例8: Example_redeclaration

func Example_redeclaration() {
	_, err := ParseString("",
		`
	CONST a = 42, b = 24, a = 314;
	
	VAR b, c, d;
	
	PROCEDURE c;
	BEGIN
	END;
	
	PROCEDURE d;
	BEGIN
	END;
	
	PROCEDURE e;
	BEGIN
	END;
	
	PROCEDURE e;
	BEGIN
	END;
	
	BEGIN
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 2:24: redeclaration of a at 2:8
	// 4:6: redeclaration of b at 2:16
	// 6:12: redeclaration of c at 4:9
	// 10:12: redeclaration of d at 4:12
	// 18:12: redeclaration of e at 14:12
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:35,代码来源:all_test.go


示例9: report

func report(err error) {
	scanner.PrintError(os.Stderr, err)
	if list, ok := err.(scanner.ErrorList); ok {
		errorCount += len(list)
		return
	}
	errorCount++
}
开发者ID:4honor,项目名称:obdi,代码行数:8,代码来源:gotype.go


示例10: TestTypeCheck

func TestTypeCheck(t *testing.T) {
	flag.Parse()
	pkgRx, err := regexp.Compile(*pkgPat)
	if err != nil {
		t.Fatalf("illegal flag value %q: %s", *pkgPat, err)
	}

	pkgs, err := parser.ParseDir(fset, testDir, testFilter, 0)
	if err != nil {
		scanner.PrintError(os.Stderr, err)
		t.Fatalf("packages in %s contain syntax errors", testDir)
	}

	for _, pkg := range pkgs {
		if !pkgRx.MatchString(pkg.Name) {
			continue // only test selected packages
		}

		if *trace {
			fmt.Println(pkg.Name)
		}

		xlist := expectedErrors(t, pkg)
		err := CheckPackage(fset, pkg, nil)
		if err != nil {
			if elist, ok := err.(scanner.ErrorList); ok {
				// verify that errors match
				for i := 0; i < len(xlist) && i < len(elist); i++ {
					checkError(t, xlist[i], elist[i])
				}
				// the correct number or errors must have been found
				if len(xlist) != len(elist) {
					fmt.Fprintf(os.Stderr, "%s\n", pkg.Name)
					scanner.PrintError(os.Stderr, elist)
					fmt.Fprintln(os.Stderr)
					t.Errorf("TypeCheck(%s): %d errors expected but %d reported", pkg.Name, len(xlist), len(elist))
				}
			} else {
				t.Errorf("TypeCheck(%s): %v", pkg.Name, err)
			}
		} else if len(xlist) > 0 {
			t.Errorf("TypeCheck(%s): %d errors expected but 0 reported", pkg.Name, len(xlist))
		}
	}
}
开发者ID:WXB506,项目名称:golang,代码行数:45,代码来源:typechecker_test.go


示例11: Test

func Test(t *testing.T) {
	err := processFile("testdata/data.go", NewPrototype())
	e, ok := err.(scanner.ErrorList)
	if !ok {
		t.Fatal(err)
	}

	if len(e) != NUM_ERRORS {
		t.Errorf("expected %d errors", NUM_ERRORS)
		scanner.PrintError(os.Stderr, err)
	}
}
开发者ID:kless,项目名称:goutil,代码行数:12,代码来源:mkdef_test.go


示例12: MustCompileLexer

// MustCompileLexer is like CompileLexer but panics if the definitions cannot be compiled.
// It simplifies safe initialization of global variables holding compiled Lexers.
func MustCompileLexer(starts [][]int, tokdefs map[string]int, grammar, start string) (lexer *Lexer) {
	var err error
	if lexer, err = CompileLexer(starts, tokdefs, grammar, start); err != nil {
		if list, ok := err.(scanner.ErrorList); ok {
			scanner.PrintError(os.Stderr, list)
		} else {
			log.Fatal(err)
		}
		panic(err)
	}
	return
}
开发者ID:ericfode,项目名称:lexer,代码行数:14,代码来源:lexer.go


示例13: Main

func Main() {
	world = eval.NewWorld()
	defineFuncs()
	r := bufio.NewReader(os.Stdin)
	for {
		print("; ")
		line, err := r.ReadSlice('\n')
		if err != nil {
			break
		}

		// Try line as a command
		cmd, rest := getCmd(line)
		if cmd != nil {
			err := cmd.handler(rest)
			if err != nil {
				scanner.PrintError(os.Stderr, err)
			}
			continue
		}

		// Try line as code
		code, err := world.Compile(string(line))
		if err != nil {
			scanner.PrintError(os.Stderr, err)
			continue
		}
		v, err := code.Run()
		if err != nil {
			fmt.Fprintf(os.Stderr, err.String())
			continue
		}
		if v != nil {
			println(v.String())
		}
	}
}
开发者ID:edisonwsk,项目名称:golang-on-cygwin,代码行数:37,代码来源:cmd.go


示例14: generate

func generate(arch, header, out, test, predefined string) error {
	m, err := ccgo.NewModel(arch)
	if err != nil {
		return err
	}

	var cpplog *os.File
	var s []string
	opts := []cc.Opt{cc.SysIncludePaths([]string{ccgo.LibcIncludePath})}
	if *cpp {
		var err error
		if cpplog, err = os.Create("log-cpp-" + arch); err != nil {
			return err
		}

		defer cpplog.Close()

		opts = append(opts, cc.Cpp(func(a []xc.Token) {
			if len(a) == 0 {
				return
			}

			s = s[:0]
			for _, v := range a {
				s = append(s, cc.TokSrc(v))
			}
			fmt.Fprintf(cpplog, "%s: %s\n", a[0].Position(), strings.Join(s, " "))
		}))
	}

	predefined += fmt.Sprintf("\n#define __MODEL%v\n", ccgo.Archs[arch])
	tu, err := cc.Parse(predefined, paths, m, opts...)
	if err != nil {
		var buf bytes.Buffer
		scanner.PrintError(&buf, err)
		return fmt.Errorf("%s", buf.Bytes())
	}

	return (&ccgo.Job{
		DeclarationComments: *pos,
		Header:              header,
		ImportPath:          importPath,
		In:                  tu,
		Model:               m,
		Out:                 out,
		Root:                root,
		Test:                test,
	}).Run()
}
开发者ID:cznic,项目名称:c,代码行数:49,代码来源:generator.go


示例15: 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


示例16: Example_illegalFactor

func Example_illegalFactor() {
	_, err := ParseString("",
		`
	CONST a = 42;
	
	VAR b;
	
	PROCEDURE c;
	BEGIN
	END;
	
	BEGIN
		b := a;
		b := b;
		b := c;
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 13:8: c is not a constant or a variable
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:22,代码来源:all_test.go


示例17: Example_illegalAssignment

func Example_illegalAssignment() {
	_, err := ParseString("",
		`
	CONST a = 42;
	
	VAR b;
	
	PROCEDURE c;
	BEGIN
	END;
	
	BEGIN
		a := 1;
		b := 1;
		c := 1;
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 11:3: a is not a variable
	// 13:3: c is not a variable
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:23,代码来源:all_test.go


示例18: Example_illegalCall

func Example_illegalCall() {
	_, err := ParseString("",
		`
	CONST a = 42;
	
	VAR b;
	
	PROCEDURE c;
	BEGIN
	END;
	
	BEGIN
		CALL a;
		CALL b;
		CALL c;
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 11:8: a is not a procedure
	// 12:8: b is not a procedure
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:23,代码来源:all_test.go


示例19: Example_illegalRead

func Example_illegalRead() {
	_, err := ParseString("",
		`
	CONST a = 42;
	
	VAR b;
	
	PROCEDURE c;
	BEGIN
	END;
	
	BEGIN
		? a;
		? b;
		? c;
	END.
`)

	scanner.PrintError(os.Stdout, err)
	// Output:
	// 11:5: a is not a variable
	// 13:5: c is not a variable
}
开发者ID:JamesLinus,项目名称:pl0,代码行数:23,代码来源:all_test.go


示例20: main

func main() {
	flag.Usage = usage
	flag.Parse()

	if len(os.Args) == 1 {
		usage()
	}

	log.SetFlags(0)
	log.SetPrefix("FAIL! ")

	exitCode := 0
	proto := NewPrototype()
	filenamePath := ""

	// Scan all files passed in command line.
	for _, filename := range flag.Args() {
		switch info, err := os.Stat(filename); {
		case err != nil:
			log.Print(err)
			exitCode = 1
		case info.Mode()&os.ModeType == 0: // regular file
			if err := processFile(filename, proto); err != nil {
				log.Printf("\t%s\n\n", filename)
				scanner.PrintError(os.Stderr, err)
				exitCode = 1
			} else if filename == "" {
				filenamePath = filename
			}
		default:
			log.Print("not regular file: ", filename)
			exitCode = 1
		}
	}
	if exitCode != 0 {
		os.Exit(exitCode)
	}

	// Find in header files
	if errList := proto.find(); errList != nil {
		for _, e := range errList {
			log.Print(e)
		}
		os.Exit(1)
	}
	if len(proto.includes) == 0 {
		log.Print("prototypes not found")
		os.Exit(1)
	}

	// Create file
	var err error
	filew := os.Stdout
	if *Write {
		filew, err = os.Create(filepath.Join(filepath.Dir(filenamePath),
			fmt.Sprintf("z-sys_%s_%s.go", runtime.GOOS, runtime.GOARCH)))
		if err != nil {
			log.Fatal(err)
		}
		defer func() {
			if err = filew.Close(); err != nil {
				log.Print(err)
			}
		}()
	}

	sort.Strings(proto.includes)
	sort.Strings(proto.enums)
	sort.Strings(proto.structs)
	sort.Strings(proto.unions)

	// Return '_' for constants not exported.
	exportConst := func(name string) string {
		v, found := proto.export[name]
		if found {
			if !v {
				return "_"
			}
		} else if !*Export {
			return "_"
		}
		return ""
	}

	// Return the name in title case if it is exported.
	exportIdent := func(name string) string {
		v, found := proto.export[name]
		if found {
			if !v {
				return name
			}
		} else if !*Export {
			return name
		}
		return strings.Title(name)
	}

	// Write

	HEADER = fmt.Sprintf("// %s\n%s", strings.Join(os.Args, " "), HEADER)
//.........这里部分代码省略.........
开发者ID:kless,项目名称:goutil,代码行数:101,代码来源:mkdef.go



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang scanner.ErrorList类代码示例发布时间:2022-05-28
下一篇:
Golang printer.Config类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap