本文整理汇总了Golang中go/token.Pos函数的典型用法代码示例。如果您正苦于以下问题:Golang Pos函数的具体用法?Golang Pos怎么用?Golang Pos使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Pos函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: makeCallExpr
func makeCallExpr(name string, params *st.SymbolTable, pointerSymbols map[st.Symbol]int, pos token.Pos, recvSym *st.VariableSymbol, pack *st.Package, filename string) (*ast.CallExpr, int) {
var Fun ast.Expr
if recvSym != nil {
x := ast.NewIdent(recvSym.Name())
x.NamePos = pos
Fun = &ast.SelectorExpr{x, ast.NewIdent(name)}
} else {
x := ast.NewIdent(name)
x.NamePos = pos
Fun = x
}
l, _ := utils.GetNodeLength(Fun)
l += 2
args, i := make([]ast.Expr, params.Count()), 0
params.ForEachNoLock(func(sym st.Symbol) {
args[i] = sym.ToAstExpr(pack, filename)
if depth, ok := pointerSymbols[sym]; ok {
for depth > 0 {
args[i] = &ast.UnaryExpr{token.NoPos, token.AND, args[i]}
depth--
}
}
ll, _ := utils.GetNodeLength(args[i])
l += ll + 2
i++
})
l -= 2
return &ast.CallExpr{Fun, token.NoPos, args, token.NoPos, pos + token.Pos(l-1)}, l
}
开发者ID:vpavkin,项目名称:GoRefactor,代码行数:30,代码来源:extractMethod.go
示例17: parseStructType
func (p *parser) parseStructType(n *parse.Node) ast.Expr {
struct_ := n.Child(0)
return &ast.StructType{
Struct: token.Pos(struct_.Pos()),
// TODO: Fields
}
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:parser.go
示例18: statementBoundary
// statementBoundary finds the location in s that terminates the current basic
// block in the source.
func (f *File) statementBoundary(s ast.Stmt) token.Pos {
// Control flow statements are easy.
switch s := s.(type) {
case *ast.BlockStmt:
// Treat blocks like basic blocks to avoid overlapping counters.
return s.Lbrace
case *ast.IfStmt:
return s.Body.Lbrace
case *ast.ForStmt:
return s.Body.Lbrace
case *ast.LabeledStmt:
return f.statementBoundary(s.Stmt)
case *ast.RangeStmt:
return s.Body.Lbrace
case *ast.SwitchStmt:
return s.Body.Lbrace
case *ast.SelectStmt:
return s.Body.Lbrace
case *ast.TypeSwitchStmt:
return s.Body.Lbrace
}
// If not a control flow statement, it is a declaration, expression, call, etc. and it may have a function literal.
// If it does, that's tricky because we want to exclude the body of the function from this block.
// Draw a line at the start of the body of the first function literal we find.
// TODO: what if there's more than one? Probably doesn't matter much.
var literal funcLitFinder
ast.Walk(&literal, s)
if literal.found() {
return token.Pos(literal)
}
return s.End()
}
开发者ID:nagyistge,项目名称:hm-workspace,代码行数:34,代码来源:cover.go
示例19: parseKeyValue
func (p *parser) parseKeyValue(n *parse.Node) *ast.KeyValueExpr {
return &ast.KeyValueExpr{
Key: p.parseExpr(n.Child(0)),
Colon: token.Pos(n.Child(1).Pos()),
Value: p.parseValue(n.Child(2)),
}
}
开发者ID:h12w,项目名称:gombi,代码行数:7,代码来源:parser.go
示例20: LookupImport
func (w *PkgWalker) LookupImport(pkg *types.Package, pkgInfo *types.Info, cursor *FileCursor, is *ast.ImportSpec) {
fpath, err := strconv.Unquote(is.Path.Value)
if err != nil {
return
}
fbase := fpath
pos := strings.LastIndexAny(fpath, "./-\\")
if pos != -1 {
fbase = fpath[pos+1:]
}
fid := fpath + "." + fbase
//kind := ObjPkgName
//fmt.Println(kind, true)
if typeFindDef {
fmt.Println(w.fset.Position(is.Pos()))
}
if typeFindInfo {
fmt.Println("package", fpath)
}
if !typeFindUse {
return
}
var usages []int
for id, obj := range pkgInfo.Uses {
if obj != nil && obj.Id() == fid { //!= nil && cursorObj.Pos() == obj.Pos() {
usages = append(usages, int(id.Pos()))
}
}
(sort.IntSlice(usages)).Sort()
for _, pos := range usages {
fmt.Println(w.fset.Position(token.Pos(pos)))
}
}
开发者ID:RavenZZ,项目名称:liteide,代码行数:34,代码来源:type.go
注:本文中的go/token.Pos函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论