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


Golang token.Pos函数代码示例

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


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

示例1: makeNewNode

func (vis *pointerTransformVisitor) makeNewNode(i *ast.Ident, depth int) ast.Expr {
	d := depth
	i.NamePos += token.Pos(d)
	switch {
	case depth > 0:
		res := &ast.UnaryExpr{i.NamePos - token.Pos(depth), token.AND, nil}
		e := res
		for depth > 1 {
			e.X = &ast.UnaryExpr{i.NamePos - token.Pos(depth), token.AND, nil}
			e = e.X.(*ast.UnaryExpr)
			depth--
		}
		e.X = i
		return res
	case depth < 0:
		res := &ast.StarExpr{i.NamePos - token.Pos(depth), nil}
		e := res
		for depth < -1 {
			e.X = &ast.StarExpr{i.NamePos - token.Pos(depth), nil}
			e = e.X.(*ast.StarExpr)
			depth++
		}
		e.X = i
		return res
	}
	return i
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:27,代码来源:extractMethod.go

示例2: parsePackageClause

func (p *parser) parsePackageClause(n *parse.Node) (token.Pos, *ast.Ident) {
	pac, name := n.Child(0), n.Child(1)
	return token.Pos(pac.Pos()), &ast.Ident{
		NamePos: token.Pos(name.Pos()),
		Name:    string(name.Value()),
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:parser.go

示例3: parseIndex

func (p *parser) parseIndex(n *parse.Node) ast.Expr {
	index := n.Child(1)
	return &ast.IndexExpr{
		X:      p.parsePrimaryExpr(n.Child(0)),
		Lbrack: token.Pos(index.Child(0).Pos()),
		Index:  p.parseExpr(index.Child(1)),
		Rbrack: token.Pos(index.Child(2).Pos()),
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:9,代码来源:parser.go

示例4: parseCompositeLit

func (p *parser) parseCompositeLit(n *parse.Node) ast.Expr {
	litValue := n.Child(1)
	return &ast.CompositeLit{
		Type:   p.parseLiteralType(n.Child(0)),
		Lbrace: token.Pos(litValue.Child(0).Pos()),
		Elts:   p.parseLiteralValue(litValue),
		Rbrace: token.Pos(litValue.LastChild().Pos()),
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:9,代码来源:parser.go

示例5: parseBlock

func (p *parser) parseBlock(n *parse.Node, scope *ast.Scope) *ast.BlockStmt {
	block := ast.BlockStmt{
		Lbrace: token.Pos(n.Child(0).Pos()),
		Rbrace: token.Pos(n.LastChild().Pos()),
	}
	eachListItem(stmt, n.Child(1), func(item *parse.Node) {
		block.List = append(block.List, p.parseStmt(item))
	})
	return &block
}
开发者ID:h12w,项目名称:gombi,代码行数:10,代码来源:parser.go

示例6: GetLines

func GetLines(f *token.File) []int {
	lines := make([]int, 0, 20)
	l := -1
	for i := f.Base(); i < f.Base()+f.Size(); i++ {
		if f.Line(token.Pos(i)) > l {
			l = f.Line(token.Pos(i))
			lines = append(lines, f.Offset(token.Pos(i)))
		}
	}
	return lines
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:11,代码来源:printer.go

示例7: parseCallExpr

func (p *parser) parseCallExpr(n *parse.Node) *ast.CallExpr {
	call := n.Child(1)
	callExpr := ast.CallExpr{
		Fun:    p.parsePrimaryExpr(n.Child(0)),
		Lparen: token.Pos(call.Child(0).Pos()),
		Rparen: token.Pos(call.LastChild().Pos()),
	}
	if call.ChildCount() > 2 {
		callExpr.Args, callExpr.Ellipsis = p.parseArgs(call.Child(1))
	}
	return &callExpr
}
开发者ID:h12w,项目名称:gombi,代码行数:12,代码来源:parser.go

示例8: parseParams

func (p *parser) parseParams(n *parse.Node, scope *ast.Scope) *ast.FieldList {
	fieldList := ast.FieldList{
		Opening: token.Pos(n.Child(0).Pos()),
		Closing: token.Pos(n.LastChild().Pos()),
	}
	if n.Child(1).Is(parameterList) {
		eachListItem(parameterDecl, n.Child(1), func(item *parse.Node) {
			fieldList.List = append(fieldList.List, p.parseParamDecl(item, scope))
		})
	}
	return &fieldList
}
开发者ID:h12w,项目名称:gombi,代码行数:12,代码来源:parser.go

示例9: parseVarDecl

func (p *parser) parseVarDecl(n *parse.Node) ast.Decl {
	var specs []ast.Spec
	lParen, rParen := declListEach(n.Child(1), func(item *parse.Node) {
		specs = append(specs, p.parseVarSpec(item))
	})
	return &ast.GenDecl{
		TokPos: token.Pos(n.Child(0).Pos()),
		Tok:    token.Token(n.Child(0).ID()),
		Lparen: token.Pos(lParen),
		Specs:  specs,
		Rparen: token.Pos(rParen),
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:13,代码来源:parser.go

示例10: makeStmtList

func makeStmtList(block *vector.Vector) []ast.Stmt {
	stmtList := make([]ast.Stmt, len(*block))
	for i, stmt := range *block {
		switch el := stmt.(type) {
		case ast.Stmt:
			stmtList[i] = el
		case []ast.Expr: // i == 0
			stmtList[i] = &ast.ReturnStmt{el[0].Pos() - token.Pos(7), el}
		case ast.Expr: // i == 0
			stmtList[i] = &ast.ReturnStmt{el.Pos() - token.Pos(7), []ast.Expr{el}}
		}
	}
	return stmtList
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:14,代码来源:extractMethod.go

示例11: commentsBetween

func commentsBetween(f *ast.File, begin token.Pos, end token.Pos) string {
	var buf bytes.Buffer
	var ignore token.Pos
	ignoreUntilNextGroup := func(c *ast.Comment) {
		ignore = c.Slash + token.Pos(len(c.Text)) + 3 // allow for newlines, tabs, etc..
	}
	for _, group := range f.Comments {
		for _, v := range group.List {
			if v.Slash > begin && v.Slash < end {
				if v.Slash < ignore {
					ignoreUntilNextGroup(v)
				}
				text := strings.TrimSpace(strings.TrimPrefix(v.Text, "//"))
				if text != "" {
					if buf.Len() == 0 && text[0] == '!' {
						// Marked as non-doc comment
						ignoreUntilNextGroup(v)
						continue
					}
					if buf.Len() > 0 {
						buf.WriteByte(' ')
					}
					buf.WriteString(text)
				}
			}
		}
	}
	return buf.String()
}
开发者ID:rainycape,项目名称:gondola,代码行数:29,代码来源:make_reference.go

示例12: BeforeComments

// BeforeComments rewinds start past any blank lines or line comments
// and return the result. It does not rewind past leading blank lines:
// the returned position, if changed, is always the start of a non-blank line.
func (b *EditBuffer) BeforeComments(start token.Pos) token.Pos {
	i := b.tx(start)
	// Back up to newline.
	for i > 0 && (b.text[i-1] == ' ' || b.text[i-1] == '\t') {
		i--
	}
	if i > 0 && b.text[i-1] != '\n' {
		return start
	}

	// Go backward by lines.
	lastNonBlank := i
	for i > 0 {
		j := i - 1
		for j > 0 && b.text[j-1] != '\n' {
			j--
		}
		trim := strings.TrimSpace(b.text[j:i])
		if len(trim) > 0 && !strings.HasPrefix(trim, "//") {
			break
		}
		if len(trim) > 0 {
			lastNonBlank = j
		}
		i = j
	}
	return start - token.Pos(b.tx(start)-lastNonBlank)
}
开发者ID:niltonkummer,项目名称:grind,代码行数:31,代码来源:edit.go

示例13: parseBasicLit

func (p *parser) parseBasicLit(n *parse.Node) *ast.BasicLit {
	return &ast.BasicLit{
		ValuePos: token.Pos(n.Pos()),
		Kind:     token.Token(n.ID()),
		Value:    string(n.Value()),
	}
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:parser.go

示例14: getImports

func getImports(node *parser.CallNode) ast.Decl {
	if len(node.Args) < 2 {
		return nil
	}

	imports := node.Args[1:]
	specs := make([]ast.Spec, len(imports))

	for i, imp := range imports {
		if t := imp.Type(); t == parser.NodeVector {
			specs[i] = makeImportSpecFromVector(imp.(*parser.VectorNode))
		} else if t == parser.NodeString {
			importPath := imp.(*parser.StringNode).Value
			if importPath[1] == '/' {
				importPath = "\"" + standardLibrary + importPath[1:]
			}
			path := makeBasicLit(token.STRING, importPath)
			specs[i] = makeImportSpec(path, nil)
		} else {
			panic("invalid import!")
		}
	}

	decl := makeGeneralDecl(token.IMPORT, specs)
	decl.Lparen = token.Pos(1) // Need this so we can have multiple imports
	return decl
}
开发者ID:8l,项目名称:gsp,代码行数:27,代码来源:imports.go

示例15: parseForStmt

func (p *parser) parseForStmt(n *parse.Node) (r ast.Stmt) {
	p.openScope()
	forPos := token.Pos(n.Child(0).Pos())
	n = n.Child(1)
	if n.Is(block) {
		return &ast.ForStmt{
			For:  forPos,
			Body: p.parseBlock(n, p.topScope),
		}
	}
	option := n.Child(0).Child(0)
	body := p.parseBlock(n.Child(1), p.topScope)
	switch option.Rule() {
	case condition:
		fmt.Println(option)
	case forClause:
		fmt.Println(option)
	case rangeClause:
		forStmt := p.parseRangeStmt(option)
		forStmt.For, forStmt.Body = forPos, body
		r = forStmt
	}
	p.closeScope()
	return
}
开发者ID:h12w,项目名称:gombi,代码行数:25,代码来源:parser.go


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