PHP 8 Update

- nullsafe operator (?->)
- Remove (real) cast
- Named arguments
- Remove (unset) cast
- Remove {} access
- match expression
- Union types in type hints and static typehint
- Block catch without variable
- Trailing comma in parameter lists
- throw can be used as an expression
- Concatenation precedence
- Declaring properties in the constructor
- Attributes
- Names in the namespace are treated as a single token
- Trailing comma in closure use list
- Check that ::class on object works
- Deferencable changes and arbitrary expressions in new/instanceof
This commit is contained in:
Makhnev Petr
2021-07-30 20:53:27 +03:00
committed by GitHub
parent 367eff9de6
commit 049ce7ddc6
40 changed files with 108754 additions and 264 deletions

View File

@@ -13,6 +13,10 @@ type Visitor interface {
Parameter(n *Parameter)
Identifier(n *Identifier)
Argument(n *Argument)
MatchArm(n *MatchArm)
Union(n *Union)
Attribute(n *Attribute)
AttributeGroup(n *AttributeGroup)
StmtBreak(n *StmtBreak)
StmtCase(n *StmtCase)
@@ -85,6 +89,8 @@ type Visitor interface {
ExprIsset(n *ExprIsset)
ExprList(n *ExprList)
ExprMethodCall(n *ExprMethodCall)
ExprNullsafeMethodCall(n *ExprNullsafeMethodCall)
ExprMatch(n *ExprMatch)
ExprNew(n *ExprNew)
ExprPostDec(n *ExprPostDec)
ExprPostInc(n *ExprPostInc)
@@ -92,12 +98,14 @@ type Visitor interface {
ExprPreInc(n *ExprPreInc)
ExprPrint(n *ExprPrint)
ExprPropertyFetch(n *ExprPropertyFetch)
ExprNullsafePropertyFetch(n *ExprNullsafePropertyFetch)
ExprRequire(n *ExprRequire)
ExprRequireOnce(n *ExprRequireOnce)
ExprShellExec(n *ExprShellExec)
ExprStaticCall(n *ExprStaticCall)
ExprStaticPropertyFetch(n *ExprStaticPropertyFetch)
ExprTernary(n *ExprTernary)
ExprThrow(n *ExprThrow)
ExprUnaryMinus(n *ExprUnaryMinus)
ExprUnaryPlus(n *ExprUnaryPlus)
ExprVariable(n *ExprVariable)

View File

@@ -20,7 +20,7 @@ func (n *Root) GetPosition() *position.Position {
return n.Position
}
// Nullable node
// Nullable node is ?Expr
type Nullable struct {
Position *position.Position
QuestionTkn *token.Token
@@ -35,9 +35,26 @@ func (n *Nullable) GetPosition() *position.Position {
return n.Position
}
// Union node is Expr|Expr1|...
type Union struct {
Position *position.Position
Types []Vertex
SeparatorTkns []*token.Token
}
func (n *Union) Accept(v Visitor) {
v.Union(n)
}
func (n *Union) GetPosition() *position.Position {
return n.Position
}
// Parameter node
type Parameter struct {
Position *position.Position
AttrGroups []Vertex
Visibility Vertex
Type Vertex
AmpersandTkn *token.Token
VariadicTkn *token.Token
@@ -72,6 +89,8 @@ func (n *Identifier) GetPosition() *position.Position {
// Argument node
type Argument struct {
Position *position.Position
Name Vertex
ColonTkn *token.Token
VariadicTkn *token.Token
AmpersandTkn *token.Token
Expr Vertex
@@ -85,6 +104,41 @@ func (n *Argument) GetPosition() *position.Position {
return n.Position
}
// Attribute node
type Attribute struct {
Position *position.Position
Name Vertex
OpenParenthesisTkn *token.Token
Args []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}
func (n *Attribute) Accept(v Visitor) {
v.Attribute(n)
}
func (n *Attribute) GetPosition() *position.Position {
return n.Position
}
// AttributeGroup node
type AttributeGroup struct {
Position *position.Position
OpenAttributeTkn *token.Token
Attrs []Vertex
SeparatorTkns []*token.Token
CloseAttributeTkn *token.Token
}
func (n *AttributeGroup) Accept(v Visitor) {
v.AttributeGroup(n)
}
func (n *AttributeGroup) GetPosition() *position.Position {
return n.Position
}
// ScalarDnumber node
type ScalarDnumber struct {
Position *position.Position
@@ -286,6 +340,7 @@ func (n *StmtCatch) GetPosition() *position.Position {
// StmtClass node
type StmtClass struct {
Position *position.Position
AttrGroups []Vertex
Modifiers []Vertex
ClassTkn *token.Token
Name Vertex
@@ -314,6 +369,7 @@ func (n *StmtClass) GetPosition() *position.Position {
// StmtClassConstList node
type StmtClassConstList struct {
Position *position.Position
AttrGroups []Vertex
Modifiers []Vertex
ConstTkn *token.Token
Consts []Vertex
@@ -332,6 +388,7 @@ func (n *StmtClassConstList) GetPosition() *position.Position {
// StmtClassMethod node
type StmtClassMethod struct {
Position *position.Position
AttrGroups []Vertex
Modifiers []Vertex
FunctionTkn *token.Token
AmpersandTkn *token.Token
@@ -601,6 +658,7 @@ func (n *StmtForeach) GetPosition() *position.Position {
// StmtFunction node
type StmtFunction struct {
Position *position.Position
AttrGroups []Vertex
FunctionTkn *token.Token
AmpersandTkn *token.Token
Name Vertex
@@ -714,6 +772,7 @@ func (n *StmtInlineHtml) GetPosition() *position.Position {
// StmtInterface node
type StmtInterface struct {
Position *position.Position
AttrGroups []Vertex
InterfaceTkn *token.Token
Name Vertex
ExtendsTkn *token.Token
@@ -799,6 +858,7 @@ func (n *StmtProperty) GetPosition() *position.Position {
// StmtPropertyList node
type StmtPropertyList struct {
Position *position.Position
AttrGroups []Vertex
Modifiers []Vertex
Type Vertex
Props []Vertex
@@ -922,6 +982,7 @@ func (n *StmtThrow) GetPosition() *position.Position {
// StmtTrait node
type StmtTrait struct {
Position *position.Position
AttrGroups []Vertex
TraitTkn *token.Token
Name Vertex
OpenCurlyBracketTkn *token.Token
@@ -1171,6 +1232,7 @@ func (n *ExprArrayItem) GetPosition() *position.Position {
// ExprArrowFunction node
type ExprArrowFunction struct {
Position *position.Position
AttrGroups []Vertex
StaticTkn *token.Token
FnTkn *token.Token
AmpersandTkn *token.Token
@@ -1271,6 +1333,7 @@ func (n *ExprClone) GetPosition() *position.Position {
// ExprClosure node
type ExprClosure struct {
Position *position.Position
AttrGroups []Vertex
StaticTkn *token.Token
FunctionTkn *token.Token
AmpersandTkn *token.Token
@@ -1515,6 +1578,28 @@ func (n *ExprMethodCall) GetPosition() *position.Position {
return n.Position
}
// ExprNullsafeMethodCall node is $a?->methodName()
type ExprNullsafeMethodCall struct {
Position *position.Position
Var Vertex
ObjectOperatorTkn *token.Token
OpenCurlyBracketTkn *token.Token
Method Vertex
CloseCurlyBracketTkn *token.Token
OpenParenthesisTkn *token.Token
Args []Vertex
SeparatorTkns []*token.Token
CloseParenthesisTkn *token.Token
}
func (n *ExprNullsafeMethodCall) Accept(v Visitor) {
v.ExprNullsafeMethodCall(n)
}
func (n *ExprNullsafeMethodCall) GetPosition() *position.Position {
return n.Position
}
// ExprNew node
type ExprNew struct {
Position *position.Position
@@ -1627,6 +1712,24 @@ func (n *ExprPropertyFetch) GetPosition() *position.Position {
return n.Position
}
// ExprNullsafePropertyFetch node
type ExprNullsafePropertyFetch struct {
Position *position.Position
Var Vertex
ObjectOperatorTkn *token.Token
OpenCurlyBracketTkn *token.Token
Prop Vertex
CloseCurlyBracketTkn *token.Token
}
func (n *ExprNullsafePropertyFetch) Accept(v Visitor) {
v.ExprNullsafePropertyFetch(n)
}
func (n *ExprNullsafePropertyFetch) GetPosition() *position.Position {
return n.Position
}
// ExprRequire node
type ExprRequire struct {
Position *position.Position
@@ -2586,6 +2689,62 @@ func (n *ExprBinarySpaceship) GetPosition() *position.Position {
return n.Position
}
// ExprMatch node is match(expr) { list<MatchArm> }
type ExprMatch struct {
Position *position.Position
MatchTkn *token.Token
OpenParenthesisTkn *token.Token
Expr Vertex
CloseParenthesisTkn *token.Token
OpenCurlyBracketTkn *token.Token
Arms []Vertex
SeparatorTkns []*token.Token
CloseCurlyBracketTkn *token.Token
}
func (n *ExprMatch) Accept(v Visitor) {
v.ExprMatch(n)
}
func (n *ExprMatch) GetPosition() *position.Position {
return n.Position
}
// ExprThrow node is 'throw Expr'
type ExprThrow struct {
Position *position.Position
ThrowTkn *token.Token
Expr Vertex
SemiColonTkn *token.Token
}
func (n *ExprThrow) Accept(v Visitor) {
v.ExprThrow(n)
}
func (n *ExprThrow) GetPosition() *position.Position {
return n.Position
}
// MatchArm node is [expr, expr1, ...]|default => return_expr
type MatchArm struct {
Position *position.Position
DefaultTkn *token.Token
DefaultCommaTkn *token.Token
Exprs []Vertex
SeparatorTkns []*token.Token
DoubleArrowTkn *token.Token
ReturnExpr Vertex
}
func (n *MatchArm) Accept(v Visitor) {
v.MatchArm(n)
}
func (n *MatchArm) GetPosition() *position.Position {
return n.Position
}
type Name struct {
Position *position.Position
Parts []Vertex

View File

@@ -5,6 +5,7 @@ import (
"github.com/z7zmey/php-parser/internal/php5"
"github.com/z7zmey/php-parser/internal/php7"
"github.com/z7zmey/php-parser/internal/php8"
"github.com/z7zmey/php-parser/internal/scanner"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/conf"
@@ -20,6 +21,9 @@ var (
php7RangeStart = &version.Version{Major: 7}
php7RangeEnd = &version.Version{Major: 7, Minor: 4}
php8RangeStart = &version.Version{Major: 8}
php8RangeEnd = &version.Version{Major: 8, Minor: 1}
)
// Parser interface
@@ -49,5 +53,12 @@ func Parse(src []byte, config conf.Config) (ast.Vertex, error) {
return parser.GetRootNode(), nil
}
if config.Version.InRange(php8RangeStart, php8RangeEnd) {
lexer := php8.NewLexer(src, config)
parser = php8.NewParser(lexer, config)
parser.Parse()
return parser.GetRootNode(), nil
}
return nil, ErrVersionOutOfRange
}

View File

@@ -144,6 +144,12 @@ const (
T_IS_NOT_EQUAL
T_IS_SMALLER_OR_EQUAL
T_IS_GREATER_OR_EQUAL
T_NULLSAFE_OBJECT_OPERATOR
T_MATCH
T_ATTRIBUTE
T_NAME_RELATIVE
T_NAME_QUALIFIED
T_NAME_FULLY_QUALIFIED
)
type Token struct {

View File

@@ -146,11 +146,17 @@ func _() {
_ = x[T_IS_NOT_EQUAL-57481]
_ = x[T_IS_SMALLER_OR_EQUAL-57482]
_ = x[T_IS_GREATER_OR_EQUAL-57483]
_ = x[T_NULLSAFE_OBJECT_OPERATOR-57484]
_ = x[T_MATCH-57485]
_ = x[T_ATTRIBUTE-57486]
_ = x[T_NAME_RELATIVE-57487]
_ = x[T_NAME_QUALIFIED-57488]
_ = x[T_NAME_FULLY_QUALIFIED-57489]
}
const _ID_name = "T_INCLUDET_INCLUDE_ONCET_EXITT_IFT_LNUMBERT_DNUMBERT_STRINGT_STRING_VARNAMET_VARIABLET_NUM_STRINGT_INLINE_HTMLT_CHARACTERT_BAD_CHARACTERT_ENCAPSED_AND_WHITESPACET_CONSTANT_ENCAPSED_STRINGT_ECHOT_DOT_WHILET_ENDWHILET_FORT_ENDFORT_FOREACHT_ENDFOREACHT_DECLARET_ENDDECLARET_AST_SWITCHT_ENDSWITCHT_CASET_DEFAULTT_BREAKT_CONTINUET_GOTOT_FUNCTIONT_FNT_CONSTT_RETURNT_TRYT_CATCHT_FINALLYT_THROWT_USET_INSTEADOFT_GLOBALT_VART_UNSETT_ISSETT_EMPTYT_HALT_COMPILERT_CLASST_TRAITT_INTERFACET_EXTENDST_IMPLEMENTST_OBJECT_OPERATORT_DOUBLE_ARROWT_LISTT_ARRAYT_CALLABLET_CLASS_CT_TRAIT_CT_METHOD_CT_FUNC_CT_LINET_FILET_COMMENTT_DOC_COMMENTT_OPEN_TAGT_OPEN_TAG_WITH_ECHOT_CLOSE_TAGT_WHITESPACET_START_HEREDOCT_END_HEREDOCT_DOLLAR_OPEN_CURLY_BRACEST_CURLY_OPENT_PAAMAYIM_NEKUDOTAYIMT_NAMESPACET_NS_CT_DIRT_NS_SEPARATORT_ELLIPSIST_EVALT_REQUIRET_REQUIRE_ONCET_LOGICAL_ORT_LOGICAL_XORT_LOGICAL_ANDT_INSTANCEOFT_NEWT_CLONET_ELSEIFT_ELSET_ENDIFT_PRINTT_YIELDT_STATICT_ABSTRACTT_FINALT_PRIVATET_PROTECTEDT_PUBLICT_INCT_DECT_YIELD_FROMT_INT_CASTT_DOUBLE_CASTT_STRING_CASTT_ARRAY_CASTT_OBJECT_CASTT_BOOL_CASTT_UNSET_CASTT_COALESCET_SPACESHIPT_NOELSET_PLUS_EQUALT_MINUS_EQUALT_MUL_EQUALT_POW_EQUALT_DIV_EQUALT_CONCAT_EQUALT_MOD_EQUALT_AND_EQUALT_OR_EQUALT_XOR_EQUALT_SL_EQUALT_SR_EQUALT_COALESCE_EQUALT_BOOLEAN_ORT_BOOLEAN_ANDT_POWT_SLT_SRT_IS_IDENTICALT_IS_NOT_IDENTICALT_IS_EQUALT_IS_NOT_EQUALT_IS_SMALLER_OR_EQUALT_IS_GREATER_OR_EQUAL"
const _ID_name = "T_INCLUDET_INCLUDE_ONCET_EXITT_IFT_LNUMBERT_DNUMBERT_STRINGT_STRING_VARNAMET_VARIABLET_NUM_STRINGT_INLINE_HTMLT_CHARACTERT_BAD_CHARACTERT_ENCAPSED_AND_WHITESPACET_CONSTANT_ENCAPSED_STRINGT_ECHOT_DOT_WHILET_ENDWHILET_FORT_ENDFORT_FOREACHT_ENDFOREACHT_DECLARET_ENDDECLARET_AST_SWITCHT_ENDSWITCHT_CASET_DEFAULTT_BREAKT_CONTINUET_GOTOT_FUNCTIONT_FNT_CONSTT_RETURNT_TRYT_CATCHT_FINALLYT_THROWT_USET_INSTEADOFT_GLOBALT_VART_UNSETT_ISSETT_EMPTYT_HALT_COMPILERT_CLASST_TRAITT_INTERFACET_EXTENDST_IMPLEMENTST_OBJECT_OPERATORT_DOUBLE_ARROWT_LISTT_ARRAYT_CALLABLET_CLASS_CT_TRAIT_CT_METHOD_CT_FUNC_CT_LINET_FILET_COMMENTT_DOC_COMMENTT_OPEN_TAGT_OPEN_TAG_WITH_ECHOT_CLOSE_TAGT_WHITESPACET_START_HEREDOCT_END_HEREDOCT_DOLLAR_OPEN_CURLY_BRACEST_CURLY_OPENT_PAAMAYIM_NEKUDOTAYIMT_NAMESPACET_NS_CT_DIRT_NS_SEPARATORT_ELLIPSIST_EVALT_REQUIRET_REQUIRE_ONCET_LOGICAL_ORT_LOGICAL_XORT_LOGICAL_ANDT_INSTANCEOFT_NEWT_CLONET_ELSEIFT_ELSET_ENDIFT_PRINTT_YIELDT_STATICT_ABSTRACTT_FINALT_PRIVATET_PROTECTEDT_PUBLICT_INCT_DECT_YIELD_FROMT_INT_CASTT_DOUBLE_CASTT_STRING_CASTT_ARRAY_CASTT_OBJECT_CASTT_BOOL_CASTT_UNSET_CASTT_COALESCET_SPACESHIPT_NOELSET_PLUS_EQUALT_MINUS_EQUALT_MUL_EQUALT_POW_EQUALT_DIV_EQUALT_CONCAT_EQUALT_MOD_EQUALT_AND_EQUALT_OR_EQUALT_XOR_EQUALT_SL_EQUALT_SR_EQUALT_COALESCE_EQUALT_BOOLEAN_ORT_BOOLEAN_ANDT_POWT_SLT_SRT_IS_IDENTICALT_IS_NOT_IDENTICALT_IS_EQUALT_IS_NOT_EQUALT_IS_SMALLER_OR_EQUALT_IS_GREATER_OR_EQUALT_NULLSAFE_OBJECT_OPERATORT_MATCHT_ATTRIBUTET_NAME_RELATIVET_NAME_QUALIFIEDT_NAME_FULLY_QUALIFIED"
var _ID_index = [...]uint16{0, 9, 23, 29, 33, 42, 51, 59, 75, 85, 97, 110, 121, 136, 161, 187, 193, 197, 204, 214, 219, 227, 236, 248, 257, 269, 273, 281, 292, 298, 307, 314, 324, 330, 340, 344, 351, 359, 364, 371, 380, 387, 392, 403, 411, 416, 423, 430, 437, 452, 459, 466, 477, 486, 498, 515, 529, 535, 542, 552, 561, 570, 580, 588, 594, 600, 609, 622, 632, 652, 663, 675, 690, 703, 729, 741, 763, 774, 780, 785, 799, 809, 815, 824, 838, 850, 863, 876, 888, 893, 900, 908, 914, 921, 928, 935, 943, 953, 960, 969, 980, 988, 993, 998, 1010, 1020, 1033, 1046, 1058, 1071, 1082, 1094, 1104, 1115, 1123, 1135, 1148, 1159, 1170, 1181, 1195, 1206, 1217, 1227, 1238, 1248, 1258, 1274, 1286, 1299, 1304, 1308, 1312, 1326, 1344, 1354, 1368, 1389, 1410}
var _ID_index = [...]uint16{0, 9, 23, 29, 33, 42, 51, 59, 75, 85, 97, 110, 121, 136, 161, 187, 193, 197, 204, 214, 219, 227, 236, 248, 257, 269, 273, 281, 292, 298, 307, 314, 324, 330, 340, 344, 351, 359, 364, 371, 380, 387, 392, 403, 411, 416, 423, 430, 437, 452, 459, 466, 477, 486, 498, 515, 529, 535, 542, 552, 561, 570, 580, 588, 594, 600, 609, 622, 632, 652, 663, 675, 690, 703, 729, 741, 763, 774, 780, 785, 799, 809, 815, 824, 838, 850, 863, 876, 888, 893, 900, 908, 914, 921, 928, 935, 943, 953, 960, 969, 980, 988, 993, 998, 1010, 1020, 1033, 1046, 1058, 1071, 1082, 1094, 1104, 1115, 1123, 1135, 1148, 1159, 1170, 1181, 1195, 1206, 1217, 1227, 1238, 1248, 1258, 1274, 1286, 1299, 1304, 1308, 1312, 1326, 1344, 1354, 1368, 1389, 1410, 1436, 1443, 1454, 1469, 1485, 1507}
func (i ID) String() string {
i -= 57346

View File

@@ -22,6 +22,9 @@ var (
php7RangeStart = &Version{Major: 7}
php7RangeEnd = &Version{Major: 7, Minor: 4}
php8RangeStart = &Version{Major: 8}
php8RangeEnd = &Version{Major: 8, Minor: 1}
)
func New(v string) (*Version, error) {
@@ -48,7 +51,9 @@ func New(v string) (*Version, error) {
}
func (v *Version) Validate() error {
if !v.InRange(php5RangeStart, php5RangeEnd) && !v.InRange(php7RangeStart, php7RangeEnd) {
if !v.InRange(php5RangeStart, php5RangeEnd) &&
!v.InRange(php7RangeStart, php7RangeEnd) &&
!v.InRange(php8RangeStart, php8RangeEnd) {
return ErrUnsupportedVer
}
@@ -75,7 +80,7 @@ func (v *Version) GreaterOrEqual(o *Version) bool {
return v.Compare(o) >= 0
}
// GreaterOrEqual tests if one version is greater than another one or equal
// InRange tests if version is in range in another one
func (v *Version) InRange(s, e *Version) bool {
return v.Compare(s) >= 0 && v.Compare(e) <= 0
}

View File

@@ -1,9 +1,10 @@
package version_test
import (
"gotest.tools/assert"
"testing"
"gotest.tools/assert"
"github.com/z7zmey/php-parser/pkg/version"
)
@@ -46,3 +47,19 @@ func TestInRange(t *testing.T) {
assert.NilError(t, err)
assert.Assert(t, ver.InRange(s, e))
}
func TestInRangePHP8(t *testing.T) {
s, err := version.New("8.0")
assert.NilError(t, err)
e, err := version.New("8.1")
assert.NilError(t, err)
ver, err := version.New("8.0")
assert.NilError(t, err)
assert.Assert(t, ver.InRange(s, e))
ver, err = version.New("8.1")
assert.NilError(t, err)
assert.Assert(t, ver.InRange(s, e))
}

View File

@@ -1,12 +1,13 @@
package dumper
import (
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token"
"io"
"strconv"
"strings"
"github.com/z7zmey/php-parser/pkg/position"
"github.com/z7zmey/php-parser/pkg/token"
"github.com/z7zmey/php-parser/pkg/ast"
)
@@ -192,6 +193,8 @@ func (v *Dumper) Parameter(n *ast.Parameter) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpVertex("Visibility", n.Visibility)
v.dumpVertex("Type", n.Type)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
v.dumpToken("VariadicTkn", n.VariadicTkn)
@@ -221,6 +224,8 @@ func (v *Dumper) Argument(n *ast.Argument) {
v.dumpPosition(n.Position)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
v.dumpVertex("Name", n.Name)
v.dumpToken("ColonTkn", n.ColonTkn)
v.dumpToken("VariadicTkn", n.VariadicTkn)
v.dumpVertex("Expr", n.Expr)
@@ -228,6 +233,63 @@ func (v *Dumper) Argument(n *ast.Argument) {
v.print(v.indent, "},\n")
}
func (v *Dumper) MatchArm(n *ast.MatchArm) {
v.print(0, "&ast.MatchArm{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("DefaultTkn", n.DefaultTkn)
v.dumpToken("DefaultCommaTkn", n.DefaultCommaTkn)
v.dumpVertexList("Exprs", n.Exprs)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("DoubleArrowTkn", n.DoubleArrowTkn)
v.dumpVertex("ReturnExpr", n.ReturnExpr)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) Union(n *ast.Union) {
v.print(0, "&ast.Union{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("Types", n.Types)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) Attribute(n *ast.Attribute) {
v.print(0, "&ast.Attribute{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Name", n.Name)
v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
v.dumpVertexList("Args", n.Args)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) AttributeGroup(n *ast.AttributeGroup) {
v.print(0, "&ast.AttributeGroup{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("OpenAttributeTkn", n.OpenAttributeTkn)
v.dumpVertexList("Attrs", n.Attrs)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("CloseAttributeTkn", n.CloseAttributeTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) StmtBreak(n *ast.StmtBreak) {
v.print(0, "&ast.StmtBreak{\n")
v.indent++
@@ -279,6 +341,7 @@ func (v *Dumper) StmtClass(n *ast.StmtClass) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpVertexList("Modifiers", n.Modifiers)
v.dumpToken("ClassTkn", n.ClassTkn)
v.dumpVertex("Name", n.Name)
@@ -304,6 +367,7 @@ func (v *Dumper) StmtClassConstList(n *ast.StmtClassConstList) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpVertexList("Modifiers", n.Modifiers)
v.dumpToken("ConstTkn", n.ConstTkn)
v.dumpVertexList("Consts", n.Consts)
@@ -319,6 +383,7 @@ func (v *Dumper) StmtClassMethod(n *ast.StmtClassMethod) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpVertexList("Modifiers", n.Modifiers)
v.dumpToken("FunctionTkn", n.FunctionTkn)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
@@ -547,6 +612,7 @@ func (v *Dumper) StmtFunction(n *ast.StmtFunction) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpToken("FunctionTkn", n.FunctionTkn)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
v.dumpVertex("Name", n.Name)
@@ -642,6 +708,7 @@ func (v *Dumper) StmtInterface(n *ast.StmtInterface) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpToken("InterfaceTkn", n.InterfaceTkn)
v.dumpVertex("Name", n.Name)
v.dumpToken("ExtendsTkn", n.ExtendsTkn)
@@ -712,6 +779,7 @@ func (v *Dumper) StmtPropertyList(n *ast.StmtPropertyList) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpVertexList("Modifiers", n.Modifiers)
v.dumpVertex("Type", n.Type)
v.dumpVertexList("Props", n.Props)
@@ -814,6 +882,7 @@ func (v *Dumper) StmtTrait(n *ast.StmtTrait) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpToken("TraitTkn", n.TraitTkn)
v.dumpVertex("Name", n.Name)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
@@ -1024,6 +1093,7 @@ func (v *Dumper) ExprArrowFunction(n *ast.ExprArrowFunction) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpToken("StaticTkn", n.StaticTkn)
v.dumpToken("FnTkn", n.FnTkn)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
@@ -1107,6 +1177,7 @@ func (v *Dumper) ExprClosure(n *ast.ExprClosure) {
v.indent++
v.dumpPosition(n.Position)
v.dumpVertexList("AttrGroups", n.AttrGroups)
v.dumpToken("StaticTkn", n.StaticTkn)
v.dumpToken("FunctionTkn", n.FunctionTkn)
v.dumpToken("AmpersandTkn", n.AmpersandTkn)
@@ -1307,6 +1378,25 @@ func (v *Dumper) ExprMethodCall(n *ast.ExprMethodCall) {
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprNullsafeMethodCall(n *ast.ExprNullsafeMethodCall) {
v.print(0, "&ast.ExprNullsafeMethodCall{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Var", n.Var)
v.dumpToken("ObjectOperatorTkn", n.ObjectOperatorTkn)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertex("Method", n.Method)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
v.dumpVertexList("Args", n.Args)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprNew(n *ast.ExprNew) {
v.print(0, "&ast.ExprNew{\n")
v.indent++
@@ -1398,6 +1488,21 @@ func (v *Dumper) ExprPropertyFetch(n *ast.ExprPropertyFetch) {
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprNullsafePropertyFetch(n *ast.ExprNullsafePropertyFetch) {
v.print(0, "&ast.ExprNullsafePropertyFetch{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpVertex("Var", n.Var)
v.dumpToken("ObjectOperatorTkn", n.ObjectOperatorTkn)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertex("Prop", n.Prop)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprRequire(n *ast.ExprRequire) {
v.print(0, "&ast.ExprRequire{\n")
v.indent++
@@ -2177,6 +2282,37 @@ func (v *Dumper) ExprCastUnset(n *ast.ExprCastUnset) {
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprMatch(n *ast.ExprMatch) {
v.print(0, "&ast.ExprMatch{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("MatchTkn", n.MatchTkn)
v.dumpToken("OpenParenthesisTkn", n.OpenParenthesisTkn)
v.dumpVertex("Expr", n.Expr)
v.dumpToken("CloseParenthesisTkn", n.CloseParenthesisTkn)
v.dumpToken("OpenCurlyBracketTkn", n.OpenCurlyBracketTkn)
v.dumpVertexList("Arms", n.Arms)
v.dumpTokenList("SeparatorTkns", n.SeparatorTkns)
v.dumpToken("CloseCurlyBracketTkn", n.CloseCurlyBracketTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) ExprThrow(n *ast.ExprThrow) {
v.print(0, "&ast.ExprThrow{\n")
v.indent++
v.dumpPosition(n.Position)
v.dumpToken("ThrowTkn", n.ThrowTkn)
v.dumpVertex("Expr", n.Expr)
v.dumpToken("SemiColonTkn", n.SemiColonTkn)
v.indent--
v.print(v.indent, "},\n")
}
func (v *Dumper) ScalarDnumber(n *ast.ScalarDnumber) {
v.print(0, "&ast.ScalarDnumber{\n")
v.indent++

View File

@@ -2,6 +2,7 @@ package formatter
import (
"bytes"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/token"
)
@@ -153,6 +154,18 @@ func (f *formatter) Nullable(n *ast.Nullable) {
}
func (f *formatter) Parameter(n *ast.Parameter) {
if n.AttrGroups != nil {
for _, group := range n.AttrGroups {
group.Accept(f)
}
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
if n.Visibility != nil {
n.Visibility.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
if n.Type != nil {
n.Type.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -185,6 +198,14 @@ func (f *formatter) Identifier(n *ast.Identifier) {
}
func (f *formatter) Argument(n *ast.Argument) {
if n.Name != nil {
n.Name.Accept(f)
}
if n.ColonTkn != nil {
n.ColonTkn = f.newToken(':', []byte(":"))
}
if n.VariadicTkn != nil {
n.VariadicTkn = f.newToken(token.T_ELLIPSIS, []byte("..."))
}
@@ -196,6 +217,45 @@ func (f *formatter) Argument(n *ast.Argument) {
n.Expr.Accept(f)
}
func (f *formatter) MatchArm(n *ast.MatchArm) {
if n.DefaultTkn != nil {
n.DefaultTkn = f.newToken(token.T_DEFAULT, []byte("default"))
}
if n.DefaultCommaTkn != nil {
n.DefaultCommaTkn = f.newToken(',', []byte(","))
}
n.SeparatorTkns = nil
if len(n.Exprs) > 0 {
n.SeparatorTkns = f.formatList(n.Exprs, ',')
}
n.DoubleArrowTkn = f.newToken(token.T_DOUBLE_ARROW, []byte("=>"))
}
func (f *formatter) Union(n *ast.Union) {
if len(n.Types) > 0 {
n.SeparatorTkns = f.formatList(n.Types, '|')
}
}
func (f *formatter) Attribute(n *ast.Attribute) {
n.Name.Accept(f)
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
n.SeparatorTkns = nil
if len(n.Args) > 0 {
n.SeparatorTkns = f.formatList(n.Args, ',')
}
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
}
func (f *formatter) AttributeGroup(n *ast.AttributeGroup) {
n.OpenAttributeTkn = f.newToken(token.T_ATTRIBUTE, []byte("#["))
n.SeparatorTkns = nil
if len(n.Attrs) > 0 {
n.SeparatorTkns = f.formatList(n.Attrs, ',')
}
n.CloseAttributeTkn = f.newToken(']', []byte("]"))
}
func (f *formatter) StmtBreak(n *ast.StmtBreak) {
n.BreakTkn = f.newToken(token.T_BREAK, []byte("break"))
@@ -307,6 +367,10 @@ func (f *formatter) StmtClass(n *ast.StmtClass) {
}
func (f *formatter) StmtClassConstList(n *ast.StmtClassConstList) {
for _, m := range n.AttrGroups {
m.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte("\n"))
}
for _, m := range n.Modifiers {
m.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -736,6 +800,10 @@ func (f *formatter) StmtProperty(n *ast.StmtProperty) {
}
func (f *formatter) StmtPropertyList(n *ast.StmtPropertyList) {
for _, m := range n.AttrGroups {
m.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte("\n"))
}
for _, m := range n.Modifiers {
m.Accept(f)
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -1061,6 +1129,13 @@ func (f *formatter) ExprArrayItem(n *ast.ExprArrayItem) {
}
func (f *formatter) ExprArrowFunction(n *ast.ExprArrowFunction) {
if n.AttrGroups != nil {
for _, group := range n.AttrGroups {
group.Accept(f)
}
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
if n.StaticTkn != nil {
n.StaticTkn = f.newToken(token.T_STATIC, []byte("static"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -1123,6 +1198,13 @@ func (f *formatter) ExprClone(n *ast.ExprClone) {
}
func (f *formatter) ExprClosure(n *ast.ExprClosure) {
if n.AttrGroups != nil {
for _, group := range n.AttrGroups {
group.Accept(f)
}
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
}
if n.StaticTkn != nil {
n.StaticTkn = f.newToken(token.T_STATIC, []byte("static"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -1287,6 +1369,30 @@ func (f *formatter) ExprMethodCall(n *ast.ExprMethodCall) {
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
}
func (f *formatter) ExprNullsafeMethodCall(n *ast.ExprNullsafeMethodCall) {
n.Var.Accept(f)
n.ObjectOperatorTkn = f.newToken(token.T_NULLSAFE_OBJECT_OPERATOR, []byte("?->"))
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
switch n.Method.(type) {
case *ast.Identifier:
case *ast.ExprVariable:
default:
n.OpenCurlyBracketTkn = f.newToken('{', []byte("{"))
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
}
n.Method.Accept(f)
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
n.SeparatorTkns = nil
if len(n.Args) > 0 {
n.SeparatorTkns = f.formatList(n.Args, ',')
}
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
}
func (f *formatter) ExprNew(n *ast.ExprNew) {
n.NewTkn = f.newToken(token.T_NEW, []byte("new"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -1347,6 +1453,23 @@ func (f *formatter) ExprPropertyFetch(n *ast.ExprPropertyFetch) {
n.Prop.Accept(f)
}
func (f *formatter) ExprNullsafePropertyFetch(n *ast.ExprNullsafePropertyFetch) {
n.Var.Accept(f)
n.ObjectOperatorTkn = f.newToken(token.T_NULLSAFE_OBJECT_OPERATOR, []byte("?->"))
n.OpenCurlyBracketTkn = nil
n.CloseCurlyBracketTkn = nil
switch n.Prop.(type) {
case *ast.Identifier:
case *ast.ExprVariable:
default:
n.OpenCurlyBracketTkn = f.newToken('{', []byte("{"))
n.CloseCurlyBracketTkn = f.newToken('}', []byte("}"))
}
n.Prop.Accept(f)
}
func (f *formatter) ExprRequire(n *ast.ExprRequire) {
n.RequireTkn = f.newToken(token.T_REQUIRE, []byte("require"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
@@ -1916,6 +2039,27 @@ func (f *formatter) ExprCastUnset(n *ast.ExprCastUnset) {
n.Expr.Accept(f)
}
func (f *formatter) ExprMatch(n *ast.ExprMatch) {
n.MatchTkn = f.newToken(token.T_MATCH, []byte("match"))
n.OpenParenthesisTkn = f.newToken('(', []byte("("))
n.CloseParenthesisTkn = f.newToken(')', []byte(")"))
n.OpenCurlyBracketTkn = f.newToken('}', []byte("}"))
n.SeparatorTkns = nil
if len(n.Arms) > 0 {
n.SeparatorTkns = f.formatList(n.Arms, ',')
}
n.CloseCurlyBracketTkn = f.newToken('{', []byte("{"))
}
func (f *formatter) ExprThrow(n *ast.ExprThrow) {
n.ThrowTkn = f.newToken(token.T_THROW, []byte("throw"))
f.addFreeFloating(token.T_WHITESPACE, []byte(" "))
n.Expr.Accept(f)
n.SemiColonTkn = f.newSemicolonTkn()
}
func (f *formatter) ScalarDnumber(n *ast.ScalarDnumber) {
if n.NumberTkn == nil {
n.NumberTkn = f.newToken(token.T_STRING, n.Value)

View File

@@ -3,9 +3,10 @@ package nsresolver
import (
"errors"
"strings"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/visitor"
"strings"
)
// NamespaceResolver visitor

View File

@@ -42,6 +42,22 @@ func (v *Null) Argument(_ *ast.Argument) {
// do nothing
}
func (v *Null) MatchArm(_ *ast.MatchArm) {
// do nothing
}
func (v *Null) Union(_ *ast.Union) {
// do nothing
}
func (v *Null) Attribute(_ *ast.Attribute) {
// do nothing
}
func (v *Null) AttributeGroup(_ *ast.AttributeGroup) {
// do nothing
}
func (v *Null) StmtBreak(_ *ast.StmtBreak) {
// do nothing
}
@@ -322,6 +338,10 @@ func (v *Null) ExprMethodCall(_ *ast.ExprMethodCall) {
// do nothing
}
func (v *Null) ExprNullsafeMethodCall(_ *ast.ExprNullsafeMethodCall) {
// do nothing
}
func (v *Null) ExprNew(_ *ast.ExprNew) {
// do nothing
}
@@ -350,6 +370,10 @@ func (v *Null) ExprPropertyFetch(_ *ast.ExprPropertyFetch) {
// do nothing
}
func (v *Null) ExprNullsafePropertyFetch(_ *ast.ExprNullsafePropertyFetch) {
// do nothing
}
func (v *Null) ExprRequire(_ *ast.ExprRequire) {
// do nothing
}
@@ -590,6 +614,14 @@ func (v *Null) ExprCastUnset(_ *ast.ExprCastUnset) {
// do nothing
}
func (v *Null) ExprMatch(_ *ast.ExprMatch) {
// do nothing
}
func (v *Null) ExprThrow(_ *ast.ExprThrow) {
// do nothing
}
func (v *Null) ScalarDnumber(_ *ast.ScalarDnumber) {
// do nothing
}

View File

@@ -2,9 +2,10 @@ package printer
import (
"bytes"
"io"
"github.com/z7zmey/php-parser/pkg/ast"
"github.com/z7zmey/php-parser/pkg/token"
"io"
)
type printerState int
@@ -145,6 +146,8 @@ func (p *printer) Nullable(n *ast.Nullable) {
}
func (p *printer) Parameter(n *ast.Parameter) {
p.printList(n.AttrGroups)
p.printNode(n.Visibility)
p.printNode(n.Type)
p.printToken(n.AmpersandTkn, nil)
p.printToken(n.VariadicTkn, nil)
@@ -158,11 +161,38 @@ func (p *printer) Identifier(n *ast.Identifier) {
}
func (p *printer) Argument(n *ast.Argument) {
p.printNode(n.Name)
p.printToken(n.ColonTkn, nil)
p.printToken(n.VariadicTkn, nil)
p.printToken(n.AmpersandTkn, nil)
p.printNode(n.Expr)
}
func (p *printer) MatchArm(n *ast.MatchArm) {
p.printToken(n.DefaultTkn, nil)
p.printToken(n.DefaultCommaTkn, nil)
p.printSeparatedList(n.Exprs, n.SeparatorTkns, []byte(","))
p.printToken(n.DoubleArrowTkn, []byte("=>"))
p.printNode(n.ReturnExpr)
}
func (p *printer) Union(n *ast.Union) {
p.printSeparatedList(n.Types, n.SeparatorTkns, []byte("|"))
}
func (p *printer) Attribute(n *ast.Attribute) {
p.printNode(n.Name)
p.printToken(n.OpenParenthesisTkn, p.ifNodeList(n.Args, []byte("(")))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.CloseParenthesisTkn, p.ifNodeList(n.Args, []byte(")")))
}
func (p *printer) AttributeGroup(n *ast.AttributeGroup) {
p.printToken(n.OpenAttributeTkn, []byte("#["))
p.printSeparatedList(n.Attrs, n.SeparatorTkns, []byte(","))
p.printToken(n.CloseAttributeTkn, []byte("]"))
}
func (p *printer) StmtBreak(n *ast.StmtBreak) {
p.printToken(n.BreakTkn, []byte("break"))
p.printNode(n.Expr)
@@ -188,6 +218,7 @@ func (p *printer) StmtCatch(n *ast.StmtCatch) {
}
func (p *printer) StmtClass(n *ast.StmtClass) {
p.printList(n.AttrGroups)
p.printList(n.Modifiers)
p.printToken(n.ClassTkn, []byte("class"))
p.printNode(n.Name)
@@ -204,6 +235,7 @@ func (p *printer) StmtClass(n *ast.StmtClass) {
}
func (p *printer) StmtClassConstList(n *ast.StmtClassConstList) {
p.printList(n.AttrGroups)
p.printList(n.Modifiers)
p.printToken(n.ConstTkn, []byte("const"))
p.printSeparatedList(n.Consts, n.SeparatorTkns, []byte(","))
@@ -211,6 +243,7 @@ func (p *printer) StmtClassConstList(n *ast.StmtClassConstList) {
}
func (p *printer) StmtClassMethod(n *ast.StmtClassMethod) {
p.printList(n.AttrGroups)
p.printList(n.Modifiers)
p.printToken(n.FunctionTkn, []byte("function"))
p.printToken(n.AmpersandTkn, nil)
@@ -364,6 +397,7 @@ func (p *printer) StmtForeach(n *ast.StmtForeach) {
}
func (p *printer) StmtFunction(n *ast.StmtFunction) {
p.printList(n.AttrGroups)
p.printToken(n.FunctionTkn, []byte("function"))
p.printToken(n.AmpersandTkn, nil)
p.printNode(n.Name)
@@ -426,6 +460,7 @@ func (p *printer) StmtInlineHtml(n *ast.StmtInlineHtml) {
}
func (p *printer) StmtInterface(n *ast.StmtInterface) {
p.printList(n.AttrGroups)
p.printToken(n.InterfaceTkn, []byte("interface"))
p.printNode(n.Name)
p.printToken(n.ExtendsTkn, p.ifNodeList(n.Extends, []byte("extends")))
@@ -460,6 +495,7 @@ func (p *printer) StmtProperty(n *ast.StmtProperty) {
}
func (p *printer) StmtPropertyList(n *ast.StmtPropertyList) {
p.printList(n.AttrGroups)
p.printList(n.Modifiers)
p.printNode(n.Type)
p.printSeparatedList(n.Props, n.SeparatorTkns, []byte(","))
@@ -511,6 +547,7 @@ func (p *printer) StmtThrow(n *ast.StmtThrow) {
}
func (p *printer) StmtTrait(n *ast.StmtTrait) {
p.printList(n.AttrGroups)
p.printToken(n.TraitTkn, []byte("trait"))
p.printNode(n.Name)
p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
@@ -630,6 +667,7 @@ func (p *printer) ExprArrayItem(n *ast.ExprArrayItem) {
}
func (p *printer) ExprArrowFunction(n *ast.ExprArrowFunction) {
p.printList(n.AttrGroups)
p.printToken(n.StaticTkn, nil)
p.printToken(n.FnTkn, []byte("fn"))
p.printToken(n.AmpersandTkn, nil)
@@ -670,6 +708,7 @@ func (p *printer) ExprClone(n *ast.ExprClone) {
}
func (p *printer) ExprClosure(n *ast.ExprClosure) {
p.printList(n.AttrGroups)
p.printToken(n.StaticTkn, nil)
p.printToken(n.FunctionTkn, []byte("function"))
p.printToken(n.AmpersandTkn, nil)
@@ -770,6 +809,17 @@ func (p *printer) ExprMethodCall(n *ast.ExprMethodCall) {
p.printToken(n.CloseParenthesisTkn, []byte(")"))
}
func (p *printer) ExprNullsafeMethodCall(n *ast.ExprNullsafeMethodCall) {
p.printNode(n.Var)
p.printToken(n.ObjectOperatorTkn, []byte("?->"))
p.printToken(n.OpenCurlyBracketTkn, nil)
p.printNode(n.Method)
p.printToken(n.CloseCurlyBracketTkn, nil)
p.printToken(n.OpenParenthesisTkn, []byte("("))
p.printSeparatedList(n.Args, n.SeparatorTkns, []byte(","))
p.printToken(n.CloseParenthesisTkn, []byte(")"))
}
func (p *printer) ExprNew(n *ast.ExprNew) {
p.printToken(n.NewTkn, []byte("new"))
p.printNode(n.Class)
@@ -811,6 +861,14 @@ func (p *printer) ExprPropertyFetch(n *ast.ExprPropertyFetch) {
p.printToken(n.CloseCurlyBracketTkn, nil)
}
func (p *printer) ExprNullsafePropertyFetch(n *ast.ExprNullsafePropertyFetch) {
p.printNode(n.Var)
p.printToken(n.ObjectOperatorTkn, []byte("?->"))
p.printToken(n.OpenCurlyBracketTkn, nil)
p.printNode(n.Prop)
p.printToken(n.CloseCurlyBracketTkn, nil)
}
func (p *printer) ExprRequire(n *ast.ExprRequire) {
p.printToken(n.RequireTkn, []byte("require"))
p.printNode(n.Expr)
@@ -1169,6 +1227,21 @@ func (p *printer) ExprCastUnset(n *ast.ExprCastUnset) {
p.printNode(n.Expr)
}
func (p *printer) ExprMatch(n *ast.ExprMatch) {
p.printToken(n.MatchTkn, []byte("match"))
p.printToken(n.OpenParenthesisTkn, []byte("("))
p.printNode(n.Expr)
p.printToken(n.CloseParenthesisTkn, []byte(")"))
p.printToken(n.OpenCurlyBracketTkn, []byte("{"))
p.printSeparatedList(n.Arms, n.SeparatorTkns, []byte(","))
p.printToken(n.CloseCurlyBracketTkn, []byte("}"))
}
func (p *printer) ExprThrow(n *ast.ExprThrow) {
p.printToken(n.ThrowTkn, []byte("throw"))
p.printNode(n.Expr)
}
func (p *printer) ScalarDnumber(n *ast.ScalarDnumber) {
p.printToken(n.NumberTkn, n.Value)
}

File diff suppressed because it is too large Load Diff

View File

@@ -37,6 +37,11 @@ func (t *Traverser) Nullable(n *ast.Nullable) {
func (t *Traverser) Parameter(n *ast.Parameter) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
t.Traverse(n.Visibility)
t.Traverse(n.Type)
t.Traverse(n.Var)
t.Traverse(n.DefaultValue)
@@ -49,9 +54,44 @@ func (t *Traverser) Identifier(n *ast.Identifier) {
func (t *Traverser) Argument(n *ast.Argument) {
n.Accept(t.v)
t.Traverse(n.Name)
t.Traverse(n.Expr)
}
func (t *Traverser) MatchArm(n *ast.MatchArm) {
n.Accept(t.v)
for _, nn := range n.Exprs {
nn.Accept(t)
}
t.Traverse(n.ReturnExpr)
}
func (t *Traverser) Union(n *ast.Union) {
n.Accept(t.v)
for _, nn := range n.Types {
nn.Accept(t)
}
}
func (t *Traverser) Attribute(n *ast.Attribute) {
n.Accept(t.v)
t.Traverse(n.Name)
for _, nn := range n.Args {
nn.Accept(t)
}
}
func (t *Traverser) AttributeGroup(n *ast.AttributeGroup) {
n.Accept(t.v)
for _, nn := range n.Attrs {
nn.Accept(t)
}
}
func (t *Traverser) StmtBreak(n *ast.StmtBreak) {
n.Accept(t.v)
@@ -82,6 +122,9 @@ func (t *Traverser) StmtCatch(n *ast.StmtCatch) {
func (t *Traverser) StmtClass(n *ast.StmtClass) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Modifiers {
nn.Accept(t)
}
@@ -101,6 +144,9 @@ func (t *Traverser) StmtClass(n *ast.StmtClass) {
func (t *Traverser) StmtClassConstList(n *ast.StmtClassConstList) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Modifiers {
nn.Accept(t)
}
@@ -112,6 +158,9 @@ func (t *Traverser) StmtClassConstList(n *ast.StmtClassConstList) {
func (t *Traverser) StmtClassMethod(n *ast.StmtClassMethod) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Modifiers {
nn.Accept(t)
}
@@ -230,6 +279,9 @@ func (t *Traverser) StmtForeach(n *ast.StmtForeach) {
func (t *Traverser) StmtFunction(n *ast.StmtFunction) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
t.Traverse(n.Name)
for _, nn := range n.Params {
nn.Accept(t)
@@ -276,6 +328,9 @@ func (t *Traverser) StmtInlineHtml(n *ast.StmtInlineHtml) {
func (t *Traverser) StmtInterface(n *ast.StmtInterface) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
t.Traverse(n.Name)
for _, nn := range n.Extends {
nn.Accept(t)
@@ -314,6 +369,9 @@ func (t *Traverser) StmtProperty(n *ast.StmtProperty) {
func (t *Traverser) StmtPropertyList(n *ast.StmtPropertyList) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Modifiers {
nn.Accept(t)
}
@@ -370,6 +428,9 @@ func (t *Traverser) StmtThrow(n *ast.StmtThrow) {
func (t *Traverser) StmtTrait(n *ast.StmtTrait) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
t.Traverse(n.Name)
for _, nn := range n.Stmts {
nn.Accept(t)
@@ -485,6 +546,9 @@ func (t *Traverser) ExprArrayItem(n *ast.ExprArrayItem) {
func (t *Traverser) ExprArrowFunction(n *ast.ExprArrowFunction) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Params {
nn.Accept(t)
}
@@ -526,6 +590,9 @@ func (t *Traverser) ExprClone(n *ast.ExprClone) {
func (t *Traverser) ExprClosure(n *ast.ExprClosure) {
n.Accept(t.v)
for _, nn := range n.AttrGroups {
nn.Accept(t)
}
for _, nn := range n.Params {
nn.Accept(t)
}
@@ -628,6 +695,16 @@ func (t *Traverser) ExprMethodCall(n *ast.ExprMethodCall) {
}
}
func (t *Traverser) ExprNullsafeMethodCall(n *ast.ExprNullsafeMethodCall) {
n.Accept(t.v)
t.Traverse(n.Var)
t.Traverse(n.Method)
for _, nn := range n.Args {
nn.Accept(t)
}
}
func (t *Traverser) ExprNew(n *ast.ExprNew) {
n.Accept(t.v)
@@ -674,6 +751,13 @@ func (t *Traverser) ExprPropertyFetch(n *ast.ExprPropertyFetch) {
t.Traverse(n.Prop)
}
func (t *Traverser) ExprNullsafePropertyFetch(n *ast.ExprNullsafePropertyFetch) {
n.Accept(t.v)
t.Traverse(n.Var)
t.Traverse(n.Prop)
}
func (t *Traverser) ExprRequire(n *ast.ExprRequire) {
n.Accept(t.v)
@@ -1086,6 +1170,21 @@ func (t *Traverser) ExprCastUnset(n *ast.ExprCastUnset) {
t.Traverse(n.Expr)
}
func (t *Traverser) ExprMatch(n *ast.ExprMatch) {
n.Accept(t.v)
t.Traverse(n.Expr)
for _, nn := range n.Arms {
nn.Accept(t)
}
}
func (t *Traverser) ExprThrow(n *ast.ExprThrow) {
n.Accept(t.v)
t.Traverse(n.Expr)
}
func (t *Traverser) ScalarDnumber(n *ast.ScalarDnumber) {
n.Accept(t.v)
}