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


Golang FileSet.AddFile方法代码示例

本文整理汇总了Golang中go/token.FileSet.AddFile方法的典型用法代码示例。如果您正苦于以下问题:Golang FileSet.AddFile方法的具体用法?Golang FileSet.AddFile怎么用?Golang FileSet.AddFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在go/token.FileSet的用法示例。


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

示例1: init

func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode uint) {
	p.file = fset.AddFile(filename, fset.Base(), len(src))
	p.scanner.Init(p.file, src, p, scannerMode(mode))
	p.mode = mode
	p.trace = mode&Trace != 0 // for convenience (p.trace is used frequently)
	p.next()
}
开发者ID:IntegerCompany,项目名称:linaro-android-gcc,代码行数:7,代码来源:parser.go

示例2: init

func (p *parser) init(fset *token.FileSet, filename string, src []byte) {
	p.ErrorVector.Reset()
	p.file = fset.AddFile(filename, fset.Base(), len(src))
	p.scanner.Init(p.file, src, p, scanner.AllowIllegalChars) // return '@' as token.ILLEGAL w/o error message
	p.next()                                                  // initializes pos, tok, lit
	p.packs = make(map[string]string)
	p.rules = make(map[string]expr)
}
开发者ID:go-nosql,项目名称:golang,代码行数:8,代码来源:parser.go

示例3: init

func (p *parser) init(fset *token.FileSet, filename string, src []byte) {
	p.file = fset.AddFile(filename, -1, len(src))
	var m scanner.Mode
	eh := func(pos token.Position, msg string) { p.errors.Add(pos, msg) }
	p.scanner.Init(p.file, src, eh, m)

	p.next()
}
开发者ID:obask,项目名称:goCrazy,代码行数:8,代码来源:parser.go

示例4: init

func (p *parser) init(fset *token.FileSet, filename string, src []byte, mode Mode) {
	p.file = fset.AddFile(filename, -1, len(src))
	var m scanner.Mode
	if mode&ParseComments != 0 {
		m = scanner.ScanComments
	}
	eh := func(pos token.Position, msg string) { p.errors.Add(pos, msg) }
	p.scanner.Init(p.file, src, eh, m)

	p.mode = mode
	p.trace = mode&Trace != 0 // for convenience (p.trace is used frequently)

	//p.next()
}
开发者ID:h12w,项目名称:gombi,代码行数:14,代码来源:parser.go

示例5: parse

func (p *ebnfParser) parse(fset *token.FileSet, out io.Writer, src []byte) {
	// initialize ebnfParser
	p.out = out
	p.src = src
	p.file = fset.AddFile("", fset.Base(), len(src))
	p.scanner.Init(p.file, src, p, scanner.AllowIllegalChars)
	p.next() // initializes pos, tok, lit

	// process source
	for p.tok != token.EOF {
		p.parseProduction()
	}
	p.flush()
}
开发者ID:jnwhiteh,项目名称:go,代码行数:14,代码来源:spec.go

示例6: parse

func (p *parser) parse(fset *token.FileSet, filename string, src []byte) Grammar {
	// initialize parser
	p.fset = fset
	p.ErrorVector.Reset()
	p.scanner.Init(fset.AddFile(filename, fset.Base(), len(src)), src, p, scanner.AllowIllegalChars)
	p.next() // initializes pos, tok, lit

	grammar := make(Grammar)
	for p.tok != token.EOF {
		prod := p.parseProduction()
		name := prod.Name.String
		if _, found := grammar[name]; !found {
			grammar[name] = prod
		} else {
			p.error(prod.Pos(), name+" declared already")
		}
	}

	return grammar
}
开发者ID:jnwhiteh,项目名称:go,代码行数:20,代码来源:parser.go

示例7: Parse

// Parse parses src as a single yacc source file fname and returns the
// corresponding Specification. If the source couldn't be read, the returned
// Specification is nil and the error indicates all of the specific failures.
func Parse(fset *token.FileSet, fname string, src []byte) (s *Specification, err error) {
	r := bytes.NewBuffer(src)
	file := fset.AddFile(fname, -1, len(src))
	lx, err := newLexer(file, r)
	if err != nil {
		return nil, err
	}

	y := yyParse(lx)
	n := len(lx.errors)
	if y != 0 || n != 0 {
		if n == 0 {
			panic("internal error")
		}

		return nil, lx.errors
	}

	return lx.spec, nil
}
开发者ID:qiuyesuifeng,项目名称:goyacc,代码行数:23,代码来源:api.go

示例8: ParseFile

func ParseFile(fset *token.FileSet, filename string) ATree {

	fmt.Println("dbg 1")

	// get source
	text, err := ioutil.ReadFile(filename)
	if err != nil {
		return nil
	}

	var lexer scanner.Scanner

	fileSet := fset.AddFile(filename, -1, len(text))

	errorHandler := func(pos token.Position, msg string) {
		// FIXME this happened for ILLEGAL tokens, forex '?'
		panic("SUCCESS in scanner errorHandler")
	}

	var m scanner.Mode
	lexer.Init(fileSet, text, errorHandler, m)

	fmt.Println("dbg 2.1")

	// Repeated calls to Scan yield the token sequence found in the input.
	//	for {
	//		_, tok, lit := lexer.Scan()
	//		if tok == token.EOF {
	//			break
	//		}
	//		fmt.Printf("\t%s    %q\n", tok, lit)
	//	}
	//

	fmt.Println("dbg 2.2")

	return parseCode(&lexer, []ATree{})
}
开发者ID:obask,项目名称:lispify,代码行数:38,代码来源:main.go

示例9: printDecl

func printDecl(decl ast.Node, fset *token.FileSet, buf []byte) (Code, []byte) {
	v := &annotationVisitor{}
	ast.Walk(v, decl)

	buf = buf[:0]
	err := (&printer.Config{Mode: printer.UseSpaces, Tabwidth: 4}).Fprint(sliceWriter{&buf}, fset, decl)
	if err != nil {
		return Code{Text: err.Error()}, buf
	}

	var annotations []Annotation
	var s scanner.Scanner
	fset = token.NewFileSet()
	file := fset.AddFile("", fset.Base(), len(buf))
	s.Init(file, buf, nil, scanner.ScanComments)
loop:
	for {
		pos, tok, lit := s.Scan()
		switch tok {
		case token.EOF:
			break loop
		case token.COMMENT:
			p := file.Offset(pos)
			e := p + len(lit)
			if p > math.MaxInt16 || e > math.MaxInt16 {
				break loop
			}
			annotations = append(annotations, Annotation{Kind: CommentAnnotation, Pos: int16(p), End: int16(e)})
		case token.IDENT:
			if len(v.annotations) == 0 {
				// Oops!
				break loop
			}
			annotation := v.annotations[0]
			v.annotations = v.annotations[1:]
			if annotation.Kind == -1 {
				continue
			}
			p := file.Offset(pos)
			e := p + len(lit)
			if p > math.MaxInt16 || e > math.MaxInt16 {
				break loop
			}
			annotation.Pos = int16(p)
			annotation.End = int16(e)
			if len(annotations) > 0 && annotation.Kind == ExportLinkAnnotation {
				prev := annotations[len(annotations)-1]
				if prev.Kind == PackageLinkAnnotation &&
					prev.ImportPath == annotation.ImportPath &&
					prev.End+1 == annotation.Pos {
					// merge with previous
					annotation.Pos = prev.Pos
					annotations[len(annotations)-1] = annotation
					continue loop
				}
			}
			annotations = append(annotations, annotation)
		}
	}
	return Code{Text: string(buf), Annotations: annotations}, buf
}
开发者ID:JessonChan,项目名称:bee,代码行数:61,代码来源:code.go


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