Documentation ¶
Overview ¶
Package visitor contains walker.visitor implementations
Package visitor contains walker.visitor implementations
Index ¶
- type Dumper
- type Namespace
- type NamespaceResolver
- func (nsr *NamespaceResolver) AddAlias(useType string, nn node.Node, prefix []node.Node)
- func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string)
- func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool
- func (nsr *NamespaceResolver) GetChildrenVisitor(key string) walker.Visitor
- func (nsr *NamespaceResolver) LeaveNode(w walker.Walkable)
- func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string)
- func (nsr *NamespaceResolver) ResolveType(n node.Node)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Dumper ¶
type Dumper struct { Writer io.Writer Indent string Comments parser.Comments Positions parser.Positions NsResolver *NamespaceResolver }
Dumper writes ast hierarchy to an io.Writer Also prints comments and positions attached to nodes
Example ¶
package main import ( "bytes" "os" "github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/visitor" ) func main() { src := `<?php namespace Foo { class Bar { public function FunctionName(Type $var = null) { // some comment $var; } } }` php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser.Parse() nodes := php7parser.GetRootNode() nsResolver := visitor.NewNamespaceResolver() nodes.Walk(nsResolver) dumper := visitor.Dumper{ Writer: os.Stdout, Indent: "| ", Comments: php7parser.GetComments(), Positions: php7parser.GetPositions(), NsResolver: nsResolver, } nodes.Walk(dumper) }
Output: | [*node.Root] | "Position": Pos{Line: 3-11 Pos: 10-143}; | "Stmts": | [*stmt.Namespace] | "Position": Pos{Line: 3-11 Pos: 10-143}; | "NamespaceName": | [*name.Name] | "Position": Pos{Line: 3-3 Pos: 20-22}; | "Parts": | [*name.NamePart] | "Position": Pos{Line: 3-3 Pos: 20-22}; | "Value": Foo; | "Stmts": | [*stmt.Class] | "Position": Pos{Line: 4-10 Pos: 29-139}; | "NamespacedName": Foo\Bar; | "PhpDocComment": ; | "ClassName": | [*node.Identifier] | "Position": Pos{Line: 4-4 Pos: 35-37}; | "Value": Bar; | "Stmts": | [*stmt.ClassMethod] | "Position": Pos{Line: 5-9 Pos: 45-134}; | "ReturnsRef": false; | "PhpDocComment": ; | "MethodName": | [*node.Identifier] | "Position": Pos{Line: 5-5 Pos: 61-72}; | "Value": FunctionName; | "Modifiers": | [*node.Identifier] | "Position": Pos{Line: 5-5 Pos: 45-50}; | "Value": public; | "Params": | [*node.Parameter] | "Position": Pos{Line: 5-5 Pos: 74-89}; | "ByRef": false; | "Variadic": false; | "VariableType": | [*name.Name] | "Position": Pos{Line: 5-5 Pos: 74-77}; | "NamespacedName": Foo\Type; | "Parts": | [*name.NamePart] | "Position": Pos{Line: 5-5 Pos: 74-77}; | "Value": Type; | "Variable": | [*expr.Variable] | "Position": Pos{Line: 5-5 Pos: 79-82}; | "VarName": | [*node.Identifier] | "Position": Pos{Line: 5-5 Pos: 79-82}; | "Value": var; | "DefaultValue": | [*expr.ConstFetch] | "Position": Pos{Line: 5-5 Pos: 86-89}; | "Constant": | [*name.Name] | "Position": Pos{Line: 5-5 Pos: 86-89}; | "NamespacedName": Foo\null; | "Parts": | [*name.NamePart] | "Position": Pos{Line: 5-5 Pos: 86-89}; | "Value": null; | "Stmt": | [*stmt.StmtList] | "Position": Pos{Line: 6-9 Pos: 96-134}; | "Stmts": | [*stmt.Expression] | "Position": Pos{Line: 8-8 Pos: 124-128}; | "Expr": | [*expr.Variable] | "Position": Pos{Line: 8-8 Pos: 124-127}; | "Comments": | "// some comment\n" before "VariableToken" | "VarName": | [*node.Identifier] | "Position": Pos{Line: 8-8 Pos: 124-127}; | "Value": var;
func (Dumper) GetChildrenVisitor ¶
GetChildrenVisitor is invoked at every node parameter that contains children nodes
type Namespace ¶ added in v0.3.0
Namespace context
func NewNamespace ¶ added in v0.3.0
NewNamespace constructor
func (*Namespace) ResolveAlias ¶ added in v0.3.0
ResolveAlias returns alias or error if not found
type NamespaceResolver ¶ added in v0.3.0
NamespaceResolver visitor
func NewNamespaceResolver ¶ added in v0.3.0
func NewNamespaceResolver() *NamespaceResolver
NewNamespaceResolver NamespaceResolver type constructor
func (*NamespaceResolver) AddNamespacedName ¶ added in v0.3.0
func (nsr *NamespaceResolver) AddNamespacedName(nn node.Node, nodeName string)
AddNamespacedName adds namespaced name by node
func (*NamespaceResolver) EnterNode ¶ added in v0.3.0
func (nsr *NamespaceResolver) EnterNode(w walker.Walkable) bool
EnterNode is invoked at every node in heirerchy
func (*NamespaceResolver) GetChildrenVisitor ¶ added in v0.3.0
func (nsr *NamespaceResolver) GetChildrenVisitor(key string) walker.Visitor
GetChildrenVisitor is invoked at every node parameter that contains children nodes
func (*NamespaceResolver) LeaveNode ¶ added in v0.3.0
func (nsr *NamespaceResolver) LeaveNode(w walker.Walkable)
LeaveNode is invoked after node process
func (*NamespaceResolver) ResolveName ¶ added in v0.3.0
func (nsr *NamespaceResolver) ResolveName(nameNode node.Node, aliasType string)
ResolveName adds a resolved fully qualified name by node
func (*NamespaceResolver) ResolveType ¶ added in v0.3.0
func (nsr *NamespaceResolver) ResolveType(n node.Node)
ResolveType adds a resolved fully qualified type name