commit
d07e234393
9
.gitignore
vendored
9
.gitignore
vendored
@ -1,8 +1,9 @@
|
||||
.vscode
|
||||
php-parser
|
||||
**/*.test
|
||||
|
||||
*example.php
|
||||
|
||||
cpu.prof
|
||||
mem.prof
|
||||
php7.test
|
||||
php5.test
|
||||
cpu.pprof
|
||||
mem.pprof
|
||||
trace.out
|
@ -3,8 +3,9 @@ branches:
|
||||
only:
|
||||
- master
|
||||
before_script:
|
||||
- go get -u gotest.tools/assert
|
||||
- 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/yookoala/realpath
|
||||
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
||||
|
17
Makefile
17
Makefile
@ -6,10 +6,11 @@ fmt:
|
||||
find . -type f -iregex '.*\.go' -exec gofmt -l -s -w '{}' +
|
||||
|
||||
build:
|
||||
go generate ./...
|
||||
go build
|
||||
|
||||
run:
|
||||
./php-parser $(PHPFILE)
|
||||
./php-parser -d go $(PHPFILE)
|
||||
|
||||
test:
|
||||
go test ./...
|
||||
@ -21,7 +22,7 @@ bench:
|
||||
go test -benchmem -bench=. ./php5
|
||||
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' ./php5/php5.go
|
||||
rm -f y.output
|
||||
@ -36,17 +37,17 @@ compile: ./php5/php5.go ./php7/php7.go ./scanner/scanner.go
|
||||
goyacc -o $@ $<
|
||||
|
||||
cpu_pprof:
|
||||
GOGC=off go test -cpuprofile cpu.prof -bench=. -benchtime=20s ./php7
|
||||
go tool pprof ./php7.test cpu.prof
|
||||
go test -cpuprofile cpu.pprof -bench=. -benchtime=20s ./php7
|
||||
go tool pprof ./php7.test cpu.pprof
|
||||
|
||||
mem_pprof:
|
||||
GOGC=off go test -memprofile mem.prof -bench=. -benchtime=20s -benchmem ./php7
|
||||
go tool pprof -alloc_objects ./php7.test mem.prof
|
||||
go test -memprofile mem.pprof -bench=. -benchtime=20s -benchmem ./php7
|
||||
go tool pprof -alloc_objects ./php7.test mem.pprof
|
||||
|
||||
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
|
||||
|
||||
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
|
||||
|
99
README.md
99
README.md
@ -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
|
||||
========================
|
||||
|
||||
@ -26,13 +19,13 @@ Features:
|
||||
- Fully support PHP 5 and PHP 7 syntax
|
||||
- Abstract syntax tree (AST) representation
|
||||
- Traversing AST
|
||||
- Namespace resolver
|
||||
- Able to parse syntax-invalid PHP files
|
||||
- Resolving namespaced names
|
||||
- Parsing syntax-invalid PHP files
|
||||
- Saving and printing free-floating comments and whitespaces
|
||||
|
||||
Roadmap
|
||||
-------
|
||||
|
||||
- Pretty printer
|
||||
- Control Flow Graph (CFG)
|
||||
- PhpDocComment parser
|
||||
- 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.
|
||||
|
||||
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 `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';
|
||||
}
|
||||
}
|
||||
```
|
||||
|
@ -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
|
||||
}
|
@ -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")
|
||||
}
|
||||
}
|
@ -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",
|
||||
}
|
@ -1,29 +1,14 @@
|
||||
package errors_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/errors"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"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 TestConstructor(t *testing.T) {
|
||||
pos := position.NewPosition(1, 2, 3, 4)
|
||||
|
||||
@ -34,7 +19,7 @@ func TestConstructor(t *testing.T) {
|
||||
Pos: pos,
|
||||
}
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPrint(t *testing.T) {
|
||||
@ -46,7 +31,7 @@ func TestPrint(t *testing.T) {
|
||||
|
||||
expected := "message at line 1"
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestPrintWithotPos(t *testing.T) {
|
||||
@ -56,5 +41,5 @@ func TestPrintWithotPos(t *testing.T) {
|
||||
|
||||
expected := "message"
|
||||
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
16
freefloating/position_string.go
Normal file
16
freefloating/position_string.go
Normal 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
112
freefloating/string.go
Normal 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
126
main.go
@ -1,50 +1,81 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"bytes"
|
||||
"flag"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"runtime"
|
||||
"sync"
|
||||
|
||||
"github.com/pkg/profile"
|
||||
"github.com/yookoala/realpath"
|
||||
"github.com/z7zmey/php-parser/parser"
|
||||
"github.com/z7zmey/php-parser/php5"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
"github.com/z7zmey/php-parser/printer"
|
||||
"github.com/z7zmey/php-parser/visitor"
|
||||
)
|
||||
|
||||
var wg sync.WaitGroup
|
||||
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() {
|
||||
usePhp5 = flag.Bool("php5", false, "use PHP5 parserWorker")
|
||||
noDump = flag.Bool("noDump", false, "disable dumping to stdout")
|
||||
usePhp5 = flag.Bool("php5", false, "parse as PHP5")
|
||||
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()
|
||||
|
||||
pathCh := make(chan string)
|
||||
resultCh := make(chan parser.Parser)
|
||||
switch profiler {
|
||||
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
|
||||
for i := 0; i < 4; i++ {
|
||||
go parserWorker(pathCh, resultCh)
|
||||
for i := 0; i < numCpu; i++ {
|
||||
go parserWorker(fileCh, resultCh)
|
||||
}
|
||||
|
||||
// run printer goroutine
|
||||
go printer(resultCh)
|
||||
go printerWorker(resultCh)
|
||||
|
||||
// process files
|
||||
processPath(flag.Args(), pathCh)
|
||||
processPath(flag.Args(), fileCh)
|
||||
|
||||
// wait the all files done
|
||||
wg.Wait()
|
||||
close(pathCh)
|
||||
close(fileCh)
|
||||
close(resultCh)
|
||||
}
|
||||
|
||||
func processPath(pathList []string, pathCh chan<- string) {
|
||||
func processPath(pathList []string, fileCh chan<- *file) {
|
||||
for _, path := range pathList {
|
||||
real, err := realpath.Realpath(path)
|
||||
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 {
|
||||
if !f.IsDir() && filepath.Ext(path) == ".php" {
|
||||
wg.Add(1)
|
||||
pathCh <- path
|
||||
content, err := ioutil.ReadFile(path)
|
||||
checkErr(err)
|
||||
fileCh <- &file{path, content}
|
||||
}
|
||||
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
|
||||
|
||||
for {
|
||||
path, ok := <-pathCh
|
||||
f, ok := <-fileCh
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
src, _ := os.Open(path)
|
||||
src := bytes.NewReader(f.content)
|
||||
|
||||
if *usePhp5 {
|
||||
parserWorker = php5.NewParser(src, path)
|
||||
parserWorker = php5.NewParser(src, f.path)
|
||||
} else {
|
||||
parserWorker = php7.NewParser(src, path)
|
||||
parserWorker = php7.NewParser(src, f.path)
|
||||
}
|
||||
|
||||
if *withFreeFloating {
|
||||
parserWorker.WithFreeFloating()
|
||||
}
|
||||
|
||||
parserWorker.Parse()
|
||||
|
||||
result <- parserWorker
|
||||
}
|
||||
}
|
||||
|
||||
func printer(result <-chan parser.Parser) {
|
||||
func printerWorker(result <-chan parser.Parser) {
|
||||
var counter int
|
||||
|
||||
w := bufio.NewWriter(os.Stdout)
|
||||
|
||||
for {
|
||||
parserWorker, ok := <-result
|
||||
if !ok {
|
||||
w.Flush()
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Printf("==> %s\n", parserWorker.GetPath())
|
||||
counter++
|
||||
|
||||
fmt.Fprintf(w, "==> [%d] %s\n", counter, parserWorker.GetPath())
|
||||
|
||||
for _, e := range parserWorker.GetErrors() {
|
||||
fmt.Println(e)
|
||||
fmt.Fprintln(w, e)
|
||||
}
|
||||
|
||||
if !*noDump {
|
||||
nsResolver := visitor.NewNamespaceResolver()
|
||||
parserWorker.GetRootNode().Walk(nsResolver)
|
||||
if *printBack {
|
||||
o := bytes.NewBuffer([]byte{})
|
||||
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,
|
||||
Indent: " | ",
|
||||
Comments: parserWorker.GetComments(),
|
||||
Positions: parserWorker.GetPositions(),
|
||||
Indent: "| ",
|
||||
NsResolver: nsResolver,
|
||||
}
|
||||
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()
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Assign node
|
||||
type Assign struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewAssign node constructor
|
||||
func NewAssign(Variable node.Node, Expression node.Node) *Assign {
|
||||
return &Assign{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Assign) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Assign) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Reference node
|
||||
type Reference struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewReference node constructor
|
||||
func NewReference(Variable node.Node, Expression node.Node) *Reference {
|
||||
return &Reference{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Reference) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Reference) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseAnd node
|
||||
type BitwiseAnd struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseAnd node constructor
|
||||
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
|
||||
return &BitwiseAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseOr node
|
||||
type BitwiseOr struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseOr node constructor
|
||||
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
|
||||
return &BitwiseOr{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseXor node
|
||||
type BitwiseXor struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseXor node constructor
|
||||
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
|
||||
return &BitwiseXor{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseXor) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Concat node
|
||||
type Concat struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewConcat node constructor
|
||||
func NewConcat(Variable node.Node, Expression node.Node) *Concat {
|
||||
return &Concat{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Concat) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Concat) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Div node
|
||||
type Div struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewDiv node constructor
|
||||
func NewDiv(Variable node.Node, Expression node.Node) *Div {
|
||||
return &Div{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Div) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Div) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Minus node
|
||||
type Minus struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewMinus node constructor
|
||||
func NewMinus(Variable node.Node, Expression node.Node) *Minus {
|
||||
return &Minus{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Minus) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Minus) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mod node
|
||||
type Mod struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewMod node constructor
|
||||
func NewMod(Variable node.Node, Expression node.Node) *Mod {
|
||||
return &Mod{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Mod) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Mod) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mul node
|
||||
type Mul struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewMul node constructor
|
||||
func NewMul(Variable node.Node, Expression node.Node) *Mul {
|
||||
return &Mul{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Mul) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Mul) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Plus node
|
||||
type Plus struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewPlus node constructor
|
||||
func NewPlus(Variable node.Node, Expression node.Node) *Plus {
|
||||
return &Plus{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Plus) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Plus) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Pow node
|
||||
type Pow struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewPow node constructor
|
||||
func NewPow(Variable node.Node, Expression node.Node) *Pow {
|
||||
return &Pow{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Pow) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Pow) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftLeft node
|
||||
type ShiftLeft struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewShiftLeft node constructor
|
||||
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
|
||||
return &ShiftLeft{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ShiftLeft) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package assign
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftRight node
|
||||
type ShiftRight struct {
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Expression node.Node
|
||||
}
|
||||
|
||||
// NewShiftRight node constructor
|
||||
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
|
||||
return &ShiftRight{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ShiftRight) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Expression != nil {
|
||||
vv := v.GetChildrenVisitor("Expression")
|
||||
n.Expression.Walk(vv)
|
||||
v.EnterChildNode("Expression", n)
|
||||
n.Expression.Walk(v)
|
||||
v.LeaveChildNode("Expression", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
File diff suppressed because it is too large
Load Diff
81
node/expr/assign/t_freefloating_test.go
Normal file
81
node/expr/assign/t_freefloating_test.go
Normal 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)
|
||||
}
|
||||
}
|
18
node/expr/assign/t_position_test.go
Normal file
18
node/expr/assign/t_position_test.go
Normal 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)
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
package assign_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/z7zmey/php-parser/node/expr/assign"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/assign"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
@ -20,115 +18,115 @@ var nodesToTest = []struct {
|
||||
}{
|
||||
{
|
||||
&assign.Reference{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Assign{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.BitwiseAnd{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.BitwiseOr{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.BitwiseXor{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Concat{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Div{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Minus{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Mod{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Mul{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Plus{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.Pow{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.ShiftLeft{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]string{"Variable", "Expression"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&assign.ShiftRight{
|
||||
Variable: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expression: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Variable: &expr.Variable{},
|
||||
Expression: &expr.Variable{},
|
||||
},
|
||||
[]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) 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)
|
||||
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) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{false, nil}
|
||||
v := &visitorMock{false, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := []string{}
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVisitor(t *testing.T) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{true, nil}
|
||||
v := &visitorMock{true, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := tt.expectedVisitedKeys
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,9 +177,6 @@ func TestNameAttributes(t *testing.T) {
|
||||
expected := tt.expectedAttributes
|
||||
actual := tt.node.Attributes()
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseAnd node
|
||||
type BitwiseAnd struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseAnd node constructor
|
||||
func NewBitwiseAnd(Variable node.Node, Expression node.Node) *BitwiseAnd {
|
||||
return &BitwiseAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseAnd) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseOr node
|
||||
type BitwiseOr struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseOr node constructor
|
||||
func NewBitwiseOr(Variable node.Node, Expression node.Node) *BitwiseOr {
|
||||
return &BitwiseOr{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseOr) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseXor node
|
||||
type BitwiseXor struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseXor node constructor
|
||||
func NewBitwiseXor(Variable node.Node, Expression node.Node) *BitwiseXor {
|
||||
return &BitwiseXor{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BitwiseXor) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BitwiseXor) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BooleanAnd node
|
||||
type BooleanAnd struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBooleanAnd node constructor
|
||||
func NewBooleanAnd(Variable node.Node, Expression node.Node) *BooleanAnd {
|
||||
return &BooleanAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BooleanAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BooleanAnd) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BooleanOr node
|
||||
type BooleanOr struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewBooleanOr node constructor
|
||||
func NewBooleanOr(Variable node.Node, Expression node.Node) *BooleanOr {
|
||||
return &BooleanOr{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *BooleanOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *BooleanOr) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Coalesce node
|
||||
type Coalesce struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewCoalesce node constructor
|
||||
func NewCoalesce(Variable node.Node, Expression node.Node) *Coalesce {
|
||||
return &Coalesce{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Coalesce) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Coalesce) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Concat node
|
||||
type Concat struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewConcat node constructor
|
||||
func NewConcat(Variable node.Node, Expression node.Node) *Concat {
|
||||
return &Concat{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Concat) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Concat) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Div node
|
||||
type Div struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewDiv node constructor
|
||||
func NewDiv(Variable node.Node, Expression node.Node) *Div {
|
||||
return &Div{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Div) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Div) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Equal node
|
||||
type Equal struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewEqual node constructor
|
||||
func NewEqual(Variable node.Node, Expression node.Node) *Equal {
|
||||
return &Equal{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Equal) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Equal) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Greater node
|
||||
type Greater struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewGreater node constructor
|
||||
func NewGreater(Variable node.Node, Expression node.Node) *Greater {
|
||||
return &Greater{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Greater) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Greater) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// GreaterOrEqual node
|
||||
type GreaterOrEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewGreaterOrEqual node constructor
|
||||
func NewGreaterOrEqual(Variable node.Node, Expression node.Node) *GreaterOrEqual {
|
||||
return &GreaterOrEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *GreaterOrEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *GreaterOrEqual) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Identical node
|
||||
type Identical struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewIdentical node constructor
|
||||
func NewIdentical(Variable node.Node, Expression node.Node) *Identical {
|
||||
return &Identical{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Identical) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Identical) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalAnd node
|
||||
type LogicalAnd struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalAnd node constructor
|
||||
func NewLogicalAnd(Variable node.Node, Expression node.Node) *LogicalAnd {
|
||||
return &LogicalAnd{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *LogicalAnd) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *LogicalAnd) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalOr node
|
||||
type LogicalOr struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalOr node constructor
|
||||
func NewLogicalOr(Variable node.Node, Expression node.Node) *LogicalOr {
|
||||
return &LogicalOr{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *LogicalOr) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *LogicalOr) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// LogicalXor node
|
||||
type LogicalXor struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewLogicalXor node constructor
|
||||
func NewLogicalXor(Variable node.Node, Expression node.Node) *LogicalXor {
|
||||
return &LogicalXor{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *LogicalXor) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *LogicalXor) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Minus node
|
||||
type Minus struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewMinus node constructor
|
||||
func NewMinus(Variable node.Node, Expression node.Node) *Minus {
|
||||
return &Minus{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Minus) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Minus) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mod node
|
||||
type Mod struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewMod node constructor
|
||||
func NewMod(Variable node.Node, Expression node.Node) *Mod {
|
||||
return &Mod{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Mod) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Mod) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Mul node
|
||||
type Mul struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewMul node constructor
|
||||
func NewMul(Variable node.Node, Expression node.Node) *Mul {
|
||||
return &Mul{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Mul) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Mul) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// NotEqual node
|
||||
type NotEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewNotEqual node constructor
|
||||
func NewNotEqual(Variable node.Node, Expression node.Node) *NotEqual {
|
||||
return &NotEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *NotEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *NotEqual) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// NotIdentical node
|
||||
type NotIdentical struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewNotIdentical node constructor
|
||||
func NewNotIdentical(Variable node.Node, Expression node.Node) *NotIdentical {
|
||||
return &NotIdentical{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *NotIdentical) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *NotIdentical) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Plus node
|
||||
type Plus struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewPlus node constructor
|
||||
func NewPlus(Variable node.Node, Expression node.Node) *Plus {
|
||||
return &Plus{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Plus) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Plus) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Pow node
|
||||
type Pow struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewPow node constructor
|
||||
func NewPow(Variable node.Node, Expression node.Node) *Pow {
|
||||
return &Pow{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Pow) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Pow) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftLeft node
|
||||
type ShiftLeft struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewShiftLeft node constructor
|
||||
func NewShiftLeft(Variable node.Node, Expression node.Node) *ShiftLeft {
|
||||
return &ShiftLeft{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ShiftLeft) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ShiftLeft) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ShiftRight node
|
||||
type ShiftRight struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewShiftRight node constructor
|
||||
func NewShiftRight(Variable node.Node, Expression node.Node) *ShiftRight {
|
||||
return &ShiftRight{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ShiftRight) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ShiftRight) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Smaller node
|
||||
type Smaller struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSmaller node constructor
|
||||
func NewSmaller(Variable node.Node, Expression node.Node) *Smaller {
|
||||
return &Smaller{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Smaller) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Smaller) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// SmallerOrEqual node
|
||||
type SmallerOrEqual struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSmallerOrEqual node constructor
|
||||
func NewSmallerOrEqual(Variable node.Node, Expression node.Node) *SmallerOrEqual {
|
||||
return &SmallerOrEqual{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *SmallerOrEqual) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *SmallerOrEqual) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package binary
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Spaceship node
|
||||
type Spaceship struct {
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Left node.Node
|
||||
Right node.Node
|
||||
}
|
||||
|
||||
// NewSpaceship node constructor
|
||||
func NewSpaceship(Variable node.Node, Expression node.Node) *Spaceship {
|
||||
return &Spaceship{
|
||||
Variable,
|
||||
Expression,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *Spaceship) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *Spaceship) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Left != nil {
|
||||
vv := v.GetChildrenVisitor("Left")
|
||||
n.Left.Walk(vv)
|
||||
v.EnterChildNode("Left", n)
|
||||
n.Left.Walk(v)
|
||||
v.LeaveChildNode("Left", n)
|
||||
}
|
||||
|
||||
if n.Right != nil {
|
||||
vv := v.GetChildrenVisitor("Right")
|
||||
n.Right.Walk(vv)
|
||||
v.EnterChildNode("Right", n)
|
||||
n.Right.Walk(v)
|
||||
v.LeaveChildNode("Right", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
File diff suppressed because it is too large
Load Diff
117
node/expr/binary/t_freefloating_test.go
Normal file
117
node/expr/binary/t_freefloating_test.go
Normal 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)
|
||||
}
|
||||
}
|
18
node/expr/binary/t_position_test.go
Normal file
18
node/expr/binary/t_position_test.go
Normal 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)
|
||||
}
|
||||
}
|
@ -1,15 +1,13 @@
|
||||
package binary_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
"github.com/z7zmey/php-parser/node/expr/binary"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
"gotest.tools/assert"
|
||||
)
|
||||
|
||||
var nodesToTest = []struct {
|
||||
@ -19,219 +17,219 @@ var nodesToTest = []struct {
|
||||
}{
|
||||
{
|
||||
&binary.BitwiseAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.BitwiseOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.BitwiseXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.BooleanAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.BooleanOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Coalesce{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Concat{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Div{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Equal{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.GreaterOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Greater{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Identical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.LogicalAnd{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.LogicalOr{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.LogicalXor{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Minus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Mod{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Mul{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.NotEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.NotIdentical{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Plus{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Pow{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.ShiftLeft{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.ShiftRight{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.SmallerOrEqual{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Smaller{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]string{"Left", "Right"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&binary.Spaceship{
|
||||
Left: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Right: &expr.Variable{VarName: &node.Identifier{Value: "b"}},
|
||||
Left: &expr.Variable{},
|
||||
Right: &expr.Variable{},
|
||||
},
|
||||
[]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) 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)
|
||||
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) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{false, nil}
|
||||
v := &visitorMock{false, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := []string{}
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVisitor(t *testing.T) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{true, nil}
|
||||
v := &visitorMock{true, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := tt.expectedVisitedKeys
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@ -284,9 +280,6 @@ func TestNameAttributes(t *testing.T) {
|
||||
expected := tt.expectedAttributes
|
||||
actual := tt.node.Attributes()
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Array node
|
||||
type Array struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewArray node constructor
|
||||
func NewArray(Expr node.Node) *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
|
||||
func (n *Array) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Array) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Bool node
|
||||
type Bool struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewBool node constructor
|
||||
func NewBool(Expr node.Node) *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
|
||||
func (n *Bool) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Bool) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Double node
|
||||
type Double struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewDouble node constructor
|
||||
func NewDouble(Expr node.Node) *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
|
||||
func (n *Double) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Double) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Int node
|
||||
type Int struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewInt node constructor
|
||||
func NewInt(Expr node.Node) *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
|
||||
func (n *Int) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Int) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Object node
|
||||
type Object struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewObject node constructor
|
||||
func NewObject(Expr node.Node) *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
|
||||
func (n *Object) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Object) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// String node
|
||||
type String struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewString node constructor
|
||||
func NewString(Expr node.Node) *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
|
||||
func (n *String) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *String) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package cast
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Unset node
|
||||
type Unset struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewUnset node constructor
|
||||
func NewUnset(Expr node.Node) *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
|
||||
func (n *Unset) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Unset) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -2,10 +2,9 @@ package cast_test
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
@ -13,28 +12,51 @@ import (
|
||||
"github.com/z7zmey/php-parser/node/stmt"
|
||||
"github.com/z7zmey/php-parser/php5"
|
||||
"github.com/z7zmey/php-parser/php7"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
)
|
||||
|
||||
func 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) {
|
||||
src := `<? (array)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestBool(t *testing.T) {
|
||||
src := `<? (boolean)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 15,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 15,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestBoolShort(t *testing.T) {
|
||||
src := `<? (bool)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 12,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 12,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestDouble(t *testing.T) {
|
||||
src := `<? (double)$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.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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestCastFloat(t *testing.T) {
|
||||
src := `<? (float)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestInt(t *testing.T) {
|
||||
src := `<? (integer)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 15,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 15,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestIntShort(t *testing.T) {
|
||||
src := `<? (int)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 11,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 11,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestObject(t *testing.T) {
|
||||
src := `<? (object)$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.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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestString(t *testing.T) {
|
||||
src := `<? (string)$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{
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
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) {
|
||||
src := `<? (unset)$a;`
|
||||
|
||||
expected := &node.Root{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
Stmts: []node.Node{
|
||||
&stmt.Expression{
|
||||
Position: &position.Position{
|
||||
StartLine: 1,
|
||||
EndLine: 1,
|
||||
StartPos: 4,
|
||||
EndPos: 13,
|
||||
},
|
||||
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.Parse()
|
||||
actual := php7parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
|
||||
php5parser := php5.NewParser(bytes.NewBufferString(src), "test.php")
|
||||
php5parser.Parse()
|
||||
actual = php5parser.GetRootNode()
|
||||
assertEqual(t, expected, actual)
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
|
57
node/expr/cast/t_freefloating_test.go
Normal file
57
node/expr/cast/t_freefloating_test.go
Normal 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)
|
||||
}
|
||||
}
|
18
node/expr/cast/t_position_test.go
Normal file
18
node/expr/cast/t_position_test.go
Normal 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)
|
||||
}
|
||||
}
|
@ -1,10 +1,9 @@
|
||||
package cast_test
|
||||
|
||||
import (
|
||||
"reflect"
|
||||
"testing"
|
||||
|
||||
"github.com/kylelemons/godebug/pretty"
|
||||
"gotest.tools/assert"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/node/expr"
|
||||
@ -19,52 +18,52 @@ var nodesToTest = []struct {
|
||||
}{
|
||||
{
|
||||
&cast.Array{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Bool{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Double{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Int{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Object{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.String{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]string{"Expr"},
|
||||
map[string]interface{}{},
|
||||
nil,
|
||||
},
|
||||
{
|
||||
&cast.Unset{
|
||||
Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}},
|
||||
Expr: &expr.Variable{},
|
||||
},
|
||||
[]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) 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)
|
||||
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) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{false, nil}
|
||||
v := &visitorMock{false, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := []string{}
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestVisitor(t *testing.T) {
|
||||
for _, tt := range nodesToTest {
|
||||
v := &visitorMock{true, nil}
|
||||
v := &visitorMock{true, []string{}}
|
||||
tt.node.Walk(v)
|
||||
|
||||
expected := tt.expectedVisitedKeys
|
||||
actual := v.visitedKeys
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
||||
@ -117,9 +114,6 @@ func TestNameAttributes(t *testing.T) {
|
||||
expected := tt.expectedAttributes
|
||||
actual := tt.node.Attributes()
|
||||
|
||||
diff := pretty.Compare(expected, actual)
|
||||
if diff != "" {
|
||||
t.Errorf("%s diff: (-expected +actual)\n%s", reflect.TypeOf(tt.node), diff)
|
||||
}
|
||||
assert.DeepEqual(t, expected, actual)
|
||||
}
|
||||
}
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Array node
|
||||
type Array struct {
|
||||
Items []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Items []node.Node
|
||||
}
|
||||
|
||||
// NewArray node constructor
|
||||
func NewArray(Items []node.Node) *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
|
||||
func (n *Array) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,12 +49,13 @@ func (n *Array) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Items != nil {
|
||||
vv := v.GetChildrenVisitor("Items")
|
||||
v.EnterChildList("Items", n)
|
||||
for _, nn := range n.Items {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Items", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ArrayDimFetch node
|
||||
type ArrayDimFetch struct {
|
||||
Variable node.Node
|
||||
Dim node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Dim node.Node
|
||||
}
|
||||
|
||||
// NewArrayDimFetch node constructor
|
||||
func NewArrayDimFetch(Variable node.Node, Dim node.Node) *ArrayDimFetch {
|
||||
return &ArrayDimFetch{
|
||||
Variable,
|
||||
Dim,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ArrayDimFetch) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ArrayDimFetch) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Dim != nil {
|
||||
vv := v.GetChildrenVisitor("Dim")
|
||||
n.Dim.Walk(vv)
|
||||
v.EnterChildNode("Dim", n)
|
||||
n.Dim.Walk(v)
|
||||
v.LeaveChildNode("Dim", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ArrayItem node
|
||||
type ArrayItem struct {
|
||||
Key node.Node
|
||||
Val node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Key node.Node
|
||||
Val node.Node
|
||||
}
|
||||
|
||||
// NewArrayItem node constructor
|
||||
func NewArrayItem(Key node.Node, Val node.Node) *ArrayItem {
|
||||
return &ArrayItem{
|
||||
Key,
|
||||
Val,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ArrayItem) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ArrayItem) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Key != nil {
|
||||
vv := v.GetChildrenVisitor("Key")
|
||||
n.Key.Walk(vv)
|
||||
v.EnterChildNode("Key", n)
|
||||
n.Key.Walk(v)
|
||||
v.LeaveChildNode("Key", n)
|
||||
}
|
||||
|
||||
if n.Val != nil {
|
||||
vv := v.GetChildrenVisitor("Val")
|
||||
n.Val.Walk(vv)
|
||||
v.EnterChildNode("Val", n)
|
||||
n.Val.Walk(v)
|
||||
v.LeaveChildNode("Val", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BitwiseNot node
|
||||
type BitwiseNot struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewBitwiseNot node constructor
|
||||
func NewBitwiseNot(Expression node.Node) *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
|
||||
func (n *BitwiseNot) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *BitwiseNot) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// BooleanNot node
|
||||
type BooleanNot struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewBooleanNot node constructor
|
||||
func NewBooleanNot(Expression node.Node) *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
|
||||
func (n *BooleanNot) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *BooleanNot) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,12 +1,16 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ClassConstFetch node
|
||||
type ClassConstFetch struct {
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Class node.Node
|
||||
ConstantName node.Node
|
||||
}
|
||||
@ -14,11 +18,26 @@ type ClassConstFetch struct {
|
||||
// NewClassConstFetch node constructor
|
||||
func NewClassConstFetch(Class node.Node, ConstantName node.Node) *ClassConstFetch {
|
||||
return &ClassConstFetch{
|
||||
Class,
|
||||
ConstantName,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *ClassConstFetch) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *ClassConstFetch) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Class != nil {
|
||||
vv := v.GetChildrenVisitor("Class")
|
||||
n.Class.Walk(vv)
|
||||
v.EnterChildNode("Class", n)
|
||||
n.Class.Walk(v)
|
||||
v.LeaveChildNode("Class", n)
|
||||
}
|
||||
|
||||
if n.ConstantName != nil {
|
||||
vv := v.GetChildrenVisitor("ConstantName")
|
||||
n.ConstantName.Walk(vv)
|
||||
v.EnterChildNode("ConstantName", n)
|
||||
n.ConstantName.Walk(v)
|
||||
v.LeaveChildNode("ConstantName", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Clone node
|
||||
type Clone struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewClone node constructor
|
||||
func NewClone(Expression node.Node) *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
|
||||
func (n *Clone) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Clone) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,12 +1,16 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Closure node
|
||||
type Closure struct {
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
ReturnsRef bool
|
||||
Static bool
|
||||
PhpDocComment string
|
||||
@ -19,16 +23,31 @@ type Closure struct {
|
||||
// NewClosure node constructor
|
||||
func NewClosure(Params []node.Node, ClosureUse *ClosureUse, ReturnType node.Node, Stmts []node.Node, Static bool, ReturnsRef bool, PhpDocComment string) *Closure {
|
||||
return &Closure{
|
||||
ReturnsRef,
|
||||
Static,
|
||||
PhpDocComment,
|
||||
Params,
|
||||
ClosureUse,
|
||||
ReturnType,
|
||||
Stmts,
|
||||
FreeFloating: nil,
|
||||
ReturnsRef: ReturnsRef,
|
||||
Static: Static,
|
||||
PhpDocComment: PhpDocComment,
|
||||
Params: Params,
|
||||
ClosureUse: ClosureUse,
|
||||
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
|
||||
func (n *Closure) Attributes() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
@ -46,31 +65,35 @@ func (n *Closure) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Params != nil {
|
||||
vv := v.GetChildrenVisitor("Params")
|
||||
v.EnterChildList("Params", n)
|
||||
for _, nn := range n.Params {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Params", n)
|
||||
}
|
||||
|
||||
if n.ClosureUse != nil {
|
||||
vv := v.GetChildrenVisitor("ClosureUse")
|
||||
n.ClosureUse.Walk(vv)
|
||||
v.EnterChildNode("ClosureUse", n)
|
||||
n.ClosureUse.Walk(v)
|
||||
v.LeaveChildNode("ClosureUse", n)
|
||||
}
|
||||
|
||||
if n.ReturnType != nil {
|
||||
vv := v.GetChildrenVisitor("ReturnType")
|
||||
n.ReturnType.Walk(vv)
|
||||
v.EnterChildNode("ReturnType", n)
|
||||
n.ReturnType.Walk(v)
|
||||
v.LeaveChildNode("ReturnType", n)
|
||||
}
|
||||
|
||||
if n.Stmts != nil {
|
||||
vv := v.GetChildrenVisitor("Stmts")
|
||||
v.EnterChildList("Stmts", n)
|
||||
for _, nn := range n.Stmts {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Stmts", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ClosureUse node
|
||||
type ClosureUse struct {
|
||||
Uses []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Uses []node.Node
|
||||
}
|
||||
|
||||
// NewClosureUse node constructor
|
||||
func NewClosureUse(Uses []node.Node) *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
|
||||
func (n *ClosureUse) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,12 +49,13 @@ func (n *ClosureUse) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Uses != nil {
|
||||
vv := v.GetChildrenVisitor("Uses")
|
||||
v.EnterChildList("Uses", n)
|
||||
for _, nn := range n.Uses {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Uses", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ConstFetch node
|
||||
type ConstFetch struct {
|
||||
Constant node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Constant node.Node
|
||||
}
|
||||
|
||||
// NewConstFetch node constructor
|
||||
func NewConstFetch(Constant node.Node) *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
|
||||
func (n *ConstFetch) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *ConstFetch) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Constant != nil {
|
||||
vv := v.GetChildrenVisitor("Constant")
|
||||
n.Constant.Walk(vv)
|
||||
v.EnterChildNode("Constant", n)
|
||||
n.Constant.Walk(v)
|
||||
v.LeaveChildNode("Constant", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -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)
|
||||
}
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Empty node
|
||||
type Empty struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewEmpty node constructor
|
||||
func NewEmpty(Expression node.Node) *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
|
||||
func (n *Empty) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Empty) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// ErrorSuppress node
|
||||
type ErrorSuppress struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewErrorSuppress node constructor
|
||||
func NewErrorSuppress(Expression node.Node) *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
|
||||
func (n *ErrorSuppress) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *ErrorSuppress) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Eval node
|
||||
type Eval struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewEval node constructor
|
||||
func NewEval(Expression node.Node) *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
|
||||
func (n *Eval) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Eval) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,25 +1,47 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Exit node
|
||||
type Exit struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Die bool
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewExit node constructor
|
||||
func NewExit(Expr node.Node) *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
|
||||
func (n *Exit) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
return map[string]interface{}{
|
||||
"Die": n.Die,
|
||||
}
|
||||
}
|
||||
|
||||
// Walk traverses nodes
|
||||
@ -30,8 +52,9 @@ func (n *Exit) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,12 +1,16 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// FunctionCall node
|
||||
type FunctionCall struct {
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Function node.Node
|
||||
ArgumentList *node.ArgumentList
|
||||
}
|
||||
@ -14,11 +18,26 @@ type FunctionCall struct {
|
||||
// NewFunctionCall node constructor
|
||||
func NewFunctionCall(Function node.Node, ArgumentList *node.ArgumentList) *FunctionCall {
|
||||
return &FunctionCall{
|
||||
Function,
|
||||
ArgumentList,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *FunctionCall) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *FunctionCall) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Function != nil {
|
||||
vv := v.GetChildrenVisitor("Function")
|
||||
n.Function.Walk(vv)
|
||||
v.EnterChildNode("Function", n)
|
||||
n.Function.Walk(v)
|
||||
v.LeaveChildNode("Function", n)
|
||||
}
|
||||
|
||||
if n.ArgumentList != nil {
|
||||
vv := v.GetChildrenVisitor("ArgumentList")
|
||||
n.ArgumentList.Walk(vv)
|
||||
v.EnterChildNode("ArgumentList", n)
|
||||
n.ArgumentList.Walk(v)
|
||||
v.LeaveChildNode("ArgumentList", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Include node
|
||||
type Include struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewInclude node constructor
|
||||
func NewInclude(Expression node.Node) *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
|
||||
func (n *Include) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Include) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// IncludeOnce node
|
||||
type IncludeOnce struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewIncludeOnce node constructor
|
||||
func NewIncludeOnce(Expression node.Node) *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
|
||||
func (n *IncludeOnce) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *IncludeOnce) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// InstanceOf node
|
||||
type InstanceOf struct {
|
||||
Expr node.Node
|
||||
Class node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
Class node.Node
|
||||
}
|
||||
|
||||
// NewInstanceOf node constructor
|
||||
func NewInstanceOf(Expr node.Node, Class node.Node) *InstanceOf {
|
||||
return &InstanceOf{
|
||||
Expr,
|
||||
Class,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *InstanceOf) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *InstanceOf) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
if n.Class != nil {
|
||||
vv := v.GetChildrenVisitor("Class")
|
||||
n.Class.Walk(vv)
|
||||
v.EnterChildNode("Class", n)
|
||||
n.Class.Walk(v)
|
||||
v.LeaveChildNode("Class", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Isset node
|
||||
type Isset struct {
|
||||
Variables []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variables []node.Node
|
||||
}
|
||||
|
||||
// NewIsset node constructor
|
||||
func NewIsset(Variables []node.Node) *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
|
||||
func (n *Isset) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,12 +49,13 @@ func (n *Isset) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variables != nil {
|
||||
vv := v.GetChildrenVisitor("Variables")
|
||||
v.EnterChildList("Variables", n)
|
||||
for _, nn := range n.Variables {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Variables", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// List node
|
||||
type List struct {
|
||||
Items []node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Items []node.Node
|
||||
}
|
||||
|
||||
// NewList node constructor
|
||||
func NewList(Items []node.Node) *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
|
||||
func (n *List) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,12 +49,13 @@ func (n *List) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Items != nil {
|
||||
vv := v.GetChildrenVisitor("Items")
|
||||
v.EnterChildList("Items", n)
|
||||
for _, nn := range n.Items {
|
||||
if nn != nil {
|
||||
nn.Walk(vv)
|
||||
nn.Walk(v)
|
||||
}
|
||||
}
|
||||
v.LeaveChildList("Items", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,12 +1,16 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// MethodCall node
|
||||
type MethodCall struct {
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Method node.Node
|
||||
ArgumentList *node.ArgumentList
|
||||
@ -15,12 +19,27 @@ type MethodCall struct {
|
||||
// NewMethodCall node constructor
|
||||
func NewMethodCall(Variable node.Node, Method node.Node, ArgumentList *node.ArgumentList) *MethodCall {
|
||||
return &MethodCall{
|
||||
Variable,
|
||||
Method,
|
||||
ArgumentList,
|
||||
FreeFloating: nil,
|
||||
Variable: Variable,
|
||||
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
|
||||
func (n *MethodCall) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -34,18 +53,21 @@ func (n *MethodCall) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Method != nil {
|
||||
vv := v.GetChildrenVisitor("Method")
|
||||
n.Method.Walk(vv)
|
||||
v.EnterChildNode("Method", n)
|
||||
n.Method.Walk(v)
|
||||
v.LeaveChildNode("Method", n)
|
||||
}
|
||||
|
||||
if n.ArgumentList != nil {
|
||||
vv := v.GetChildrenVisitor("ArgumentList")
|
||||
n.ArgumentList.Walk(vv)
|
||||
v.EnterChildNode("ArgumentList", n)
|
||||
n.ArgumentList.Walk(v)
|
||||
v.LeaveChildNode("ArgumentList", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,12 +1,16 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// New node
|
||||
type New struct {
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Class node.Node
|
||||
ArgumentList *node.ArgumentList
|
||||
}
|
||||
@ -14,11 +18,26 @@ type New struct {
|
||||
// NewNew node constructor
|
||||
func NewNew(Class node.Node, ArgumentList *node.ArgumentList) *New {
|
||||
return &New{
|
||||
Class,
|
||||
ArgumentList,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *New) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *New) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Class != nil {
|
||||
vv := v.GetChildrenVisitor("Class")
|
||||
n.Class.Walk(vv)
|
||||
v.EnterChildNode("Class", n)
|
||||
n.Class.Walk(v)
|
||||
v.LeaveChildNode("Class", n)
|
||||
}
|
||||
|
||||
if n.ArgumentList != nil {
|
||||
vv := v.GetChildrenVisitor("ArgumentList")
|
||||
n.ArgumentList.Walk(vv)
|
||||
v.EnterChildNode("ArgumentList", n)
|
||||
n.ArgumentList.Walk(v)
|
||||
v.LeaveChildNode("ArgumentList", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// PostDec node
|
||||
type PostDec struct {
|
||||
Variable node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
}
|
||||
|
||||
// NewPostDec node constructor
|
||||
func NewPostDec(Variable node.Node) *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
|
||||
func (n *PostDec) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *PostDec) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// PostInc node
|
||||
type PostInc struct {
|
||||
Variable node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
}
|
||||
|
||||
// NewPostInc node constructor
|
||||
func NewPostInc(Variable node.Node) *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
|
||||
func (n *PostInc) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *PostInc) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// PreDec node
|
||||
type PreDec struct {
|
||||
Variable node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
}
|
||||
|
||||
// NewPreDec node constructor
|
||||
func NewPreDec(Variable node.Node) *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
|
||||
func (n *PreDec) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *PreDec) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// PreInc node
|
||||
type PreInc struct {
|
||||
Variable node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
}
|
||||
|
||||
// NewPreInc node constructor
|
||||
func NewPreInc(Variable node.Node) *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
|
||||
func (n *PreInc) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *PreInc) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,22 +1,41 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// Print node
|
||||
type Print struct {
|
||||
Expr node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Expr node.Node
|
||||
}
|
||||
|
||||
// NewPrint node constructor
|
||||
func NewPrint(Expression node.Node) *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
|
||||
func (n *Print) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -30,8 +49,9 @@ func (n *Print) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Expr != nil {
|
||||
vv := v.GetChildrenVisitor("Expr")
|
||||
n.Expr.Walk(vv)
|
||||
v.EnterChildNode("Expr", n)
|
||||
n.Expr.Walk(v)
|
||||
v.LeaveChildNode("Expr", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
@ -1,24 +1,43 @@
|
||||
package expr
|
||||
|
||||
import (
|
||||
"github.com/z7zmey/php-parser/freefloating"
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/position"
|
||||
"github.com/z7zmey/php-parser/walker"
|
||||
)
|
||||
|
||||
// PropertyFetch node
|
||||
type PropertyFetch struct {
|
||||
Variable node.Node
|
||||
Property node.Node
|
||||
FreeFloating freefloating.Collection
|
||||
Position *position.Position
|
||||
Variable node.Node
|
||||
Property node.Node
|
||||
}
|
||||
|
||||
// NewPropertyFetch node constructor
|
||||
func NewPropertyFetch(Variable node.Node, Property node.Node) *PropertyFetch {
|
||||
return &PropertyFetch{
|
||||
Variable,
|
||||
Property,
|
||||
FreeFloating: nil,
|
||||
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
|
||||
func (n *PropertyFetch) Attributes() map[string]interface{} {
|
||||
return nil
|
||||
@ -32,13 +51,15 @@ func (n *PropertyFetch) Walk(v walker.Visitor) {
|
||||
}
|
||||
|
||||
if n.Variable != nil {
|
||||
vv := v.GetChildrenVisitor("Variable")
|
||||
n.Variable.Walk(vv)
|
||||
v.EnterChildNode("Variable", n)
|
||||
n.Variable.Walk(v)
|
||||
v.LeaveChildNode("Variable", n)
|
||||
}
|
||||
|
||||
if n.Property != nil {
|
||||
vv := v.GetChildrenVisitor("Property")
|
||||
n.Property.Walk(vv)
|
||||
v.EnterChildNode("Property", n)
|
||||
n.Property.Walk(v)
|
||||
v.LeaveChildNode("Property", n)
|
||||
}
|
||||
|
||||
v.LeaveNode(n)
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user