Exemple #1
0
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
}
Exemple #2
0
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
}
Exemple #3
0
func (p *parser) parseValueSpec(n *parse.Node) *ast.ValueSpec {
	n = n.Child(0)
	spec := ast.ValueSpec{}
	if n.Is(identifierList) {
		spec.Names = p.parseIdentList(n)
	} else {
		spec.Names = p.parseIdentList(n.Child(0))
		if n.Child(1).Is(type_) {
			spec.Type = p.parseType(n.Child(1))
		}
		spec.Values = p.parseExprList(n.LastChild())
	}
	return &spec
}
Exemple #4
0
func (p *parser) parseInterfaceType(n *parse.Node) ast.Expr {
	keywordPos := token.Pos(n.Child(0).Pos())
	n = n.Child(1)
	specs := ast.FieldList{
		Opening: token.Pos(n.Child(0).Pos()),
		Closing: token.Pos(n.LastChild().Pos()),
	}
	if n.ChildCount() > 2 {
		eachListItem(methodSpec, n.Child(1), func(item *parse.Node) {
			specs.List = append(specs.List, p.parseMethodSpec(item))
		})
	}
	return &ast.InterfaceType{
		Interface: keywordPos,
		Methods:   &specs,
	}
}
Exemple #5
0
func (p *parser) parseImportDecl(n *parse.Node) (decl *ast.GenDecl, specs []*ast.ImportSpec) {
	decl = &ast.GenDecl{
		TokPos: token.Pos(n.Child(0).Pos()),
		Tok:    token.IMPORT,
	}
	n = n.Child(1)
	if n.Is(importSpec) {
		spec := p.parseImportSpec(n)
		specs = append(specs, spec)
		decl.Specs = append(decl.Specs, spec)
		return
	}
	decl.Lparen = token.Pos(n.Child(0).Pos())
	decl.Rparen = token.Pos(n.LastChild().Pos())
	if n.ChildCount() == 3 {
		eachListItem(importSpec, n.Child(1), func(item *parse.Node) {
			spec := p.parseImportSpec(item)
			specs = append(specs, spec)
			decl.Specs = append(decl.Specs, spec)
		})
	}
	return
}