Merge pull request #75 from z7zmey/dev

v0.6.0
This commit is contained in:
Vadym Slizov 2019-02-25 18:17:56 +02:00 committed by GitHub
commit d07e234393
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
318 changed files with 78751 additions and 16983 deletions

9
.gitignore vendored
View File

@ -1,8 +1,9 @@
.vscode .vscode
php-parser php-parser
**/*.test
*example.php *example.php
cpu.prof cpu.pprof
mem.prof mem.pprof
php7.test trace.out
php5.test

View File

@ -3,8 +3,9 @@ branches:
only: only:
- master - master
before_script: before_script:
- go get -u gotest.tools/assert
- go get -u golang.org/x/tools/cmd/goyacc - go get -u golang.org/x/tools/cmd/goyacc
- go get -u github.com/kylelemons/godebug/pretty - go get -u github.com/pkg/profile
- go get -u github.com/cznic/golex/lex - go get -u github.com/cznic/golex/lex
- go get -u github.com/yookoala/realpath - go get -u github.com/yookoala/realpath
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter

View File

@ -6,10 +6,11 @@ fmt:
find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' + find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' +
build: build:
go generate ./...
go build go build
run: run:
./php-parser $(PHPFILE) ./php-parser -d go $(PHPFILE)
test: test:
go test ./... go test ./...
@ -21,7 +22,7 @@ bench:
go test -benchmem -bench=. ./php5 go test -benchmem -bench=. ./php5
go test -benchmem -bench=. ./php7 go test -benchmem -bench=. ./php7
compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go fmt
sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php7/php7.go sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php7/php7.go
sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php5/php5.go sed -i '' -e 's/yyErrorVerbose = false/yyErrorVerbose = true/g' ./php5/php5.go
rm -f y.output rm -f y.output
@ -36,17 +37,17 @@ compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go
goyacc -o $@ $< goyacc -o $@ $<
cpu_pprof: cpu_pprof:
GOGC=off go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php7 go test -cpuprofile cpu.pprof -bench=. -benchtime=20s ./php7
go tool pprof ./php7.test cpu.prof go tool pprof ./php7.test cpu.pprof
mem_pprof: mem_pprof:
GOGC=off go test -memprofile mem.prof -bench=. -benchtime=20s -benchmem ./php7 go test -memprofile mem.pprof -bench=. -benchtime=20s -benchmem ./php7
go tool pprof -alloc_objects ./php7.test mem.prof go tool pprof -alloc_objects ./php7.test mem.pprof
cpu_pprof_php5: cpu_pprof_php5:
GOGC=off go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php5 go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php5
go tool pprof ./php5.test cpu.prof go tool pprof ./php5.test cpu.prof
mem_pprof_php5: mem_pprof_php5:
GOGC=off go test -memprofile mem.prof -bench=. -benchtime=20s -benchmem ./php5 go test -memprofile mem.prof -bench=. -benchtime=20s -benchmem ./php5
go tool pprof -alloc_objects ./php5.test mem.prof go tool pprof -alloc_objects ./php5.test mem.prof

View File

@ -1,10 +1,3 @@
<!--
Title: PHP Parser
Description: A Parser for PHP written in Go.
Author: Slizov Vadym
Keywords: php parser go golang ast
-->
PHP Parser written in Go PHP Parser written in Go
======================== ========================
@ -26,13 +19,13 @@ Features:
- Fully support PHP 5 and PHP 7 syntax - Fully support PHP 5 and PHP 7 syntax
- Abstract syntax tree (AST) representation - Abstract syntax tree (AST) representation
- Traversing AST - Traversing AST
- Namespace resolver - Resolving namespaced names
- Able to parse syntax-invalid PHP files - Parsing syntax-invalid PHP files
- Saving and printing free-floating comments and whitespaces
Roadmap Roadmap
------- -------
- Pretty printer
- Control Flow Graph (CFG) - Control Flow Graph (CFG)
- PhpDocComment parser - PhpDocComment parser
- Stabilize api - Stabilize api
@ -48,9 +41,17 @@ CLI
--- ---
``` ```
php-parser [-php5 -noDump] <path> ... php-parser [flags] <path> ...
``` ```
| flag | type | description |
|-------|------|----------------------------------------------|
| -d |string| dump format: [custom, go, json, pretty-json] |
| -r | bool | resolve names |
| -ff | bool | parse and show free floating strings |
| -prof |string| start profiler: [cpu, mem, trace] |
| -php5 | bool | parse as PHP5 |
Dump AST to stdout. Dump AST to stdout.
Example Example
@ -97,79 +98,3 @@ Namespace resolver is a visitor that resolves nodes fully qualified name and sav
- For `Class`, `Interface`, `Trait`, `Function`, `Constant` nodes it saves name with current namespace. - For `Class`, `Interface`, `Trait`, `Function`, `Constant` nodes it saves name with current namespace.
- For `Name`, `Relative`, `FullyQualified` nodes it resolves `use` aliases and saves a fully qualified name. - For `Name`, `Relative`, `FullyQualified` nodes it resolves `use` aliases and saves a fully qualified name.
Parsing syntax-invalid PHP files
--------------------------------
If we try to parse `$a$b;` then the parser triggers error 'syntax error: unexpected T_VARIABLE'. Token `$b` is unexpected, but parser recovers parsing process and returns `$b;` statement to AST, because it is syntactically correct.
Pretty printer [work in progress]
---------------------------------
```Golang
nodes := &stmt.StmtList{
Stmts: []node.Node{
&stmt.Namespace{
NamespaceName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Foo"},
},
},
},
&stmt.Class{
Modifiers: []node.Node{
&node.Identifier{Value: "abstract"},
},
ClassName: &name.Name{
Parts: []node.Node{
&name.NamePart{Value: "Bar"},
},
},
Extends: &stmt.ClassExtends{
ClassName: &name.Name{
Parts: []node.Node{
&name.NamePart{
Value: "Baz"
},
},
},
},
Stmts: []node.Node{
&stmt.ClassMethod{
Modifiers: []node.Node{
&node.Identifier{Value: "public"},
},
MethodName: &node.Identifier{Value: "greet"},
Stmt: &stmt.StmtList{
Stmts: []node.Node{
&stmt.Echo{
Exprs: []node.Node{
&scalar.String{Value: "'Hello world'"},
},
},
},
},
},
},
},
},
}
file := os.Stdout
p := printer.NewPrinter(file, " ")
p.Print(nodes)
```
It prints to stdout:
```PHP
<?php
namespace Foo;
abstract class Bar extends Baz
{
public function greet()
{
echo 'Hello world';
}
}
```

View File

@ -1,40 +0,0 @@
package comment
import (
"github.com/z7zmey/php-parser/position"
)
// Comment aggrigates information about comment /**
type Comment struct {
value string
position *position.Position
tokenName TokenName
}
// NewComment - Comment constructor
func NewComment(value string, pos *position.Position) *Comment {
return &Comment{
value,
pos,
UnknownToken,
}
}
// SetTokenName sets token name
func (c *Comment) SetTokenName(tokenName TokenName) {
c.tokenName = tokenName
}
// TokenName returns token name
func (c *Comment) TokenName() TokenName {
return c.tokenName
}
func (c *Comment) String() string {
return c.value
}
// Position returns comment position
func (c *Comment) Position() *position.Position {
return c.position
}

View File

@ -1,33 +0,0 @@
package comment_test
import (
"testing"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/comment"
)
func TestCommentGetPosition(t *testing.T) {
expected := position.NewPosition(0, 0, 0, 0)
comment := comment.NewComment("/** hello world */", expected)
actual := comment.Position()
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}
func TestCommentPrint(t *testing.T) {
expected := "/** hello world */"
comment := comment.NewComment(expected, nil)
actual := comment.String()
if expected != actual {
t.Errorf("expected and actual are not equal\n")
}
}

View File

@ -1,328 +0,0 @@
package comment
// TokenName is used to specify a comment position
type TokenName int
const (
UnknownToken TokenName = iota
IncludeToken
IncludeOnceToken
ExitToken
IfToken
LnumberToken
DnumberToken
StringToken
StringVarnameToken
VariableToken
NumStringToken
InlineHTMLToken
EncapsedAndWhitespaceToken
ConstantEncapsedStringToken
EchoToken
DoToken
WhileToken
EndwhileToken
ForInitSemicolonToken
ForCondSemicolonToken
ForToken
EndforToken
ForeachToken
EndforeachToken
DeclareToken
EnddeclareToken
AsToken
SwitchToken
EndswitchToken
CaseToken
DefaultToken
BreakToken
ContinueToken
GotoToken
FunctionToken
ConstToken
ReturnToken
TryToken
CatchToken
FinallyToken
ThrowToken
UseToken
InsteadofToken
GlobalToken
VarToken
UnsetToken
IssetToken
EmptyToken
ClassToken
TraitToken
InterfaceToken
ExtendsToken
ImplementsToken
DoubleArrowToken
ListToken
ArrayToken
CallableToken
ClassCToken
TraitCToken
MethodCToken
FuncCToken
LineToken
FileToken
StartHeredocToken
DollarOpenCurlyBracesToken
CurlyOpenToken
PaamayimNekudotayimToken
NamespaceToken
NsCToken
DirToken
NsSeparatorToken
EllipsisToken
EvalToken
RequireToken
RequireOnceToken
LogicalOrToken
LogicalXorToken
LogicalAndToken
InstanceofToken
NewToken
CloneToken
ElseifToken
ElseToken
EndifToken
PrintToken
YieldToken
StaticToken
AbstractToken
FinalToken
PrivateToken
ProtectedToken
PublicToken
IncToken
DecToken
YieldFromToken
ObjectOperatorToken
IntCastToken
DoubleCastToken
StringCastToken
ArrayCastToken
ObjectCastToken
BoolCastToken
UnsetCastToken
CoalesceToken
SpaceshipToken
PlusEqualToken
MinusEqualToken
MulEqualToken
PowEqualToken
DivEqualToken
ConcatEqualToken
ModEqualToken
AndEqualToken
OrEqualToken
XorEqualToken
SlEqualToken
SrEqualToken
BooleanOrToken
BooleanAndToken
PowToken
SlToken
SrToken
IsIdenticalToken
IsNotIdenticalToken
IsEqualToken
IsNotEqualToken
IsSmallerOrEqualToken
IsGreaterOrEqualToken
HaltCompilerToken
IdentifierToken
CaseSeparatorToken // ';' or ':'
DoubleQuoteToken // '"'
BackquoteToken // '`'
OpenCurlyBracesToken // '{'
CloseCurlyBracesToken // '}'
SemiColonToken // ';'
ColonToken // ':'
OpenParenthesisToken // '('
CloseParenthesisToken // ')'
OpenSquareBracket // '['
CloseSquareBracket // ']'
QuestionMarkToken // '?'
AmpersandToken // '&'
MinusToken // '-'
PlusToken // '+'
ExclamationMarkToken // '!'
TildeToken // '~'
AtToken // '@'
DollarToken // '$'
CommaToken // ','
VerticalBarToken // '|'
EqualToken // '='
CaretToken // '^'
AsteriskToken // '*'
SlashToken // '/'
PercentToken // '%'
LessToken // '<'
GreaterToken // '>'
DotToken // '.'
)
var TokenNames = map[TokenName]string{
UnknownToken: "UnknownToken",
IncludeToken: "IncludeToken",
IncludeOnceToken: "IncludeOnceToken",
ExitToken: "ExitToken",
IfToken: "IfToken",
LnumberToken: "LnumberToken",
DnumberToken: "DnumberToken",
StringToken: "StringToken",
StringVarnameToken: "StringVarnameToken",
VariableToken: "VariableToken",
NumStringToken: "NumStringToken",
InlineHTMLToken: "InlineHTMLToken",
EncapsedAndWhitespaceToken: "EncapsedAndWhitespaceToken",
ConstantEncapsedStringToken: "ConstantEncapsedStringToken",
EchoToken: "EchoToken",
DoToken: "DoToken",
WhileToken: "WhileToken",
EndwhileToken: "EndwhileToken",
ForInitSemicolonToken: "ForInitSemicolonToken",
ForCondSemicolonToken: "ForCondSemicolonToken",
ForToken: "ForToken",
EndforToken: "EndforToken",
ForeachToken: "ForeachToken",
EndforeachToken: "EndforeachToken",
DeclareToken: "DeclareToken",
EnddeclareToken: "EnddeclareToken",
AsToken: "AsToken",
SwitchToken: "SwitchToken",
EndswitchToken: "EndswitchToken",
CaseToken: "CaseToken",
DefaultToken: "DefaultToken",
BreakToken: "BreakToken",
ContinueToken: "ContinueToken",
GotoToken: "GotoToken",
FunctionToken: "FunctionToken",
ConstToken: "ConstToken",
ReturnToken: "ReturnToken",
TryToken: "TryToken",
CatchToken: "CatchToken",
FinallyToken: "FinallyToken",
ThrowToken: "ThrowToken",
UseToken: "UseToken",
InsteadofToken: "InsteadofToken",
GlobalToken: "GlobalToken",
VarToken: "VarToken",
UnsetToken: "UnsetToken",
IssetToken: "IssetToken",
EmptyToken: "EmptyToken",
ClassToken: "ClassToken",
TraitToken: "TraitToken",
InterfaceToken: "InterfaceToken",
ExtendsToken: "ExtendsToken",
ImplementsToken: "ImplementsToken",
DoubleArrowToken: "DoubleArrowToken",
ListToken: "ListToken",
ArrayToken: "ArrayToken",
CallableToken: "CallableToken",
ClassCToken: "ClassCToken",
TraitCToken: "TraitCToken",
MethodCToken: "MethodCToken",
FuncCToken: "FuncCToken",
LineToken: "LineToken",
FileToken: "FileToken",
StartHeredocToken: "StartHeredocToken",
DollarOpenCurlyBracesToken: "DollarOpenCurlyBracesToken",
CurlyOpenToken: "CurlyOpenToken",
PaamayimNekudotayimToken: "PaamayimNekudotayimToken",
NamespaceToken: "NamespaceToken",
NsCToken: "NsCToken",
DirToken: "DirToken",
NsSeparatorToken: "NsSeparatorToken",
EllipsisToken: "EllipsisToken",
EvalToken: "EvalToken",
RequireToken: "RequireToken",
RequireOnceToken: "RequireOnceToken",
LogicalOrToken: "LogicalOrToken",
LogicalXorToken: "LogicalXorToken",
LogicalAndToken: "LogicalAndToken",
InstanceofToken: "InstanceofToken",
NewToken: "NewToken",
CloneToken: "CloneToken",
ElseifToken: "ElseifToken",
ElseToken: "ElseToken",
EndifToken: "EndifToken",
PrintToken: "PrintToken",
YieldToken: "YieldToken",
StaticToken: "StaticToken",
AbstractToken: "AbstractToken",
FinalToken: "FinalToken",
PrivateToken: "PrivateToken",
ProtectedToken: "ProtectedToken",
PublicToken: "PublicToken",
IncToken: "IncToken",
DecToken: "DecToken",
YieldFromToken: "YieldFromToken",
ObjectOperatorToken: "ObjectOperatorToken",
IntCastToken: "IntCastToken",
DoubleCastToken: "DoubleCastToken",
StringCastToken: "StringCastToken",
ArrayCastToken: "ArrayCastToken",
ObjectCastToken: "ObjectCastToken",
BoolCastToken: "BoolCastToken",
UnsetCastToken: "UnsetCastToken",
CoalesceToken: "CoalesceToken",
SpaceshipToken: "SpaceshipToken",
PlusEqualToken: "PlusEqualToken",
MinusEqualToken: "MinusEqualToken",
MulEqualToken: "MulEqualToken",
PowEqualToken: "PowEqualToken",
DivEqualToken: "DivEqualToken",
ConcatEqualToken: "ConcatEqualToken",
ModEqualToken: "ModEqualToken",
AndEqualToken: "AndEqualToken",
OrEqualToken: "OrEqualToken",
XorEqualToken: "XorEqualToken",
SlEqualToken: "SlEqualToken",
SrEqualToken: "SrEqualToken",
BooleanOrToken: "BooleanOrToken",
BooleanAndToken: "BooleanAndToken",
PowToken: "PowToken",
SlToken: "SlToken",
SrToken: "SrToken",
IsIdenticalToken: "IsIdenticalToken",
IsNotIdenticalToken: "IsNotIdenticalToken",
IsEqualToken: "IsEqualToken",
IsNotEqualToken: "IsNotEqualToken",
IsSmallerOrEqualToken: "IsSmallerOrEqualToken",
IsGreaterOrEqualToken: "IsGreaterOrEqualToken",
HaltCompilerToken: "HaltCompilerToken",
IdentifierToken: "IdentifierToken",
CaseSeparatorToken: "CaseSeparatorToken",
DoubleQuoteToken: "DoubleQuoteToken",
BackquoteToken: "BackquoteToken",
OpenCurlyBracesToken: "OpenCurlyBracesToken",
CloseCurlyBracesToken: "CloseCurlyBracesToken",
SemiColonToken: "SemiColonToken",
ColonToken: "ColonToken",
OpenParenthesisToken: "OpenParenthesisToken",
CloseParenthesisToken: "CloseParenthesisToken",
OpenSquareBracket: "OpenSquareBracket",
CloseSquareBracket: "CloseSquareBracket",
QuestionMarkToken: "QuestionMarkToken",
AmpersandToken: "AmpersandToken",
MinusToken: "MinusToken",
PlusToken: "PlusToken",
ExclamationMarkToken: "ExclamationMarkToken",
TildeToken: "TildeToken",
AtToken: "AtToken",
DollarToken: "DollarToken",
CommaToken: "CommaToken",
VerticalBarToken: "VerticalBarToken",
EqualToken: "EqualToken",
CaretToken: "CaretToken",
AsteriskToken: "AsteriskToken",
SlashToken: "SlashToken",
PercentToken: "PercentToken",
LessToken: "LessToken",
GreaterToken: "GreaterToken",
DotToken: "DotToken",
}

View File

@ -1,29 +1,14 @@
package errors_test package errors_test
import ( import (
"reflect"
"testing" "testing"
"github.com/z7zmey/php-parser/position" "gotest.tools/assert"
"github.com/z7zmey/php-parser/errors" "github.com/z7zmey/php-parser/errors"
"github.com/z7zmey/php-parser/position"
"github.com/kylelemons/godebug/pretty"
) )
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
diff := pretty.Compare(expected, actual)
if diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
} else {
t.Errorf("expected and actual are not equal\n")
}
}
}
func TestConstructor(t *testing.T) { func TestConstructor(t *testing.T) {
pos := position.NewPosition(1, 2, 3, 4) pos := position.NewPosition(1, 2, 3, 4)
@ -34,7 +19,7 @@ func TestConstructor(t *testing.T) {
Pos: pos, Pos: pos,
} }
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestPrint(t *testing.T) { func TestPrint(t *testing.T) {
@ -46,7 +31,7 @@ func TestPrint(t *testing.T) {
expected := "message at line 1" expected := "message at line 1"
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestPrintWithotPos(t *testing.T) { func TestPrintWithotPos(t *testing.T) {
@ -56,5 +41,5 @@ func TestPrintWithotPos(t *testing.T) {
expected := "message" expected := "message"
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }

View File

@ -0,0 +1,16 @@
// Code generated by "stringer -type=Position -output ./position_string.go"; DO NOT EDIT.
package freefloating
import "strconv"
const _Position_name = "StartEndSlashColonSemiColonAltEndDollarAmpersandNamePrefixKeyVarUseTypeReturnTypeOptionalTypeCaseSeparatorLexicalVarsParamsRefCastExprInitExprCondExprIncExprTrueCondHaltCompillerNamespaceStaticClassUseWhileForSwitchBreakForeachDeclareLabelFinallyListDefaultIfElseIfElseVariadicFunctionAliasAsEqualExitArrayIssetEmptyEvalEchoTryCatchUnsetStmtsVarListConstListNameListParamListModifierListArrayPairListCaseListStartCaseListEndArgumentListPropertyListParameterListAdaptationListLexicalVarListUseDeclarationListOpenParenthesisTokenCloseParenthesisToken"
var _Position_index = [...]uint16{0, 5, 8, 13, 18, 27, 33, 39, 48, 52, 58, 61, 64, 71, 81, 93, 106, 117, 123, 126, 130, 134, 142, 150, 157, 161, 165, 178, 187, 193, 198, 201, 206, 209, 215, 220, 227, 234, 239, 246, 250, 257, 259, 265, 269, 277, 285, 290, 292, 297, 301, 306, 311, 316, 320, 324, 327, 332, 337, 342, 349, 358, 366, 375, 387, 400, 413, 424, 436, 448, 461, 475, 489, 507, 527, 548}
func (i Position) String() string {
if i < 0 || i >= Position(len(_Position_index)-1) {
return "Position(" + strconv.FormatInt(int64(i), 10) + ")"
}
return _Position_name[_Position_index[i]:_Position_index[i+1]]
}

112
freefloating/string.go Normal file
View File

@ -0,0 +1,112 @@
package freefloating
import "github.com/z7zmey/php-parser/position"
type StringType int
const (
WhiteSpaceType StringType = iota
CommentType
TokenType
)
type Position int
//go:generate stringer -type=Position -output ./position_string.go
const (
Start Position = iota
End
Slash
Colon
SemiColon
AltEnd
Dollar
Ampersand
Name
Prefix
Key
Var
UseType
ReturnType
OptionalType
CaseSeparator
LexicalVars
Params
Ref
Cast
Expr
InitExpr
CondExpr
IncExpr
True
Cond
HaltCompiller
Namespace
Static
Class
Use
While
For
Switch
Break
Foreach
Declare
Label
Finally
List
Default
If
ElseIf
Else
Variadic
Function
Alias
As
Equal
Exit
Array
Isset
Empty
Eval
Echo
Try
Catch
Unset
Stmts
VarList
ConstList
NameList
ParamList
ModifierList
ArrayPairList
CaseListStart
CaseListEnd
ArgumentList
PropertyList
ParameterList
AdaptationList
LexicalVarList
UseDeclarationList
OpenParenthesisToken
CloseParenthesisToken
)
type String struct {
StringType StringType
Value string
Position *position.Position
}
type Collection map[Position][]String
func (c Collection) IsEmpty() bool {
for _, v := range c {
if len(v) > 0 {
return false
}
}
return true
}

126
main.go
View File

@ -1,50 +1,81 @@
package main package main
import ( import (
"bufio"
"bytes"
"flag" "flag"
"fmt" "fmt"
"io/ioutil"
"log" "log"
"os" "os"
"path/filepath" "path/filepath"
"runtime"
"sync" "sync"
"github.com/pkg/profile"
"github.com/yookoala/realpath" "github.com/yookoala/realpath"
"github.com/z7zmey/php-parser/parser" "github.com/z7zmey/php-parser/parser"
"github.com/z7zmey/php-parser/php5" "github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/printer"
"github.com/z7zmey/php-parser/visitor" "github.com/z7zmey/php-parser/visitor"
) )
var wg sync.WaitGroup var wg sync.WaitGroup
var usePhp5 *bool var usePhp5 *bool
var noDump *bool var dumpType string
var profiler string
var withFreeFloating *bool
var showResolvedNs *bool
var printBack *bool
type file struct {
path string
content []byte
}
func main() { func main() {
usePhp5 = flag.Bool("php5", false, "use PHP5 parserWorker") usePhp5 = flag.Bool("php5", false, "parse as PHP5")
noDump = flag.Bool("noDump", false, "disable dumping to stdout") withFreeFloating = flag.Bool("ff", false, "parse and show free floating strings")
showResolvedNs = flag.Bool("r", false, "resolve names")
printBack = flag.Bool("pb", false, "print AST back into the parsed file")
flag.StringVar(&dumpType, "d", "", "dump format: [custom, go, json, pretty_json]")
flag.StringVar(&profiler, "prof", "", "start profiler: [cpu, mem, trace]")
flag.Parse() flag.Parse()
pathCh := make(chan string) switch profiler {
resultCh := make(chan parser.Parser) case "cpu":
defer profile.Start(profile.ProfilePath("."), profile.NoShutdownHook).Stop()
case "mem":
defer profile.Start(profile.MemProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
case "trace":
defer profile.Start(profile.TraceProfile, profile.ProfilePath("."), profile.NoShutdownHook).Stop()
}
numCpu := runtime.NumCPU()
fileCh := make(chan *file, numCpu)
resultCh := make(chan parser.Parser, numCpu)
// run 4 concurrent parserWorkers // run 4 concurrent parserWorkers
for i := 0; i < 4; i++ { for i := 0; i < numCpu; i++ {
go parserWorker(pathCh, resultCh) go parserWorker(fileCh, resultCh)
} }
// run printer goroutine // run printer goroutine
go printer(resultCh) go printerWorker(resultCh)
// process files // process files
processPath(flag.Args(), pathCh) processPath(flag.Args(), fileCh)
// wait the all files done // wait the all files done
wg.Wait() wg.Wait()
close(pathCh) close(fileCh)
close(resultCh) close(resultCh)
} }
func processPath(pathList []string, pathCh chan<- string) { func processPath(pathList []string, fileCh chan<- *file) {
for _, path := range pathList { for _, path := range pathList {
real, err := realpath.Realpath(path) real, err := realpath.Realpath(path)
checkErr(err) checkErr(err)
@ -52,7 +83,9 @@ func processPath(pathList []string, pathCh chan<- string) {
err = filepath.Walk(real, func(path string, f os.FileInfo, err error) error { err = filepath.Walk(real, func(path string, f os.FileInfo, err error) error {
if !f.IsDir() && filepath.Ext(path) == ".php" { if !f.IsDir() && filepath.Ext(path) == ".php" {
wg.Add(1) wg.Add(1)
pathCh <- path content, err := ioutil.ReadFile(path)
checkErr(err)
fileCh <- &file{path, content}
} }
return nil return nil
}) })
@ -60,54 +93,93 @@ func processPath(pathList []string, pathCh chan<- string) {
} }
} }
func parserWorker(pathCh <-chan string, result chan<- parser.Parser) { func parserWorker(fileCh <-chan *file, result chan<- parser.Parser) {
var parserWorker parser.Parser var parserWorker parser.Parser
for { for {
path, ok := <-pathCh f, ok := <-fileCh
if !ok { if !ok {
return return
} }
src, _ := os.Open(path) src := bytes.NewReader(f.content)
if *usePhp5 { if *usePhp5 {
parserWorker = php5.NewParser(src, path) parserWorker = php5.NewParser(src, f.path)
} else { } else {
parserWorker = php7.NewParser(src, path) parserWorker = php7.NewParser(src, f.path)
}
if *withFreeFloating {
parserWorker.WithFreeFloating()
} }
parserWorker.Parse() parserWorker.Parse()
result <- parserWorker result <- parserWorker
} }
} }
func printer(result <-chan parser.Parser) { func printerWorker(result <-chan parser.Parser) {
var counter int
w := bufio.NewWriter(os.Stdout)
for { for {
parserWorker, ok := <-result parserWorker, ok := <-result
if !ok { if !ok {
w.Flush()
return return
} }
fmt.Printf("==> %s\n", parserWorker.GetPath()) counter++
fmt.Fprintf(w, "==> [%d] %s\n", counter, parserWorker.GetPath())
for _, e := range parserWorker.GetErrors() { for _, e := range parserWorker.GetErrors() {
fmt.Println(e) fmt.Fprintln(w, e)
} }
if !*noDump { if *printBack {
nsResolver := visitor.NewNamespaceResolver() o := bytes.NewBuffer([]byte{})
parserWorker.GetRootNode().Walk(nsResolver) p := printer.NewPrinter(o)
p.Print(parserWorker.GetRootNode())
dumper := visitor.Dumper{ err := ioutil.WriteFile(parserWorker.GetPath(), o.Bytes(), 0644)
checkErr(err)
}
var nsResolver *visitor.NamespaceResolver
if *showResolvedNs {
nsResolver = visitor.NewNamespaceResolver()
parserWorker.GetRootNode().Walk(nsResolver)
}
switch dumpType {
case "custom":
dumper := &visitor.Dumper{
Writer: os.Stdout, Writer: os.Stdout,
Indent: " | ", Indent: "| ",
Comments: parserWorker.GetComments(),
Positions: parserWorker.GetPositions(),
NsResolver: nsResolver, NsResolver: nsResolver,
} }
parserWorker.GetRootNode().Walk(dumper) parserWorker.GetRootNode().Walk(dumper)
case "json":
dumper := &visitor.JsonDumper{
Writer: os.Stdout,
NsResolver: nsResolver,
}
parserWorker.GetRootNode().Walk(dumper)
case "pretty_json":
dumper := &visitor.PrettyJsonDumper{
Writer: os.Stdout,
NsResolver: nsResolver,
}
parserWorker.GetRootNode().Walk(dumper)
case "go":
dumper := &visitor.GoDumper{Writer: os.Stdout}
parserWorker.GetRootNode().Walk(dumper)
} }
wg.Done() wg.Done()
} }
} }

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Assign node // Assign node
type Assign struct { type Assign struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewAssign node constructor // NewAssign node constructor
func NewAssign(Variable node.Node, Expression node.Node) *Assign { func NewAssign(Variable node.Node, Expression node.Node) *Assign {
return &Assign{ return &Assign{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Assign) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Assign) GetPosition() *position.Position {
return n.Position
}
func (n *Assign) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Assign) Attributes() map[string]interface{} { func (n *Assign) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Assign) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Reference node // Reference node
type Reference struct { type Reference struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewReference node constructor // NewReference node constructor
func NewReference(Variable node.Node, Expression node.Node) *Reference { func NewReference(Variable node.Node, Expression node.Node) *Reference {
return &Reference{ return &Reference{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Reference) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Reference) GetPosition() *position.Position {
return n.Position
}
func (n *Reference) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Reference) Attributes() map[string]interface{} { func (n *Reference) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Reference) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseAnd node // BitwiseAnd node
type BitwiseAnd struct { type BitwiseAnd struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewBitwiseAnd node constructor // NewBitwiseAnd node constructor
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd { func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{ return &BitwiseAnd{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseAnd) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseAnd) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseAnd) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseAnd) Attributes() map[string]interface{} { func (n *BitwiseAnd) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseOr node // BitwiseOr node
type BitwiseOr struct { type BitwiseOr struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewBitwiseOr node constructor // NewBitwiseOr node constructor
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr { func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
return &BitwiseOr{ return &BitwiseOr{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseOr) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseOr) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseOr) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseOr) Attributes() map[string]interface{} { func (n *BitwiseOr) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseXor node // BitwiseXor node
type BitwiseXor struct { type BitwiseXor struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewBitwiseXor node constructor // NewBitwiseXor node constructor
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor { func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
return &BitwiseXor{ return &BitwiseXor{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseXor) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseXor) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseXor) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseXor) Attributes() map[string]interface{} { func (n *BitwiseXor) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Concat node // Concat node
type Concat struct { type Concat struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewConcat node constructor // NewConcat node constructor
func NewConcat(Variable node.Node, Expression node.Node) *Concat { func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{ return &Concat{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Concat) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Concat) GetPosition() *position.Position {
return n.Position
}
func (n *Concat) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Concat) Attributes() map[string]interface{} { func (n *Concat) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Concat) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Div node // Div node
type Div struct { type Div struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewDiv node constructor // NewDiv node constructor
func NewDiv(Variable node.Node, Expression node.Node) *Div { func NewDiv(Variable node.Node, Expression node.Node) *Div {
return &Div{ return &Div{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Div) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Div) GetPosition() *position.Position {
return n.Position
}
func (n *Div) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Div) Attributes() map[string]interface{} { func (n *Div) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Div) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Minus node // Minus node
type Minus struct { type Minus struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewMinus node constructor // NewMinus node constructor
func NewMinus(Variable node.Node, Expression node.Node) *Minus { func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{ return &Minus{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Minus) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Minus) GetPosition() *position.Position {
return n.Position
}
func (n *Minus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Minus) Attributes() map[string]interface{} { func (n *Minus) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Minus) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Mod node // Mod node
type Mod struct { type Mod struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewMod node constructor // NewMod node constructor
func NewMod(Variable node.Node, Expression node.Node) *Mod { func NewMod(Variable node.Node, Expression node.Node) *Mod {
return &Mod{ return &Mod{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Mod) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Mod) GetPosition() *position.Position {
return n.Position
}
func (n *Mod) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Mod) Attributes() map[string]interface{} { func (n *Mod) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Mod) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Mul node // Mul node
type Mul struct { type Mul struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewMul node constructor // NewMul node constructor
func NewMul(Variable node.Node, Expression node.Node) *Mul { func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{ return &Mul{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Mul) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Mul) GetPosition() *position.Position {
return n.Position
}
func (n *Mul) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Mul) Attributes() map[string]interface{} { func (n *Mul) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Mul) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Plus node // Plus node
type Plus struct { type Plus struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewPlus node constructor // NewPlus node constructor
func NewPlus(Variable node.Node, Expression node.Node) *Plus { func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{ return &Plus{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Plus) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Plus) GetPosition() *position.Position {
return n.Position
}
func (n *Plus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Plus) Attributes() map[string]interface{} { func (n *Plus) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Plus) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Pow node // Pow node
type Pow struct { type Pow struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewPow node constructor // NewPow node constructor
func NewPow(Variable node.Node, Expression node.Node) *Pow { func NewPow(Variable node.Node, Expression node.Node) *Pow {
return &Pow{ return &Pow{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *Pow) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Pow) GetPosition() *position.Position {
return n.Position
}
func (n *Pow) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Pow) Attributes() map[string]interface{} { func (n *Pow) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Pow) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ShiftLeft node // ShiftLeft node
type ShiftLeft struct { type ShiftLeft struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewShiftLeft node constructor // NewShiftLeft node constructor
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft { func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{ return &ShiftLeft{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *ShiftLeft) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ShiftLeft) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftLeft) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ShiftLeft) Attributes() map[string]interface{} { func (n *ShiftLeft) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package assign package assign
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ShiftRight node // ShiftRight node
type ShiftRight struct { type ShiftRight struct {
Variable node.Node FreeFloating freefloating.Collection
Expression node.Node Position *position.Position
Variable node.Node
Expression node.Node
} }
// NewShiftRight node constructor // NewShiftRight node constructor
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight { func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
return &ShiftRight{ return &ShiftRight{
Variable, FreeFloating: nil,
Expression, Variable: Variable,
Expression: Expression,
} }
} }
// SetPosition sets node position
func (n *ShiftRight) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ShiftRight) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftRight) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ShiftRight) Attributes() map[string]interface{} { func (n *ShiftRight) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Expression != nil { if n.Expression != nil {
vv := v.GetChildrenVisitor("Expression") v.EnterChildNode("Expression", n)
n.Expression.Walk(vv) n.Expression.Walk(v)
v.LeaveChildNode("Expression", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,81 @@
package assign_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr/assign"
)
var expected freefloating.Collection = freefloating.Collection{
freefloating.Start: []freefloating.String{
{
StringType: freefloating.WhiteSpaceType,
Value: " ",
Position: nil,
},
{
StringType: freefloating.CommentType,
Value: "//comment\n",
Position: nil,
},
},
}
var nodes = []node.Node{
&assign.Reference{
FreeFloating: expected,
},
&assign.Assign{
FreeFloating: expected,
},
&assign.BitwiseAnd{
FreeFloating: expected,
},
&assign.BitwiseOr{
FreeFloating: expected,
},
&assign.BitwiseXor{
FreeFloating: expected,
},
&assign.Concat{
FreeFloating: expected,
},
&assign.Div{
FreeFloating: expected,
},
&assign.Minus{
FreeFloating: expected,
},
&assign.Mod{
FreeFloating: expected,
},
&assign.Mul{
FreeFloating: expected,
},
&assign.Plus{
FreeFloating: expected,
},
&assign.Pow{
FreeFloating: expected,
},
&assign.ShiftLeft{
FreeFloating: expected,
},
&assign.ShiftRight{
FreeFloating: expected,
},
&assign.ShiftRight{
FreeFloating: expected,
},
}
func TestMeta(t *testing.T) {
for _, n := range nodes {
actual := *n.GetFreeFloating()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,18 @@
package assign_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -1,15 +1,13 @@
package assign_test package assign_test
import ( import (
"reflect"
"testing" "testing"
"github.com/z7zmey/php-parser/node/expr/assign" "gotest.tools/assert"
"github.com/kylelemons/godebug/pretty"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr" "github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
@ -20,115 +18,115 @@ var nodesToTest = []struct {
}{ }{
{ {
&assign.Reference{ &assign.Reference{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Assign{ &assign.Assign{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.BitwiseAnd{ &assign.BitwiseAnd{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.BitwiseOr{ &assign.BitwiseOr{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.BitwiseXor{ &assign.BitwiseXor{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Concat{ &assign.Concat{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Div{ &assign.Div{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Minus{ &assign.Minus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Mod{ &assign.Mod{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Mul{ &assign.Mul{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Plus{ &assign.Plus{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.Pow{ &assign.Pow{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.ShiftLeft{ &assign.ShiftLeft{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
{ {
&assign.ShiftRight{ &assign.ShiftRight{
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Variable: &expr.Variable{},
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Expression: &expr.Variable{},
}, },
[]string{"Variable", "Expression"}, []string{"Variable", "Expression"},
map[string]interface{}{}, nil,
}, },
} }
@ -138,39 +136,37 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{false, nil} v := &visitorMock{false, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := []string{} expected := []string{}
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
func TestVisitor(t *testing.T) { func TestVisitor(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{true, nil} v := &visitorMock{true, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := tt.expectedVisitedKeys expected := tt.expectedVisitedKeys
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
@ -181,9 +177,6 @@ func TestNameAttributes(t *testing.T) {
expected := tt.expectedAttributes expected := tt.expectedAttributes
actual := tt.node.Attributes() actual := tt.node.Attributes()
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseAnd node // BitwiseAnd node
type BitwiseAnd struct { type BitwiseAnd struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewBitwiseAnd node constructor // NewBitwiseAnd node constructor
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd { func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
return &BitwiseAnd{ return &BitwiseAnd{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseAnd) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseAnd) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseAnd) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseAnd) Attributes() map[string]interface{} { func (n *BitwiseAnd) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseOr node // BitwiseOr node
type BitwiseOr struct { type BitwiseOr struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewBitwiseOr node constructor // NewBitwiseOr node constructor
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr { func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
return &BitwiseOr{ return &BitwiseOr{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseOr) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseOr) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseOr) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseOr) Attributes() map[string]interface{} { func (n *BitwiseOr) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseXor node // BitwiseXor node
type BitwiseXor struct { type BitwiseXor struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewBitwiseXor node constructor // NewBitwiseXor node constructor
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor { func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
return &BitwiseXor{ return &BitwiseXor{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseXor) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseXor) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseXor) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseXor) Attributes() map[string]interface{} { func (n *BitwiseXor) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BooleanAnd node // BooleanAnd node
type BooleanAnd struct { type BooleanAnd struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewBooleanAnd node constructor // NewBooleanAnd node constructor
func NewBooleanAnd(Variable node.Node, Expression node.Node) *BooleanAnd { func NewBooleanAnd(Variable node.Node, Expression node.Node) *BooleanAnd {
return &BooleanAnd{ return &BooleanAnd{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *BooleanAnd) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BooleanAnd) GetPosition() *position.Position {
return n.Position
}
func (n *BooleanAnd) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BooleanAnd) Attributes() map[string]interface{} { func (n *BooleanAnd) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BooleanAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BooleanOr node // BooleanOr node
type BooleanOr struct { type BooleanOr struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewBooleanOr node constructor // NewBooleanOr node constructor
func NewBooleanOr(Variable node.Node, Expression node.Node) *BooleanOr { func NewBooleanOr(Variable node.Node, Expression node.Node) *BooleanOr {
return &BooleanOr{ return &BooleanOr{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *BooleanOr) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BooleanOr) GetPosition() *position.Position {
return n.Position
}
func (n *BooleanOr) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BooleanOr) Attributes() map[string]interface{} { func (n *BooleanOr) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *BooleanOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Coalesce node // Coalesce node
type Coalesce struct { type Coalesce struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewCoalesce node constructor // NewCoalesce node constructor
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce { func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
return &Coalesce{ return &Coalesce{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Coalesce) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Coalesce) GetPosition() *position.Position {
return n.Position
}
func (n *Coalesce) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Coalesce) Attributes() map[string]interface{} { func (n *Coalesce) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Coalesce) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Concat node // Concat node
type Concat struct { type Concat struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewConcat node constructor // NewConcat node constructor
func NewConcat(Variable node.Node, Expression node.Node) *Concat { func NewConcat(Variable node.Node, Expression node.Node) *Concat {
return &Concat{ return &Concat{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Concat) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Concat) GetPosition() *position.Position {
return n.Position
}
func (n *Concat) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Concat) Attributes() map[string]interface{} { func (n *Concat) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Concat) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Div node // Div node
type Div struct { type Div struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewDiv node constructor // NewDiv node constructor
func NewDiv(Variable node.Node, Expression node.Node) *Div { func NewDiv(Variable node.Node, Expression node.Node) *Div {
return &Div{ return &Div{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Div) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Div) GetPosition() *position.Position {
return n.Position
}
func (n *Div) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Div) Attributes() map[string]interface{} { func (n *Div) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Div) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Equal node // Equal node
type Equal struct { type Equal struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewEqual node constructor // NewEqual node constructor
func NewEqual(Variable node.Node, Expression node.Node) *Equal { func NewEqual(Variable node.Node, Expression node.Node) *Equal {
return &Equal{ return &Equal{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Equal) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Equal) GetPosition() *position.Position {
return n.Position
}
func (n *Equal) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Equal) Attributes() map[string]interface{} { func (n *Equal) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Equal) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Greater node // Greater node
type Greater struct { type Greater struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewGreater node constructor // NewGreater node constructor
func NewGreater(Variable node.Node, Expression node.Node) *Greater { func NewGreater(Variable node.Node, Expression node.Node) *Greater {
return &Greater{ return &Greater{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Greater) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Greater) GetPosition() *position.Position {
return n.Position
}
func (n *Greater) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Greater) Attributes() map[string]interface{} { func (n *Greater) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Greater) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// GreaterOrEqual node // GreaterOrEqual node
type GreaterOrEqual struct { type GreaterOrEqual struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewGreaterOrEqual node constructor // NewGreaterOrEqual node constructor
func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual { func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
return &GreaterOrEqual{ return &GreaterOrEqual{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *GreaterOrEqual) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *GreaterOrEqual) GetPosition() *position.Position {
return n.Position
}
func (n *GreaterOrEqual) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *GreaterOrEqual) Attributes() map[string]interface{} { func (n *GreaterOrEqual) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *GreaterOrEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Identical node // Identical node
type Identical struct { type Identical struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewIdentical node constructor // NewIdentical node constructor
func NewIdentical(Variable node.Node, Expression node.Node) *Identical { func NewIdentical(Variable node.Node, Expression node.Node) *Identical {
return &Identical{ return &Identical{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Identical) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Identical) GetPosition() *position.Position {
return n.Position
}
func (n *Identical) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Identical) Attributes() map[string]interface{} { func (n *Identical) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Identical) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// LogicalAnd node // LogicalAnd node
type LogicalAnd struct { type LogicalAnd struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewLogicalAnd node constructor // NewLogicalAnd node constructor
func NewLogicalAnd(Variable node.Node, Expression node.Node) *LogicalAnd { func NewLogicalAnd(Variable node.Node, Expression node.Node) *LogicalAnd {
return &LogicalAnd{ return &LogicalAnd{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *LogicalAnd) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *LogicalAnd) GetPosition() *position.Position {
return n.Position
}
func (n *LogicalAnd) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *LogicalAnd) Attributes() map[string]interface{} { func (n *LogicalAnd) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *LogicalAnd) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// LogicalOr node // LogicalOr node
type LogicalOr struct { type LogicalOr struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewLogicalOr node constructor // NewLogicalOr node constructor
func NewLogicalOr(Variable node.Node, Expression node.Node) *LogicalOr { func NewLogicalOr(Variable node.Node, Expression node.Node) *LogicalOr {
return &LogicalOr{ return &LogicalOr{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *LogicalOr) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *LogicalOr) GetPosition() *position.Position {
return n.Position
}
func (n *LogicalOr) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *LogicalOr) Attributes() map[string]interface{} { func (n *LogicalOr) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *LogicalOr) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// LogicalXor node // LogicalXor node
type LogicalXor struct { type LogicalXor struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewLogicalXor node constructor // NewLogicalXor node constructor
func NewLogicalXor(Variable node.Node, Expression node.Node) *LogicalXor { func NewLogicalXor(Variable node.Node, Expression node.Node) *LogicalXor {
return &LogicalXor{ return &LogicalXor{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *LogicalXor) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *LogicalXor) GetPosition() *position.Position {
return n.Position
}
func (n *LogicalXor) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *LogicalXor) Attributes() map[string]interface{} { func (n *LogicalXor) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *LogicalXor) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Minus node // Minus node
type Minus struct { type Minus struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewMinus node constructor // NewMinus node constructor
func NewMinus(Variable node.Node, Expression node.Node) *Minus { func NewMinus(Variable node.Node, Expression node.Node) *Minus {
return &Minus{ return &Minus{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Minus) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Minus) GetPosition() *position.Position {
return n.Position
}
func (n *Minus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Minus) Attributes() map[string]interface{} { func (n *Minus) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Minus) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Mod node // Mod node
type Mod struct { type Mod struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewMod node constructor // NewMod node constructor
func NewMod(Variable node.Node, Expression node.Node) *Mod { func NewMod(Variable node.Node, Expression node.Node) *Mod {
return &Mod{ return &Mod{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Mod) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Mod) GetPosition() *position.Position {
return n.Position
}
func (n *Mod) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Mod) Attributes() map[string]interface{} { func (n *Mod) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Mod) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Mul node // Mul node
type Mul struct { type Mul struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewMul node constructor // NewMul node constructor
func NewMul(Variable node.Node, Expression node.Node) *Mul { func NewMul(Variable node.Node, Expression node.Node) *Mul {
return &Mul{ return &Mul{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Mul) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Mul) GetPosition() *position.Position {
return n.Position
}
func (n *Mul) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Mul) Attributes() map[string]interface{} { func (n *Mul) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Mul) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// NotEqual node // NotEqual node
type NotEqual struct { type NotEqual struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewNotEqual node constructor // NewNotEqual node constructor
func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual { func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
return &NotEqual{ return &NotEqual{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *NotEqual) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *NotEqual) GetPosition() *position.Position {
return n.Position
}
func (n *NotEqual) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *NotEqual) Attributes() map[string]interface{} { func (n *NotEqual) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *NotEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// NotIdentical node // NotIdentical node
type NotIdentical struct { type NotIdentical struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewNotIdentical node constructor // NewNotIdentical node constructor
func NewNotIdentical(Variable node.Node, Expression node.Node) *NotIdentical { func NewNotIdentical(Variable node.Node, Expression node.Node) *NotIdentical {
return &NotIdentical{ return &NotIdentical{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *NotIdentical) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *NotIdentical) GetPosition() *position.Position {
return n.Position
}
func (n *NotIdentical) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *NotIdentical) Attributes() map[string]interface{} { func (n *NotIdentical) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *NotIdentical) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Plus node // Plus node
type Plus struct { type Plus struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewPlus node constructor // NewPlus node constructor
func NewPlus(Variable node.Node, Expression node.Node) *Plus { func NewPlus(Variable node.Node, Expression node.Node) *Plus {
return &Plus{ return &Plus{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Plus) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Plus) GetPosition() *position.Position {
return n.Position
}
func (n *Plus) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Plus) Attributes() map[string]interface{} { func (n *Plus) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Plus) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Pow node // Pow node
type Pow struct { type Pow struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewPow node constructor // NewPow node constructor
func NewPow(Variable node.Node, Expression node.Node) *Pow { func NewPow(Variable node.Node, Expression node.Node) *Pow {
return &Pow{ return &Pow{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Pow) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Pow) GetPosition() *position.Position {
return n.Position
}
func (n *Pow) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Pow) Attributes() map[string]interface{} { func (n *Pow) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Pow) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ShiftLeft node // ShiftLeft node
type ShiftLeft struct { type ShiftLeft struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewShiftLeft node constructor // NewShiftLeft node constructor
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft { func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
return &ShiftLeft{ return &ShiftLeft{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *ShiftLeft) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ShiftLeft) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftLeft) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ShiftLeft) Attributes() map[string]interface{} { func (n *ShiftLeft) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ShiftRight node // ShiftRight node
type ShiftRight struct { type ShiftRight struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewShiftRight node constructor // NewShiftRight node constructor
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight { func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
return &ShiftRight{ return &ShiftRight{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *ShiftRight) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ShiftRight) GetPosition() *position.Position {
return n.Position
}
func (n *ShiftRight) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ShiftRight) Attributes() map[string]interface{} { func (n *ShiftRight) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Smaller node // Smaller node
type Smaller struct { type Smaller struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewSmaller node constructor // NewSmaller node constructor
func NewSmaller(Variable node.Node, Expression node.Node) *Smaller { func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
return &Smaller{ return &Smaller{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Smaller) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Smaller) GetPosition() *position.Position {
return n.Position
}
func (n *Smaller) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Smaller) Attributes() map[string]interface{} { func (n *Smaller) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Smaller) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// SmallerOrEqual node // SmallerOrEqual node
type SmallerOrEqual struct { type SmallerOrEqual struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewSmallerOrEqual node constructor // NewSmallerOrEqual node constructor
func NewSmallerOrEqual(Variable node.Node, Expression node.Node) *SmallerOrEqual { func NewSmallerOrEqual(Variable node.Node, Expression node.Node) *SmallerOrEqual {
return &SmallerOrEqual{ return &SmallerOrEqual{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *SmallerOrEqual) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *SmallerOrEqual) GetPosition() *position.Position {
return n.Position
}
func (n *SmallerOrEqual) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *SmallerOrEqual) Attributes() map[string]interface{} { func (n *SmallerOrEqual) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *SmallerOrEqual) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package binary package binary
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Spaceship node // Spaceship node
type Spaceship struct { type Spaceship struct {
Left node.Node FreeFloating freefloating.Collection
Right node.Node Position *position.Position
Left node.Node
Right node.Node
} }
// NewSpaceship node constructor // NewSpaceship node constructor
func NewSpaceship(Variable node.Node, Expression node.Node) *Spaceship { func NewSpaceship(Variable node.Node, Expression node.Node) *Spaceship {
return &Spaceship{ return &Spaceship{
Variable, FreeFloating: nil,
Expression, Left: Variable,
Right: Expression,
} }
} }
// SetPosition sets node position
func (n *Spaceship) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Spaceship) GetPosition() *position.Position {
return n.Position
}
func (n *Spaceship) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Spaceship) Attributes() map[string]interface{} { func (n *Spaceship) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *Spaceship) Walk(v walker.Visitor) {
} }
if n.Left != nil { if n.Left != nil {
vv := v.GetChildrenVisitor("Left") v.EnterChildNode("Left", n)
n.Left.Walk(vv) n.Left.Walk(v)
v.LeaveChildNode("Left", n)
} }
if n.Right != nil { if n.Right != nil {
vv := v.GetChildrenVisitor("Right") v.EnterChildNode("Right", n)
n.Right.Walk(vv) n.Right.Walk(v)
v.LeaveChildNode("Right", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,117 @@
package binary_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr/binary"
)
var expected freefloating.Collection = freefloating.Collection{
freefloating.Start: []freefloating.String{
{
StringType: freefloating.WhiteSpaceType,
Value: " ",
Position: nil,
},
{
StringType: freefloating.CommentType,
Value: "//comment\n",
Position: nil,
},
},
}
var nodes = []node.Node{
&binary.BitwiseAnd{
FreeFloating: expected,
},
&binary.BitwiseOr{
FreeFloating: expected,
},
&binary.BitwiseXor{
FreeFloating: expected,
},
&binary.BooleanAnd{
FreeFloating: expected,
},
&binary.BooleanOr{
FreeFloating: expected,
},
&binary.Coalesce{
FreeFloating: expected,
},
&binary.Concat{
FreeFloating: expected,
},
&binary.Div{
FreeFloating: expected,
},
&binary.Equal{
FreeFloating: expected,
},
&binary.GreaterOrEqual{
FreeFloating: expected,
},
&binary.Greater{
FreeFloating: expected,
},
&binary.Identical{
FreeFloating: expected,
},
&binary.LogicalAnd{
FreeFloating: expected,
},
&binary.LogicalOr{
FreeFloating: expected,
},
&binary.LogicalXor{
FreeFloating: expected,
},
&binary.Minus{
FreeFloating: expected,
},
&binary.Mod{
FreeFloating: expected,
},
&binary.Mul{
FreeFloating: expected,
},
&binary.NotEqual{
FreeFloating: expected,
},
&binary.NotIdentical{
FreeFloating: expected,
},
&binary.Plus{
FreeFloating: expected,
},
&binary.Pow{
FreeFloating: expected,
},
&binary.ShiftLeft{
FreeFloating: expected,
},
&binary.ShiftRight{
FreeFloating: expected,
},
&binary.SmallerOrEqual{
FreeFloating: expected,
},
&binary.Smaller{
FreeFloating: expected,
},
&binary.Spaceship{
FreeFloating: expected,
},
}
func TestMeta(t *testing.T) {
for _, n := range nodes {
actual := *n.GetFreeFloating()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,18 @@
package binary_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -1,15 +1,13 @@
package binary_test package binary_test
import ( import (
"reflect"
"testing" "testing"
"github.com/kylelemons/godebug/pretty"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr" "github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/binary" "github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
"gotest.tools/assert"
) )
var nodesToTest = []struct { var nodesToTest = []struct {
@ -19,219 +17,219 @@ var nodesToTest = []struct {
}{ }{
{ {
&binary.BitwiseAnd{ &binary.BitwiseAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.BitwiseOr{ &binary.BitwiseOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.BitwiseXor{ &binary.BitwiseXor{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.BooleanAnd{ &binary.BooleanAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.BooleanOr{ &binary.BooleanOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Coalesce{ &binary.Coalesce{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Concat{ &binary.Concat{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Div{ &binary.Div{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Equal{ &binary.Equal{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.GreaterOrEqual{ &binary.GreaterOrEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Greater{ &binary.Greater{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Identical{ &binary.Identical{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.LogicalAnd{ &binary.LogicalAnd{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.LogicalOr{ &binary.LogicalOr{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.LogicalXor{ &binary.LogicalXor{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Minus{ &binary.Minus{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Mod{ &binary.Mod{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Mul{ &binary.Mul{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.NotEqual{ &binary.NotEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.NotIdentical{ &binary.NotIdentical{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Plus{ &binary.Plus{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Pow{ &binary.Pow{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.ShiftLeft{ &binary.ShiftLeft{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.ShiftRight{ &binary.ShiftRight{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.SmallerOrEqual{ &binary.SmallerOrEqual{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Smaller{ &binary.Smaller{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
{ {
&binary.Spaceship{ &binary.Spaceship{
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Left: &expr.Variable{},
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}}, Right: &expr.Variable{},
}, },
[]string{"Left", "Right"}, []string{"Left", "Right"},
map[string]interface{}{}, nil,
}, },
} }
@ -241,39 +239,37 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{false, nil} v := &visitorMock{false, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := []string{} expected := []string{}
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
func TestVisitor(t *testing.T) { func TestVisitor(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{true, nil} v := &visitorMock{true, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := tt.expectedVisitedKeys expected := tt.expectedVisitedKeys
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
@ -284,9 +280,6 @@ func TestNameAttributes(t *testing.T) {
expected := tt.expectedAttributes expected := tt.expectedAttributes
actual := tt.node.Attributes() actual := tt.node.Attributes()
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Array node // Array node
type Array struct { type Array struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewArray node constructor // NewArray node constructor
func NewArray(Expr node.Node) *Array { func NewArray(Expr node.Node) *Array {
return &Array{ return &Array{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Array) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Array) GetPosition() *position.Position {
return n.Position
}
func (n *Array) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Array) Attributes() map[string]interface{} { func (n *Array) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Array) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Bool node // Bool node
type Bool struct { type Bool struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewBool node constructor // NewBool node constructor
func NewBool(Expr node.Node) *Bool { func NewBool(Expr node.Node) *Bool {
return &Bool{ return &Bool{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Bool) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Bool) GetPosition() *position.Position {
return n.Position
}
func (n *Bool) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Bool) Attributes() map[string]interface{} { func (n *Bool) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Bool) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Double node // Double node
type Double struct { type Double struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewDouble node constructor // NewDouble node constructor
func NewDouble(Expr node.Node) *Double { func NewDouble(Expr node.Node) *Double {
return &Double{ return &Double{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Double) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Double) GetPosition() *position.Position {
return n.Position
}
func (n *Double) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Double) Attributes() map[string]interface{} { func (n *Double) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Double) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Int node // Int node
type Int struct { type Int struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewInt node constructor // NewInt node constructor
func NewInt(Expr node.Node) *Int { func NewInt(Expr node.Node) *Int {
return &Int{ return &Int{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Int) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Int) GetPosition() *position.Position {
return n.Position
}
func (n *Int) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Int) Attributes() map[string]interface{} { func (n *Int) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Int) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Object node // Object node
type Object struct { type Object struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewObject node constructor // NewObject node constructor
func NewObject(Expr node.Node) *Object { func NewObject(Expr node.Node) *Object {
return &Object{ return &Object{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Object) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Object) GetPosition() *position.Position {
return n.Position
}
func (n *Object) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Object) Attributes() map[string]interface{} { func (n *Object) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Object) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// String node // String node
type String struct { type String struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewString node constructor // NewString node constructor
func NewString(Expr node.Node) *String { func NewString(Expr node.Node) *String {
return &String{ return &String{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *String) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *String) GetPosition() *position.Position {
return n.Position
}
func (n *String) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *String) Attributes() map[string]interface{} { func (n *String) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *String) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package cast package cast
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Unset node // Unset node
type Unset struct { type Unset struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewUnset node constructor // NewUnset node constructor
func NewUnset(Expr node.Node) *Unset { func NewUnset(Expr node.Node) *Unset {
return &Unset{ return &Unset{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// 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
}
func (n *Unset) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Unset) Attributes() map[string]interface{} { func (n *Unset) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Unset) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -2,10 +2,9 @@ package cast_test
import ( import (
"bytes" "bytes"
"reflect"
"testing" "testing"
"github.com/kylelemons/godebug/pretty" "gotest.tools/assert"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr" "github.com/z7zmey/php-parser/node/expr"
@ -13,28 +12,51 @@ import (
"github.com/z7zmey/php-parser/node/stmt" "github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/php5" "github.com/z7zmey/php-parser/php5"
"github.com/z7zmey/php-parser/php7" "github.com/z7zmey/php-parser/php7"
"github.com/z7zmey/php-parser/position"
) )
func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
if !reflect.DeepEqual(expected, actual) {
diff := pretty.Compare(expected, actual)
if diff != "" {
t.Errorf("diff: (-expected +actual)\n%s", diff)
} else {
t.Errorf("expected and actual are not equal\n")
}
}
}
func TestArray(t *testing.T) { func TestArray(t *testing.T) {
src := `<? (array)$a;` src := `<? (array)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &cast.Array{ Expr: &cast.Array{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Expr: &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",
},
},
}, },
}, },
}, },
@ -43,22 +65,56 @@ func TestArray(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestBool(t *testing.T) { func TestBool(t *testing.T) {
src := `<? (boolean)$a;` src := `<? (boolean)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Expr: &cast.Bool{ Expr: &cast.Bool{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
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",
},
},
}, },
}, },
}, },
@ -67,22 +123,56 @@ func TestBool(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestBoolShort(t *testing.T) { func TestBoolShort(t *testing.T) {
src := `<? (bool)$a;` src := `<? (bool)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Expr: &cast.Bool{ Expr: &cast.Bool{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
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: "a",
},
},
}, },
}, },
}, },
@ -91,22 +181,56 @@ func TestBoolShort(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestDouble(t *testing.T) { func TestDouble(t *testing.T) {
src := `<? (double)$a;` src := `<? (double)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Expr: &cast.Double{ Expr: &cast.Double{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Value: "a",
},
},
}, },
}, },
}, },
@ -115,22 +239,56 @@ func TestDouble(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestCastFloat(t *testing.T) { func TestCastFloat(t *testing.T) {
src := `<? (float)$a;` src := `<? (float)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &cast.Double{ Expr: &cast.Double{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Expr: &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",
},
},
}, },
}, },
}, },
@ -139,22 +297,56 @@ func TestCastFloat(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestInt(t *testing.T) { func TestInt(t *testing.T) {
src := `<? (integer)$a;` src := `<? (integer)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 15,
},
Expr: &cast.Int{ Expr: &cast.Int{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
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",
},
},
}, },
}, },
}, },
@ -163,22 +355,56 @@ func TestInt(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestIntShort(t *testing.T) { func TestIntShort(t *testing.T) {
src := `<? (int)$a;` src := `<? (int)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 11,
},
Expr: &cast.Int{ Expr: &cast.Int{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 10,
},
Expr: &expr.Variable{
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",
},
},
}, },
}, },
}, },
@ -187,22 +413,56 @@ func TestIntShort(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestObject(t *testing.T) { func TestObject(t *testing.T) {
src := `<? (object)$a;` src := `<? (object)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Expr: &cast.Object{ Expr: &cast.Object{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Value: "a",
},
},
}, },
}, },
}, },
@ -211,22 +471,56 @@ func TestObject(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }
func TestString(t *testing.T) { func TestString(t *testing.T) {
src := `<? (string)$a;` src := `<? (string)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Expr: &cast.String{ Expr: &cast.String{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Value: "a",
},
},
}, },
}, },
}, },
@ -235,22 +529,114 @@ func TestString(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
}
func TestBinaryString(t *testing.T) {
src := `<? (binary)$a;`
expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Stmts: []node.Node{
&stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 14,
},
Expr: &cast.String{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &expr.Variable{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
VarName: &node.Identifier{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 12,
EndPos: 13,
},
Value: "a",
},
},
},
},
},
}
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse()
actual := php7parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse()
actual = php5parser.GetRootNode()
assert.DeepEqual(t, expected, actual)
} }
func TestUnset(t *testing.T) { func TestUnset(t *testing.T) {
src := `<? (unset)$a;` src := `<? (unset)$a;`
expected := &node.Root{ expected := &node.Root{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Stmts: []node.Node{ Stmts: []node.Node{
&stmt.Expression{ &stmt.Expression{
Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 13,
},
Expr: &cast.Unset{ Expr: &cast.Unset{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Position: &position.Position{
StartLine: 1,
EndLine: 1,
StartPos: 4,
EndPos: 12,
},
Expr: &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",
},
},
}, },
}, },
}, },
@ -259,10 +645,10 @@ func TestUnset(t *testing.T) {
php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php") php7parser := php7.NewParser(bytes.NewBufferString(src), "test.php")
php7parser.Parse() php7parser.Parse()
actual := php7parser.GetRootNode() actual := php7parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php") php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
php5parser.Parse() php5parser.Parse()
actual = php5parser.GetRootNode() actual = php5parser.GetRootNode()
assertEqual(t, expected, actual) assert.DeepEqual(t, expected, actual)
} }

View File

@ -0,0 +1,57 @@
package cast_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr/cast"
)
var expected freefloating.Collection = freefloating.Collection{
freefloating.Start: []freefloating.String{
{
StringType: freefloating.WhiteSpaceType,
Value: " ",
Position: nil,
},
{
StringType: freefloating.CommentType,
Value: "//comment\n",
Position: nil,
},
},
}
var nodes = []node.Node{
&cast.Array{
FreeFloating: expected,
},
&cast.Bool{
FreeFloating: expected,
},
&cast.Double{
FreeFloating: expected,
},
&cast.Int{
FreeFloating: expected,
},
&cast.Object{
FreeFloating: expected,
},
&cast.String{
FreeFloating: expected,
},
&cast.Unset{
FreeFloating: expected,
},
}
func TestMeta(t *testing.T) {
for _, n := range nodes {
actual := *n.GetFreeFloating()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -0,0 +1,18 @@
package cast_test
import (
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/position"
)
func TestPosition(t *testing.T) {
expected := position.NewPosition(1, 1, 1, 1)
for _, n := range nodes {
n.SetPosition(expected)
actual := n.GetPosition()
assert.DeepEqual(t, expected, actual)
}
}

View File

@ -1,10 +1,9 @@
package cast_test package cast_test
import ( import (
"reflect"
"testing" "testing"
"github.com/kylelemons/godebug/pretty" "gotest.tools/assert"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr" "github.com/z7zmey/php-parser/node/expr"
@ -19,52 +18,52 @@ var nodesToTest = []struct {
}{ }{
{ {
&cast.Array{ &cast.Array{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.Bool{ &cast.Bool{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.Double{ &cast.Double{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.Int{ &cast.Int{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.Object{ &cast.Object{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.String{ &cast.String{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
{ {
&cast.Unset{ &cast.Unset{
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}, Expr: &expr.Variable{},
}, },
[]string{"Expr"}, []string{"Expr"},
map[string]interface{}{}, nil,
}, },
} }
@ -74,39 +73,37 @@ type visitorMock struct {
} }
func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren } func (v *visitorMock) EnterNode(n walker.Walkable) bool { return v.visitChildren }
func (v *visitorMock) GetChildrenVisitor(key string) walker.Visitor { func (v *visitorMock) LeaveNode(n walker.Walkable) {}
func (v *visitorMock) EnterChildNode(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key) v.visitedKeys = append(v.visitedKeys, key)
return &visitorMock{v.visitChildren, nil}
} }
func (v *visitorMock) LeaveNode(n walker.Walkable) {} func (v *visitorMock) LeaveChildNode(key string, w walker.Walkable) {}
func (v *visitorMock) EnterChildList(key string, w walker.Walkable) {
v.visitedKeys = append(v.visitedKeys, key)
}
func (v *visitorMock) LeaveChildList(key string, w walker.Walkable) {}
func TestVisitorDisableChildren(t *testing.T) { func TestVisitorDisableChildren(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{false, nil} v := &visitorMock{false, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := []string{} expected := []string{}
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
func TestVisitor(t *testing.T) { func TestVisitor(t *testing.T) {
for _, tt := range nodesToTest { for _, tt := range nodesToTest {
v := &visitorMock{true, nil} v := &visitorMock{true, []string{}}
tt.node.Walk(v) tt.node.Walk(v)
expected := tt.expectedVisitedKeys expected := tt.expectedVisitedKeys
actual := v.visitedKeys actual := v.visitedKeys
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }
@ -117,9 +114,6 @@ func TestNameAttributes(t *testing.T) {
expected := tt.expectedAttributes expected := tt.expectedAttributes
actual := tt.node.Attributes() actual := tt.node.Attributes()
diff := pretty.Compare(expected, actual) assert.DeepEqual(t, expected, actual)
if diff != "" {
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
}
} }
} }

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Array node // Array node
type Array struct { type Array struct {
Items []node.Node FreeFloating freefloating.Collection
Position *position.Position
Items []node.Node
} }
// NewArray node constructor // NewArray node constructor
func NewArray(Items []node.Node) *Array { func NewArray(Items []node.Node) *Array {
return &Array{ return &Array{
Items, FreeFloating: nil,
Items: Items,
} }
} }
// SetPosition sets node position
func (n *Array) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Array) GetPosition() *position.Position {
return n.Position
}
func (n *Array) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Array) Attributes() map[string]interface{} { func (n *Array) Attributes() map[string]interface{} {
return nil return nil
@ -30,12 +49,13 @@ func (n *Array) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ArrayDimFetch node // ArrayDimFetch node
type ArrayDimFetch struct { type ArrayDimFetch struct {
Variable node.Node FreeFloating freefloating.Collection
Dim node.Node Position *position.Position
Variable node.Node
Dim node.Node
} }
// NewArrayDimFetch node constructor // NewArrayDimFetch node constructor
func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch { func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch {
return &ArrayDimFetch{ return &ArrayDimFetch{
Variable, FreeFloating: nil,
Dim, Variable: Variable,
Dim: Dim,
} }
} }
// SetPosition sets node position
func (n *ArrayDimFetch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ArrayDimFetch) GetPosition() *position.Position {
return n.Position
}
func (n *ArrayDimFetch) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ArrayDimFetch) Attributes() map[string]interface{} { func (n *ArrayDimFetch) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ArrayDimFetch) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Dim != nil { if n.Dim != nil {
vv := v.GetChildrenVisitor("Dim") v.EnterChildNode("Dim", n)
n.Dim.Walk(vv) n.Dim.Walk(v)
v.LeaveChildNode("Dim", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ArrayItem node // ArrayItem node
type ArrayItem struct { type ArrayItem struct {
Key node.Node FreeFloating freefloating.Collection
Val node.Node Position *position.Position
Key node.Node
Val node.Node
} }
// NewArrayItem node constructor // NewArrayItem node constructor
func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem { func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem {
return &ArrayItem{ return &ArrayItem{
Key, FreeFloating: nil,
Val, Key: Key,
Val: Val,
} }
} }
// SetPosition sets node position
func (n *ArrayItem) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ArrayItem) GetPosition() *position.Position {
return n.Position
}
func (n *ArrayItem) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ArrayItem) Attributes() map[string]interface{} { func (n *ArrayItem) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ArrayItem) Walk(v walker.Visitor) {
} }
if n.Key != nil { if n.Key != nil {
vv := v.GetChildrenVisitor("Key") v.EnterChildNode("Key", n)
n.Key.Walk(vv) n.Key.Walk(v)
v.LeaveChildNode("Key", n)
} }
if n.Val != nil { if n.Val != nil {
vv := v.GetChildrenVisitor("Val") v.EnterChildNode("Val", n)
n.Val.Walk(vv) n.Val.Walk(v)
v.LeaveChildNode("Val", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BitwiseNot node // BitwiseNot node
type BitwiseNot struct { type BitwiseNot struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewBitwiseNot node constructor // NewBitwiseNot node constructor
func NewBitwiseNot(Expression node.Node) *BitwiseNot { func NewBitwiseNot(Expression node.Node) *BitwiseNot {
return &BitwiseNot{ return &BitwiseNot{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *BitwiseNot) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BitwiseNot) GetPosition() *position.Position {
return n.Position
}
func (n *BitwiseNot) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BitwiseNot) Attributes() map[string]interface{} { func (n *BitwiseNot) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *BitwiseNot) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// BooleanNot node // BooleanNot node
type BooleanNot struct { type BooleanNot struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewBooleanNot node constructor // NewBooleanNot node constructor
func NewBooleanNot(Expression node.Node) *BooleanNot { func NewBooleanNot(Expression node.Node) *BooleanNot {
return &BooleanNot{ return &BooleanNot{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *BooleanNot) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *BooleanNot) GetPosition() *position.Position {
return n.Position
}
func (n *BooleanNot) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *BooleanNot) Attributes() map[string]interface{} { func (n *BooleanNot) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *BooleanNot) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,12 +1,16 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ClassConstFetch node // ClassConstFetch node
type ClassConstFetch struct { type ClassConstFetch struct {
FreeFloating freefloating.Collection
Position *position.Position
Class node.Node Class node.Node
ConstantName node.Node ConstantName node.Node
} }
@ -14,11 +18,26 @@ type ClassConstFetch struct {
// NewClassConstFetch node constructor // NewClassConstFetch node constructor
func NewClassConstFetch(Class node.Node, ConstantName node.Node) *ClassConstFetch { func NewClassConstFetch(Class node.Node, ConstantName node.Node) *ClassConstFetch {
return &ClassConstFetch{ return &ClassConstFetch{
Class, FreeFloating: nil,
ConstantName, Class: Class,
ConstantName: ConstantName,
} }
} }
// SetPosition sets node position
func (n *ClassConstFetch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClassConstFetch) GetPosition() *position.Position {
return n.Position
}
func (n *ClassConstFetch) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ClassConstFetch) Attributes() map[string]interface{} { func (n *ClassConstFetch) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *ClassConstFetch) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.ConstantName != nil { if n.ConstantName != nil {
vv := v.GetChildrenVisitor("ConstantName") v.EnterChildNode("ConstantName", n)
n.ConstantName.Walk(vv) n.ConstantName.Walk(v)
v.LeaveChildNode("ConstantName", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Clone node // Clone node
type Clone struct { type Clone struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewClone node constructor // NewClone node constructor
func NewClone(Expression node.Node) *Clone { func NewClone(Expression node.Node) *Clone {
return &Clone{ return &Clone{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *Clone) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Clone) GetPosition() *position.Position {
return n.Position
}
func (n *Clone) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Clone) Attributes() map[string]interface{} { func (n *Clone) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Clone) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,12 +1,16 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Closure node // Closure node
type Closure struct { type Closure struct {
FreeFloating freefloating.Collection
Position *position.Position
ReturnsRef bool ReturnsRef bool
Static bool Static bool
PhpDocComment string PhpDocComment string
@ -19,16 +23,31 @@ type Closure struct {
// NewClosure node constructor // NewClosure node constructor
func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure { func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure {
return &Closure{ return &Closure{
ReturnsRef, FreeFloating: nil,
Static, ReturnsRef: ReturnsRef,
PhpDocComment, Static: Static,
Params, PhpDocComment: PhpDocComment,
ClosureUse, Params: Params,
ReturnType, ClosureUse: ClosureUse,
Stmts, ReturnType: ReturnType,
Stmts: Stmts,
} }
} }
// SetPosition sets node position
func (n *Closure) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Closure) GetPosition() *position.Position {
return n.Position
}
func (n *Closure) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Closure) Attributes() map[string]interface{} { func (n *Closure) Attributes() map[string]interface{} {
return map[string]interface{}{ return map[string]interface{}{
@ -46,31 +65,35 @@ func (n *Closure) Walk(v walker.Visitor) {
} }
if n.Params != nil { if n.Params != nil {
vv := v.GetChildrenVisitor("Params") v.EnterChildList("Params", n)
for _, nn := range n.Params { for _, nn := range n.Params {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Params", n)
} }
if n.ClosureUse != nil { if n.ClosureUse != nil {
vv := v.GetChildrenVisitor("ClosureUse") v.EnterChildNode("ClosureUse", n)
n.ClosureUse.Walk(vv) n.ClosureUse.Walk(v)
v.LeaveChildNode("ClosureUse", n)
} }
if n.ReturnType != nil { if n.ReturnType != nil {
vv := v.GetChildrenVisitor("ReturnType") v.EnterChildNode("ReturnType", n)
n.ReturnType.Walk(vv) n.ReturnType.Walk(v)
v.LeaveChildNode("ReturnType", n)
} }
if n.Stmts != nil { if n.Stmts != nil {
vv := v.GetChildrenVisitor("Stmts") v.EnterChildList("Stmts", n)
for _, nn := range n.Stmts { for _, nn := range n.Stmts {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Stmts", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ClosureUse node // ClosureUse node
type ClosureUse struct { type ClosureUse struct {
Uses []node.Node FreeFloating freefloating.Collection
Position *position.Position
Uses []node.Node
} }
// NewClosureUse node constructor // NewClosureUse node constructor
func NewClosureUse(Uses []node.Node) *ClosureUse { func NewClosureUse(Uses []node.Node) *ClosureUse {
return &ClosureUse{ return &ClosureUse{
Uses, FreeFloating: nil,
Uses: Uses,
} }
} }
// SetPosition sets node position
func (n *ClosureUse) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ClosureUse) GetPosition() *position.Position {
return n.Position
}
func (n *ClosureUse) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ClosureUse) Attributes() map[string]interface{} { func (n *ClosureUse) Attributes() map[string]interface{} {
return nil return nil
@ -30,12 +49,13 @@ func (n *ClosureUse) Walk(v walker.Visitor) {
} }
if n.Uses != nil { if n.Uses != nil {
vv := v.GetChildrenVisitor("Uses") v.EnterChildList("Uses", n)
for _, nn := range n.Uses { for _, nn := range n.Uses {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Uses", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ConstFetch node // ConstFetch node
type ConstFetch struct { type ConstFetch struct {
Constant node.Node FreeFloating freefloating.Collection
Position *position.Position
Constant node.Node
} }
// NewConstFetch node constructor // NewConstFetch node constructor
func NewConstFetch(Constant node.Node) *ConstFetch { func NewConstFetch(Constant node.Node) *ConstFetch {
return &ConstFetch{ return &ConstFetch{
Constant, FreeFloating: nil,
Constant: Constant,
} }
} }
// SetPosition sets node position
func (n *ConstFetch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ConstFetch) GetPosition() *position.Position {
return n.Position
}
func (n *ConstFetch) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ConstFetch) Attributes() map[string]interface{} { func (n *ConstFetch) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *ConstFetch) Walk(v walker.Visitor) {
} }
if n.Constant != nil { if n.Constant != nil {
vv := v.GetChildrenVisitor("Constant") v.EnterChildNode("Constant", n)
n.Constant.Walk(vv) n.Constant.Walk(v)
v.LeaveChildNode("Constant", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,38 +0,0 @@
package expr
import (
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/walker"
)
// Die node
type Die struct {
Expr node.Node
}
// NewDie node constructor
func NewDie(Expr node.Node) *Die {
return &Die{
Expr,
}
}
// Attributes returns node attributes as map
func (n *Die) Attributes() map[string]interface{} {
return nil
}
// Walk traverses nodes
// Walk is invoked recursively until v.EnterNode returns true
func (n *Die) Walk(v walker.Visitor) {
if v.EnterNode(n) == false {
return
}
if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr")
n.Expr.Walk(vv)
}
v.LeaveNode(n)
}

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Empty node // Empty node
type Empty struct { type Empty struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewEmpty node constructor // NewEmpty node constructor
func NewEmpty(Expression node.Node) *Empty { func NewEmpty(Expression node.Node) *Empty {
return &Empty{ return &Empty{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *Empty) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Empty) GetPosition() *position.Position {
return n.Position
}
func (n *Empty) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Empty) Attributes() map[string]interface{} { func (n *Empty) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Empty) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// ErrorSuppress node // ErrorSuppress node
type ErrorSuppress struct { type ErrorSuppress struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewErrorSuppress node constructor // NewErrorSuppress node constructor
func NewErrorSuppress(Expression node.Node) *ErrorSuppress { func NewErrorSuppress(Expression node.Node) *ErrorSuppress {
return &ErrorSuppress{ return &ErrorSuppress{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *ErrorSuppress) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *ErrorSuppress) GetPosition() *position.Position {
return n.Position
}
func (n *ErrorSuppress) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *ErrorSuppress) Attributes() map[string]interface{} { func (n *ErrorSuppress) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *ErrorSuppress) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Eval node // Eval node
type Eval struct { type Eval struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewEval node constructor // NewEval node constructor
func NewEval(Expression node.Node) *Eval { func NewEval(Expression node.Node) *Eval {
return &Eval{ return &Eval{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *Eval) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Eval) GetPosition() *position.Position {
return n.Position
}
func (n *Eval) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Eval) Attributes() map[string]interface{} { func (n *Eval) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Eval) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,25 +1,47 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Exit node // Exit node
type Exit struct { type Exit struct {
Expr node.Node FreeFloating freefloating.Collection
Die bool
Position *position.Position
Expr node.Node
} }
// NewExit node constructor // NewExit node constructor
func NewExit(Expr node.Node) *Exit { func NewExit(Expr node.Node) *Exit {
return &Exit{ return &Exit{
Expr, FreeFloating: nil,
Expr: Expr,
} }
} }
// SetPosition sets node position
func (n *Exit) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Exit) GetPosition() *position.Position {
return n.Position
}
func (n *Exit) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Exit) Attributes() map[string]interface{} { func (n *Exit) Attributes() map[string]interface{} {
return nil return map[string]interface{}{
"Die": n.Die,
}
} }
// Walk traverses nodes // Walk traverses nodes
@ -30,8 +52,9 @@ func (n *Exit) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,12 +1,16 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// FunctionCall node // FunctionCall node
type FunctionCall struct { type FunctionCall struct {
FreeFloating freefloating.Collection
Position *position.Position
Function node.Node Function node.Node
ArgumentList *node.ArgumentList ArgumentList *node.ArgumentList
} }
@ -14,11 +18,26 @@ type FunctionCall struct {
// NewFunctionCall node constructor // NewFunctionCall node constructor
func NewFunctionCall(Function node.Node, ArgumentList *node.ArgumentList) *FunctionCall { func NewFunctionCall(Function node.Node, ArgumentList *node.ArgumentList) *FunctionCall {
return &FunctionCall{ return &FunctionCall{
Function, FreeFloating: nil,
ArgumentList, Function: Function,
ArgumentList: ArgumentList,
} }
} }
// SetPosition sets node position
func (n *FunctionCall) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *FunctionCall) GetPosition() *position.Position {
return n.Position
}
func (n *FunctionCall) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *FunctionCall) Attributes() map[string]interface{} { func (n *FunctionCall) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *FunctionCall) Walk(v walker.Visitor) {
} }
if n.Function != nil { if n.Function != nil {
vv := v.GetChildrenVisitor("Function") v.EnterChildNode("Function", n)
n.Function.Walk(vv) n.Function.Walk(v)
v.LeaveChildNode("Function", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Include node // Include node
type Include struct { type Include struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewInclude node constructor // NewInclude node constructor
func NewInclude(Expression node.Node) *Include { func NewInclude(Expression node.Node) *Include {
return &Include{ return &Include{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *Include) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Include) GetPosition() *position.Position {
return n.Position
}
func (n *Include) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Include) Attributes() map[string]interface{} { func (n *Include) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Include) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// IncludeOnce node // IncludeOnce node
type IncludeOnce struct { type IncludeOnce struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewIncludeOnce node constructor // NewIncludeOnce node constructor
func NewIncludeOnce(Expression node.Node) *IncludeOnce { func NewIncludeOnce(Expression node.Node) *IncludeOnce {
return &IncludeOnce{ return &IncludeOnce{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *IncludeOnce) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *IncludeOnce) GetPosition() *position.Position {
return n.Position
}
func (n *IncludeOnce) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *IncludeOnce) Attributes() map[string]interface{} { func (n *IncludeOnce) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *IncludeOnce) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// InstanceOf node // InstanceOf node
type InstanceOf struct { type InstanceOf struct {
Expr node.Node FreeFloating freefloating.Collection
Class node.Node Position *position.Position
Expr node.Node
Class node.Node
} }
// NewInstanceOf node constructor // NewInstanceOf node constructor
func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf { func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf {
return &InstanceOf{ return &InstanceOf{
Expr, FreeFloating: nil,
Class, Expr: Expr,
Class: Class,
} }
} }
// SetPosition sets node position
func (n *InstanceOf) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *InstanceOf) GetPosition() *position.Position {
return n.Position
}
func (n *InstanceOf) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *InstanceOf) Attributes() map[string]interface{} { func (n *InstanceOf) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *InstanceOf) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Isset node // Isset node
type Isset struct { type Isset struct {
Variables []node.Node FreeFloating freefloating.Collection
Position *position.Position
Variables []node.Node
} }
// NewIsset node constructor // NewIsset node constructor
func NewIsset(Variables []node.Node) *Isset { func NewIsset(Variables []node.Node) *Isset {
return &Isset{ return &Isset{
Variables, FreeFloating: nil,
Variables: Variables,
} }
} }
// SetPosition sets node position
func (n *Isset) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Isset) GetPosition() *position.Position {
return n.Position
}
func (n *Isset) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Isset) Attributes() map[string]interface{} { func (n *Isset) Attributes() map[string]interface{} {
return nil return nil
@ -30,12 +49,13 @@ func (n *Isset) Walk(v walker.Visitor) {
} }
if n.Variables != nil { if n.Variables != nil {
vv := v.GetChildrenVisitor("Variables") v.EnterChildList("Variables", n)
for _, nn := range n.Variables { for _, nn := range n.Variables {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Variables", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// List node // List node
type List struct { type List struct {
Items []node.Node FreeFloating freefloating.Collection
Position *position.Position
Items []node.Node
} }
// NewList node constructor // NewList node constructor
func NewList(Items []node.Node) *List { func NewList(Items []node.Node) *List {
return &List{ return &List{
Items, FreeFloating: nil,
Items: Items,
} }
} }
// SetPosition sets node position
func (n *List) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *List) GetPosition() *position.Position {
return n.Position
}
func (n *List) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *List) Attributes() map[string]interface{} { func (n *List) Attributes() map[string]interface{} {
return nil return nil
@ -30,12 +49,13 @@ func (n *List) Walk(v walker.Visitor) {
} }
if n.Items != nil { if n.Items != nil {
vv := v.GetChildrenVisitor("Items") v.EnterChildList("Items", n)
for _, nn := range n.Items { for _, nn := range n.Items {
if nn != nil { if nn != nil {
nn.Walk(vv) nn.Walk(v)
} }
} }
v.LeaveChildList("Items", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,12 +1,16 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// MethodCall node // MethodCall node
type MethodCall struct { type MethodCall struct {
FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node Variable node.Node
Method node.Node Method node.Node
ArgumentList *node.ArgumentList ArgumentList *node.ArgumentList
@ -15,12 +19,27 @@ type MethodCall struct {
// NewMethodCall node constructor // NewMethodCall node constructor
func NewMethodCall(Variable node.Node, Method node.Node, ArgumentList *node.ArgumentList) *MethodCall { func NewMethodCall(Variable node.Node, Method node.Node, ArgumentList *node.ArgumentList) *MethodCall {
return &MethodCall{ return &MethodCall{
Variable, FreeFloating: nil,
Method, Variable: Variable,
ArgumentList, Method: Method,
ArgumentList: ArgumentList,
} }
} }
// SetPosition sets node position
func (n *MethodCall) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *MethodCall) GetPosition() *position.Position {
return n.Position
}
func (n *MethodCall) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *MethodCall) Attributes() map[string]interface{} { func (n *MethodCall) Attributes() map[string]interface{} {
return nil return nil
@ -34,18 +53,21 @@ func (n *MethodCall) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Method != nil { if n.Method != nil {
vv := v.GetChildrenVisitor("Method") v.EnterChildNode("Method", n)
n.Method.Walk(vv) n.Method.Walk(v)
v.LeaveChildNode("Method", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,12 +1,16 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// New node // New node
type New struct { type New struct {
FreeFloating freefloating.Collection
Position *position.Position
Class node.Node Class node.Node
ArgumentList *node.ArgumentList ArgumentList *node.ArgumentList
} }
@ -14,11 +18,26 @@ type New struct {
// NewNew node constructor // NewNew node constructor
func NewNew(Class node.Node, ArgumentList *node.ArgumentList) *New { func NewNew(Class node.Node, ArgumentList *node.ArgumentList) *New {
return &New{ return &New{
Class, FreeFloating: nil,
ArgumentList, Class: Class,
ArgumentList: ArgumentList,
} }
} }
// SetPosition sets node position
func (n *New) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *New) GetPosition() *position.Position {
return n.Position
}
func (n *New) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *New) Attributes() map[string]interface{} { func (n *New) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *New) Walk(v walker.Visitor) {
} }
if n.Class != nil { if n.Class != nil {
vv := v.GetChildrenVisitor("Class") v.EnterChildNode("Class", n)
n.Class.Walk(vv) n.Class.Walk(v)
v.LeaveChildNode("Class", n)
} }
if n.ArgumentList != nil { if n.ArgumentList != nil {
vv := v.GetChildrenVisitor("ArgumentList") v.EnterChildNode("ArgumentList", n)
n.ArgumentList.Walk(vv) n.ArgumentList.Walk(v)
v.LeaveChildNode("ArgumentList", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// PostDec node // PostDec node
type PostDec struct { type PostDec struct {
Variable node.Node FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
} }
// NewPostDec node constructor // NewPostDec node constructor
func NewPostDec(Variable node.Node) *PostDec { func NewPostDec(Variable node.Node) *PostDec {
return &PostDec{ return &PostDec{
Variable, FreeFloating: nil,
Variable: Variable,
} }
} }
// SetPosition sets node position
func (n *PostDec) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PostDec) GetPosition() *position.Position {
return n.Position
}
func (n *PostDec) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *PostDec) Attributes() map[string]interface{} { func (n *PostDec) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *PostDec) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// PostInc node // PostInc node
type PostInc struct { type PostInc struct {
Variable node.Node FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
} }
// NewPostInc node constructor // NewPostInc node constructor
func NewPostInc(Variable node.Node) *PostInc { func NewPostInc(Variable node.Node) *PostInc {
return &PostInc{ return &PostInc{
Variable, FreeFloating: nil,
Variable: Variable,
} }
} }
// SetPosition sets node position
func (n *PostInc) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PostInc) GetPosition() *position.Position {
return n.Position
}
func (n *PostInc) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *PostInc) Attributes() map[string]interface{} { func (n *PostInc) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *PostInc) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// PreDec node // PreDec node
type PreDec struct { type PreDec struct {
Variable node.Node FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
} }
// NewPreDec node constructor // NewPreDec node constructor
func NewPreDec(Variable node.Node) *PreDec { func NewPreDec(Variable node.Node) *PreDec {
return &PreDec{ return &PreDec{
Variable, FreeFloating: nil,
Variable: Variable,
} }
} }
// SetPosition sets node position
func (n *PreDec) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PreDec) GetPosition() *position.Position {
return n.Position
}
func (n *PreDec) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *PreDec) Attributes() map[string]interface{} { func (n *PreDec) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *PreDec) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// PreInc node // PreInc node
type PreInc struct { type PreInc struct {
Variable node.Node FreeFloating freefloating.Collection
Position *position.Position
Variable node.Node
} }
// NewPreInc node constructor // NewPreInc node constructor
func NewPreInc(Variable node.Node) *PreInc { func NewPreInc(Variable node.Node) *PreInc {
return &PreInc{ return &PreInc{
Variable, FreeFloating: nil,
Variable: Variable,
} }
} }
// SetPosition sets node position
func (n *PreInc) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PreInc) GetPosition() *position.Position {
return n.Position
}
func (n *PreInc) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *PreInc) Attributes() map[string]interface{} { func (n *PreInc) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *PreInc) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,22 +1,41 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// Print node // Print node
type Print struct { type Print struct {
Expr node.Node FreeFloating freefloating.Collection
Position *position.Position
Expr node.Node
} }
// NewPrint node constructor // NewPrint node constructor
func NewPrint(Expression node.Node) *Print { func NewPrint(Expression node.Node) *Print {
return &Print{ return &Print{
Expression, FreeFloating: nil,
Expr: Expression,
} }
} }
// SetPosition sets node position
func (n *Print) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *Print) GetPosition() *position.Position {
return n.Position
}
func (n *Print) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *Print) Attributes() map[string]interface{} { func (n *Print) Attributes() map[string]interface{} {
return nil return nil
@ -30,8 +49,9 @@ func (n *Print) Walk(v walker.Visitor) {
} }
if n.Expr != nil { if n.Expr != nil {
vv := v.GetChildrenVisitor("Expr") v.EnterChildNode("Expr", n)
n.Expr.Walk(vv) n.Expr.Walk(v)
v.LeaveChildNode("Expr", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

View File

@ -1,24 +1,43 @@
package expr package expr
import ( import (
"github.com/z7zmey/php-parser/freefloating"
"github.com/z7zmey/php-parser/node" "github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/position"
"github.com/z7zmey/php-parser/walker" "github.com/z7zmey/php-parser/walker"
) )
// PropertyFetch node // PropertyFetch node
type PropertyFetch struct { type PropertyFetch struct {
Variable node.Node FreeFloating freefloating.Collection
Property node.Node Position *position.Position
Variable node.Node
Property node.Node
} }
// NewPropertyFetch node constructor // NewPropertyFetch node constructor
func NewPropertyFetch(Variable node.Node, Property node.Node) *PropertyFetch { func NewPropertyFetch(Variable node.Node, Property node.Node) *PropertyFetch {
return &PropertyFetch{ return &PropertyFetch{
Variable, FreeFloating: nil,
Property, Variable: Variable,
Property: Property,
} }
} }
// SetPosition sets node position
func (n *PropertyFetch) SetPosition(p *position.Position) {
n.Position = p
}
// GetPosition returns node positions
func (n *PropertyFetch) GetPosition() *position.Position {
return n.Position
}
func (n *PropertyFetch) GetFreeFloating() *freefloating.Collection {
return &n.FreeFloating
}
// Attributes returns node attributes as map // Attributes returns node attributes as map
func (n *PropertyFetch) Attributes() map[string]interface{} { func (n *PropertyFetch) Attributes() map[string]interface{} {
return nil return nil
@ -32,13 +51,15 @@ func (n *PropertyFetch) Walk(v walker.Visitor) {
} }
if n.Variable != nil { if n.Variable != nil {
vv := v.GetChildrenVisitor("Variable") v.EnterChildNode("Variable", n)
n.Variable.Walk(vv) n.Variable.Walk(v)
v.LeaveChildNode("Variable", n)
} }
if n.Property != nil { if n.Property != nil {
vv := v.GetChildrenVisitor("Property") v.EnterChildNode("Property", n)
n.Property.Walk(vv) n.Property.Walk(v)
v.LeaveChildNode("Property", n)
} }
v.LeaveNode(n) v.LeaveNode(n)

Some files were not shown because too many files have changed in this diff Show More