#25: save position within node

This commit is contained in:
z7zmey
2018-06-24 10:19:44 +03:00
parent 6ac67675d5
commit 1ebb0c6fad
268 changed files with 53606 additions and 7719 deletions

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltElse node
type AltElse struct {
Stmt node.Node
Position *position.Position
Stmt node.Node
}
// NewAltElse node constructor
func NewAltElse(Stmt node.Node) *AltElse {
return &AltElse{
Stmt,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *AltElse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltElse) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltElse) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltElseIf node
type AltElseIf struct {
Cond node.Node
Stmt node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
}
// NewAltElseIf node constructor
func NewAltElseIf(Cond node.Node, Stmt node.Node) *AltElseIf {
return &AltElseIf{
Cond,
Stmt,
Cond: Cond,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *AltElseIf) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltElseIf) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltElseIf) Attributes() map[string]interface{} {
return nil

View File

@@ -2,27 +2,39 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltFor node
type AltFor struct {
Init []node.Node
Cond []node.Node
Loop []node.Node
Stmt node.Node
Position *position.Position
Init []node.Node
Cond []node.Node
Loop []node.Node
Stmt node.Node
}
// NewAltFor node constructor
func NewAltFor(Init []node.Node, Cond []node.Node, Loop []node.Node, Stmt node.Node) *AltFor {
return &AltFor{
Init,
Cond,
Loop,
Stmt,
Init: Init,
Cond: Cond,
Loop: Loop,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *AltFor) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltFor) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltFor) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltForeach node
type AltForeach struct {
Position *position.Position
Expr node.Node
Key node.Node
Variable node.Node
@@ -16,13 +18,23 @@ type AltForeach struct {
// NewAltForeach node constructor
func NewAltForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *AltForeach {
return &AltForeach{
Expr,
Key,
Variable,
Stmt,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *AltForeach) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltForeach) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltForeach) Attributes() map[string]interface{} {
return nil

View File

@@ -2,27 +2,39 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltIf node
type AltIf struct {
Cond node.Node
Stmt node.Node
ElseIf []node.Node
Else node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
ElseIf []node.Node
Else node.Node
}
// NewAltIf node constructor
func NewAltIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *AltIf {
return &AltIf{
Cond,
Stmt,
ElseIf,
Else,
Cond: Cond,
Stmt: Stmt,
ElseIf: ElseIf,
Else: Else,
}
}
// SetPosition sets node position
func (n *AltIf) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltIf) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltIf) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltSwitch node
type AltSwitch struct {
Position *position.Position
Cond node.Node
CaseList *CaseList
}
@@ -14,11 +16,21 @@ type AltSwitch struct {
// NewAltSwitch node constructor
func NewAltSwitch(Cond node.Node, CaseList *CaseList) *AltSwitch {
return &AltSwitch{
Cond,
CaseList,
Cond: Cond,
CaseList: CaseList,
}
}
// SetPosition sets node position
func (n *AltSwitch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltSwitch) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltSwitch) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// AltWhile node
type AltWhile struct {
Cond node.Node
Stmt node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
}
// NewAltWhile node constructor
func NewAltWhile(Cond node.Node, Stmt node.Node) *AltWhile {
return &AltWhile{
Cond,
Stmt,
Cond: Cond,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *AltWhile) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *AltWhile) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *AltWhile) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Break node
type Break struct {
Expr node.Node
Position *position.Position
Expr node.Node
}
// NewBreak node constructor
func NewBreak(Expr node.Node) *Break {
return &Break{
Expr,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Break) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Break) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Break) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Case node
type Case struct {
Cond node.Node
Stmts []node.Node
Position *position.Position
Cond node.Node
Stmts []node.Node
}
// NewCase node constructor
func NewCase(Cond node.Node, Stmts []node.Node) *Case {
return &Case{
Cond,
Stmts,
Cond: Cond,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Case) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Case) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Case) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// CaseList node
type CaseList struct {
Cases []node.Node
Position *position.Position
Cases []node.Node
}
// NewCaseList node constructor
func NewCaseList(Cases []node.Node) *CaseList {
return &CaseList{
Cases,
Cases: Cases,
}
}
// SetPosition sets node position
func (n *CaseList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *CaseList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *CaseList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Catch node
type Catch struct {
Position *position.Position
Types []node.Node
Variable node.Node
Stmts []node.Node
@@ -15,12 +17,22 @@ type Catch struct {
// NewCatch node constructor
func NewCatch(Types []node.Node, Variable node.Node, Stmts []node.Node) *Catch {
return &Catch{
Types,
Variable,
Stmts,
Types: Types,
Variable: Variable,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Catch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Catch) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Catch) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Class node
type Class struct {
Position *position.Position
PhpDocComment string
ClassName node.Node
Modifiers []node.Node
@@ -19,16 +21,26 @@ type Class struct {
// NewClass node constructor
func NewClass(ClassName node.Node, Modifiers []node.Node, ArgumentList *node.ArgumentList, Extends *ClassExtends, Implements *ClassImplements, Stmts []node.Node, PhpDocComment string) *Class {
return &Class{
PhpDocComment,
ClassName,
Modifiers,
ArgumentList,
Extends,
Implements,
Stmts,
PhpDocComment: PhpDocComment,
ClassName: ClassName,
Modifiers: Modifiers,
ArgumentList: ArgumentList,
Extends: Extends,
Implements: Implements,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Class) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Class) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Class) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ClassConstList node
type ClassConstList struct {
Position *position.Position
Modifiers []node.Node
Consts []node.Node
}
@@ -14,11 +16,21 @@ type ClassConstList struct {
// NewClassConstList node constructor
func NewClassConstList(Modifiers []node.Node, Consts []node.Node) *ClassConstList {
return &ClassConstList{
Modifiers,
Consts,
Modifiers: Modifiers,
Consts: Consts,
}
}
// SetPosition sets node position
func (n *ClassConstList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClassConstList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ClassConstList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ClassExtends node
type ClassExtends struct {
Position *position.Position
ClassName node.Node
}
// NewClassExtends node constructor
func NewClassExtends(className node.Node) *ClassExtends {
return &ClassExtends{
className,
ClassName: className,
}
}
// SetPosition sets node position
func (n *ClassExtends) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClassExtends) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ClassExtends) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ClassImplements node
type ClassImplements struct {
Position *position.Position
InterfaceNames []node.Node
}
// NewClassImplements node constructor
func NewClassImplements(interfaceNames []node.Node) *ClassImplements {
return &ClassImplements{
interfaceNames,
InterfaceNames: interfaceNames,
}
}
// SetPosition sets node position
func (n *ClassImplements) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClassImplements) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ClassImplements) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ClassMethod node
type ClassMethod struct {
Position *position.Position
ReturnsRef bool
PhpDocComment string
MethodName node.Node
@@ -19,16 +21,26 @@ type ClassMethod struct {
// NewClassMethod node constructor
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
return &ClassMethod{
ReturnsRef,
PhpDocComment,
MethodName,
Modifiers,
Params,
ReturnType,
Stmt,
ReturnsRef: ReturnsRef,
PhpDocComment: PhpDocComment,
MethodName: MethodName,
Modifiers: Modifiers,
Params: Params,
ReturnType: ReturnType,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *ClassMethod) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClassMethod) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ClassMethod) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ConstList node
type ConstList struct {
Consts []node.Node
Position *position.Position
Consts []node.Node
}
// NewConstList node constructor
func NewConstList(Consts []node.Node) *ConstList {
return &ConstList{
Consts,
Consts: Consts,
}
}
// SetPosition sets node position
func (n *ConstList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ConstList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ConstList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Constant node
type Constant struct {
Position *position.Position
PhpDocComment string
ConstantName node.Node
Expr node.Node
@@ -15,12 +17,22 @@ type Constant struct {
// NewConstant node constructor
func NewConstant(ConstantName node.Node, Expr node.Node, PhpDocComment string) *Constant {
return &Constant{
PhpDocComment,
ConstantName,
Expr,
PhpDocComment: PhpDocComment,
ConstantName: ConstantName,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Constant) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Constant) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Constant) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Continue node
type Continue struct {
Expr node.Node
Position *position.Position
Expr node.Node
}
// NewContinue node constructor
func NewContinue(Expr node.Node) *Continue {
return &Continue{
Expr,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Continue) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Continue) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Continue) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Declare node
type Declare struct {
Consts []node.Node
Stmt node.Node
Position *position.Position
Consts []node.Node
Stmt node.Node
}
// NewDeclare node constructor
func NewDeclare(Consts []node.Node, Stmt node.Node) *Declare {
return &Declare{
Consts,
Stmt,
Consts: Consts,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *Declare) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Declare) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Declare) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Default node
type Default struct {
Stmts []node.Node
Position *position.Position
Stmts []node.Node
}
// NewDefault node constructor
func NewDefault(Stmts []node.Node) *Default {
return &Default{
Stmts,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Default) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Default) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Default) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Do node
type Do struct {
Stmt node.Node
Cond node.Node
Position *position.Position
Stmt node.Node
Cond node.Node
}
// NewDo node constructor
func NewDo(Stmt node.Node, Cond node.Node) *Do {
return &Do{
Stmt,
Cond,
Stmt: Stmt,
Cond: Cond,
}
}
// SetPosition sets node position
func (n *Do) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Do) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Do) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Echo node
type Echo struct {
Exprs []node.Node
Position *position.Position
Exprs []node.Node
}
// NewEcho node constructor
func NewEcho(Exprs []node.Node) *Echo {
return &Echo{
Exprs,
Exprs: Exprs,
}
}
// SetPosition sets node position
func (n *Echo) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Echo) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Echo) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Else node
type Else struct {
Stmt node.Node
Position *position.Position
Stmt node.Node
}
// NewElse node constructor
func NewElse(Stmt node.Node) *Else {
return &Else{
Stmt,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *Else) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Else) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Else) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// ElseIf node
type ElseIf struct {
Cond node.Node
Stmt node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
}
// NewElseIf node constructor
func NewElseIf(Cond node.Node, Stmt node.Node) *ElseIf {
return &ElseIf{
Cond,
Stmt,
Cond: Cond,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *ElseIf) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ElseIf) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *ElseIf) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Expression node
type Expression struct {
Expr node.Node
Position *position.Position
Expr node.Node
}
// NewExpression node constructor
func NewExpression(Expr node.Node) *Expression {
return &Expression{
Expr,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Expression) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Expression) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Expression) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Finally node
type Finally struct {
Stmts []node.Node
Position *position.Position
Stmts []node.Node
}
// NewFinally node constructor
func NewFinally(Stmts []node.Node) *Finally {
return &Finally{
Stmts,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Finally) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Finally) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Finally) Attributes() map[string]interface{} {
return nil

View File

@@ -2,27 +2,39 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// For node
type For struct {
Init []node.Node
Cond []node.Node
Loop []node.Node
Stmt node.Node
Position *position.Position
Init []node.Node
Cond []node.Node
Loop []node.Node
Stmt node.Node
}
// NewFor node constructor
func NewFor(Init []node.Node, Cond []node.Node, Loop []node.Node, Stmt node.Node) *For {
return &For{
Init,
Cond,
Loop,
Stmt,
Init: Init,
Cond: Cond,
Loop: Loop,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *For) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *For) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *For) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Foreach node
type Foreach struct {
Position *position.Position
Expr node.Node
Key node.Node
Variable node.Node
@@ -16,13 +18,23 @@ type Foreach struct {
// NewForeach node constructor
func NewForeach(Expr node.Node, Key node.Node, Variable node.Node, Stmt node.Node) *Foreach {
return &Foreach{
Expr,
Key,
Variable,
Stmt,
Expr: Expr,
Key: Key,
Variable: Variable,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *Foreach) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Foreach) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Foreach) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Function node
type Function struct {
Position *position.Position
ReturnsRef bool
PhpDocComment string
FunctionName node.Node
@@ -18,15 +20,25 @@ type Function struct {
// NewFunction node constructor
func NewFunction(FunctionName node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmts []node.Node, PhpDocComment string) *Function {
return &Function{
ReturnsRef,
PhpDocComment,
FunctionName,
Params,
ReturnType,
Stmts,
ReturnsRef: ReturnsRef,
PhpDocComment: PhpDocComment,
FunctionName: FunctionName,
Params: Params,
ReturnType: ReturnType,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Function) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Function) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Function) Attributes() map[string]interface{} {
// return n.attributes

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Global node
type Global struct {
Vars []node.Node
Position *position.Position
Vars []node.Node
}
// NewGlobal node constructor
func NewGlobal(Vars []node.Node) *Global {
return &Global{
Vars,
Vars: Vars,
}
}
// SetPosition sets node position
func (n *Global) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Global) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Global) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Goto node
type Goto struct {
Label node.Node
Position *position.Position
Label node.Node
}
// NewGoto node constructor
func NewGoto(Label node.Node) *Goto {
return &Goto{
Label,
Label: Label,
}
}
// SetPosition sets node position
func (n *Goto) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Goto) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Goto) Attributes() map[string]interface{} {
return nil

View File

@@ -2,25 +2,37 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// GroupUse node
type GroupUse struct {
UseType node.Node
Prefix node.Node
UseList []node.Node
Position *position.Position
UseType node.Node
Prefix node.Node
UseList []node.Node
}
// NewGroupUse node constructor
func NewGroupUse(UseType node.Node, Prefix node.Node, UseList []node.Node) *GroupUse {
return &GroupUse{
UseType,
Prefix,
UseList,
UseType: UseType,
Prefix: Prefix,
UseList: UseList,
}
}
// SetPosition sets node position
func (n *GroupUse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *GroupUse) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *GroupUse) Attributes() map[string]interface{} {
return nil

View File

@@ -1,9 +1,13 @@
package stmt
import "github.com/z7zmey/php-parser/walker"
import (
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// HaltCompiler node
type HaltCompiler struct {
Position *position.Position
}
// NewHaltCompiler node constructor
@@ -11,6 +15,16 @@ func NewHaltCompiler() *HaltCompiler {
return &HaltCompiler{}
}
// SetPosition sets node position
func (n *HaltCompiler) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *HaltCompiler) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *HaltCompiler) Attributes() map[string]interface{} {
return nil

View File

@@ -2,27 +2,39 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// If node
type If struct {
Cond node.Node
Stmt node.Node
ElseIf []node.Node
Else node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
ElseIf []node.Node
Else node.Node
}
// NewIf node constructor
func NewIf(Cond node.Node, Stmt node.Node, ElseIf []node.Node, Else node.Node) *If {
return &If{
Cond,
Stmt,
ElseIf,
Else,
Cond: Cond,
Stmt: Stmt,
ElseIf: ElseIf,
Else: Else,
}
}
// SetPosition sets node position
func (n *If) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *If) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *If) Attributes() map[string]interface{} {
return nil

View File

@@ -1,19 +1,33 @@
package stmt
import "github.com/z7zmey/php-parser/walker"
import (
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// InlineHtml node
type InlineHtml struct {
Value string
Position *position.Position
Value string
}
// NewInlineHtml node constructor
func NewInlineHtml(Value string) *InlineHtml {
return &InlineHtml{
Value,
Value: Value,
}
}
// SetPosition sets node position
func (n *InlineHtml) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *InlineHtml) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *InlineHtml) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Interface node
type Interface struct {
Position *position.Position
PhpDocComment string
InterfaceName node.Node
Extends *InterfaceExtends
@@ -16,13 +18,23 @@ type Interface struct {
// NewInterface node constructor
func NewInterface(InterfaceName node.Node, Extends *InterfaceExtends, Stmts []node.Node, PhpDocComment string) *Interface {
return &Interface{
PhpDocComment,
InterfaceName,
Extends,
Stmts,
PhpDocComment: PhpDocComment,
InterfaceName: InterfaceName,
Extends: Extends,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Interface) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Interface) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Interface) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// InterfaceExtends node
type InterfaceExtends struct {
Position *position.Position
InterfaceNames []node.Node
}
// NewInterfaceExtends node constructor
func NewInterfaceExtends(InterfaceNames []node.Node) *InterfaceExtends {
return &InterfaceExtends{
InterfaceNames,
InterfaceNames: InterfaceNames,
}
}
// SetPosition sets node position
func (n *InterfaceExtends) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *InterfaceExtends) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *InterfaceExtends) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Label node
type Label struct {
Position *position.Position
LabelName node.Node
}
// NewLabel node constructor
func NewLabel(LabelName node.Node) *Label {
return &Label{
LabelName,
LabelName: LabelName,
}
}
// SetPosition sets node position
func (n *Label) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Label) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Label) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Namespace node
type Namespace struct {
Position *position.Position
NamespaceName node.Node
Stmts []node.Node
}
@@ -14,11 +16,21 @@ type Namespace struct {
// NewNamespace node constructor
func NewNamespace(NamespaceName node.Node, Stmts []node.Node) *Namespace {
return &Namespace{
NamespaceName,
Stmts,
NamespaceName: NamespaceName,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Namespace) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Namespace) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Namespace) Attributes() map[string]interface{} {
return nil

View File

@@ -1,9 +1,13 @@
package stmt
import "github.com/z7zmey/php-parser/walker"
import (
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Nop node
type Nop struct {
Position *position.Position
}
// NewNop node constructor
@@ -11,6 +15,16 @@ func NewNop() *Nop {
return &Nop{}
}
// SetPosition sets node position
func (n *Nop) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Nop) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Nop) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Property node
type Property struct {
Position *position.Position
PhpDocComment string
Variable node.Node
Expr node.Node
@@ -15,12 +17,22 @@ type Property struct {
// NewProperty node constructor
func NewProperty(Variable node.Node, Expr node.Node, PhpDocComment string) *Property {
return &Property{
PhpDocComment,
Variable,
Expr,
PhpDocComment: PhpDocComment,
Variable: Variable,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Property) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Property) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Property) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// PropertyList node
type PropertyList struct {
Position *position.Position
Modifiers []node.Node
Properties []node.Node
}
@@ -14,11 +16,21 @@ type PropertyList struct {
// NewPropertyList node constructor
func NewPropertyList(Modifiers []node.Node, Properties []node.Node) *PropertyList {
return &PropertyList{
Modifiers,
Properties,
Modifiers: Modifiers,
Properties: Properties,
}
}
// SetPosition sets node position
func (n *PropertyList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PropertyList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *PropertyList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Return node
type Return struct {
Expr node.Node
Position *position.Position
Expr node.Node
}
// NewReturn node constructor
func NewReturn(Expr node.Node) *Return {
return &Return{
Expr,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Return) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Return) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Return) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Static node
type Static struct {
Vars []node.Node
Position *position.Position
Vars []node.Node
}
// NewStatic node constructor
func NewStatic(Vars []node.Node) *Static {
return &Static{
Vars,
Vars: Vars,
}
}
// SetPosition sets node position
func (n *Static) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Static) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Static) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// StaticVar node
type StaticVar struct {
Position *position.Position
Variable node.Node
Expr node.Node
}
@@ -14,11 +16,21 @@ type StaticVar struct {
// NewStaticVar node constructor
func NewStaticVar(Variable node.Node, Expr node.Node) *StaticVar {
return &StaticVar{
Variable,
Expr,
Variable: Variable,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *StaticVar) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *StaticVar) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *StaticVar) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// StmtList node
type StmtList struct {
Stmts []node.Node
Position *position.Position
Stmts []node.Node
}
// NewStmtList node constructor
func NewStmtList(Stmts []node.Node) *StmtList {
return &StmtList{
Stmts,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *StmtList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *StmtList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *StmtList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Switch node
type Switch struct {
Position *position.Position
Cond node.Node
CaseList *CaseList
}
@@ -14,11 +16,21 @@ type Switch struct {
// NewSwitch node constructor
func NewSwitch(Cond node.Node, CaseList *CaseList) *Switch {
return &Switch{
Cond,
CaseList,
Cond: Cond,
CaseList: CaseList,
}
}
// SetPosition sets node position
func (n *Switch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Switch) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Switch) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Throw node
type Throw struct {
Expr node.Node
Position *position.Position
Expr node.Node
}
// NewThrow node constructor
func NewThrow(Expr node.Node) *Throw {
return &Throw{
Expr,
Expr: Expr,
}
}
// SetPosition sets node position
func (n *Throw) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Throw) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Throw) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Trait node
type Trait struct {
Position *position.Position
PhpDocComment string
TraitName node.Node
Stmts []node.Node
@@ -15,12 +17,22 @@ type Trait struct {
// NewTrait node constructor
func NewTrait(TraitName node.Node, Stmts []node.Node, PhpDocComment string) *Trait {
return &Trait{
PhpDocComment,
TraitName,
Stmts,
PhpDocComment: PhpDocComment,
TraitName: TraitName,
Stmts: Stmts,
}
}
// SetPosition sets node position
func (n *Trait) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Trait) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Trait) Attributes() map[string]interface{} {
return map[string]interface{}{

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitAdaptationList node
type TraitAdaptationList struct {
Position *position.Position
Adaptations []node.Node
}
// NewTraitAdaptationList node constructor
func NewTraitAdaptationList(Adaptations []node.Node) *TraitAdaptationList {
return &TraitAdaptationList{
Adaptations,
Adaptations: Adaptations,
}
}
// SetPosition sets node position
func (n *TraitAdaptationList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitAdaptationList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *TraitAdaptationList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitMethodRef node
type TraitMethodRef struct {
Trait node.Node
Method node.Node
Position *position.Position
Trait node.Node
Method node.Node
}
// NewTraitMethodRef node constructor
func NewTraitMethodRef(Trait node.Node, Method node.Node) *TraitMethodRef {
return &TraitMethodRef{
Trait,
Method,
Trait: Trait,
Method: Method,
}
}
// SetPosition sets node position
func (n *TraitMethodRef) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitMethodRef) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *TraitMethodRef) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitUse node
type TraitUse struct {
Position *position.Position
Traits []node.Node
TraitAdaptationList *TraitAdaptationList
}
@@ -14,11 +16,21 @@ type TraitUse struct {
// NewTraitUse node constructor
func NewTraitUse(Traits []node.Node, InnerAdaptationList *TraitAdaptationList) *TraitUse {
return &TraitUse{
Traits,
InnerAdaptationList,
Traits: Traits,
TraitAdaptationList: InnerAdaptationList,
}
}
// SetPosition sets node position
func (n *TraitUse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitUse) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *TraitUse) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitUseAlias node
type TraitUseAlias struct {
Position *position.Position
Ref node.Node
Modifier node.Node
Alias node.Node
@@ -15,12 +17,22 @@ type TraitUseAlias struct {
// NewTraitUseAlias node constructor
func NewTraitUseAlias(Ref node.Node, Modifier node.Node, Alias node.Node) *TraitUseAlias {
return &TraitUseAlias{
Ref,
Modifier,
Alias,
Ref: Ref,
Modifier: Modifier,
Alias: Alias,
}
}
// SetPosition sets node position
func (n *TraitUseAlias) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitUseAlias) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *TraitUseAlias) Attributes() map[string]interface{} {
return nil

View File

@@ -2,11 +2,13 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// TraitUsePrecedence node
type TraitUsePrecedence struct {
Position *position.Position
Ref node.Node
Insteadof []node.Node
}
@@ -14,11 +16,21 @@ type TraitUsePrecedence struct {
// NewTraitUsePrecedence node constructor
func NewTraitUsePrecedence(Ref node.Node, Insteadof []node.Node) *TraitUsePrecedence {
return &TraitUsePrecedence{
Ref,
Insteadof,
Ref: Ref,
Insteadof: Insteadof,
}
}
// SetPosition sets node position
func (n *TraitUsePrecedence) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *TraitUsePrecedence) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *TraitUsePrecedence) Attributes() map[string]interface{} {
return nil

View File

@@ -2,25 +2,37 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Try node
type Try struct {
Stmts []node.Node
Catches []node.Node
Finally node.Node
Position *position.Position
Stmts []node.Node
Catches []node.Node
Finally node.Node
}
// NewTry node constructor
func NewTry(Stmts []node.Node, Catches []node.Node, Finally node.Node) *Try {
return &Try{
Stmts,
Catches,
Finally,
Stmts: Stmts,
Catches: Catches,
Finally: Finally,
}
}
// SetPosition sets node position
func (n *Try) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Try) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Try) Attributes() map[string]interface{} {
return nil

View File

@@ -2,21 +2,33 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Unset node
type Unset struct {
Vars []node.Node
Position *position.Position
Vars []node.Node
}
// NewUnset node constructor
func NewUnset(Vars []node.Node) *Unset {
return &Unset{
Vars,
Vars: Vars,
}
}
// SetPosition sets node position
func (n *Unset) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Unset) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Unset) Attributes() map[string]interface{} {
return nil

View File

@@ -2,25 +2,37 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// Use node
type Use struct {
UseType node.Node
Use node.Node
Alias node.Node
Position *position.Position
UseType node.Node
Use node.Node
Alias node.Node
}
// NewUse node constructor
func NewUse(UseType node.Node, use node.Node, Alias node.Node) *Use {
return &Use{
UseType,
use,
Alias,
UseType: UseType,
Use: use,
Alias: Alias,
}
}
// SetPosition sets node position
func (n *Use) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Use) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *Use) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// UseList node
type UseList struct {
UseType node.Node
Uses []node.Node
Position *position.Position
UseType node.Node
Uses []node.Node
}
// NewUseList node constructor
func NewUseList(UseType node.Node, Uses []node.Node) *UseList {
return &UseList{
UseType,
Uses,
UseType: UseType,
Uses: Uses,
}
}
// SetPosition sets node position
func (n *UseList) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *UseList) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *UseList) Attributes() map[string]interface{} {
return nil

View File

@@ -2,23 +2,35 @@ package stmt
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker"
)
// While node
type While struct {
Cond node.Node
Stmt node.Node
Position *position.Position
Cond node.Node
Stmt node.Node
}
// NewWhile node constructor
func NewWhile(Cond node.Node, Stmt node.Node) *While {
return &While{
Cond,
Stmt,
Cond: Cond,
Stmt: Stmt,
}
}
// SetPosition sets node position
func (n *While) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *While) GetPosition() *position.Position {
return n.Position
}
// Attributes returns node attributes as map
func (n *While) Attributes() map[string]interface{} {
return nil

View File

@@ -6,6 +6,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/position"
"github.com/kylelemons/godebug/pretty"
"github.com/z7zmey/php-parser/node"
@@ -34,10 +35,46 @@ func TestAltIf(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 3,
StartPos: 6,
EndPos: 23,
},
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 2,
EndLine: 3,
StartPos: 6,
EndPos: 23,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
}
@@ -61,14 +98,80 @@ func TestAltElseIf(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
EndPos: 38,
},
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
EndPos: 38,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
ElseIf: []node.Node{
&stmt.AltElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
EndPos: 27,
},
Value: "b",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
},
@@ -94,12 +197,62 @@ func TestAltElse(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
EndPos: 31,
},
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 2,
EndLine: 4,
StartPos: 6,
EndPos: 31,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
Else: &stmt.AltElse{
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
EndPos: -1,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
},
@@ -126,22 +279,132 @@ func TestAltElseElseIf(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 6,
EndPos: 61,
},
Stmts: []node.Node{
&stmt.AltIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 6,
EndPos: 61,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
ElseIf: []node.Node{
&stmt.AltElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 18,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 26,
EndPos: 27,
},
Value: "b",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
&stmt.AltElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 33,
EndPos: -1,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
EndPos: 42,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
EndPos: 42,
},
Value: "c",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
Else: &stmt.AltElse{
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 48,
EndPos: -1,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,24 +17,103 @@ func TestClassConstList(t *testing.T) {
src := `<? class foo{ public const FOO = 1, BAR = 2; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 46,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 46,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassConstList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 44,
},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Value: "public",
},
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 34,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "FOO"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 30,
},
Value: "FOO",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
EndPos: 34,
},
Value: "1",
},
},
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 43,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "BAR"},
Expr: &scalar.Lnumber{Value: "2"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 39,
},
Value: "BAR",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
EndPos: 43,
},
Value: "2",
},
},
},
},
@@ -52,21 +132,92 @@ func TestClassConstListWithoutModifiers(t *testing.T) {
src := `<? class foo{ const FOO = 1, BAR = 2; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 39,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 39,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassConstList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 37,
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 27,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "FOO"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 23,
},
Value: "FOO",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 27,
},
Value: "1",
},
},
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 36,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "BAR"},
Expr: &scalar.Lnumber{Value: "2"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 32,
},
Value: "BAR",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 36,
},
Value: "2",
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,14 +17,56 @@ func TestSimpleClassMethod(t *testing.T) {
src := `<? class foo{ function bar() {} }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 33,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 33,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassMethod{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 31,
},
ReturnsRef: false,
PhpDocComment: "",
MethodName: &node.Identifier{Value: "bar"},
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 26,
},
Value: "bar",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 31,
},
Stmts: []node.Node{},
},
},
@@ -47,30 +90,115 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
src := `<? class foo{ final private function bar() {} protected function baz() {} }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 75,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 75,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 45,
},
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 40,
},
Value: "bar",
},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
&node.Identifier{Value: "private"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 19,
},
Value: "final",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 27,
},
Value: "private",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
EndPos: 45,
},
Stmts: []node.Node{},
},
},
&stmt.ClassMethod{
PhpDocComment: "",
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
EndPos: 73,
},
ReturnsRef: false,
MethodName: &node.Identifier{Value: "baz"},
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 66,
EndPos: 68,
},
Value: "baz",
},
Modifiers: []node.Node{
&node.Identifier{Value: "protected"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
EndPos: 55,
},
Value: "protected",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 72,
EndPos: 73,
},
Stmts: []node.Node{},
},
},
@@ -94,19 +222,76 @@ func TestPhp5ClassMethod(t *testing.T) {
src := `<? class foo{ public static function &bar() {} }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 48,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 48,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 46,
},
ReturnsRef: true,
MethodName: &node.Identifier{Value: "bar"},
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 41,
},
Value: "bar",
},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Value: "public",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 27,
},
Value: "static",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
EndPos: 46,
},
Stmts: []node.Node{},
},
},
@@ -125,24 +310,95 @@ func TestPhp7ClassMethod(t *testing.T) {
src := `<? class foo{ public static function &bar(): void {} }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 54,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 54,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 52,
},
ReturnsRef: true,
MethodName: &node.Identifier{Value: "bar"},
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 41,
},
Value: "bar",
},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Value: "public",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 27,
},
Value: "static",
},
},
ReturnType: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
EndPos: 49,
},
Parts: []node.Node{
&name.NamePart{Value: "void"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
EndPos: 49,
},
Value: "void",
},
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
EndPos: 52,
},
Stmts: []node.Node{},
},
},
@@ -161,20 +417,88 @@ func TestAbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ abstract public function bar(); }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 56,
},
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
ClassName: &node.Identifier{Value: "Foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 56,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 21,
},
Value: "Foo",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
Value: "abstract",
},
},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "abstract"},
&node.Identifier{Value: "public"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 54,
},
ReturnsRef: false,
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 49,
EndPos: 51,
},
Value: "bar",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 31,
},
Value: "abstract",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 38,
},
Value: "public",
},
},
Stmt: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 54,
EndPos: 54,
},
},
Stmt: &stmt.Nop{},
},
},
},
@@ -196,24 +520,98 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
src := `<? abstract class Foo{ public function bar(): void; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 53,
},
Stmts: []node.Node{
&stmt.Class{
Modifiers: []node.Node{&node.Identifier{Value: "abstract"}},
ClassName: &node.Identifier{Value: "Foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 53,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 21,
},
Value: "Foo",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
Value: "abstract",
},
},
Stmts: []node.Node{
&stmt.ClassMethod{
PhpDocComment: "",
ReturnsRef: false,
MethodName: &node.Identifier{Value: "bar"},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 51,
},
ReturnType: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "void"},
ReturnsRef: false,
PhpDocComment: "",
MethodName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 40,
EndPos: 42,
},
Value: "bar",
},
Modifiers: []node.Node{
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 29,
},
Value: "public",
},
},
ReturnType: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
EndPos: 50,
},
Parts: []node.Node{
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 47,
EndPos: 50,
},
Value: "void",
},
},
},
Stmt: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
EndPos: 51,
},
},
Stmt: &stmt.Nop{},
},
},
},

View File

@@ -6,6 +6,7 @@ import (
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -17,10 +18,31 @@ func TestSimpleClass(t *testing.T) {
src := `<? class foo{ }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{},
},
},
}
@@ -40,11 +62,40 @@ func TestAbstractClass(t *testing.T) {
src := `<? abstract class foo{ }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 21,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{Value: "abstract"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
Value: "abstract",
},
},
Stmts: []node.Node{},
},
@@ -66,16 +117,65 @@ func TestClassExtends(t *testing.T) {
src := `<? final class foo extends bar { }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 34,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 34,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 18,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 8,
},
Value: "final",
},
},
Extends: &stmt.ClassExtends{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 30,
},
ClassName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 30,
},
Parts: []node.Node{
&name.NamePart{Value: "bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 30,
},
Value: "bar",
},
},
},
},
@@ -99,17 +199,66 @@ func TestClassImplement(t *testing.T) {
src := `<? final class foo implements bar { }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 37,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 37,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 18,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 8,
},
Value: "final",
},
},
Implements: &stmt.ClassImplements{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 33,
},
InterfaceNames: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Parts: []node.Node{
&name.NamePart{Value: "bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "bar",
},
},
},
},
@@ -134,22 +283,85 @@ func TestClassImplements(t *testing.T) {
src := `<? final class foo implements bar, baz { }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 42,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 42,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 18,
},
Value: "foo",
},
Modifiers: []node.Node{
&node.Identifier{Value: "final"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 8,
},
Value: "final",
},
},
Implements: &stmt.ClassImplements{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 38,
},
InterfaceNames: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Parts: []node.Node{
&name.NamePart{Value: "bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 38,
},
Parts: []node.Node{
&name.NamePart{Value: "baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 38,
},
Value: "baz",
},
},
},
},
@@ -174,28 +386,114 @@ func TestAnonimousClass(t *testing.T) {
src := `<? new class() extends foo implements bar, baz { };`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
Expr: &expr.New{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 50,
},
Class: &stmt.Class{
ArgumentList: &node.ArgumentList{},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 50,
},
PhpDocComment: "",
ArgumentList: &node.ArgumentList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
},
Extends: &stmt.ClassExtends{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 26,
},
ClassName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 26,
},
Parts: []node.Node{
&name.NamePart{Value: "foo"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 26,
},
Value: "foo",
},
},
},
},
Implements: &stmt.ClassImplements{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 46,
},
InterfaceNames: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 41,
},
Parts: []node.Node{
&name.NamePart{Value: "bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 41,
},
Value: "bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
EndPos: 46,
},
Parts: []node.Node{
&name.NamePart{Value: "baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 44,
EndPos: 46,
},
Value: "baz",
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,18 +17,74 @@ func TestConstList(t *testing.T) {
src := `<? const FOO = 1, BAR = 2;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 26,
},
Stmts: []node.Node{
&stmt.ConstList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 26,
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 16,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "FOO"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "FOO",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 16,
},
Value: "1",
},
},
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 25,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "BAR"},
Expr: &scalar.Lnumber{Value: "2"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 21,
},
Value: "BAR",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 25,
},
Value: "2",
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,12 +17,45 @@ func TestContinueEmpty(t *testing.T) {
src := `<? while (1) { continue; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 26,
},
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 26,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 26,
},
Stmts: []node.Node{
&stmt.Continue{Expr: nil},
&stmt.Continue{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 24,
},
},
},
},
},
@@ -43,13 +77,53 @@ func TestContinueLight(t *testing.T) {
src := `<? while (1) { continue 2; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 28,
},
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 28,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 28,
},
Stmts: []node.Node{
&stmt.Continue{
Expr: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 26,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 25,
},
Value: "2",
},
},
},
},
@@ -72,13 +146,53 @@ func TestContinue(t *testing.T) {
src := `<? while (1) { continue(3); }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 29,
},
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 29,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 29,
},
Stmts: []node.Node{
&stmt.Continue{
Expr: &scalar.Lnumber{Value: "3"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 27,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 25,
},
Value: "3",
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,16 +17,57 @@ func TestDeclare(t *testing.T) {
src := `<? declare(ticks=1);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 20,
},
Stmts: []node.Node{
&stmt.Declare{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 20,
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 18,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "ticks"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 16,
},
Value: "ticks",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 18,
},
Value: "1",
},
},
},
Stmt: &stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 20,
},
},
Stmt: &stmt.Nop{},
},
},
}
@@ -45,21 +87,83 @@ func TestDeclareStmts(t *testing.T) {
src := `<? declare(ticks=1, strict_types=1) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 38,
},
Stmts: []node.Node{
&stmt.Declare{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 38,
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 18,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "ticks"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 16,
},
Value: "ticks",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 18,
},
Value: "1",
},
},
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 34,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "strict_types"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 32,
},
Value: "strict_types",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
EndPos: 34,
},
Value: "1",
},
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 38,
},
Stmts: []node.Node{},
},
},
@@ -81,16 +185,56 @@ func TestAltDeclare(t *testing.T) {
src := `<? declare(ticks=1): enddeclare;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
Stmts: []node.Node{
&stmt.Declare{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
Consts: []node.Node{
&stmt.Constant{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 18,
},
PhpDocComment: "",
ConstantName: &node.Identifier{Value: "ticks"},
Expr: &scalar.Lnumber{Value: "1"},
ConstantName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 16,
},
Value: "ticks",
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 18,
},
Value: "1",
},
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 32,
},
Stmts: []node.Node{},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,12 +17,38 @@ func TestDo(t *testing.T) {
src := `<? do {} while(1);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 18,
},
Stmts: []node.Node{
&stmt.Do{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 18,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 8,
},
Stmts: []node.Node{},
},
Cond: &scalar.Lnumber{Value: "1"},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 16,
},
Value: "1",
},
},
},
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node/scalar"
@@ -18,13 +19,47 @@ func TestSimpleEcho(t *testing.T) {
src := `<? echo $a, 1;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Stmts: []node.Node{
&stmt.Echo{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Exprs: []node.Node{
&expr.Variable{
VarName: &node.Identifier{Value: "a"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 10,
},
Value: "a",
},
},
&scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 13,
},
Value: "1",
},
&scalar.Lnumber{Value: "1"},
},
},
},
@@ -45,11 +80,37 @@ func TestEcho(t *testing.T) {
src := `<? echo($a);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Stmts: []node.Node{
&stmt.Echo{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Exprs: []node.Node{
&expr.Variable{
VarName: &node.Identifier{Value: "a"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 10,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 9,
EndPos: 10,
},
Value: "a",
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,9 +17,29 @@ func TestExpression(t *testing.T) {
src := `<? 1;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 5,
},
Stmts: []node.Node{
&stmt.Expression{
Expr: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 5,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 4,
},
Value: "1",
},
},
},
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/assign"
@@ -21,29 +22,153 @@ func TestFor(t *testing.T) {
src := `<? for($i = 0; $i < 10; $i++, $i++) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 38,
},
Stmts: []node.Node{
&stmt.For{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 38,
},
Init: []node.Node{
&assign.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Expression: &scalar.Lnumber{Value: "0"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 13,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "i",
},
},
Expression: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 13,
},
Value: "0",
},
},
},
Cond: []node.Node{
&binary.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Right: &scalar.Lnumber{Value: "10"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 22,
},
Left: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 17,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 17,
},
Value: "i",
},
},
Right: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 22,
},
Value: "10",
},
},
},
Loop: []node.Node{
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 28,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
Value: "i",
},
},
},
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 34,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 32,
},
Value: "i",
},
},
},
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 38,
},
Stmts: []node.Node{},
},
},
},
}
@@ -63,20 +188,92 @@ func TestAltFor(t *testing.T) {
src := `<? for(; $i < 10; $i++) : endfor;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 33,
},
Stmts: []node.Node{
&stmt.AltFor{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 33,
},
Cond: []node.Node{
&binary.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Right: &scalar.Lnumber{Value: "10"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 16,
},
Left: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
Value: "i",
},
},
Right: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
Value: "10",
},
},
},
Loop: []node.Node{
&expr.PostInc{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "i"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 22,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "i",
},
},
},
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,11 +17,63 @@ func TestForeach(t *testing.T) {
src := `<? foreach ($a as $v) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Value: "a",
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "v",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Stmts: []node.Node{},
},
},
},
}
@@ -40,11 +93,55 @@ func TestForeachExpr(t *testing.T) {
src := `<? foreach ([] as $v) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 24,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Items: []node.Node{},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "v",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Stmts: []node.Node{},
},
},
},
}
@@ -64,11 +161,63 @@ func TestAltForeach(t *testing.T) {
src := `<? foreach ($a as $v) : endforeach;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 35,
},
Stmts: []node.Node{
&stmt.AltForeach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 35,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Value: "a",
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "v",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: -1,
EndLine: -1,
StartPos: -1,
EndPos: -1,
},
Stmts: []node.Node{},
},
},
},
}
@@ -88,12 +237,80 @@ func TestForeachWithKey(t *testing.T) {
src := `<? foreach ($a as $k => $v) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Value: "a",
},
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "k",
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
Value: "v",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
Stmts: []node.Node{},
},
},
},
}
@@ -113,12 +330,72 @@ func TestForeachExprWithKey(t *testing.T) {
src := `<? foreach ([] as $k => $v) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.ShortArray{Items: []node.Node{}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Expr: &expr.ShortArray{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Items: []node.Node{},
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "k",
},
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 26,
},
Value: "v",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
Stmts: []node.Node{},
},
},
},
}
@@ -138,12 +415,88 @@ func TestForeachWithRef(t *testing.T) {
src := `<? foreach ($a as $k => &$v) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 31,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
Variable: &expr.Reference{Variable: &expr.Variable{VarName: &node.Identifier{Value: "v"}}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 31,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Value: "a",
},
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "k",
},
},
Variable: &expr.Reference{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 27,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 27,
},
Value: "v",
},
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 31,
},
Stmts: []node.Node{},
},
},
},
}
@@ -163,18 +516,98 @@ func TestForeachWithList(t *testing.T) {
src := `<? foreach ($a as $k => list($v)) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 36,
},
Stmts: []node.Node{
&stmt.Foreach{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Key: &expr.Variable{VarName: &node.Identifier{Value: "k"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 36,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 14,
},
Value: "a",
},
},
Key: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "k",
},
},
Variable: &expr.List{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 32,
},
Items: []node.Node{
&expr.ArrayItem{
Val: &expr.Variable{VarName: &node.Identifier{Value: "v"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 31,
},
Val: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 31,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 31,
},
Value: "v",
},
},
},
},
},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 36,
},
Stmts: []node.Node{},
},
},
},
}

View File

@@ -6,6 +6,7 @@ import (
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
@@ -18,12 +19,32 @@ func TestSimpleFunction(t *testing.T) {
src := `<? function foo() {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 20,
},
Stmts: []node.Node{
&stmt.Function{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 20,
},
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
Stmts: []node.Node{},
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 15,
},
Value: "foo",
},
Stmts: []node.Node{},
},
},
}
@@ -43,13 +64,40 @@ func TestFunctionReturn(t *testing.T) {
src := `<? function foo() {return;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 27,
},
Stmts: []node.Node{
&stmt.Function{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 27,
},
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 15,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.Return{},
&stmt.Return{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 26,
},
},
},
},
},
@@ -70,28 +118,130 @@ func TestFunctionReturnVar(t *testing.T) {
src := `<? function foo(array $a, callable $b) {return $a;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
Stmts: []node.Node{
&stmt.Function{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
ReturnsRef: false,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 13,
EndPos: 15,
},
Value: "foo",
},
Params: []node.Node{
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "array"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
EndPos: 24,
},
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 17,
EndPos: 21,
},
Value: "array",
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Value: "a",
},
},
},
&node.Parameter{
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{Value: "callable"},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 37,
},
ByRef: false,
Variadic: false,
VariableType: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 34,
},
Value: "callable",
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 37,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 37,
},
Value: "b",
},
},
},
},
Stmts: []node.Node{
&stmt.Return{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 41,
EndPos: 50,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 48,
EndPos: 49,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 48,
EndPos: 49,
},
Value: "a",
},
},
},
},
},
@@ -113,14 +263,48 @@ func TestRefFunction(t *testing.T) {
src := `<? function &foo() {return 1;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Stmts: []node.Node{
&stmt.Function{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
ReturnsRef: true,
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.Return{
Expr: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 29,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 28,
},
Value: "1",
},
},
},
},
@@ -142,14 +326,48 @@ func TestReturnTypeFunction(t *testing.T) {
src := `<? function &foo(): void {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 27,
},
Stmts: []node.Node{
&stmt.Function{
ReturnsRef: true,
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 27,
},
PhpDocComment: "",
FunctionName: &node.Identifier{Value: "foo"},
ReturnsRef: true,
FunctionName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "foo",
},
ReturnType: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 24,
},
Parts: []node.Node{
&name.NamePart{Value: "void"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 21,
EndPos: 24,
},
Value: "void",
},
},
},
Stmts: []node.Node{},

View File

@@ -10,16 +10,45 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestGlobal(t *testing.T) {
src := `<? global $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.Global{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Value: "a",
},
},
},
},
},
@@ -40,20 +69,121 @@ func TestGlobalVars(t *testing.T) {
src := `<? global $a, $b, $$c, ${foo()};`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
Stmts: []node.Node{
&stmt.Global{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
&expr.Variable{VarName: &node.Identifier{Value: "b"}},
&expr.Variable{VarName: &expr.Variable{VarName: &node.Identifier{Value: "c"}}},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Value: "a",
},
},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
Value: "b",
},
},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 21,
},
VarName: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 21,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 21,
},
Value: "c",
},
},
},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 24,
EndPos: 31,
},
VarName: &expr.FunctionCall{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 30,
},
Function: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Parts: []node.Node{
&name.NamePart{Value: "foo"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Value: "foo",
},
},
},
ArgumentList: &node.ArgumentList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
ArgumentList: &node.ArgumentList{},
},
},
},

View File

@@ -8,18 +8,53 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestGotoLabel(t *testing.T) {
src := `<? a: goto a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.Label{
LabelName: &node.Identifier{Value: "a"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 5,
},
LabelName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 4,
},
Value: "a",
},
},
&stmt.Goto{
Label: &node.Identifier{Value: "a"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 13,
},
Label: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 12,
},
Value: "a",
},
},
},
}

View File

@@ -8,14 +8,28 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestHaltCompiler(t *testing.T) {
src := `<? __halt_compiler();`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Stmts: []node.Node{
&stmt.HaltCompiler{},
&stmt.HaltCompiler{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
},
},
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,10 +17,46 @@ func TestIf(t *testing.T) {
src := `<? if ($a) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Stmts: []node.Node{},
},
},
},
}
@@ -36,18 +73,83 @@ func TestIf(t *testing.T) {
}
func TestElseIf(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {}
`
src := `<? if ($a) {} elseif ($b) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 28,
},
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Stmts: []node.Node{},
},
ElseIf: []node.Node{
&stmt.ElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Value: "b",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 28,
},
Stmts: []node.Node{},
},
},
},
},
@@ -69,12 +171,62 @@ func TestElse(t *testing.T) {
src := `<? if ($a) {} else {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Stmts: []node.Node{},
},
Else: &stmt.Else{
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 21,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 21,
},
Stmts: []node.Node{},
},
},
},
},
@@ -95,22 +247,132 @@ func TestElseElseIf(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {} elseif ($c) {} else {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 51,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Stmts: []node.Node{},
},
ElseIf: []node.Node{
&stmt.ElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Value: "b",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 28,
},
Stmts: []node.Node{},
},
},
&stmt.ElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 43,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 39,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 39,
},
Value: "c",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 42,
EndPos: 43,
},
Stmts: []node.Node{},
},
},
},
Else: &stmt.Else{
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
EndPos: 51,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
EndPos: 51,
},
Stmts: []node.Node{},
},
},
},
},
@@ -131,22 +393,138 @@ func TestElseIfElseIfElse(t *testing.T) {
src := `<? if ($a) {} elseif ($b) {} else if ($c) {} else {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 52,
},
Stmts: []node.Node{
&stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 52,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 8,
EndPos: 9,
},
Value: "a",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Stmts: []node.Node{},
},
ElseIf: []node.Node{
&stmt.ElseIf{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 28,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 23,
EndPos: 24,
},
Value: "b",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 27,
EndPos: 28,
},
Stmts: []node.Node{},
},
},
},
Else: &stmt.Else{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 30,
EndPos: 52,
},
Stmt: &stmt.If{
Cond: &expr.Variable{VarName: &node.Identifier{Value: "c"}},
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 52,
},
Cond: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 40,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 39,
EndPos: 40,
},
Value: "c",
},
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
EndPos: 44,
},
Stmts: []node.Node{},
},
Else: &stmt.Else{
Stmt: &stmt.StmtList{Stmts: []node.Node{}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 46,
EndPos: 52,
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 51,
EndPos: 52,
},
Stmts: []node.Node{},
},
},
},
},

View File

@@ -8,15 +8,37 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestInlineHtml(t *testing.T) {
src := `<? ?> <div></div>`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 17,
},
Stmts: []node.Node{
&stmt.Nop{},
&stmt.InlineHtml{Value: "<div></div>"},
&stmt.Nop{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 5,
},
},
&stmt.InlineHtml{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 7,
EndPos: 17,
},
Value: "<div></div>",
},
},
}

View File

@@ -2,9 +2,11 @@ package stmt_test
import (
"bytes"
"github.com/z7zmey/php-parser/node/name"
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
@@ -15,11 +17,31 @@ func TestInterface(t *testing.T) {
src := `<? interface Foo {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 19,
},
Stmts: []node.Node{
&stmt.Interface{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 19,
},
PhpDocComment: "",
InterfaceName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{},
InterfaceName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "Foo",
},
Stmts: []node.Node{},
},
},
}
@@ -39,15 +61,55 @@ func TestInterfaceExtend(t *testing.T) {
src := `<? interface Foo extends Bar {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 31,
},
Stmts: []node.Node{
&stmt.Interface{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 31,
},
PhpDocComment: "",
InterfaceName: &node.Identifier{Value: "Foo"},
InterfaceName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "Foo",
},
Extends: &stmt.InterfaceExtends{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 28,
},
InterfaceNames: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Value: "Bar",
},
},
},
},
@@ -72,20 +134,74 @@ func TestInterfaceExtends(t *testing.T) {
src := `<? interface Foo extends Bar, Baz {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 36,
},
Stmts: []node.Node{
&stmt.Interface{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 36,
},
PhpDocComment: "",
InterfaceName: &node.Identifier{Value: "Foo"},
InterfaceName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "Foo",
},
Extends: &stmt.InterfaceExtends{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 33,
},
InterfaceNames: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 26,
EndPos: 28,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "Baz",
},
},
},
},

View File

@@ -2,9 +2,11 @@ package stmt_test
import (
"bytes"
"github.com/z7zmey/php-parser/node/name"
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
@@ -15,11 +17,37 @@ func TestNamespace(t *testing.T) {
src := `<? namespace Foo;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 17,
},
Stmts: []node.Node{
&stmt.Namespace{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 17,
},
NamespaceName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "Foo",
},
},
},
},
@@ -41,11 +69,37 @@ func TestNamespaceStmts(t *testing.T) {
src := `<? namespace Foo {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 19,
},
Stmts: []node.Node{
&stmt.Namespace{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 19,
},
NamespaceName: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 16,
},
Value: "Foo",
},
},
},
Stmts: []node.Node{},
@@ -68,8 +122,20 @@ func TestAnonymousNamespace(t *testing.T) {
src := `<? namespace {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{
&stmt.Namespace{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{},
},
},

View File

@@ -2,9 +2,11 @@ package stmt_test
import (
"bytes"
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/scalar"
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,18 +18,75 @@ func TestProperty(t *testing.T) {
src := `<? class foo {var $a;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 22,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 22,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.PropertyList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 21,
},
Modifiers: []node.Node{
&node.Identifier{Value: "var"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 17,
},
Value: "var",
},
},
Properties: []node.Node{
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
PhpDocComment: "",
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "a",
},
},
},
},
},
@@ -51,24 +110,119 @@ func TestProperties(t *testing.T) {
src := `<? class foo {public static $a, $b = 1;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 40,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 40,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.PropertyList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 39,
},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Value: "public",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 27,
},
Value: "static",
},
},
Properties: []node.Node{
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
PhpDocComment: "",
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
Value: "a",
},
},
},
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 38,
},
PhpDocComment: "",
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Expr: &scalar.Lnumber{Value: "1"},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 34,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 33,
EndPos: 34,
},
Value: "b",
},
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 38,
},
Value: "1",
},
},
},
},
@@ -92,24 +246,119 @@ func TestProperties2(t *testing.T) {
src := `<? class foo {public static $a = 1, $b;}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 40,
},
Stmts: []node.Node{
&stmt.Class{
ClassName: &node.Identifier{Value: "foo"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 40,
},
PhpDocComment: "",
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "foo",
},
Stmts: []node.Node{
&stmt.PropertyList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 39,
},
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
&node.Identifier{Value: "static"},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Value: "public",
},
&node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 27,
},
Value: "static",
},
},
Properties: []node.Node{
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 34,
},
PhpDocComment: "",
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expr: &scalar.Lnumber{Value: "1"},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
Value: "a",
},
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 34,
EndPos: 34,
},
Value: "1",
},
},
&stmt.Property{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 38,
},
PhpDocComment: "",
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 38,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 37,
EndPos: 38,
},
Value: "b",
},
},
},
},
},

View File

@@ -10,17 +10,52 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestStaticVar(t *testing.T) {
src := `<? static $a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.Static{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Vars: []node.Node{
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Value: "a",
},
},
},
},
},
@@ -42,15 +77,79 @@ func TestStaticVars(t *testing.T) {
src := `<? static $a, $b = 1;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Stmts: []node.Node{
&stmt.Static{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Vars: []node.Node{
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Value: "a",
},
},
},
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Expr: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 20,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 15,
EndPos: 16,
},
Value: "b",
},
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 20,
},
Value: "1",
},
},
},
},
@@ -72,15 +171,79 @@ func TestStaticVars2(t *testing.T) {
src := `<? static $a = 1, $b;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Stmts: []node.Node{
&stmt.Static{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 21,
},
Vars: []node.Node{
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
Expr: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 16,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 12,
},
Value: "a",
},
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 16,
},
Value: "1",
},
},
&stmt.StaticVar{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Variable: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 19,
EndPos: 20,
},
Value: "b",
},
},
},
},
},

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -22,20 +23,80 @@ func TestAltSwitch(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 7,
EndPos: 65,
},
Stmts: []node.Node{
&stmt.AltSwitch{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 2,
EndLine: 6,
StartPos: 7,
EndPos: 65,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 23,
EndPos: -1,
},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 23,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 28,
EndPos: 28,
},
Value: "1",
},
Stmts: []node.Node{},
},
&stmt.Default{
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 34,
EndPos: -1,
},
Stmts: []node.Node{},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 5,
EndLine: -1,
StartPos: 46,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 5,
EndLine: 5,
StartPos: 51,
EndPos: 51,
},
Value: "2",
},
Stmts: []node.Node{},
},
},
@@ -64,17 +125,71 @@ func TestAltSwitchSemicolon(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 54,
},
Stmts: []node.Node{
&stmt.AltSwitch{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 54,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 24,
EndPos: -1,
},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 3,
EndLine: -1,
StartPos: 24,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 29,
EndPos: 29,
},
Value: "1",
},
Stmts: []node.Node{},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 4,
EndLine: -1,
StartPos: 35,
EndPos: -1,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 40,
EndPos: 40,
},
Value: "2",
},
Stmts: []node.Node{},
},
},
@@ -103,21 +218,89 @@ func TestSwitch(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 58,
},
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 58,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 18,
EndPos: 58,
},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 23,
EndPos: 36,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 28,
EndPos: 28,
},
Value: "1",
},
Stmts: []node.Node{
&stmt.Break{},
&stmt.Break{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 31,
EndPos: 36,
},
},
},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 41,
EndPos: 54,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 46,
EndPos: 46,
},
Value: "2",
},
Stmts: []node.Node{
&stmt.Break{},
&stmt.Break{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 49,
EndPos: 54,
},
},
},
},
},
@@ -146,21 +329,89 @@ func TestSwitchSemicolon(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 59,
},
Stmts: []node.Node{
&stmt.Switch{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 7,
EndPos: 59,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 15,
EndPos: 15,
},
Value: "1",
},
CaseList: &stmt.CaseList{
Position: &position.Position{
StartLine: 2,
EndLine: 5,
StartPos: 18,
EndPos: 59,
},
Cases: []node.Node{
&stmt.Case{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 24,
EndPos: 37,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 29,
EndPos: 29,
},
Value: "1",
},
Stmts: []node.Node{
&stmt.Break{},
&stmt.Break{
Position: &position.Position{
StartLine: 3,
EndLine: 3,
StartPos: 32,
EndPos: 37,
},
},
},
},
&stmt.Case{
Cond: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 42,
EndPos: 55,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 47,
EndPos: 47,
},
Value: "2",
},
Stmts: []node.Node{
&stmt.Break{},
&stmt.Break{
Position: &position.Position{
StartLine: 4,
EndLine: 4,
StartPos: 50,
EndPos: 55,
},
},
},
},
},

View File

@@ -9,15 +9,44 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestThrow(t *testing.T) {
src := `<? throw $e;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Stmts: []node.Node{
&stmt.Throw{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "e"}},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
Value: "e",
},
},
},
},
}

View File

@@ -8,17 +8,38 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestTrait(t *testing.T) {
src := `<? trait Foo {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{
&stmt.Trait{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
PhpDocComment: "",
TraitName: &node.Identifier{Value: "Foo"},
Stmts: []node.Node{},
TraitName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{},
},
},
}

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,16 +17,56 @@ func TestTraitUse(t *testing.T) {
src := `<? class Foo { use Bar; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 25,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 25,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 23,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
},
@@ -50,21 +91,75 @@ func TestTraitsUse(t *testing.T) {
src := `<? class Foo { use Bar, Baz; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 30,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 28,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Value: "Baz",
},
},
},
},
@@ -89,25 +184,86 @@ func TestTraitsUseEmptyAdaptations(t *testing.T) {
src := `<? class Foo { use Bar, Baz {} }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 32,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 30,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Value: "Baz",
},
},
},
},
TraitAdaptationList: &stmt.TraitAdaptationList{},
TraitAdaptationList: &stmt.TraitAdaptationList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 30,
},
},
},
},
},
@@ -129,31 +285,119 @@ func TestTraitsUseModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public; } }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 48,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 48,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 46,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Value: "Baz",
},
},
},
},
TraitAdaptationList: &stmt.TraitAdaptationList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 46,
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 43,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "one",
},
},
Modifier: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 43,
},
Value: "public",
},
Modifier: &node.Identifier{Value: "public"},
},
},
},
@@ -178,32 +422,128 @@ func TestTraitsUseAliasModifier(t *testing.T) {
src := `<? class Foo { use Bar, Baz { one as public two; } }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 52,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 52,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 50,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Value: "Baz",
},
},
},
},
TraitAdaptationList: &stmt.TraitAdaptationList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 50,
},
Adaptations: []node.Node{
&stmt.TraitUseAlias{
Ref: &stmt.TraitMethodRef{
Method: &node.Identifier{Value: "one"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 47,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "one",
},
},
Modifier: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 38,
EndPos: 43,
},
Value: "public",
},
Alias: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 45,
EndPos: 47,
},
Value: "two",
},
Modifier: &node.Identifier{Value: "public"},
Alias: &node.Identifier{Value: "two"},
},
},
},
@@ -228,58 +568,222 @@ func TestTraitsUseAdaptions(t *testing.T) {
src := `<? class Foo { use Bar, Baz { Bar::one insteadof Baz, Quux; Baz::one as two; } }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 80,
},
Stmts: []node.Node{
&stmt.Class{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 80,
},
PhpDocComment: "",
ClassName: &node.Identifier{Value: "Foo"},
ClassName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 12,
},
Value: "Foo",
},
Stmts: []node.Node{
&stmt.TraitUse{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 78,
},
Traits: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 20,
EndPos: 22,
},
Value: "Bar",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 25,
EndPos: 27,
},
Value: "Baz",
},
},
},
},
TraitAdaptationList: &stmt.TraitAdaptationList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 29,
EndPos: 78,
},
Adaptations: []node.Node{
&stmt.TraitUsePrecedence{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 58,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 38,
},
Trait: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 31,
EndPos: 33,
},
Value: "Bar",
},
},
},
Method: &node.Identifier{Value: "one"},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 36,
EndPos: 38,
},
Value: "one",
},
},
Insteadof: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
EndPos: 52,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 50,
EndPos: 52,
},
Value: "Baz",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 55,
EndPos: 58,
},
Parts: []node.Node{
&name.NamePart{Value: "Quux"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 55,
EndPos: 58,
},
Value: "Quux",
},
},
},
},
},
&stmt.TraitUseAlias{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
EndPos: 75,
},
Ref: &stmt.TraitMethodRef{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
EndPos: 68,
},
Trait: &name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
EndPos: 63,
},
Parts: []node.Node{
&name.NamePart{Value: "Baz"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 61,
EndPos: 63,
},
Value: "Baz",
},
},
},
Method: &node.Identifier{Value: "one"},
Method: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 66,
EndPos: 68,
},
Value: "one",
},
},
Alias: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 73,
EndPos: 75,
},
Value: "two",
},
Alias: &node.Identifier{Value: "two"},
},
},
},

View File

@@ -2,9 +2,11 @@ package stmt_test
import (
"bytes"
"testing"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/name"
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -18,8 +20,20 @@ func TestTry(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: -1,
StartPos: 7,
EndPos: -1,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 2,
EndLine: -1,
StartPos: 7,
EndPos: -1,
},
Stmts: []node.Node{},
Catches: []node.Node{},
},
@@ -43,20 +57,66 @@ func TestTryCatch(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 36,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 36,
},
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
EndPos: 36,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Value: "Exception",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
@@ -82,25 +142,85 @@ func TestPhp7TryCatch(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 53,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 53,
},
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
EndPos: 53,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Value: "Exception",
},
},
},
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 46,
},
Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 46,
},
Value: "RuntimeException",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 48,
EndPos: 49,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 48,
EndPos: 49,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
@@ -121,33 +241,113 @@ func TestTryCatchCatch(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 67,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 67,
},
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
EndPos: 36,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Value: "Exception",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 38,
EndPos: 67,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 45,
EndPos: 60,
},
Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 45,
EndPos: 60,
},
Value: "RuntimeException",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 62,
EndPos: 63,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 62,
EndPos: 63,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
@@ -173,25 +373,77 @@ func TestTryCatchFinally(t *testing.T) {
`
expected := &node.Root{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 47,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 7,
EndPos: 47,
},
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 14,
EndPos: 36,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
&name.NamePart{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 21,
EndPos: 29,
},
Value: "Exception",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 31,
EndPos: 32,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
},
Finally: &stmt.Finally{
Position: &position.Position{
StartLine: 2,
EndLine: 2,
StartPos: 38,
EndPos: 47,
},
Stmts: []node.Node{},
},
},
@@ -213,46 +465,160 @@ func TestTryCatchCatchCatch(t *testing.T) {
src := `<? try {} catch (Exception $e) {} catch (\RuntimeException $e) {} catch (namespace\AdditionException $e) {}`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 107,
},
Stmts: []node.Node{
&stmt.Try{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 107,
},
Stmts: []node.Node{},
Catches: []node.Node{
&stmt.Catch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 33,
},
Types: []node.Node{
&name.Name{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 26,
},
Parts: []node.Node{
&name.NamePart{Value: "Exception"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 18,
EndPos: 26,
},
Value: "Exception",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 29,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 28,
EndPos: 29,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 35,
EndPos: 65,
},
Types: []node.Node{
&name.FullyQualified{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 42,
EndPos: 58,
},
Parts: []node.Node{
&name.NamePart{Value: "RuntimeException"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 43,
EndPos: 58,
},
Value: "RuntimeException",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 61,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 60,
EndPos: 61,
},
Value: "e",
},
},
Stmts: []node.Node{},
},
&stmt.Catch{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 67,
EndPos: 107,
},
Types: []node.Node{
&name.Relative{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 74,
EndPos: 100,
},
Parts: []node.Node{
&name.NamePart{Value: "AdditionException"},
&name.NamePart{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 84,
EndPos: 100,
},
Value: "AdditionException",
},
},
},
},
Variable: &expr.Variable{
VarName: &node.Identifier{Value: "e"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 102,
EndPos: 103,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 102,
EndPos: 103,
},
Value: "e",
},
},
Stmts: []node.Node{},
},

View File

@@ -9,16 +9,45 @@ import (
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
)
func TestUnset(t *testing.T) {
src := `<? unset($a);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{
&stmt.Unset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
},
},
},
@@ -39,11 +68,55 @@ func TestUnsetVars(t *testing.T) {
src := `<? unset($a, $b);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 17,
},
Stmts: []node.Node{
&stmt.Unset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 17,
},
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
&expr.Variable{VarName: &node.Identifier{Value: "b"}},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 15,
},
Value: "b",
},
},
},
},
},
@@ -64,11 +137,55 @@ func TestUnsetTrailingComma(t *testing.T) {
src := `<? unset($a, $b,);`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 18,
},
Stmts: []node.Node{
&stmt.Unset{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 18,
},
Vars: []node.Node{
&expr.Variable{VarName: &node.Identifier{Value: "a"}},
&expr.Variable{VarName: &node.Identifier{Value: "b"}},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 10,
EndPos: 11,
},
Value: "a",
},
},
&expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 15,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 15,
},
Value: "b",
},
},
},
},
},

File diff suppressed because it is too large Load Diff

View File

@@ -5,6 +5,7 @@ import (
"testing"
"github.com/z7zmey/php-parser/node/scalar"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/stmt"
@@ -16,12 +17,45 @@ func TestBreakEmpty(t *testing.T) {
src := `<? while (1) { break; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 23,
},
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 23,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 23,
},
Stmts: []node.Node{
&stmt.Break{nil},
&stmt.Break{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 21,
},
},
},
},
},
@@ -43,13 +77,53 @@ func TestBreakLight(t *testing.T) {
src := `<? while (1) { break 2; }`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 25,
},
Stmts: []node.Node{
&stmt.While{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 25,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 14,
EndPos: 25,
},
Stmts: []node.Node{
&stmt.Break{
Expr: &scalar.Lnumber{Value: "2"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 23,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 22,
},
Value: "2",
},
},
},
},
@@ -72,13 +146,53 @@ func TestBreak(t *testing.T) {
src := `<? while (1) : break(3); endwhile;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 34,
},
Stmts: []node.Node{
&stmt.AltWhile{
Cond: &scalar.Lnumber{Value: "1"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 34,
},
Cond: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 11,
EndPos: 11,
},
Value: "1",
},
Stmt: &stmt.StmtList{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 24,
},
Stmts: []node.Node{
&stmt.Break{
Expr: &scalar.Lnumber{Value: "3"},
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 16,
EndPos: 24,
},
Expr: &scalar.Lnumber{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 22,
EndPos: 22,
},
Value: "3",
},
},
},
},