Documentation
¶
Overview ¶
Example (ComplexAST) ¶
Example_complexAST 演示构建复杂AST结构
package main
import (
"fmt"
"github.com/wudi/php-parser/ast"
"github.com/wudi/php-parser/lexer"
)
func main() {
pos := lexer.Position{Line: 1, Column: 1, Offset: 0}
builder := ast.NewASTBuilder()
// 构建: if ($x > 0) { echo "positive"; } else { echo "non-positive"; }
// 条件: $x > 0
x := builder.CreateVar(pos, "$x")
zero := builder.CreateZval(pos, 0)
condition := builder.CreateBinaryOp(pos, x, zero, ">")
// then分支: echo "positive";
positive := builder.CreateZval(pos, "positive")
echoPositive := builder.CreateEcho(pos, []ast.Node{positive})
// else分支: echo "non-positive";
nonPositive := builder.CreateZval(pos, "non-positive")
echoNonPositive := builder.CreateEcho(pos, []ast.Node{nonPositive})
// if语句
ifStmt := builder.CreateIf(pos, condition,
[]ast.Node{echoPositive},
[]ast.Node{echoNonPositive})
// 统计节点数量
nodeCount := 0
ast.Walk(ast.VisitorFunc(func(node ast.Node) bool {
nodeCount++
return true
}), ifStmt)
fmt.Printf("Total nodes: %d\n", nodeCount)
fmt.Printf("AST Kind: %s\n", ifStmt.GetKind().String())
// 找到所有echo语句
echoNodes := ast.FindAllFunc(ifStmt, func(node ast.Node) bool {
return node.GetKind() == ast.ASTEcho
})
fmt.Printf("Echo statements: %d\n", len(echoNodes))
}
Output: Total nodes: 10 AST Kind: IF Echo statements: 2
Example (JsonSerialization) ¶
Example_jsonSerialization 演示JSON序列化
package main
import (
"fmt"
"log"
"github.com/wudi/php-parser/ast"
"github.com/wudi/php-parser/lexer"
)
func main() {
pos := lexer.Position{Line: 1, Column: 1, Offset: 0}
variable := ast.NewVariable(pos, "$test")
// 序列化为JSON
jsonData, err := variable.ToJSON()
if err != nil {
log.Fatal(err)
}
fmt.Printf("JSON contains kind: %t\n",
string(jsonData) != "" && variable.GetKind() == ast.ASTVar)
fmt.Printf("JSON contains name: %t\n",
string(jsonData) != "" && variable.Name == "$test")
}
Output: JSON contains kind: true JSON contains name: true
Index ¶
- func Count(node Node, filter Filter) int
- func CountFunc(node Node, fn func(Node) bool) int
- func Inspect(node Node, inspector Inspector)
- func InspectFunc(node Node, fn func(Node) bool)
- func Walk(visitor Visitor, node Node)
- func WalkFunc(node Node, fn func(Node) bool)
- type ASTBuilder
- func (b *ASTBuilder) CreateArray(pos lexer.Position, elements []Node) Node
- func (b *ASTBuilder) CreateAssign(pos lexer.Position, left, right Node) Node
- func (b *ASTBuilder) CreateBinaryOp(pos lexer.Position, left, right Node, operator string) Node
- func (b *ASTBuilder) CreateBlock(pos lexer.Position, stmts []Node) Node
- func (b *ASTBuilder) CreateBreak(pos lexer.Position) Node
- func (b *ASTBuilder) CreateCall(pos lexer.Position, callee Node, args []Node) Node
- func (b *ASTBuilder) CreateConst(pos lexer.Position, name string) Node
- func (b *ASTBuilder) CreateContinue(pos lexer.Position) Node
- func (b *ASTBuilder) CreateEcho(pos lexer.Position, args []Node) Node
- func (b *ASTBuilder) CreateExprList(pos lexer.Position, exprs []Node) Node
- func (b *ASTBuilder) CreateExpressionStatement(pos lexer.Position, expr Node) Node
- func (b *ASTBuilder) CreateFor(pos lexer.Position, init, test, update Node, body []Node) Node
- func (b *ASTBuilder) CreateFuncDecl(pos lexer.Position, name Node, params []*ParameterNode, body []Node) Node
- func (b *ASTBuilder) CreateIf(pos lexer.Position, test Node, consequent []Node, alternate []Node) Node
- func (b *ASTBuilder) CreateReturn(pos lexer.Position, arg Node) Node
- func (b *ASTBuilder) CreateStmtList(pos lexer.Position, stmts []Node) Node
- func (b *ASTBuilder) CreateUnaryOp(pos lexer.Position, operand Node, operator string, prefix bool) Node
- func (b *ASTBuilder) CreateVar(pos lexer.Position, name string) Node
- func (b *ASTBuilder) CreateWhile(pos lexer.Position, test Node, body []Node) Node
- func (b *ASTBuilder) CreateZval(pos lexer.Position, value interface{}) Node
- type ASTKind
- type AlternativeForStatement
- type AlternativeForeachStatement
- type AlternativeIfStatement
- type AlternativeWhileStatement
- type AnonymousClass
- type AnonymousFunctionExpression
- type ArgumentList
- type ArrayAccessExpression
- type ArrayElementExpression
- type ArrayExpression
- type ArrowFunctionExpression
- type AssignmentExpression
- type Attribute
- type AttributeGroup
- type AttributeList
- type BaseNode
- func (b *BaseNode) Accept(visitor Visitor)
- func (b *BaseNode) GetAttributes() map[string]interface{}
- func (b *BaseNode) GetChildren() []Node
- func (b *BaseNode) GetKind() ASTKind
- func (b *BaseNode) GetLineNo() uint32
- func (b *BaseNode) GetPosition() lexer.Position
- func (b *BaseNode) String() string
- func (b *BaseNode) ToJSON() ([]byte, error)
- type BinaryExpression
- type BlockStatement
- type BooleanLiteral
- type BreakStatement
- type CallExpression
- type CaseExpression
- type CastExpression
- type CatchClause
- type ClassConstantAccessExpression
- type ClassConstantDeclaration
- type ClassExpression
- type CloneExpression
- type CloseTagExpression
- type CoalesceExpression
- type CommaExpression
- type ConstExpression
- type ConstantDeclarator
- type ContinueStatement
- type DeclareStatement
- type DoWhileStatement
- type DocBlockComment
- type EchoStatement
- type ElseIfClause
- type EmptyExpression
- type EnumCase
- type EnumDeclaration
- type ErrorSuppressionExpression
- type EvalExpression
- type ExitExpression
- type Expression
- type ExpressionStatement
- type Filter
- type FilterFunc
- type FirstClassCallable
- type ForStatement
- type ForeachStatement
- type FunctionDeclaration
- type GlobalStatement
- type GotoStatement
- type HaltCompilerStatement
- type HookedPropertyDeclaration
- type Identifier
- type IdentifierNode
- type IfStatement
- type IncludeOrEvalExpression
- type Inspector
- type InspectorFunc
- type InstanceofExpression
- type InterfaceDeclaration
- type InterfaceMethod
- type InterpolatedStringExpression
- type IssetExpression
- type LabelStatement
- type ListExpression
- type MagicConstantExpression
- type MatchArm
- type MatchExpression
- type MethodCallExpression
- type NamedArgument
- type NamespaceExpression
- type NamespaceNameExpression
- type NamespaceStatement
- type NewExpression
- type Node
- func FindAll(node Node, filter Filter) []Node
- func FindAllFunc(node Node, fn func(Node) bool) []Node
- func FindFirst(node Node, filter Filter) Node
- func FindFirstFunc(node Node, fn func(Node) bool) Node
- func Transform(node Node, transformer Transformer) Node
- func TransformFunc(node Node, fn func(Node) Node) Node
- type NullLiteral
- type NullsafeMethodCallExpression
- type NullsafePropertyAccessExpression
- type NumberLiteral
- type Parameter
- type ParameterList
- type ParameterNode
- type PrintExpression
- type PrintStatement
- type Program
- type PropertyAccessExpression
- type PropertyDeclaration
- type PropertyHook
- type ReturnStatement
- type ShellExecExpression
- type SpreadExpression
- type Statement
- type StaticAccessExpression
- type StaticPropertyAccessExpression
- type StaticStatement
- type StaticVariable
- type StringLiteral
- type SwitchCase
- type SwitchStatement
- type TernaryExpression
- type ThrowExpression
- type ThrowStatement
- type TraitAdaptation
- type TraitAliasStatement
- type TraitDeclaration
- type TraitMethodReference
- type TraitPrecedenceStatement
- type Transformer
- type TransformerFunc
- type TryStatement
- type TypeHint
- type UnaryExpression
- type UnsetStatement
- type UseClause
- type UseStatement
- type UseTraitStatement
- type Variable
- type VisibilityModifierExpression
- type Visitor
- type VisitorFunc
- type WhileStatement
- type YieldExpression
- type YieldFromExpression
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ASTBuilder ¶
type ASTBuilder struct {
}
ASTBuilder AST构建器,用于创建符合PHP官方结构的AST节点
Example ¶
ExampleASTBuilder 演示如何使用AST构建器
package main
import (
"fmt"
"github.com/wudi/php-parser/ast"
"github.com/wudi/php-parser/lexer"
)
func main() {
pos := lexer.Position{Line: 1, Column: 1, Offset: 0}
builder := ast.NewASTBuilder()
// 构建 $name = "John";
nameVar := builder.CreateVar(pos, "$name")
john := builder.CreateZval(pos, "John")
assignment := builder.CreateAssign(pos, nameVar, john)
assignStmt := builder.CreateExpressionStatement(pos, assignment)
// 构建 echo $name;
echoVar := builder.CreateVar(pos, "$name")
echoStmt := builder.CreateEcho(pos, []ast.Node{echoVar})
// 构建程序
program := builder.CreateStmtList(pos, []ast.Node{assignStmt, echoStmt})
fmt.Printf("AST Kind: %s\n", program.GetKind().String())
fmt.Printf("Children: %d\n", len(program.GetChildren()))
}
Output: AST Kind: STMT_LIST Children: 2
func (*ASTBuilder) CreateArray ¶
func (b *ASTBuilder) CreateArray(pos lexer.Position, elements []Node) Node
CreateArray 创建数组节点
func (*ASTBuilder) CreateAssign ¶
func (b *ASTBuilder) CreateAssign(pos lexer.Position, left, right Node) Node
CreateAssign 创建赋值节点
func (*ASTBuilder) CreateBinaryOp ¶
CreateBinaryOp 创建二元操作节点
func (*ASTBuilder) CreateBlock ¶
func (b *ASTBuilder) CreateBlock(pos lexer.Position, stmts []Node) Node
CreateBlock 创建代码块节点
func (*ASTBuilder) CreateBreak ¶
func (b *ASTBuilder) CreateBreak(pos lexer.Position) Node
CreateBreak 创建break语句节点
func (*ASTBuilder) CreateCall ¶
CreateCall 创建函数调用节点
func (*ASTBuilder) CreateConst ¶
func (b *ASTBuilder) CreateConst(pos lexer.Position, name string) Node
CreateConst 创建常量节点
func (*ASTBuilder) CreateContinue ¶
func (b *ASTBuilder) CreateContinue(pos lexer.Position) Node
CreateContinue 创建continue语句节点
func (*ASTBuilder) CreateEcho ¶
func (b *ASTBuilder) CreateEcho(pos lexer.Position, args []Node) Node
CreateEcho 创建echo语句节点
func (*ASTBuilder) CreateExprList ¶
func (b *ASTBuilder) CreateExprList(pos lexer.Position, exprs []Node) Node
CreateExprList 创建表达式列表节点
func (*ASTBuilder) CreateExpressionStatement ¶
func (b *ASTBuilder) CreateExpressionStatement(pos lexer.Position, expr Node) Node
CreateExpressionStatement 创建表达式语句节点
func (*ASTBuilder) CreateFuncDecl ¶
func (b *ASTBuilder) CreateFuncDecl(pos lexer.Position, name Node, params []*ParameterNode, body []Node) Node
CreateFuncDecl 创建函数声明节点
func (*ASTBuilder) CreateIf ¶
func (b *ASTBuilder) CreateIf(pos lexer.Position, test Node, consequent []Node, alternate []Node) Node
CreateIf 创建if语句节点
func (*ASTBuilder) CreateReturn ¶
func (b *ASTBuilder) CreateReturn(pos lexer.Position, arg Node) Node
CreateReturn 创建return语句节点
func (*ASTBuilder) CreateStmtList ¶
func (b *ASTBuilder) CreateStmtList(pos lexer.Position, stmts []Node) Node
CreateStmtList 创建语句列表节点
func (*ASTBuilder) CreateUnaryOp ¶
func (b *ASTBuilder) CreateUnaryOp(pos lexer.Position, operand Node, operator string, prefix bool) Node
CreateUnaryOp 创建一元操作节点
func (*ASTBuilder) CreateVar ¶
func (b *ASTBuilder) CreateVar(pos lexer.Position, name string) Node
CreateVar 创建变量节点
func (*ASTBuilder) CreateWhile ¶
CreateWhile 创建while语句节点
func (*ASTBuilder) CreateZval ¶
func (b *ASTBuilder) CreateZval(pos lexer.Position, value interface{}) Node
CreateZval 创建zval节点(用于字面值)
type ASTKind ¶
type ASTKind uint16
ASTKind 定义AST节点类型,严格遵循PHP官方zend_ast.h定义
Example ¶
ExampleASTKind 演示AST Kind的使用
package main
import (
"fmt"
"github.com/wudi/php-parser/ast"
)
func main() {
// 检查Kind属性
fmt.Printf("ASTZval is special: %t\n", ast.ASTZval.IsSpecial())
fmt.Printf("ASTArray is list: %t\n", ast.ASTArray.IsList())
fmt.Printf("ASTFuncDecl is declaration: %t\n", ast.ASTFuncDecl.IsDecl())
fmt.Printf("ASTBinaryOp has %d children\n", ast.ASTBinaryOp.GetNumChildren())
// Kind字符串表示
fmt.Printf("Kind names: %s, %s, %s\n",
ast.ASTVar.String(),
ast.ASTBinaryOp.String(),
ast.ASTEcho.String())
}
Output: ASTZval is special: true ASTArray is list: true ASTFuncDecl is declaration: true ASTBinaryOp has 2 children Kind names: VAR, BINARY_OP, ECHO
const ( // 特殊节点 - special nodes (bit 6 set) ASTZval ASTKind = 64 // 1 << 6 = ZEND_AST_ZVAL ASTConstant ASTKind = 65 // ZEND_AST_CONSTANT ASTZNode ASTKind = 66 // ZEND_AST_ZNODE // 声明节点 - declaration nodes ASTFuncDecl ASTKind = 67 // ZEND_AST_FUNC_DECL ASTClosure ASTKind = 68 // ZEND_AST_CLOSURE ASTMethod ASTKind = 69 // ZEND_AST_METHOD ASTClass ASTKind = 70 // ZEND_AST_CLASS (also used for interface, trait, enum) ASTArrowFunc ASTKind = 71 // ZEND_AST_ARROW_FUNC ASTPropertyHook ASTKind = 72 // ZEND_AST_PROPERTY_HOOK // 列表节点 - list nodes (bit 7 set) ASTArgList ASTKind = 128 // 1 << 7 = ZEND_AST_ARG_LIST ASTArray ASTKind = 129 // ZEND_AST_ARRAY ASTEncapsList ASTKind = 130 // ZEND_AST_ENCAPS_LIST ASTExprList ASTKind = 131 // ZEND_AST_EXPR_LIST ASTStmtList ASTKind = 132 // ZEND_AST_STMT_LIST ASTIf ASTKind = 133 // ZEND_AST_IF ASTSwitchList ASTKind = 134 // ZEND_AST_SWITCH_LIST ASTCatchList ASTKind = 135 // ZEND_AST_CATCH_LIST ASTParamList ASTKind = 136 // ZEND_AST_PARAM_LIST ASTClosureUses ASTKind = 137 // ZEND_AST_CLOSURE_USES ASTPropDecl ASTKind = 138 // ZEND_AST_PROP_DECL ASTConstDecl ASTKind = 139 // ZEND_AST_CONST_DECL ASTClassConstDecl ASTKind = 140 // ZEND_AST_CLASS_CONST_DECL ASTNameList ASTKind = 141 // ZEND_AST_NAME_LIST ASTTraitAdaptations ASTKind = 142 // ZEND_AST_TRAIT_ADAPTATIONS ASTUse ASTKind = 143 // ZEND_AST_USE ASTTypeUnion ASTKind = 144 // ZEND_AST_TYPE_UNION ASTTypeIntersection ASTKind = 145 // ZEND_AST_TYPE_INTERSECTION ASTAttributeList ASTKind = 146 // ZEND_AST_ATTRIBUTE_LIST ASTAttributeGroup ASTKind = 147 // ZEND_AST_ATTRIBUTE_GROUP ASTMatchArmList ASTKind = 148 // ZEND_AST_MATCH_ARM_LIST ASTModifierList ASTKind = 149 // ZEND_AST_MODIFIER_LIST // 0子节点 - 0 child nodes (bits 8-15 = 0) ASTMagicConst ASTKind = 0 // ZEND_AST_MAGIC_CONST ASTType ASTKind = 1 // ZEND_AST_TYPE ASTConstantClass ASTKind = 2 // ZEND_AST_CONSTANT_CLASS ASTCallableConvert ASTKind = 3 // ZEND_AST_CALLABLE_CONVERT // 1子节点 - 1 child node (bits 8-15 = 1) ASTVar ASTKind = 256 // 1 << 8 = ZEND_AST_VAR ASTConst ASTKind = 257 // ZEND_AST_CONST ASTUnpack ASTKind = 258 // ZEND_AST_UNPACK ASTUnaryPlus ASTKind = 259 // ZEND_AST_UNARY_PLUS ASTUnaryMinus ASTKind = 260 // ZEND_AST_UNARY_MINUS ASTCast ASTKind = 261 // ZEND_AST_CAST ASTEmpty ASTKind = 262 // ZEND_AST_EMPTY ASTIsset ASTKind = 263 // ZEND_AST_ISSET ASTSilence ASTKind = 264 // ZEND_AST_SILENCE ASTShellExec ASTKind = 265 // ZEND_AST_SHELL_EXEC ASTClone ASTKind = 266 // ZEND_AST_CLONE ASTExit ASTKind = 267 // ZEND_AST_EXIT ASTPrint ASTKind = 268 // ZEND_AST_PRINT ASTIncludeOrEval ASTKind = 269 // ZEND_AST_INCLUDE_OR_EVAL ASTUnaryOp ASTKind = 270 // ZEND_AST_UNARY_OP ASTPreInc ASTKind = 271 // ZEND_AST_PRE_INC ASTPreDec ASTKind = 272 // ZEND_AST_PRE_DEC ASTPostInc ASTKind = 273 // ZEND_AST_POST_INC ASTPostDec ASTKind = 274 // ZEND_AST_POST_DEC ASTYieldFrom ASTKind = 275 // ZEND_AST_YIELD_FROM ASTClassName ASTKind = 276 // ZEND_AST_CLASS_NAME ASTGlobal ASTKind = 277 // ZEND_AST_GLOBAL ASTUnset ASTKind = 278 // ZEND_AST_UNSET ASTReturn ASTKind = 279 // ZEND_AST_RETURN ASTLabel ASTKind = 280 // ZEND_AST_LABEL ASTRef ASTKind = 281 // ZEND_AST_REF ASTHaltCompiler ASTKind = 282 // ZEND_AST_HALT_COMPILER ASTEcho ASTKind = 283 // ZEND_AST_ECHO ASTThrow ASTKind = 284 // ZEND_AST_THROW ASTGoto ASTKind = 285 // ZEND_AST_GOTO ASTBreak ASTKind = 286 // ZEND_AST_BREAK ASTContinue ASTKind = 287 // ZEND_AST_CONTINUE ASTPropertyHookShortBody ASTKind = 288 // ZEND_AST_PROPERTY_HOOK_SHORT_BODY // 2子节点 - 2 child nodes (bits 8-15 = 2) ASTDim ASTKind = 512 // 2 << 8 = ZEND_AST_DIM ASTProp ASTKind = 513 // ZEND_AST_PROP ASTNullsafeProp ASTKind = 514 // ZEND_AST_NULLSAFE_PROP ASTStaticProp ASTKind = 515 // ZEND_AST_STATIC_PROP ASTCall ASTKind = 516 // ZEND_AST_CALL ASTClassConst ASTKind = 517 // ZEND_AST_CLASS_CONST ASTAssign ASTKind = 518 // ZEND_AST_ASSIGN ASTAssignRef ASTKind = 519 // ZEND_AST_ASSIGN_REF ASTAssignOp ASTKind = 520 // ZEND_AST_ASSIGN_OP ASTBinaryOp ASTKind = 521 // ZEND_AST_BINARY_OP ASTGreater ASTKind = 522 // ZEND_AST_GREATER ASTGreaterEqual ASTKind = 523 // ZEND_AST_GREATER_EQUAL ASTAnd ASTKind = 524 // ZEND_AST_AND ASTOr ASTKind = 525 // ZEND_AST_OR ASTArrayElem ASTKind = 526 // ZEND_AST_ARRAY_ELEM ASTNew ASTKind = 527 // ZEND_AST_NEW ASTInstanceof ASTKind = 528 // ZEND_AST_INSTANCEOF ASTYield ASTKind = 529 // ZEND_AST_YIELD ASTCoalesce ASTKind = 530 // ZEND_AST_COALESCE ASTAssignCoalesce ASTKind = 531 // ZEND_AST_ASSIGN_COALESCE ASTStatic ASTKind = 532 // ZEND_AST_STATIC ASTWhile ASTKind = 533 // ZEND_AST_WHILE ASTDoWhile ASTKind = 534 // ZEND_AST_DO_WHILE ASTIfElem ASTKind = 535 // ZEND_AST_IF_ELEM ASTSwitch ASTKind = 536 // ZEND_AST_SWITCH ASTSwitchCase ASTKind = 537 // ZEND_AST_SWITCH_CASE ASTDeclare ASTKind = 538 // ZEND_AST_DECLARE ASTUseTrait ASTKind = 539 // ZEND_AST_USE_TRAIT ASTTraitPrecedence ASTKind = 540 // ZEND_AST_TRAIT_PRECEDENCE ASTMethodReference ASTKind = 541 // ZEND_AST_METHOD_REFERENCE ASTNamespace ASTKind = 542 // ZEND_AST_NAMESPACE ASTUseElem ASTKind = 543 // ZEND_AST_USE_ELEM ASTTraitAlias ASTKind = 544 // ZEND_AST_TRAIT_ALIAS ASTGroupUse ASTKind = 545 // ZEND_AST_GROUP_USE ASTAttribute ASTKind = 546 // ZEND_AST_ATTRIBUTE ASTMatch ASTKind = 547 // ZEND_AST_MATCH ASTMatchArm ASTKind = 548 // ZEND_AST_MATCH_ARM ASTNamedArg ASTKind = 549 // ZEND_AST_NAMED_ARG ASTParentPropertyHookCall ASTKind = 550 // ZEND_AST_PARENT_PROPERTY_HOOK_CALL // 3子节点 - 3 child nodes (bits 8-15 = 3) ASTMethodCall ASTKind = 768 // 3 << 8 = ZEND_AST_METHOD_CALL ASTNullsafeMethodCall ASTKind = 769 // ZEND_AST_NULLSAFE_METHOD_CALL ASTStaticCall ASTKind = 770 // ZEND_AST_STATIC_CALL ASTConditional ASTKind = 771 // ZEND_AST_CONDITIONAL ASTTry ASTKind = 772 // ZEND_AST_TRY ASTCatch ASTKind = 773 // ZEND_AST_CATCH ASTPropGroup ASTKind = 774 // ZEND_AST_PROP_GROUP ASTConstElem ASTKind = 775 // ZEND_AST_CONST_ELEM ASTClassConstGroup ASTKind = 776 // ZEND_AST_CLASS_CONST_GROUP ASTConstEnumInit ASTKind = 777 // ZEND_AST_CONST_ENUM_INIT // 4子节点 - 4 child nodes (bits 8-15 = 4) ASTFor ASTKind = 1024 // 4 << 8 = ZEND_AST_FOR ASTForeach ASTKind = 1025 // ZEND_AST_FOREACH ASTEnumCase ASTKind = 1026 // ZEND_AST_ENUM_CASE ASTPropElem ASTKind = 1027 // ZEND_AST_PROP_ELEM // 6子节点 - 6 child nodes (bits 8-15 = 6) ASTParam ASTKind = 1536 // 6 << 8 = ZEND_AST_PARAM )
func (ASTKind) GetNumChildren ¶
GetNumChildren 获取子节点数量(对于非特殊、非列表节点)
type AlternativeForStatement ¶
type AlternativeForStatement struct {
BaseNode
Init []Expression `json:"init,omitempty"`
Condition []Expression `json:"condition,omitempty"`
Update []Expression `json:"update,omitempty"`
Body []Statement `json:"body"`
}
AlternativeForStatement 表示替代语法的for语句 (for: ... endfor;)
func NewAlternativeForStatement ¶
func NewAlternativeForStatement(pos lexer.Position) *AlternativeForStatement
func (*AlternativeForStatement) Accept ¶
func (afs *AlternativeForStatement) Accept(visitor Visitor)
func (*AlternativeForStatement) GetChildren ¶
func (afs *AlternativeForStatement) GetChildren() []Node
func (*AlternativeForStatement) String ¶
func (afs *AlternativeForStatement) String() string
type AlternativeForeachStatement ¶
type AlternativeForeachStatement struct {
BaseNode
Iterable Expression `json:"iterable"`
Key Expression `json:"key,omitempty"`
Value Expression `json:"value"`
Body []Statement `json:"body"`
}
AlternativeForeachStatement 表示替代语法的foreach语句 (foreach: ... endforeach;)
func NewAlternativeForeachStatement ¶
func NewAlternativeForeachStatement(pos lexer.Position, iterable, value Expression) *AlternativeForeachStatement
func (*AlternativeForeachStatement) Accept ¶
func (afs *AlternativeForeachStatement) Accept(visitor Visitor)
func (*AlternativeForeachStatement) GetChildren ¶
func (afs *AlternativeForeachStatement) GetChildren() []Node
func (*AlternativeForeachStatement) String ¶
func (afs *AlternativeForeachStatement) String() string
type AlternativeIfStatement ¶
type AlternativeIfStatement struct {
BaseNode
Condition Expression `json:"condition"`
Then []Statement `json:"then"`
ElseIfs []*ElseIfClause `json:"elseIfs,omitempty"`
Else []Statement `json:"else,omitempty"`
}
AlternativeIfStatement 表示替代语法的if语句 (if: ... endif;)
func NewAlternativeIfStatement ¶
func NewAlternativeIfStatement(pos lexer.Position, condition Expression) *AlternativeIfStatement
func (*AlternativeIfStatement) Accept ¶
func (ais *AlternativeIfStatement) Accept(visitor Visitor)
func (*AlternativeIfStatement) GetChildren ¶
func (ais *AlternativeIfStatement) GetChildren() []Node
func (*AlternativeIfStatement) String ¶
func (ais *AlternativeIfStatement) String() string
type AlternativeWhileStatement ¶
type AlternativeWhileStatement struct {
BaseNode
Condition Expression `json:"condition"`
Body []Statement `json:"body"`
}
AlternativeWhileStatement 表示替代语法的while语句 (while: ... endwhile;)
func NewAlternativeWhileStatement ¶
func NewAlternativeWhileStatement(pos lexer.Position, condition Expression) *AlternativeWhileStatement
func (*AlternativeWhileStatement) Accept ¶
func (aws *AlternativeWhileStatement) Accept(visitor Visitor)
func (*AlternativeWhileStatement) GetChildren ¶
func (aws *AlternativeWhileStatement) GetChildren() []Node
func (*AlternativeWhileStatement) String ¶
func (aws *AlternativeWhileStatement) String() string
type AnonymousClass ¶
type AnonymousClass struct {
BaseNode
Attributes []*AttributeGroup `json:"attributes,omitempty"` // 类属性 #[Attr]
Modifiers []string `json:"modifiers,omitempty"` // 类修饰符 (final, abstract, readonly)
Arguments *ArgumentList `json:"arguments,omitempty"` // 构造函数参数
Extends Expression `json:"extends,omitempty"` // 继承的类
Implements []Expression `json:"implements,omitempty"` // 实现的接口
Body []Statement `json:"body"` // 类体
}
AnonymousClass 表示匿名类表达式
func NewAnonymousClass ¶
func NewAnonymousClass(pos lexer.Position, attributes []*AttributeGroup, modifiers []string, args []Expression, extends Expression, implements []Expression, body []Statement) *AnonymousClass
func (*AnonymousClass) GetChildren ¶
func (ac *AnonymousClass) GetChildren() []Node
GetChildren 返回子节点
func (*AnonymousClass) String ¶
func (ac *AnonymousClass) String() string
type AnonymousFunctionExpression ¶
type AnonymousFunctionExpression struct {
BaseNode
Parameters *ParameterList `json:"parameters,omitempty"`
Body []Statement `json:"body"`
UseClause []Expression `json:"useClause,omitempty"`
ByReference bool `json:"byReference,omitempty"` // function &() returns by reference
Static bool `json:"static,omitempty"` // static function
ReturnType *TypeHint `json:"returnType,omitempty"` // : returnType
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
AnonymousFunctionExpression 表示匿名函数表达式
func NewAnonymousFunctionExpression ¶
func NewAnonymousFunctionExpression(pos lexer.Position, parameters []*ParameterNode, body []Statement, useClause []Expression, byReference bool, static bool, returnType *TypeHint) *AnonymousFunctionExpression
func (*AnonymousFunctionExpression) Accept ¶
func (afe *AnonymousFunctionExpression) Accept(visitor Visitor)
func (*AnonymousFunctionExpression) GetChildren ¶
func (afe *AnonymousFunctionExpression) GetChildren() []Node
func (*AnonymousFunctionExpression) String ¶
func (afe *AnonymousFunctionExpression) String() string
type ArgumentList ¶
type ArgumentList struct {
BaseNode
Arguments []Expression `json:"arguments"`
}
ArgumentList represents a list of function/method call arguments
func NewArgumentList ¶
func NewArgumentList(pos lexer.Position, arguments []Expression) *ArgumentList
func (*ArgumentList) Accept ¶
func (al *ArgumentList) Accept(visitor Visitor)
func (*ArgumentList) GetChildren ¶
func (al *ArgumentList) GetChildren() []Node
func (*ArgumentList) String ¶
func (al *ArgumentList) String() string
type ArrayAccessExpression ¶
type ArrayAccessExpression struct {
BaseNode
Array Expression `json:"array"`
Index *Expression `json:"index,omitempty"` // nil for empty []
}
ArrayAccessExpression 表示数组访问表达式 []
func NewArrayAccessExpression ¶
func NewArrayAccessExpression(pos lexer.Position, array Expression, index *Expression) *ArrayAccessExpression
func (*ArrayAccessExpression) Accept ¶
func (aae *ArrayAccessExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*ArrayAccessExpression) GetChildren ¶
func (aae *ArrayAccessExpression) GetChildren() []Node
GetChildren 返回子节点
func (*ArrayAccessExpression) String ¶
func (aae *ArrayAccessExpression) String() string
type ArrayElementExpression ¶
type ArrayElementExpression struct {
BaseNode
Key Expression `json:"key"`
Value Expression `json:"value"`
}
ArrayElementExpression 表示数组元素表达式 (key => value)
func NewArrayElementExpression ¶
func NewArrayElementExpression(pos lexer.Position, key, value Expression) *ArrayElementExpression
func (*ArrayElementExpression) Accept ¶
func (aee *ArrayElementExpression) Accept(visitor Visitor)
func (*ArrayElementExpression) GetChildren ¶
func (aee *ArrayElementExpression) GetChildren() []Node
func (*ArrayElementExpression) String ¶
func (aee *ArrayElementExpression) String() string
type ArrayExpression ¶
type ArrayExpression struct {
BaseNode
Elements []Expression `json:"elements"`
}
ArrayExpression 数组表达式
func NewArrayExpression ¶
func NewArrayExpression(pos lexer.Position) *ArrayExpression
func (*ArrayExpression) GetChildren ¶
func (ae *ArrayExpression) GetChildren() []Node
GetChildren 返回子节点
func (*ArrayExpression) String ¶
func (ae *ArrayExpression) String() string
type ArrowFunctionExpression ¶
type ArrowFunctionExpression struct {
BaseNode
Parameters *ParameterList `json:"parameters,omitempty"`
ReturnType *TypeHint `json:"returnType,omitempty"`
Body Expression `json:"body"`
Static bool `json:"static,omitempty"`
ByReference bool `json:"byReference,omitempty"` // fn &() returns by reference
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
ArrowFunctionExpression 箭头函数表达式 (PHP 7.4+)
func NewArrowFunctionExpression ¶
func NewArrowFunctionExpression(pos lexer.Position, parameters []*ParameterNode, returnType *TypeHint, body Expression, static bool, byReference bool) *ArrowFunctionExpression
func (*ArrowFunctionExpression) Accept ¶
func (af *ArrowFunctionExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*ArrowFunctionExpression) GetChildren ¶
func (af *ArrowFunctionExpression) GetChildren() []Node
GetChildren 返回子节点
func (*ArrowFunctionExpression) String ¶
func (af *ArrowFunctionExpression) String() string
type AssignmentExpression ¶
type AssignmentExpression struct {
BaseNode
Left Expression `json:"left"`
Right Expression `json:"right"`
Operator string `json:"operator"`
}
AssignmentExpression 赋值表达式
func NewAssignmentExpression ¶
func NewAssignmentExpression(pos lexer.Position, left Expression, operator string, right Expression) *AssignmentExpression
func (*AssignmentExpression) Accept ¶
func (ae *AssignmentExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*AssignmentExpression) GetChildren ¶
func (ae *AssignmentExpression) GetChildren() []Node
GetChildren 返回子节点
func (*AssignmentExpression) String ¶
func (ae *AssignmentExpression) String() string
type Attribute ¶
type Attribute struct {
BaseNode
Name *IdentifierNode `json:"name"` // 属性名称
Arguments []Expression `json:"arguments"` // 属性参数
}
Attribute 表示PHP 8.0属性/注解 - #[AttributeName(arguments)]
func NewAttribute ¶
func NewAttribute(pos lexer.Position, name *IdentifierNode, arguments []Expression) *Attribute
func (*Attribute) GetChildren ¶
type AttributeGroup ¶
AttributeGroup 表示属性组 - #[Attr1, Attr2, ...]
func NewAttributeGroup ¶
func NewAttributeGroup(pos lexer.Position, attributes []*Attribute) *AttributeGroup
func (*AttributeGroup) Accept ¶
func (ag *AttributeGroup) Accept(visitor Visitor)
func (*AttributeGroup) GetChildren ¶
func (ag *AttributeGroup) GetChildren() []Node
func (*AttributeGroup) String ¶
func (ag *AttributeGroup) String() string
type AttributeList ¶
type AttributeList struct {
BaseNode
Groups []*AttributeGroup `json:"groups"` // 属性组列表
}
AttributeList 表示多个属性组的列表
func NewAttributeList ¶
func NewAttributeList(pos lexer.Position, groups []*AttributeGroup) *AttributeList
func (*AttributeList) Accept ¶
func (al *AttributeList) Accept(visitor Visitor)
func (*AttributeList) GetChildren ¶
func (al *AttributeList) GetChildren() []Node
func (*AttributeList) String ¶
func (al *AttributeList) String() string
type BaseNode ¶
type BaseNode struct {
Kind ASTKind `json:"kind"`
Position lexer.Position `json:"position"`
Attributes map[string]interface{} `json:"attributes,omitempty"`
LineNo uint32 `json:"lineno"`
}
BaseNode 基础节点,提供公共字段和方法
func (*BaseNode) GetAttributes ¶
GetAttributes 返回节点属性
func (*BaseNode) GetChildren ¶
GetChildren 返回子节点 - 默认实现,具体类型需要重写
type BinaryExpression ¶
type BinaryExpression struct {
BaseNode
Left Expression `json:"left"`
Right Expression `json:"right"`
Operator string `json:"operator"`
}
BinaryExpression 二元表达式
func NewBinaryExpression ¶
func NewBinaryExpression(pos lexer.Position, left Expression, operator string, right Expression) *BinaryExpression
func (*BinaryExpression) GetChildren ¶
func (be *BinaryExpression) GetChildren() []Node
GetChildren 返回子节点
func (*BinaryExpression) String ¶
func (be *BinaryExpression) String() string
type BlockStatement ¶
BlockStatement 块语句
func NewBlockStatement ¶
func NewBlockStatement(pos lexer.Position) *BlockStatement
func (*BlockStatement) GetChildren ¶
func (bs *BlockStatement) GetChildren() []Node
GetChildren 返回子节点
func (*BlockStatement) String ¶
func (bs *BlockStatement) String() string
type BooleanLiteral ¶
BooleanLiteral 布尔字面量
func NewBooleanLiteral ¶
func NewBooleanLiteral(pos lexer.Position, value bool) *BooleanLiteral
func (*BooleanLiteral) GetChildren ¶
func (bl *BooleanLiteral) GetChildren() []Node
GetChildren 返回子节点
func (*BooleanLiteral) String ¶
func (bl *BooleanLiteral) String() string
type BreakStatement ¶
type BreakStatement struct {
BaseNode
}
BreakStatement break语句
func NewBreakStatement ¶
func NewBreakStatement(pos lexer.Position) *BreakStatement
func (*BreakStatement) GetChildren ¶
func (bs *BreakStatement) GetChildren() []Node
GetChildren 返回子节点
func (*BreakStatement) String ¶
func (bs *BreakStatement) String() string
type CallExpression ¶
type CallExpression struct {
BaseNode
Callee Expression `json:"callee"`
Arguments *ArgumentList `json:"arguments,omitempty"`
}
CallExpression 函数调用表达式
func NewCallExpression ¶
func NewCallExpression(pos lexer.Position, callee Expression) *CallExpression
func (*CallExpression) GetChildren ¶
func (ce *CallExpression) GetChildren() []Node
GetChildren 返回子节点
func (*CallExpression) String ¶
func (ce *CallExpression) String() string
type CaseExpression ¶
type CaseExpression struct {
BaseNode
Test Expression `json:"test"` // nil for default case
}
CaseExpression 表示 switch 语句中的 case 表达式
func NewCaseExpression ¶
func NewCaseExpression(pos lexer.Position, test Expression) *CaseExpression
func (*CaseExpression) Accept ¶
func (ce *CaseExpression) Accept(visitor Visitor)
func (*CaseExpression) GetChildren ¶
func (ce *CaseExpression) GetChildren() []Node
func (*CaseExpression) String ¶
func (ce *CaseExpression) String() string
type CastExpression ¶
type CastExpression struct {
BaseNode
CastType string `json:"castType"`
Operand Expression `json:"operand"`
}
CastExpression 类型转换表达式节点
func NewCastExpression ¶
func NewCastExpression(pos lexer.Position, castType string, operand Expression) *CastExpression
NewCastExpression 创建类型转换表达式
func (*CastExpression) GetChildren ¶
func (ce *CastExpression) GetChildren() []Node
GetChildren 返回子节点
func (*CastExpression) String ¶
func (ce *CastExpression) String() string
type CatchClause ¶
type CatchClause struct {
BaseNode
Types []Expression `json:"types"` // Exception types
Parameter Expression `json:"parameter"` // Exception variable
Body []Statement `json:"body"`
}
func NewCatchClause ¶
func NewCatchClause(pos lexer.Position, parameter Expression) *CatchClause
func (*CatchClause) Accept ¶
func (c *CatchClause) Accept(visitor Visitor)
func (*CatchClause) GetChildren ¶
func (c *CatchClause) GetChildren() []Node
func (*CatchClause) String ¶
func (c *CatchClause) String() string
type ClassConstantAccessExpression ¶
type ClassConstantAccessExpression struct {
BaseNode
Class Expression `json:"class"` // 类名表达式
Constant Expression `json:"constant"` // 常量表达式
}
ClassConstantAccessExpression 表示类常量访问表达式 Class::CONSTANT 使用 ASTClassConst (517) 节点类型,符合PHP官方zend_ast.h定义
func NewClassConstantAccessExpression ¶
func NewClassConstantAccessExpression(pos lexer.Position, class, constant Expression) *ClassConstantAccessExpression
func (*ClassConstantAccessExpression) Accept ¶
func (ccae *ClassConstantAccessExpression) Accept(visitor Visitor)
func (*ClassConstantAccessExpression) GetChildren ¶
func (ccae *ClassConstantAccessExpression) GetChildren() []Node
func (*ClassConstantAccessExpression) String ¶
func (ccae *ClassConstantAccessExpression) String() string
type ClassConstantDeclaration ¶
type ClassConstantDeclaration struct {
BaseNode
Visibility string `json:"visibility"` // private, protected, public
Type *TypeHint `json:"type,omitempty"` // PHP 8.3+ typed constants support
Constants []ConstantDeclarator `json:"constants"` // 支持一行声明多个常量
IsFinal bool `json:"isFinal,omitempty"` // final const
IsAbstract bool `json:"isAbstract,omitempty"` // abstract const
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
ClassConstantDeclaration 类常量声明语句
func NewClassConstantDeclaration ¶
func NewClassConstantDeclaration(pos lexer.Position, visibility string, constType *TypeHint, constants []ConstantDeclarator, isFinal, isAbstract bool) *ClassConstantDeclaration
func (*ClassConstantDeclaration) Accept ¶
func (ccd *ClassConstantDeclaration) Accept(visitor Visitor)
func (*ClassConstantDeclaration) GetChildren ¶
func (ccd *ClassConstantDeclaration) GetChildren() []Node
func (*ClassConstantDeclaration) String ¶
func (ccd *ClassConstantDeclaration) String() string
type ClassExpression ¶
type ClassExpression struct {
BaseNode
Name Expression `json:"name"`
Final bool `json:"final,omitempty"` // final class
ReadOnly bool `json:"readOnly,omitempty"` // readonly class
Abstract bool `json:"abstract,omitempty"` // abstract class
Extends Expression `json:"extends"`
Implements []Expression `json:"implements"`
Body []Statement `json:"body"`
Attributes []*AttributeGroup `json:"attributes,omitempty"` // class attributes #[Attr]
}
ClassExpression 表示类声明表达式
func NewClassExpression ¶
func NewClassExpression(pos lexer.Position, name, extends Expression, implements []Expression, final, readOnly, abstract bool) *ClassExpression
func (*ClassExpression) Accept ¶
func (ce *ClassExpression) Accept(visitor Visitor)
func (*ClassExpression) GetChildren ¶
func (ce *ClassExpression) GetChildren() []Node
func (*ClassExpression) String ¶
func (ce *ClassExpression) String() string
type CloneExpression ¶
type CloneExpression struct {
BaseNode
Object Expression `json:"object"`
}
CloneExpression clone 表达式
func NewCloneExpression ¶
func NewCloneExpression(pos lexer.Position, object Expression) *CloneExpression
func (*CloneExpression) Accept ¶
func (c *CloneExpression) Accept(visitor Visitor)
func (*CloneExpression) GetChildren ¶
func (c *CloneExpression) GetChildren() []Node
func (*CloneExpression) String ¶
func (c *CloneExpression) String() string
type CloseTagExpression ¶
CloseTagExpression 表示 PHP 结束标签
func NewCloseTagExpression ¶
func NewCloseTagExpression(pos lexer.Position, content string) *CloseTagExpression
func (*CloseTagExpression) Accept ¶
func (ct *CloseTagExpression) Accept(visitor Visitor)
func (*CloseTagExpression) GetChildren ¶
func (ct *CloseTagExpression) GetChildren() []Node
func (*CloseTagExpression) String ¶
func (ct *CloseTagExpression) String() string
type CoalesceExpression ¶
type CoalesceExpression struct {
BaseNode
Left Expression `json:"left"`
Right Expression `json:"right"`
}
CoalesceExpression 表示 null 合并操作符 ??
func NewCoalesceExpression ¶
func NewCoalesceExpression(pos lexer.Position, left Expression, right Expression) *CoalesceExpression
func (*CoalesceExpression) Accept ¶
func (ce *CoalesceExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*CoalesceExpression) GetChildren ¶
func (ce *CoalesceExpression) GetChildren() []Node
GetChildren 返回子节点
func (*CoalesceExpression) String ¶
func (ce *CoalesceExpression) String() string
type CommaExpression ¶
type CommaExpression struct {
BaseNode
Expressions []Expression `json:"expressions"`
}
CommaExpression 逗号表达式 (多个表达式用逗号分隔)
func NewCommaExpression ¶
func NewCommaExpression(pos lexer.Position, expressions []Expression) *CommaExpression
func (*CommaExpression) Accept ¶
func (ce *CommaExpression) Accept(visitor Visitor)
func (*CommaExpression) GetChildren ¶
func (ce *CommaExpression) GetChildren() []Node
func (*CommaExpression) String ¶
func (ce *CommaExpression) String() string
type ConstExpression ¶
type ConstExpression struct {
BaseNode
Name Expression `json:"name"`
Value Expression `json:"value"`
}
ConstExpression 表示常量声明表达式
func NewConstExpression ¶
func NewConstExpression(pos lexer.Position, name, value Expression) *ConstExpression
func (*ConstExpression) Accept ¶
func (ce *ConstExpression) Accept(visitor Visitor)
func (*ConstExpression) GetChildren ¶
func (ce *ConstExpression) GetChildren() []Node
func (*ConstExpression) String ¶
func (ce *ConstExpression) String() string
type ConstantDeclarator ¶
type ConstantDeclarator struct {
BaseNode
Name Expression `json:"name"`
Value Expression `json:"value"`
}
ConstantDeclarator 单个常量声明
func NewConstantDeclarator ¶
func NewConstantDeclarator(pos lexer.Position, name, value Expression) *ConstantDeclarator
func (*ConstantDeclarator) Accept ¶
func (cd *ConstantDeclarator) Accept(visitor Visitor)
func (*ConstantDeclarator) GetChildren ¶
func (cd *ConstantDeclarator) GetChildren() []Node
func (*ConstantDeclarator) String ¶
func (cd *ConstantDeclarator) String() string
type ContinueStatement ¶
type ContinueStatement struct {
BaseNode
}
ContinueStatement continue语句
func NewContinueStatement ¶
func NewContinueStatement(pos lexer.Position) *ContinueStatement
func (*ContinueStatement) Accept ¶
func (cs *ContinueStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*ContinueStatement) GetChildren ¶
func (cs *ContinueStatement) GetChildren() []Node
GetChildren 返回子节点
func (*ContinueStatement) String ¶
func (cs *ContinueStatement) String() string
type DeclareStatement ¶
type DeclareStatement struct {
BaseNode
Declarations []Expression `json:"declarations"`
Body []Statement `json:"body,omitempty"`
Alternative bool `json:"alternative"` // true for declare(): ... enddeclare;
}
DeclareStatement 表示declare语句
func NewDeclareStatement ¶
func NewDeclareStatement(pos lexer.Position, declarations []Expression, alternative bool) *DeclareStatement
func (*DeclareStatement) Accept ¶
func (ds *DeclareStatement) Accept(visitor Visitor)
func (*DeclareStatement) GetChildren ¶
func (ds *DeclareStatement) GetChildren() []Node
func (*DeclareStatement) String ¶
func (ds *DeclareStatement) String() string
type DoWhileStatement ¶
type DoWhileStatement struct {
BaseNode
Body Statement `json:"body"`
Condition Expression `json:"condition"`
}
DoWhileStatement do-while 循环语句
func NewDoWhileStatement ¶
func NewDoWhileStatement(pos lexer.Position, body Statement, condition Expression) *DoWhileStatement
func (*DoWhileStatement) Accept ¶
func (dw *DoWhileStatement) Accept(visitor Visitor)
func (*DoWhileStatement) GetChildren ¶
func (dw *DoWhileStatement) GetChildren() []Node
func (*DoWhileStatement) String ¶
func (dw *DoWhileStatement) String() string
type DocBlockComment ¶
DocBlockComment 文档块注释
func NewDocBlockComment ¶
func NewDocBlockComment(pos lexer.Position, content, raw string) *DocBlockComment
func (*DocBlockComment) GetChildren ¶
func (dbc *DocBlockComment) GetChildren() []Node
GetChildren 返回子节点
func (*DocBlockComment) String ¶
func (dbc *DocBlockComment) String() string
type EchoStatement ¶
type EchoStatement struct {
BaseNode
Arguments *ArgumentList `json:"arguments,omitempty"`
}
Echo 语句
func NewEchoStatement ¶
func NewEchoStatement(pos lexer.Position) *EchoStatement
func (*EchoStatement) String ¶
func (e *EchoStatement) String() string
type ElseIfClause ¶
type ElseIfClause struct {
BaseNode
Condition Expression `json:"condition"`
Body []Statement `json:"body"`
}
ElseIfClause 表示elseif子句
func NewElseIfClause ¶
func NewElseIfClause(pos lexer.Position, condition Expression) *ElseIfClause
func (*ElseIfClause) Accept ¶
func (eic *ElseIfClause) Accept(visitor Visitor)
func (*ElseIfClause) GetChildren ¶
func (eic *ElseIfClause) GetChildren() []Node
func (*ElseIfClause) String ¶
func (eic *ElseIfClause) String() string
type EmptyExpression ¶
type EmptyExpression struct {
BaseNode
Expression Expression `json:"expression"`
}
EmptyExpression 表示 empty() 函数调用
func NewEmptyExpression ¶
func NewEmptyExpression(pos lexer.Position, expr Expression) *EmptyExpression
func (*EmptyExpression) GetChildren ¶
func (ee *EmptyExpression) GetChildren() []Node
GetChildren 返回子节点
func (*EmptyExpression) String ¶
func (ee *EmptyExpression) String() string
type EnumCase ¶
type EnumCase struct {
Name *IdentifierNode `json:"name"` // 案例名称
Value Expression `json:"value,omitempty"` // 可选的值(对于支撑枚举)
}
EnumCase 表示 enum 案例
func NewEnumCase ¶
func NewEnumCase(name *IdentifierNode, value Expression) *EnumCase
type EnumDeclaration ¶
type EnumDeclaration struct {
BaseNode
Name *IdentifierNode `json:"name"` // enum 名称
BackingType *TypeHint `json:"backingType,omitempty"` // 可选的支撑类型 (string, int)
Implements []*IdentifierNode `json:"implements,omitempty"` // 实现的接口
Cases []*EnumCase `json:"cases"` // enum 案例
Constants []*ClassConstantDeclaration `json:"constants,omitempty"` // enum 常量
Methods []*FunctionDeclaration `json:"methods,omitempty"` // enum 方法
Attributes []*AttributeGroup `json:"attributes,omitempty"` // 属性组
}
EnumDeclaration 表示 enum 声明 (PHP 8.1+)
func NewEnumDeclaration ¶
func NewEnumDeclaration(pos lexer.Position, name *IdentifierNode) *EnumDeclaration
func (*EnumDeclaration) GetChildren ¶
func (e *EnumDeclaration) GetChildren() []Node
GetChildren 返回子节点
func (*EnumDeclaration) String ¶
func (e *EnumDeclaration) String() string
type ErrorSuppressionExpression ¶
type ErrorSuppressionExpression struct {
BaseNode
Expression Expression `json:"expression"`
}
ErrorSuppressionExpression 表示错误抑制操作符 @
func NewErrorSuppressionExpression ¶
func NewErrorSuppressionExpression(pos lexer.Position, expr Expression) *ErrorSuppressionExpression
func (*ErrorSuppressionExpression) Accept ¶
func (ese *ErrorSuppressionExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*ErrorSuppressionExpression) GetChildren ¶
func (ese *ErrorSuppressionExpression) GetChildren() []Node
GetChildren 返回子节点
func (*ErrorSuppressionExpression) String ¶
func (ese *ErrorSuppressionExpression) String() string
type EvalExpression ¶
type EvalExpression struct {
BaseNode
Argument Expression `json:"argument"`
}
EvalExpression 表示 eval() 表达式
func NewEvalExpression ¶
func NewEvalExpression(pos lexer.Position, argument Expression) *EvalExpression
func (*EvalExpression) Accept ¶
func (ee *EvalExpression) Accept(visitor Visitor)
func (*EvalExpression) GetChildren ¶
func (ee *EvalExpression) GetChildren() []Node
func (*EvalExpression) String ¶
func (ee *EvalExpression) String() string
type ExitExpression ¶
type ExitExpression struct {
BaseNode
Argument Expression `json:"argument,omitempty"`
}
ExitExpression 表示 exit/die 表达式
func NewExitExpression ¶
func NewExitExpression(pos lexer.Position, argument Expression) *ExitExpression
func (*ExitExpression) Accept ¶
func (ee *ExitExpression) Accept(visitor Visitor)
func (*ExitExpression) GetChildren ¶
func (ee *ExitExpression) GetChildren() []Node
func (*ExitExpression) String ¶
func (ee *ExitExpression) String() string
type Expression ¶
type Expression interface {
Node
// contains filtered or unexported methods
}
Expression 表示表达式节点
type ExpressionStatement ¶
type ExpressionStatement struct {
BaseNode
Expression Expression `json:"expression"`
}
ExpressionStatement 表达式语句
func NewExpressionStatement ¶
func NewExpressionStatement(pos lexer.Position, expr Expression) *ExpressionStatement
func (*ExpressionStatement) Accept ¶
func (es *ExpressionStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*ExpressionStatement) GetChildren ¶
func (es *ExpressionStatement) GetChildren() []Node
GetChildren 返回子节点
func (*ExpressionStatement) String ¶
func (es *ExpressionStatement) String() string
type FilterFunc ¶
FilterFunc 函数类型的过滤器
type FirstClassCallable ¶
type FirstClassCallable struct {
BaseNode
Callable Expression `json:"callable"` // 被调用的函数/方法/静态方法
}
FirstClassCallable 表示第一类可调用语法 function(...), $obj->method(...), Class::method(...)
func NewFirstClassCallable ¶
func NewFirstClassCallable(pos lexer.Position, callable Expression) *FirstClassCallable
func (*FirstClassCallable) Accept ¶
func (fcc *FirstClassCallable) Accept(visitor Visitor)
func (*FirstClassCallable) GetChildren ¶
func (fcc *FirstClassCallable) GetChildren() []Node
func (*FirstClassCallable) String ¶
func (fcc *FirstClassCallable) String() string
type ForStatement ¶
type ForStatement struct {
BaseNode
Init Expression `json:"init,omitempty"`
Test Expression `json:"test,omitempty"`
Update Expression `json:"update,omitempty"`
Body []Statement `json:"body"`
}
ForStatement for语句
func NewForStatement ¶
func NewForStatement(pos lexer.Position) *ForStatement
func (*ForStatement) String ¶
func (fs *ForStatement) String() string
type ForeachStatement ¶
type ForeachStatement struct {
BaseNode
Iterable Expression `json:"iterable"`
Key Expression `json:"key,omitempty"`
Value Expression `json:"value"`
Body Statement `json:"body"`
}
ForeachStatement foreach 循环语句
func NewForeachStatement ¶
func NewForeachStatement(pos lexer.Position, iterable, key, value Expression, body Statement) *ForeachStatement
func (*ForeachStatement) Accept ¶
func (f *ForeachStatement) Accept(visitor Visitor)
func (*ForeachStatement) GetChildren ¶
func (f *ForeachStatement) GetChildren() []Node
func (*ForeachStatement) String ¶
func (f *ForeachStatement) String() string
type FunctionDeclaration ¶
type FunctionDeclaration struct {
BaseNode
Name Identifier `json:"name"`
Parameters *ParameterList `json:"parameters,omitempty"`
ReturnType *TypeHint `json:"returnType,omitempty"`
Body []Statement `json:"body"`
ByReference bool `json:"byReference,omitempty"` // function &foo()
Visibility string `json:"visibility,omitempty"` // public, private, protected (for class methods)
IsStatic bool `json:"isStatic,omitempty"` // static function
IsAbstract bool `json:"isAbstract,omitempty"` // abstract function
IsFinal bool `json:"isFinal,omitempty"` // final function
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
FunctionDeclaration 函数声明
func NewFunctionDeclaration ¶
func NewFunctionDeclaration(pos lexer.Position, name Identifier) *FunctionDeclaration
func (*FunctionDeclaration) Accept ¶
func (fd *FunctionDeclaration) Accept(visitor Visitor)
Accept 接受访问者
func (*FunctionDeclaration) GetChildren ¶
func (fd *FunctionDeclaration) GetChildren() []Node
GetChildren 返回子节点
func (*FunctionDeclaration) String ¶
func (fd *FunctionDeclaration) String() string
type GlobalStatement ¶
type GlobalStatement struct {
BaseNode
Variables []Expression `json:"variables"`
}
GlobalStatement global 语句
func NewGlobalStatement ¶
func NewGlobalStatement(pos lexer.Position) *GlobalStatement
func (*GlobalStatement) GetChildren ¶
func (gs *GlobalStatement) GetChildren() []Node
GetChildren 返回子节点
func (*GlobalStatement) String ¶
func (gs *GlobalStatement) String() string
type GotoStatement ¶
type GotoStatement struct {
BaseNode
Label Expression `json:"label"`
}
GotoStatement goto 语句
func NewGotoStatement ¶
func NewGotoStatement(pos lexer.Position, label Expression) *GotoStatement
func (*GotoStatement) Accept ¶
func (g *GotoStatement) Accept(visitor Visitor)
func (*GotoStatement) GetChildren ¶
func (g *GotoStatement) GetChildren() []Node
func (*GotoStatement) String ¶
func (g *GotoStatement) String() string
type HaltCompilerStatement ¶
type HaltCompilerStatement struct {
BaseNode
}
HaltCompilerStatement __halt_compiler()语句
func NewHaltCompilerStatement ¶
func NewHaltCompilerStatement(pos lexer.Position) *HaltCompilerStatement
func (*HaltCompilerStatement) Accept ¶
func (hcs *HaltCompilerStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*HaltCompilerStatement) GetChildren ¶
func (hcs *HaltCompilerStatement) GetChildren() []Node
GetChildren 返回子节点
func (*HaltCompilerStatement) String ¶
func (hcs *HaltCompilerStatement) String() string
type HookedPropertyDeclaration ¶
type HookedPropertyDeclaration struct {
BaseNode
Visibility string `json:"visibility"` // private, protected, public
Static bool `json:"static,omitempty"` // static
ReadOnly bool `json:"readOnly,omitempty"` // readonly
Abstract bool `json:"abstract,omitempty"` // abstract (only for hooked properties)
Type *TypeHint `json:"type,omitempty"`
Name string `json:"name"` // Property name without $
Hooks []*PropertyHook `json:"hooks"` // List of property hooks
}
HookedPropertyDeclaration represents a property with hooks
func NewHookedPropertyDeclaration ¶
func NewHookedPropertyDeclaration(pos lexer.Position, visibility, name string, static, readOnly, abstract bool, typeHint *TypeHint, hooks []*PropertyHook) *HookedPropertyDeclaration
func (*HookedPropertyDeclaration) Accept ¶
func (hpd *HookedPropertyDeclaration) Accept(visitor Visitor)
func (*HookedPropertyDeclaration) GetChildren ¶
func (hpd *HookedPropertyDeclaration) GetChildren() []Node
func (*HookedPropertyDeclaration) String ¶
func (hpd *HookedPropertyDeclaration) String() string
type Identifier ¶
type Identifier interface {
Node
// contains filtered or unexported methods
}
Identifier 表示标识符节点
type IdentifierNode ¶
IdentifierNode 标识符节点
func NewIdentifierNode ¶
func NewIdentifierNode(pos lexer.Position, name string) *IdentifierNode
func (*IdentifierNode) GetChildren ¶
func (i *IdentifierNode) GetChildren() []Node
GetChildren 返回子节点
func (*IdentifierNode) String ¶
func (i *IdentifierNode) String() string
type IfStatement ¶
type IfStatement struct {
BaseNode
Test Expression `json:"test"`
Consequent []Statement `json:"consequent"`
Alternate []Statement `json:"alternate,omitempty"`
}
IfStatement if语句
func NewIfStatement ¶
func NewIfStatement(pos lexer.Position, test Expression) *IfStatement
func (*IfStatement) String ¶
func (is *IfStatement) String() string
type IncludeOrEvalExpression ¶
type IncludeOrEvalExpression struct {
BaseNode
Type lexer.TokenType // T_INCLUDE, T_INCLUDE_ONCE, T_REQUIRE, T_REQUIRE_ONCE, T_EVAL
Expr Node // 要包含的文件表达式
}
IncludeOrEvalExpression 表示 include/require/eval 表达式
func (*IncludeOrEvalExpression) Accept ¶
func (ie *IncludeOrEvalExpression) Accept(visitor Visitor)
func (*IncludeOrEvalExpression) GetChildren ¶
func (ie *IncludeOrEvalExpression) GetChildren() []Node
func (*IncludeOrEvalExpression) String ¶
func (ie *IncludeOrEvalExpression) String() string
type InspectorFunc ¶
InspectorFunc 函数类型的检查器
type InstanceofExpression ¶
type InstanceofExpression struct {
BaseNode
Left Expression `json:"left"`
Right Expression `json:"right"`
}
InstanceofExpression instanceof 表达式
func NewInstanceofExpression ¶
func NewInstanceofExpression(pos lexer.Position, left, right Expression) *InstanceofExpression
func (*InstanceofExpression) Accept ¶
func (i *InstanceofExpression) Accept(visitor Visitor)
func (*InstanceofExpression) GetChildren ¶
func (i *InstanceofExpression) GetChildren() []Node
func (*InstanceofExpression) String ¶
func (i *InstanceofExpression) String() string
type InterfaceDeclaration ¶
type InterfaceDeclaration struct {
BaseNode
Name *IdentifierNode `json:"name"` // 接口名称
Extends []*IdentifierNode `json:"extends,omitempty"` // 继承的接口
Methods []*InterfaceMethod `json:"methods"` // 接口方法
Attributes []*AttributeGroup `json:"attributes,omitempty"` // 属性组
}
InterfaceDeclaration 表示接口声明
func NewInterfaceDeclaration ¶
func NewInterfaceDeclaration(pos lexer.Position, name *IdentifierNode) *InterfaceDeclaration
func (*InterfaceDeclaration) Accept ¶
func (i *InterfaceDeclaration) Accept(visitor Visitor)
Accept 接受访问者
func (*InterfaceDeclaration) GetChildren ¶
func (i *InterfaceDeclaration) GetChildren() []Node
GetChildren 返回子节点
func (*InterfaceDeclaration) String ¶
func (i *InterfaceDeclaration) String() string
type InterfaceMethod ¶
type InterfaceMethod struct {
Name *IdentifierNode `json:"name"` // 方法名称
Parameters *ParameterList `json:"parameters,omitempty"` // 参数列表
ReturnType *TypeHint `json:"returnType,omitempty"` // 返回类型
Visibility string `json:"visibility"` // 可见性 (通常是 public)
ByReference bool `json:"byReference,omitempty"` // function &foo() - 引用返回
}
InterfaceMethod 表示接口方法声明
type InterpolatedStringExpression ¶
type InterpolatedStringExpression struct {
BaseNode
Parts []Expression `json:"parts"` // 字符串的各个部分
}
InterpolatedStringExpression 字符串插值表达式
func NewInterpolatedStringExpression ¶
func NewInterpolatedStringExpression(pos lexer.Position, parts []Expression) *InterpolatedStringExpression
func (*InterpolatedStringExpression) Accept ¶
func (ise *InterpolatedStringExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*InterpolatedStringExpression) GetChildren ¶
func (ise *InterpolatedStringExpression) GetChildren() []Node
GetChildren 返回子节点
func (*InterpolatedStringExpression) String ¶
func (ise *InterpolatedStringExpression) String() string
type IssetExpression ¶
type IssetExpression struct {
BaseNode
Arguments *ArgumentList `json:"arguments,omitempty"`
}
IssetExpression 表示 isset() 表达式
func NewIssetExpression ¶
func NewIssetExpression(pos lexer.Position, arguments []Expression) *IssetExpression
func (*IssetExpression) Accept ¶
func (ie *IssetExpression) Accept(visitor Visitor)
func (*IssetExpression) GetChildren ¶
func (ie *IssetExpression) GetChildren() []Node
func (*IssetExpression) String ¶
func (ie *IssetExpression) String() string
type LabelStatement ¶
type LabelStatement struct {
BaseNode
Name Expression `json:"name"`
}
LabelStatement 标签语句
func NewLabelStatement ¶
func NewLabelStatement(pos lexer.Position, name Expression) *LabelStatement
func (*LabelStatement) Accept ¶
func (l *LabelStatement) Accept(visitor Visitor)
func (*LabelStatement) GetChildren ¶
func (l *LabelStatement) GetChildren() []Node
func (*LabelStatement) String ¶
func (l *LabelStatement) String() string
type ListExpression ¶
type ListExpression struct {
BaseNode
Elements []Expression `json:"elements"`
}
ListExpression 表示 list() 表达式
func NewListExpression ¶
func NewListExpression(pos lexer.Position, elements []Expression) *ListExpression
func (*ListExpression) Accept ¶
func (le *ListExpression) Accept(visitor Visitor)
func (*ListExpression) GetChildren ¶
func (le *ListExpression) GetChildren() []Node
func (*ListExpression) String ¶
func (le *ListExpression) String() string
type MagicConstantExpression ¶
type MagicConstantExpression struct {
BaseNode
Name string `json:"name"` // 魔术常量名称,如 "__FILE__", "__METHOD__"
TokenType lexer.TokenType `json:"tokenType"` // 对应的 token 类型,如 T_FILE, T_METHOD_C
}
MagicConstantExpression 魔术常量表达式节点 (0 child nodes) 对应 PHP 的 ZEND_AST_MAGIC_CONST,用于 __FILE__, __LINE__, __METHOD__ 等魔术常量
func (*MagicConstantExpression) Accept ¶
func (m *MagicConstantExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*MagicConstantExpression) GetChildren ¶
func (m *MagicConstantExpression) GetChildren() []Node
GetChildren 返回子节点 - 魔术常量是0子节点的叶子节点
func (*MagicConstantExpression) String ¶
func (m *MagicConstantExpression) String() string
type MatchArm ¶
type MatchArm struct {
BaseNode
Conditions []Expression `json:"conditions,omitempty"` // 条件列表,empty for default
Body Expression `json:"body"` // 分支体
IsDefault bool `json:"isDefault"` // 是否为 default 分支
}
MatchArm 表示 match 表达式的一个分支
func NewMatchArm ¶
func NewMatchArm(pos lexer.Position, conditions []Expression, body Expression, isDefault bool) *MatchArm
func (*MatchArm) GetChildren ¶
type MatchExpression ¶
type MatchExpression struct {
BaseNode
Subject Expression `json:"subject"` // 匹配的表达式
Arms []*MatchArm `json:"arms"` // match arms
}
MatchExpression 表示 match 表达式 (PHP 8.0+)
func NewMatchExpression ¶
func NewMatchExpression(pos lexer.Position, subject Expression) *MatchExpression
func (*MatchExpression) Accept ¶
func (m *MatchExpression) Accept(visitor Visitor)
func (*MatchExpression) GetChildren ¶
func (m *MatchExpression) GetChildren() []Node
func (*MatchExpression) String ¶
func (m *MatchExpression) String() string
type MethodCallExpression ¶
type MethodCallExpression struct {
BaseNode
Object Expression `json:"object"` // 对象表达式
Method Expression `json:"method"` // 方法名表达式
Arguments *ArgumentList `json:"arguments,omitempty"` // 参数列表
}
MethodCallExpression 方法调用表达式 - $obj->method(args) 使用 ASTMethodCall (768) 节点类型,符合PHP官方zend_ast.h定义
func NewMethodCallExpression ¶
func NewMethodCallExpression(pos lexer.Position, object Expression, method Expression) *MethodCallExpression
func (*MethodCallExpression) Accept ¶
func (mce *MethodCallExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*MethodCallExpression) GetChildren ¶
func (mce *MethodCallExpression) GetChildren() []Node
GetChildren 返回子节点
func (*MethodCallExpression) String ¶
func (mce *MethodCallExpression) String() string
type NamedArgument ¶
type NamedArgument struct {
BaseNode
Name *IdentifierNode `json:"name"` // 参数名
Value Expression `json:"value"` // 参数值
}
NamedArgument 表示命名参数 (PHP 8.0+) - name: value
func NewNamedArgument ¶
func NewNamedArgument(pos lexer.Position, name *IdentifierNode, value Expression) *NamedArgument
func (*NamedArgument) Accept ¶
func (na *NamedArgument) Accept(visitor Visitor)
func (*NamedArgument) GetChildren ¶
func (na *NamedArgument) GetChildren() []Node
func (*NamedArgument) String ¶
func (na *NamedArgument) String() string
type NamespaceExpression ¶
NamespaceExpression 表示命名空间表达式(以 \ 开始)
func NewNamespaceExpression ¶
func NewNamespaceExpression(pos lexer.Position, name Node) *NamespaceExpression
func (*NamespaceExpression) Accept ¶
func (ne *NamespaceExpression) Accept(visitor Visitor)
func (*NamespaceExpression) GetChildren ¶
func (ne *NamespaceExpression) GetChildren() []Node
func (*NamespaceExpression) String ¶
func (ne *NamespaceExpression) String() string
type NamespaceNameExpression ¶
type NamespaceNameExpression struct {
BaseNode
Parts []string `json:"parts"` // 命名空间的各部分,如 ["Foo", "Bar"] 表示 Foo\Bar
}
NamespaceNameExpression 表示命名空间名称表达式
func NewNamespaceNameExpression ¶
func NewNamespaceNameExpression(pos lexer.Position, parts []string) *NamespaceNameExpression
func (*NamespaceNameExpression) Accept ¶
func (n *NamespaceNameExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*NamespaceNameExpression) GetChildren ¶
func (n *NamespaceNameExpression) GetChildren() []Node
GetChildren 返回子节点
func (*NamespaceNameExpression) String ¶
func (n *NamespaceNameExpression) String() string
type NamespaceStatement ¶
type NamespaceStatement struct {
BaseNode
Name *NamespaceNameExpression `json:"name,omitempty"` // nil for global namespace
Body []Statement `json:"body,omitempty"` // 可选的命名空间主体
}
NamespaceStatement 表示命名空间声明语句
func NewNamespaceStatement ¶
func NewNamespaceStatement(pos lexer.Position, name *NamespaceNameExpression) *NamespaceStatement
func (*NamespaceStatement) Accept ¶
func (n *NamespaceStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*NamespaceStatement) GetChildren ¶
func (n *NamespaceStatement) GetChildren() []Node
GetChildren 返回子节点
func (*NamespaceStatement) String ¶
func (n *NamespaceStatement) String() string
type NewExpression ¶
type NewExpression struct {
BaseNode
Class Expression `json:"class"`
Arguments *ArgumentList `json:"arguments,omitempty"`
}
NewExpression new 表达式
func NewNewExpression ¶
func NewNewExpression(pos lexer.Position, class Expression) *NewExpression
func (*NewExpression) Accept ¶
func (n *NewExpression) Accept(visitor Visitor)
func (*NewExpression) GetChildren ¶
func (n *NewExpression) GetChildren() []Node
func (*NewExpression) String ¶
func (n *NewExpression) String() string
type Node ¶
type Node interface {
// GetKind 返回节点的AST Kind类型
GetKind() ASTKind
// GetPosition 返回节点在源代码中的位置
GetPosition() lexer.Position
// GetAttributes 返回节点的属性
GetAttributes() map[string]interface{}
// GetLineNo 返回行号
GetLineNo() uint32
// GetChildren 返回子节点
GetChildren() []Node
// String 返回节点的字符串表示
String() string
// ToJSON 转换为 JSON 表示
ToJSON() ([]byte, error)
// Accept 接受访问者
Accept(visitor Visitor)
}
Node 表示抽象语法树中的节点接口
func FindFirstFunc ¶
FindFirstFunc 使用函数作为过滤器查找第一个节点
func Transform ¶
func Transform(node Node, transformer Transformer) Node
Transform 应用转换器修改AST
Example ¶
ExampleTransform 演示如何使用AST转换
package main
import (
"fmt"
"github.com/wudi/php-parser/ast"
"github.com/wudi/php-parser/lexer"
)
func main() {
pos := lexer.Position{Line: 1, Column: 1, Offset: 0}
// 创建原始变量
original := ast.NewVariable(pos, "$oldName")
// 使用转换器重命名变量
transformed := ast.TransformFunc(original, func(node ast.Node) ast.Node {
if v, ok := node.(*ast.Variable); ok && v.Name == "$oldName" {
return ast.NewVariable(pos, "$newName")
}
return node
})
if v, ok := transformed.(*ast.Variable); ok {
fmt.Printf("Transformed: %s\n", v.Name)
}
}
Output: Transformed: $newName
type NullLiteral ¶
type NullLiteral struct {
BaseNode
}
NullLiteral null字面量
func NewNullLiteral ¶
func NewNullLiteral(pos lexer.Position) *NullLiteral
func (*NullLiteral) String ¶
func (nl *NullLiteral) String() string
type NullsafeMethodCallExpression ¶
type NullsafeMethodCallExpression struct {
BaseNode
Object Expression `json:"object"` // 对象表达式
Method Expression `json:"method"` // 方法名表达式
Arguments *ArgumentList `json:"arguments,omitempty"` // 参数列表
}
NullsafeMethodCallExpression 空安全方法调用表达式 - $obj?->method(args) 使用 ASTNullsafeMethodCall (769) 节点类型,符合PHP官方zend_ast.h定义
func NewNullsafeMethodCallExpression ¶
func NewNullsafeMethodCallExpression(pos lexer.Position, object Expression, method Expression) *NullsafeMethodCallExpression
func (*NullsafeMethodCallExpression) Accept ¶
func (nmce *NullsafeMethodCallExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*NullsafeMethodCallExpression) GetChildren ¶
func (nmce *NullsafeMethodCallExpression) GetChildren() []Node
GetChildren 返回子节点
func (*NullsafeMethodCallExpression) String ¶
func (nmce *NullsafeMethodCallExpression) String() string
type NullsafePropertyAccessExpression ¶
type NullsafePropertyAccessExpression struct {
BaseNode
Object Expression `json:"object"` // 对象表达式
Property Expression `json:"property"` // 属性名称或表达式
}
NullsafePropertyAccessExpression 表示空安全属性访问表达式 Supports: $obj?->property, $obj?->$variable, $obj?->{expression}
func NewNullsafePropertyAccessExpression ¶
func NewNullsafePropertyAccessExpression(pos lexer.Position, object Expression, property Expression) *NullsafePropertyAccessExpression
func (*NullsafePropertyAccessExpression) Accept ¶
func (n *NullsafePropertyAccessExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*NullsafePropertyAccessExpression) GetChildren ¶
func (n *NullsafePropertyAccessExpression) GetChildren() []Node
GetChildren 返回子节点
func (*NullsafePropertyAccessExpression) String ¶
func (n *NullsafePropertyAccessExpression) String() string
type NumberLiteral ¶
type NumberLiteral struct {
BaseNode
Value string `json:"value"`
Kind string `json:"kind"` // "integer" or "float"
}
NumberLiteral 数字字面量
func NewNumberLiteral ¶
func NewNumberLiteral(pos lexer.Position, value, kind string) *NumberLiteral
func (*NumberLiteral) String ¶
func (nl *NumberLiteral) String() string
type Parameter ¶
type Parameter struct {
Name string `json:"name"`
DefaultValue Expression `json:"defaultValue,omitempty"`
Type *TypeHint `json:"type,omitempty"`
ByReference bool `json:"byReference,omitempty"` // &$param
Variadic bool `json:"variadic,omitempty"` // ...$params
Visibility string `json:"visibility,omitempty"` // public, private, protected
ReadOnly bool `json:"readOnly,omitempty"` // readonly
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
type ParameterList ¶
type ParameterList struct {
BaseNode
Parameters []*ParameterNode `json:"parameters"`
}
ParameterList represents a list of function/method parameters
func NewParameterList ¶
func NewParameterList(pos lexer.Position, parameters []*ParameterNode) *ParameterList
func (*ParameterList) Accept ¶
func (pl *ParameterList) Accept(visitor Visitor)
func (*ParameterList) GetChildren ¶
func (pl *ParameterList) GetChildren() []Node
func (*ParameterList) String ¶
func (pl *ParameterList) String() string
type ParameterNode ¶
type ParameterNode struct {
BaseNode
Name Identifier `json:"name"`
DefaultValue Expression `json:"defaultValue,omitempty"`
Type *TypeHint `json:"type,omitempty"`
ByReference bool `json:"byReference,omitempty"` // &$param
Variadic bool `json:"variadic,omitempty"` // ...$params
Visibility string `json:"visibility,omitempty"` // public, private, protected
ReadOnly bool `json:"readOnly,omitempty"` // readonly
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
ParameterNode represents a function/method parameter as AST node
func NewParameterNode ¶
func NewParameterNode(pos lexer.Position, name Identifier) *ParameterNode
func (*ParameterNode) Accept ¶
func (p *ParameterNode) Accept(visitor Visitor)
func (*ParameterNode) GetChildren ¶
func (p *ParameterNode) GetChildren() []Node
func (*ParameterNode) String ¶
func (p *ParameterNode) String() string
type PrintExpression ¶
type PrintExpression struct {
BaseNode
Expression Expression `json:"expression"`
}
PrintExpression 表示print表达式 (作为表达式使用的print)
func NewPrintExpression ¶
func NewPrintExpression(pos lexer.Position, expr Expression) *PrintExpression
func (*PrintExpression) GetChildren ¶
func (p *PrintExpression) GetChildren() []Node
GetChildren 返回子节点
func (*PrintExpression) String ¶
func (p *PrintExpression) String() string
type PrintStatement ¶
type PrintStatement struct {
BaseNode
Arguments *ArgumentList `json:"arguments,omitempty"`
}
PrintStatement 表示print语句
func NewPrintStatement ¶
func NewPrintStatement(pos lexer.Position) *PrintStatement
func (*PrintStatement) GetChildren ¶
func (p *PrintStatement) GetChildren() []Node
GetChildren 返回子节点
func (*PrintStatement) String ¶
func (p *PrintStatement) String() string
type PropertyAccessExpression ¶
type PropertyAccessExpression struct {
BaseNode
Object Expression `json:"object"` // 对象表达式
Property Expression `json:"property"` // 属性名称或表达式
}
PropertyAccessExpression 表示属性访问表达式 Supports: $obj->property, $obj->$variable, $obj->{expression}
func NewPropertyAccessExpression ¶
func NewPropertyAccessExpression(pos lexer.Position, object Expression, property Expression) *PropertyAccessExpression
func (*PropertyAccessExpression) Accept ¶
func (p *PropertyAccessExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*PropertyAccessExpression) GetChildren ¶
func (p *PropertyAccessExpression) GetChildren() []Node
GetChildren 返回子节点
func (*PropertyAccessExpression) String ¶
func (p *PropertyAccessExpression) String() string
type PropertyDeclaration ¶
type PropertyDeclaration struct {
BaseNode
Visibility string `json:"visibility"` // private, protected, public
Static bool `json:"static,omitempty"` // static
ReadOnly bool `json:"readOnly,omitempty"` // readonly
Type *TypeHint `json:"type,omitempty"`
Name string `json:"name"` // Property name without $
DefaultValue Expression `json:"defaultValue,omitempty"`
Attributes []*AttributeGroup `json:"attributes,omitempty"` // #[...] attributes
}
PropertyDeclaration 属性声明语句
func NewPropertyDeclaration ¶
func NewPropertyDeclaration(pos lexer.Position, visibility, name string, static, readOnly bool, typeHint *TypeHint, defaultValue Expression) *PropertyDeclaration
func (*PropertyDeclaration) Accept ¶
func (pd *PropertyDeclaration) Accept(visitor Visitor)
func (*PropertyDeclaration) GetChildren ¶
func (pd *PropertyDeclaration) GetChildren() []Node
func (*PropertyDeclaration) String ¶
func (pd *PropertyDeclaration) String() string
type PropertyHook ¶
type PropertyHook struct {
BaseNode
Type string `json:"type"` // "get" or "set"
Parameter *Parameter `json:"parameter,omitempty"` // For set hooks: set(Type $value)
Body Expression `json:"body,omitempty"` // For arrow syntax: get => expr
Statements []Statement `json:"statements,omitempty"` // For block syntax: get { ... }
ByRef bool `json:"byRef,omitempty"` // For &get
}
PropertyHook represents a single property hook (get or set)
func NewPropertyHook ¶
func NewPropertyHook(pos lexer.Position, hookType string, parameter *Parameter, body Expression, statements []Statement, byRef bool) *PropertyHook
func (*PropertyHook) Accept ¶
func (ph *PropertyHook) Accept(visitor Visitor)
func (*PropertyHook) GetChildren ¶
func (ph *PropertyHook) GetChildren() []Node
func (*PropertyHook) String ¶
func (ph *PropertyHook) String() string
type ReturnStatement ¶
type ReturnStatement struct {
BaseNode
Argument Expression `json:"argument,omitempty"`
}
ReturnStatement return语句
func NewReturnStatement ¶
func NewReturnStatement(pos lexer.Position, arg Expression) *ReturnStatement
func (*ReturnStatement) GetChildren ¶
func (rs *ReturnStatement) GetChildren() []Node
GetChildren 返回子节点
func (*ReturnStatement) String ¶
func (rs *ReturnStatement) String() string
type ShellExecExpression ¶
type ShellExecExpression struct {
BaseNode
Parts []Expression `json:"parts"` // 命令的各个部分
}
ShellExecExpression 命令执行表达式 (反引号)
func NewShellExecExpression ¶
func NewShellExecExpression(pos lexer.Position, parts []Expression) *ShellExecExpression
func (*ShellExecExpression) Accept ¶
func (se *ShellExecExpression) Accept(visitor Visitor)
Accept 接受访问者
func (*ShellExecExpression) GetChildren ¶
func (se *ShellExecExpression) GetChildren() []Node
GetChildren 返回子节点
func (*ShellExecExpression) String ¶
func (se *ShellExecExpression) String() string
type SpreadExpression ¶
type SpreadExpression struct {
BaseNode
Argument Expression `json:"argument"`
}
SpreadExpression 表示展开表达式 (...expr)
func NewSpreadExpression ¶
func NewSpreadExpression(pos lexer.Position, argument Expression) *SpreadExpression
func (*SpreadExpression) Accept ¶
func (se *SpreadExpression) Accept(visitor Visitor)
func (*SpreadExpression) GetChildren ¶
func (se *SpreadExpression) GetChildren() []Node
func (*SpreadExpression) String ¶
func (se *SpreadExpression) String() string
type Statement ¶
type Statement interface {
Node
// contains filtered or unexported methods
}
Statement 表示语句节点
type StaticAccessExpression ¶
type StaticAccessExpression struct {
BaseNode
Class Expression `json:"class"`
Property Expression `json:"property"`
}
StaticAccessExpression 表示静态访问表达式 Class::method 或 Class::$property
func NewStaticAccessExpression ¶
func NewStaticAccessExpression(pos lexer.Position, class, property Expression) *StaticAccessExpression
func (*StaticAccessExpression) Accept ¶
func (sae *StaticAccessExpression) Accept(visitor Visitor)
func (*StaticAccessExpression) GetChildren ¶
func (sae *StaticAccessExpression) GetChildren() []Node
func (*StaticAccessExpression) String ¶
func (sae *StaticAccessExpression) String() string
type StaticPropertyAccessExpression ¶
type StaticPropertyAccessExpression struct {
BaseNode
Class Expression `json:"class"` // 类名表达式
Property Expression `json:"property"` // 属性表达式
}
StaticPropertyAccessExpression 表示静态属性访问表达式 Class::$property 使用 ASTStaticProp (515) 节点类型,符合PHP官方zend_ast.h定义
func NewStaticPropertyAccessExpression ¶
func NewStaticPropertyAccessExpression(pos lexer.Position, class, property Expression) *StaticPropertyAccessExpression
func (*StaticPropertyAccessExpression) Accept ¶
func (spae *StaticPropertyAccessExpression) Accept(visitor Visitor)
func (*StaticPropertyAccessExpression) GetChildren ¶
func (spae *StaticPropertyAccessExpression) GetChildren() []Node
func (*StaticPropertyAccessExpression) String ¶
func (spae *StaticPropertyAccessExpression) String() string
type StaticStatement ¶
type StaticStatement struct {
BaseNode
Variables []*StaticVariable `json:"variables"`
}
StaticStatement static 变量声明语句
func NewStaticStatement ¶
func NewStaticStatement(pos lexer.Position) *StaticStatement
func (*StaticStatement) Accept ¶
func (s *StaticStatement) Accept(visitor Visitor)
func (*StaticStatement) GetChildren ¶
func (s *StaticStatement) GetChildren() []Node
func (*StaticStatement) String ¶
func (s *StaticStatement) String() string
type StaticVariable ¶
type StaticVariable struct {
BaseNode
Variable Expression `json:"variable"`
DefaultValue Expression `json:"defaultValue,omitempty"`
}
func NewStaticVariable ¶
func NewStaticVariable(pos lexer.Position, variable, defaultValue Expression) *StaticVariable
func (*StaticVariable) Accept ¶
func (sv *StaticVariable) Accept(visitor Visitor)
func (*StaticVariable) GetChildren ¶
func (sv *StaticVariable) GetChildren() []Node
type StringLiteral ¶
type StringLiteral struct {
BaseNode
Value string `json:"value"`
Raw string `json:"raw"` // 原始字符串(包含引号)
}
StringLiteral 字符串字面量
func NewStringLiteral ¶
func NewStringLiteral(pos lexer.Position, value, raw string) *StringLiteral
func (*StringLiteral) String ¶
func (sl *StringLiteral) String() string
type SwitchCase ¶
type SwitchCase struct {
BaseNode
Test Expression `json:"test,omitempty"` // null for default case
Body []Statement `json:"body"`
}
func NewSwitchCase ¶
func NewSwitchCase(pos lexer.Position, test Expression) *SwitchCase
func (*SwitchCase) Accept ¶
func (sc *SwitchCase) Accept(visitor Visitor)
func (*SwitchCase) GetChildren ¶
func (sc *SwitchCase) GetChildren() []Node
func (*SwitchCase) String ¶
func (sc *SwitchCase) String() string
type SwitchStatement ¶
type SwitchStatement struct {
BaseNode
Discriminant Expression `json:"discriminant"`
Cases []*SwitchCase `json:"cases"`
}
SwitchStatement switch 语句
func NewSwitchStatement ¶
func NewSwitchStatement(pos lexer.Position, discriminant Expression) *SwitchStatement
func (*SwitchStatement) Accept ¶
func (s *SwitchStatement) Accept(visitor Visitor)
func (*SwitchStatement) GetChildren ¶
func (s *SwitchStatement) GetChildren() []Node
func (*SwitchStatement) String ¶
func (s *SwitchStatement) String() string
type TernaryExpression ¶
type TernaryExpression struct {
BaseNode
Test Expression `json:"test"`
Consequent Expression `json:"consequent,omitempty"` // 短三元运算符时为 nil
Alternate Expression `json:"alternate"`
}
TernaryExpression 表示三元运算符表达式
func NewTernaryExpression ¶
func NewTernaryExpression(pos lexer.Position, test, consequent, alternate Expression) *TernaryExpression
func (*TernaryExpression) Accept ¶
func (te *TernaryExpression) Accept(visitor Visitor)
func (*TernaryExpression) GetChildren ¶
func (te *TernaryExpression) GetChildren() []Node
func (*TernaryExpression) String ¶
func (te *TernaryExpression) String() string
type ThrowExpression ¶
type ThrowExpression struct {
BaseNode
Argument Expression `json:"argument"`
}
ThrowExpression represents a throw expression (PHP 8.0+)
func NewThrowExpression ¶
func NewThrowExpression(pos lexer.Position, argument Expression) *ThrowExpression
func (*ThrowExpression) Accept ¶
func (t *ThrowExpression) Accept(visitor Visitor)
func (*ThrowExpression) GetChildren ¶
func (t *ThrowExpression) GetChildren() []Node
func (*ThrowExpression) String ¶
func (t *ThrowExpression) String() string
type ThrowStatement ¶
type ThrowStatement struct {
BaseNode
Argument Expression `json:"argument"`
}
ThrowStatement throw 语句
func NewThrowStatement ¶
func NewThrowStatement(pos lexer.Position, argument Expression) *ThrowStatement
func (*ThrowStatement) Accept ¶
func (t *ThrowStatement) Accept(visitor Visitor)
func (*ThrowStatement) GetChildren ¶
func (t *ThrowStatement) GetChildren() []Node
func (*ThrowStatement) String ¶
func (t *ThrowStatement) String() string
type TraitAdaptation ¶
type TraitAdaptation interface {
Node
// contains filtered or unexported methods
}
TraitAdaptation 表示 trait 适配规则的基础接口
type TraitAliasStatement ¶
type TraitAliasStatement struct {
BaseNode
Method *TraitMethodReference `json:"method"` // 方法引用
Alias *IdentifierNode `json:"alias,omitempty"` // 新的方法名(可选)
Visibility string `json:"visibility,omitempty"` // 可见性修饰符(可选)
}
TraitAliasStatement 表示 trait 别名声明 (A::method as newName; A::method as public newName)
func NewTraitAliasStatement ¶
func NewTraitAliasStatement(pos lexer.Position, method *TraitMethodReference, alias *IdentifierNode, visibility string) *TraitAliasStatement
func (*TraitAliasStatement) Accept ¶
func (t *TraitAliasStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*TraitAliasStatement) GetChildren ¶
func (t *TraitAliasStatement) GetChildren() []Node
GetChildren 返回子节点
func (*TraitAliasStatement) String ¶
func (t *TraitAliasStatement) String() string
type TraitDeclaration ¶
type TraitDeclaration struct {
BaseNode
Name *IdentifierNode `json:"name"` // trait 名称
Properties []*PropertyDeclaration `json:"properties"` // trait 属性
Methods []*FunctionDeclaration `json:"methods"` // trait 方法
Body []Statement `json:"body"` // trait 体的其他语句(如 use 语句、常量等)
Attributes []*AttributeGroup `json:"attributes,omitempty"` // 属性组
}
TraitDeclaration 表示 trait 声明
func NewTraitDeclaration ¶
func NewTraitDeclaration(pos lexer.Position, name *IdentifierNode) *TraitDeclaration
func (*TraitDeclaration) GetChildren ¶
func (t *TraitDeclaration) GetChildren() []Node
GetChildren 返回子节点
func (*TraitDeclaration) String ¶
func (t *TraitDeclaration) String() string
type TraitMethodReference ¶
type TraitMethodReference struct {
BaseNode
Trait *IdentifierNode `json:"trait,omitempty"` // trait 名称(可选,如果为空表示当前方法)
Method *IdentifierNode `json:"method"` // 方法名称
}
TraitMethodReference 表示 trait 方法引用 (TraitName::methodName or methodName)
func NewTraitMethodReference ¶
func NewTraitMethodReference(pos lexer.Position, trait *IdentifierNode, method *IdentifierNode) *TraitMethodReference
func (*TraitMethodReference) Accept ¶
func (t *TraitMethodReference) Accept(visitor Visitor)
Accept 接受访问者
func (*TraitMethodReference) GetChildren ¶
func (t *TraitMethodReference) GetChildren() []Node
GetChildren 返回子节点
func (*TraitMethodReference) String ¶
func (t *TraitMethodReference) String() string
type TraitPrecedenceStatement ¶
type TraitPrecedenceStatement struct {
BaseNode
Method *TraitMethodReference `json:"method"` // 方法引用
InsteadOf []*IdentifierNode `json:"insteadOf"` // 替代的 traits
}
TraitPrecedenceStatement 表示 trait 优先级声明 (A::method insteadof B, C)
func NewTraitPrecedenceStatement ¶
func NewTraitPrecedenceStatement(pos lexer.Position, method *TraitMethodReference, insteadOf []*IdentifierNode) *TraitPrecedenceStatement
func (*TraitPrecedenceStatement) Accept ¶
func (t *TraitPrecedenceStatement) Accept(visitor Visitor)
Accept 接受访问者
func (*TraitPrecedenceStatement) GetChildren ¶
func (t *TraitPrecedenceStatement) GetChildren() []Node
GetChildren 返回子节点
func (*TraitPrecedenceStatement) String ¶
func (t *TraitPrecedenceStatement) String() string
type Transformer ¶
Transformer 转换器接口,用于修改AST节点
type TransformerFunc ¶
TransformerFunc 函数类型的转换器
func (TransformerFunc) Transform ¶
func (f TransformerFunc) Transform(node Node) Node
Transform 实现Transformer接口
type TryStatement ¶
type TryStatement struct {
BaseNode
Body []Statement `json:"body"`
CatchClauses []*CatchClause `json:"catchClauses,omitempty"`
FinallyBlock []Statement `json:"finallyBlock,omitempty"`
}
TryStatement try-catch-finally 语句
func NewTryStatement ¶
func NewTryStatement(pos lexer.Position) *TryStatement
func (*TryStatement) Accept ¶
func (t *TryStatement) Accept(visitor Visitor)
func (*TryStatement) GetChildren ¶
func (t *TryStatement) GetChildren() []Node
func (*TryStatement) String ¶
func (t *TryStatement) String() string
type TypeHint ¶
type TypeHint struct {
BaseNode
Name string `json:"name"` // Simple type name
Nullable bool `json:"nullable,omitempty"` // ?Type
UnionTypes []*TypeHint `json:"unionTypes,omitempty"` // Type1|Type2
IntersectionTypes []*TypeHint `json:"intersectionTypes,omitempty"` // Type1&Type2
}
TypeHint represents a PHP type hint
func NewIntersectionTypeHint ¶
NewIntersectionTypeHint creates an intersection type hint (Type1&Type2)
func NewSimpleTypeHint ¶
NewSimpleTypeHint creates a simple type hint (possibly nullable)
func NewTypeHint ¶
NewTypeHint creates a new type hint
func NewUnionTypeHint ¶
NewUnionTypeHint creates a union type hint (Type1|Type2)
func (*TypeHint) GetChildren ¶
TypeHint AST interface implementations
type UnaryExpression ¶
type UnaryExpression struct {
BaseNode
Operator string `json:"operator"`
Operand Expression `json:"operand"`
Prefix bool `json:"prefix"` // true for ++$a, false for $a++
}
UnaryExpression 一元表达式
func NewUnaryExpression ¶
func NewUnaryExpression(pos lexer.Position, operator string, operand Expression, prefix bool) *UnaryExpression
func (*UnaryExpression) GetChildren ¶
func (ue *UnaryExpression) GetChildren() []Node
GetChildren 返回子节点
func (*UnaryExpression) String ¶
func (ue *UnaryExpression) String() string
type UnsetStatement ¶
type UnsetStatement struct {
BaseNode
Variables []Expression `json:"variables"`
}
UnsetStatement unset 语句
func NewUnsetStatement ¶
func NewUnsetStatement(pos lexer.Position) *UnsetStatement
func (*UnsetStatement) Accept ¶
func (u *UnsetStatement) Accept(visitor Visitor)
func (*UnsetStatement) GetChildren ¶
func (u *UnsetStatement) GetChildren() []Node
func (*UnsetStatement) String ¶
func (u *UnsetStatement) String() string
type UseClause ¶
type UseClause struct {
Name *NamespaceNameExpression `json:"name"` // 导入的名称
Alias string `json:"alias"` // 别名 (如 use Foo as Bar)
Type string `json:"type"` // 类型: "class", "function", "const" 或空字符串
}
type UseStatement ¶
UseStatement 表示 use 语句(导入语句)
func NewUseStatement ¶
func NewUseStatement(pos lexer.Position) *UseStatement
func (*UseStatement) String ¶
func (u *UseStatement) String() string
type UseTraitStatement ¶
type UseTraitStatement struct {
BaseNode
Traits []*IdentifierNode `json:"traits"` // 使用的 traits
Adaptations []TraitAdaptation `json:"adaptations"` // trait 适配规则
}
UseTraitStatement 表示 trait 使用语句 (use TraitA, TraitB { ... })
func NewUseTraitStatement ¶
func NewUseTraitStatement(pos lexer.Position, traits []*IdentifierNode, adaptations []TraitAdaptation) *UseTraitStatement
func (*UseTraitStatement) GetChildren ¶
func (u *UseTraitStatement) GetChildren() []Node
GetChildren 返回子节点
func (*UseTraitStatement) String ¶
func (u *UseTraitStatement) String() string
type VisibilityModifierExpression ¶
type VisibilityModifierExpression struct {
BaseNode
Modifier string `json:"modifier"` // public, private, protected
}
VisibilityModifierExpression 表示可见性修饰符表达式
func NewVisibilityModifierExpression ¶
func NewVisibilityModifierExpression(pos lexer.Position, modifier string) *VisibilityModifierExpression
func (*VisibilityModifierExpression) Accept ¶
func (vme *VisibilityModifierExpression) Accept(visitor Visitor)
func (*VisibilityModifierExpression) GetChildren ¶
func (vme *VisibilityModifierExpression) GetChildren() []Node
func (*VisibilityModifierExpression) String ¶
func (vme *VisibilityModifierExpression) String() string
type Visitor ¶
Visitor 访问者接口,用于遍历AST节点
Example ¶
ExampleVisitor 演示如何使用访问者模式
package main
import (
"fmt"
"github.com/wudi/php-parser/ast"
"github.com/wudi/php-parser/lexer"
)
func main() {
pos := lexer.Position{Line: 1, Column: 1, Offset: 0}
builder := ast.NewASTBuilder()
// 构建一个简单的AST: $x = $x + 1;
x1 := builder.CreateVar(pos, "$x")
x2 := builder.CreateVar(pos, "$x")
one := builder.CreateZval(pos, 1)
addition := builder.CreateBinaryOp(pos, x2, one, "+")
assignment := builder.CreateAssign(pos, x1, addition)
// 计算变量$x的使用次数
varCount := ast.CountFunc(assignment, func(node ast.Node) bool {
if v, ok := node.(*ast.Variable); ok && v.Name == "$x" {
return true
}
return false
})
fmt.Printf("Variable $x used %d times\n", varCount)
// 找到所有二元操作
binaryOps := ast.FindAllFunc(assignment, func(node ast.Node) bool {
return node.GetKind() == ast.ASTBinaryOp
})
fmt.Printf("Found %d binary operations\n", len(binaryOps))
}
Output: Variable $x used 2 times Found 1 binary operations
type VisitorFunc ¶
VisitorFunc 函数类型的访问者
type WhileStatement ¶
type WhileStatement struct {
BaseNode
Test Expression `json:"test"`
Body []Statement `json:"body"`
}
WhileStatement while语句
func NewWhileStatement ¶
func NewWhileStatement(pos lexer.Position, test Expression) *WhileStatement
func (*WhileStatement) GetChildren ¶
func (ws *WhileStatement) GetChildren() []Node
GetChildren 返回子节点
func (*WhileStatement) String ¶
func (ws *WhileStatement) String() string
type YieldExpression ¶
type YieldExpression struct {
BaseNode
Key Expression `json:"key,omitempty"` // 可选的键(例如:yield $key => $value)
Value Expression `json:"value,omitempty"` // 可选的值
}
YieldExpression yield 表达式
func NewYieldExpression ¶
func NewYieldExpression(pos lexer.Position, key Expression, value Expression) *YieldExpression
func (*YieldExpression) Accept ¶
func (y *YieldExpression) Accept(visitor Visitor)
func (*YieldExpression) GetChildren ¶
func (y *YieldExpression) GetChildren() []Node
func (*YieldExpression) String ¶
func (y *YieldExpression) String() string
type YieldFromExpression ¶
type YieldFromExpression struct {
BaseNode
Expression Expression `json:"expression"` // 被 yield from 的表达式
}
YieldFromExpression yield from 表达式
func NewYieldFromExpression ¶
func NewYieldFromExpression(pos lexer.Position, expression Expression) *YieldFromExpression
func (*YieldFromExpression) Accept ¶
func (y *YieldFromExpression) Accept(visitor Visitor)
func (*YieldFromExpression) GetChildren ¶
func (y *YieldFromExpression) GetChildren() []Node
func (*YieldFromExpression) String ¶
func (y *YieldFromExpression) String() string