remove nodesWithEndToken type
This commit is contained in:
parent
2abe1dfb84
commit
a488f43496
10
README.md
10
README.md
@ -103,10 +103,12 @@ nodes := &stmt.StmtList{
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
MethodName: &node.Identifier{Value: "greet"},
|
MethodName: &node.Identifier{Value: "greet"},
|
||||||
Stmts: []node.Node{
|
Stmt: &stmt.StmtList{
|
||||||
&stmt.Echo{
|
Stmts: []node.Node{
|
||||||
Exprs: []node.Node{
|
&stmt.Echo{
|
||||||
&scalar.String{Value: "'Hello world'"},
|
Exprs: []node.Node{
|
||||||
|
&scalar.String{Value: "'Hello world'"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -13,11 +13,11 @@ type ClassMethod struct {
|
|||||||
Modifiers []node.Node
|
Modifiers []node.Node
|
||||||
Params []node.Node
|
Params []node.Node
|
||||||
ReturnType node.Node
|
ReturnType node.Node
|
||||||
Stmts []node.Node
|
Stmt node.Node
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewClassMethod node constructor
|
// NewClassMethod node constructor
|
||||||
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmts []node.Node, PhpDocComment string) *ClassMethod {
|
func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool, Params []node.Node, ReturnType node.Node, Stmt node.Node, PhpDocComment string) *ClassMethod {
|
||||||
return &ClassMethod{
|
return &ClassMethod{
|
||||||
ReturnsRef,
|
ReturnsRef,
|
||||||
PhpDocComment,
|
PhpDocComment,
|
||||||
@ -25,7 +25,7 @@ func NewClassMethod(MethodName node.Node, Modifiers []node.Node, ReturnsRef bool
|
|||||||
Modifiers,
|
Modifiers,
|
||||||
Params,
|
Params,
|
||||||
ReturnType,
|
ReturnType,
|
||||||
Stmts,
|
Stmt,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -72,13 +72,9 @@ func (n *ClassMethod) Walk(v walker.Visitor) {
|
|||||||
n.ReturnType.Walk(vv)
|
n.ReturnType.Walk(vv)
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.Stmts != nil {
|
if n.Stmt != nil {
|
||||||
vv := v.GetChildrenVisitor("Stmts")
|
vv := v.GetChildrenVisitor("Stmt")
|
||||||
for _, nn := range n.Stmts {
|
n.Stmt.Walk(vv)
|
||||||
if nn != nil {
|
|
||||||
nn.Walk(vv)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
v.LeaveNode(n)
|
v.LeaveNode(n)
|
||||||
|
@ -2,9 +2,10 @@ package stmt_test
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
"github.com/z7zmey/php-parser/node/name"
|
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node/name"
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
"github.com/z7zmey/php-parser/node/stmt"
|
"github.com/z7zmey/php-parser/node/stmt"
|
||||||
"github.com/z7zmey/php-parser/php5"
|
"github.com/z7zmey/php-parser/php5"
|
||||||
@ -22,7 +23,9 @@ func TestSimpleClassMethod(t *testing.T) {
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
PhpDocComment: "",
|
PhpDocComment: "",
|
||||||
MethodName: &node.Identifier{Value: "bar"},
|
MethodName: &node.Identifier{Value: "bar"},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -56,7 +59,9 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
|
|||||||
&node.Identifier{Value: "final"},
|
&node.Identifier{Value: "final"},
|
||||||
&node.Identifier{Value: "private"},
|
&node.Identifier{Value: "private"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
PhpDocComment: "",
|
PhpDocComment: "",
|
||||||
@ -65,7 +70,9 @@ func TestPrivateProtectedClassMethod(t *testing.T) {
|
|||||||
Modifiers: []node.Node{
|
Modifiers: []node.Node{
|
||||||
&node.Identifier{Value: "protected"},
|
&node.Identifier{Value: "protected"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -99,7 +106,9 @@ func TestPhp5ClassMethod(t *testing.T) {
|
|||||||
&node.Identifier{Value: "public"},
|
&node.Identifier{Value: "public"},
|
||||||
&node.Identifier{Value: "static"},
|
&node.Identifier{Value: "static"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -133,7 +142,9 @@ func TestPhp7ClassMethod(t *testing.T) {
|
|||||||
&name.NamePart{Value: "void"},
|
&name.NamePart{Value: "void"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -163,6 +174,7 @@ func TestAbstractClassMethod(t *testing.T) {
|
|||||||
&node.Identifier{Value: "abstract"},
|
&node.Identifier{Value: "abstract"},
|
||||||
&node.Identifier{Value: "public"},
|
&node.Identifier{Value: "public"},
|
||||||
},
|
},
|
||||||
|
Stmt: &stmt.Nop{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -201,6 +213,7 @@ func TestPhp7AbstractClassMethod(t *testing.T) {
|
|||||||
&name.NamePart{Value: "void"},
|
&name.NamePart{Value: "void"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
Stmt: &stmt.Nop{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -82,9 +82,9 @@ var nodesToTest = []struct {
|
|||||||
Modifiers: []node.Node{&stmt.Expression{}},
|
Modifiers: []node.Node{&stmt.Expression{}},
|
||||||
Params: []node.Node{&stmt.Expression{}},
|
Params: []node.Node{&stmt.Expression{}},
|
||||||
ReturnType: &node.Identifier{},
|
ReturnType: &node.Identifier{},
|
||||||
Stmts: []node.Node{&stmt.Expression{}},
|
Stmt: &stmt.StmtList{},
|
||||||
},
|
},
|
||||||
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmts"},
|
[]string{"MethodName", "Modifiers", "Params", "ReturnType", "Stmt"},
|
||||||
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
map[string]interface{}{"ReturnsRef": true, "PhpDocComment": "/** */"},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@ -360,7 +360,7 @@ var nodesToTest = []struct {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
&stmt.Switch{
|
&stmt.Switch{
|
||||||
Cond: &expr.Variable{},
|
Cond: &expr.Variable{},
|
||||||
CaseList: &stmt.CaseList{},
|
CaseList: &stmt.CaseList{},
|
||||||
},
|
},
|
||||||
[]string{"Cond", "CaseList"},
|
[]string{"Cond", "CaseList"},
|
||||||
|
@ -289,7 +289,9 @@ func TestPhp7ParameterNode(t *testing.T) {
|
|||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
Params: expectedParams,
|
Params: expectedParams,
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -357,7 +359,9 @@ func TestPhp5ParameterNode(t *testing.T) {
|
|||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
Params: expectedParams,
|
Params: expectedParams,
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -174,6 +174,16 @@ func (b *PositionBuilder) NewNodeNodeListPosition(n node.Node, list []node.Node)
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewNodeListNodePosition returns new Position
|
||||||
|
func (b *PositionBuilder) NewNodeListNodePosition(list []node.Node, n node.Node) *position.Position {
|
||||||
|
return position.NewPosition(
|
||||||
|
b.getListStartPos(list).startLine,
|
||||||
|
b.getNodeEndPos(n).endLine,
|
||||||
|
b.getListStartPos(list).startPos,
|
||||||
|
b.getNodeEndPos(n).endPos,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
// NewOptionalListTokensPosition returns new Position
|
// NewOptionalListTokensPosition returns new Position
|
||||||
func (b *PositionBuilder) NewOptionalListTokensPosition(list []node.Node, t *scanner.Token, endToken *scanner.Token) *position.Position {
|
func (b *PositionBuilder) NewOptionalListTokensPosition(list []node.Node, t *scanner.Token, endToken *scanner.Token) *position.Position {
|
||||||
if list == nil {
|
if list == nil {
|
||||||
|
@ -259,6 +259,41 @@ func TestNewNodeNodeListPosition(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestNewNodeListNodePosition(t *testing.T) {
|
||||||
|
n1 := node.NewIdentifier("test node")
|
||||||
|
n2 := node.NewIdentifier("test node")
|
||||||
|
n3 := node.NewIdentifier("test node")
|
||||||
|
|
||||||
|
builder := parser.PositionBuilder{
|
||||||
|
Positions: &parser.Positions{
|
||||||
|
n1: &position.Position{
|
||||||
|
StartLine: 1,
|
||||||
|
EndLine: 1,
|
||||||
|
StartPos: 0,
|
||||||
|
EndPos: 8,
|
||||||
|
},
|
||||||
|
n2: &position.Position{
|
||||||
|
StartLine: 2,
|
||||||
|
EndLine: 2,
|
||||||
|
StartPos: 9,
|
||||||
|
EndPos: 17,
|
||||||
|
},
|
||||||
|
n3: &position.Position{
|
||||||
|
StartLine: 3,
|
||||||
|
EndLine: 3,
|
||||||
|
StartPos: 18,
|
||||||
|
EndPos: 26,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
pos := builder.NewNodeListNodePosition([]node.Node{n1, n2}, n3)
|
||||||
|
|
||||||
|
if pos.String() != `Pos{Line: 1-3 Pos: 0-26}` {
|
||||||
|
t.Errorf("token value is not equal\n")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestNewOptionalListTokensPosition(t *testing.T) {
|
func TestNewOptionalListTokensPosition(t *testing.T) {
|
||||||
builder := parser.PositionBuilder{}
|
builder := parser.PositionBuilder{}
|
||||||
|
|
||||||
|
1286
php5/php5.go
1286
php5/php5.go
File diff suppressed because it is too large
Load Diff
32
php5/php5.y
32
php5/php5.y
@ -24,7 +24,6 @@ import (
|
|||||||
boolWithToken boolWithToken
|
boolWithToken boolWithToken
|
||||||
list []node.Node
|
list []node.Node
|
||||||
foreachVariable foreachVariable
|
foreachVariable foreachVariable
|
||||||
nodesWithEndToken *nodesWithEndToken
|
|
||||||
simpleIndirectReference simpleIndirectReference
|
simpleIndirectReference simpleIndirectReference
|
||||||
altSyntaxNode altSyntaxNode
|
altSyntaxNode altSyntaxNode
|
||||||
}
|
}
|
||||||
@ -245,6 +244,7 @@ import (
|
|||||||
%type <node> ctor_arguments function_call_parameter_list
|
%type <node> ctor_arguments function_call_parameter_list
|
||||||
%type <node> trait_adaptations
|
%type <node> trait_adaptations
|
||||||
%type <node> switch_case_list
|
%type <node> switch_case_list
|
||||||
|
%type <node> method_body
|
||||||
|
|
||||||
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
|
%type <list> top_statement_list namespace_name use_declarations use_function_declarations use_const_declarations
|
||||||
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
|
%type <list> inner_statement_list global_var_list static_var_list encaps_list isset_variables non_empty_array_pair_list
|
||||||
@ -261,7 +261,6 @@ import (
|
|||||||
|
|
||||||
%type <simpleIndirectReference> simple_indirect_reference
|
%type <simpleIndirectReference> simple_indirect_reference
|
||||||
%type <foreachVariable> foreach_variable foreach_optional_arg
|
%type <foreachVariable> foreach_variable foreach_optional_arg
|
||||||
%type <nodesWithEndToken> method_body
|
|
||||||
%type <boolWithToken> is_reference is_variadic
|
%type <boolWithToken> is_reference is_variadic
|
||||||
%type <altSyntaxNode> while_statement for_statement foreach_statement
|
%type <altSyntaxNode> while_statement for_statement foreach_statement
|
||||||
|
|
||||||
@ -1574,8 +1573,14 @@ class_statement:
|
|||||||
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
|
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
|
||||||
yylex.(*Parser).comments.AddComments(name, $4.Comments())
|
yylex.(*Parser).comments.AddComments(name, $4.Comments())
|
||||||
|
|
||||||
$$ = stmt.NewClassMethod(name, $1, $3.value, $6, nil, $8.nodes, "")
|
$$ = stmt.NewClassMethod(name, $1, $3.value, $6, nil, $8, "")
|
||||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewOptionalListTokensPosition($1, $2, $8.endToken))
|
|
||||||
|
if $1 == nil {
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($2, $8))
|
||||||
|
} else {
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodeListNodePosition($1, $8))
|
||||||
|
}
|
||||||
|
|
||||||
yylex.(*Parser).comments.AddComments($$, yylex.(*Parser).listGetFirstNodeComments($1))
|
yylex.(*Parser).comments.AddComments($$, yylex.(*Parser).listGetFirstNodeComments($1))
|
||||||
}
|
}
|
||||||
;
|
;
|
||||||
@ -1711,10 +1716,18 @@ trait_modifiers:
|
|||||||
;
|
;
|
||||||
|
|
||||||
method_body:
|
method_body:
|
||||||
';' /* abstract method */
|
';' /* abstract method */
|
||||||
{ $$ = &nodesWithEndToken{nil, $1} }
|
{
|
||||||
|
$$ = stmt.NewNop()
|
||||||
|
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||||
|
}
|
||||||
| '{' inner_statement_list '}'
|
| '{' inner_statement_list '}'
|
||||||
{ $$ = &nodesWithEndToken{$2, $3} }
|
{
|
||||||
|
$$ = stmt.NewStmtList($2)
|
||||||
|
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
variable_modifiers:
|
variable_modifiers:
|
||||||
@ -3926,11 +3939,6 @@ type foreachVariable struct {
|
|||||||
byRef bool
|
byRef bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodesWithEndToken struct {
|
|
||||||
nodes []node.Node
|
|
||||||
endToken *scanner.Token
|
|
||||||
}
|
|
||||||
|
|
||||||
type boolWithToken struct {
|
type boolWithToken struct {
|
||||||
value bool
|
value bool
|
||||||
token *scanner.Token
|
token *scanner.Token
|
||||||
|
@ -514,7 +514,9 @@ func TestPhp5(t *testing.T) {
|
|||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
Params: expectedParams,
|
Params: expectedParams,
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -776,7 +778,9 @@ func TestPhp5(t *testing.T) {
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
PhpDocComment: "",
|
PhpDocComment: "",
|
||||||
MethodName: &node.Identifier{Value: "bar"},
|
MethodName: &node.Identifier{Value: "bar"},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -791,7 +795,9 @@ func TestPhp5(t *testing.T) {
|
|||||||
&node.Identifier{Value: "public"},
|
&node.Identifier{Value: "public"},
|
||||||
&node.Identifier{Value: "static"},
|
&node.Identifier{Value: "static"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -806,7 +812,9 @@ func TestPhp5(t *testing.T) {
|
|||||||
&node.Identifier{Value: "final"},
|
&node.Identifier{Value: "final"},
|
||||||
&node.Identifier{Value: "private"},
|
&node.Identifier{Value: "private"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
PhpDocComment: "",
|
PhpDocComment: "",
|
||||||
@ -815,7 +823,9 @@ func TestPhp5(t *testing.T) {
|
|||||||
Modifiers: []node.Node{
|
Modifiers: []node.Node{
|
||||||
&node.Identifier{Value: "protected"},
|
&node.Identifier{Value: "protected"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -833,6 +843,7 @@ func TestPhp5(t *testing.T) {
|
|||||||
&node.Identifier{Value: "abstract"},
|
&node.Identifier{Value: "abstract"},
|
||||||
&node.Identifier{Value: "public"},
|
&node.Identifier{Value: "public"},
|
||||||
},
|
},
|
||||||
|
Stmt: &stmt.Nop{},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
1053
php7/php7.go
1053
php7/php7.go
File diff suppressed because it is too large
Load Diff
39
php7/php7.y
39
php7/php7.y
@ -25,7 +25,6 @@ import (
|
|||||||
boolWithToken boolWithToken
|
boolWithToken boolWithToken
|
||||||
list []node.Node
|
list []node.Node
|
||||||
foreachVariable foreachVariable
|
foreachVariable foreachVariable
|
||||||
nodesWithEndToken *nodesWithEndToken
|
|
||||||
str string
|
str string
|
||||||
altSyntaxNode altSyntaxNode
|
altSyntaxNode altSyntaxNode
|
||||||
}
|
}
|
||||||
@ -266,12 +265,12 @@ import (
|
|||||||
%type <node> argument_list ctor_arguments
|
%type <node> argument_list ctor_arguments
|
||||||
%type <node> trait_adaptations
|
%type <node> trait_adaptations
|
||||||
%type <node> switch_case_list
|
%type <node> switch_case_list
|
||||||
|
%type <node> method_body
|
||||||
|
|
||||||
%type <node> member_modifier
|
%type <node> member_modifier
|
||||||
%type <node> use_type
|
%type <node> use_type
|
||||||
%type <foreachVariable> foreach_variable
|
%type <foreachVariable> foreach_variable
|
||||||
|
|
||||||
%type <nodesWithEndToken> method_body
|
|
||||||
|
|
||||||
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
|
%type <list> encaps_list backticks_expr namespace_name catch_name_list catch_list class_const_list
|
||||||
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list
|
%type <list> const_list echo_expr_list for_exprs non_empty_for_exprs global_var_list
|
||||||
@ -1945,11 +1944,15 @@ class_statement:
|
|||||||
| method_modifiers T_FUNCTION returns_ref identifier backup_doc_comment '(' parameter_list ')' return_type method_body
|
| method_modifiers T_FUNCTION returns_ref identifier backup_doc_comment '(' parameter_list ')' return_type method_body
|
||||||
{
|
{
|
||||||
name := node.NewIdentifier($4.Value)
|
name := node.NewIdentifier($4.Value)
|
||||||
$$ = stmt.NewClassMethod(name, $1, $3.value, $7, $9, $10.nodes, $5)
|
$$ = stmt.NewClassMethod(name, $1, $3.value, $7, $9, $10, $5)
|
||||||
|
|
||||||
// save position
|
// save position
|
||||||
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
|
yylex.(*Parser).positions.AddPosition(name, yylex.(*Parser).positionBuilder.NewTokenPosition($4))
|
||||||
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewOptionalListTokensPosition($1, $2, $10.endToken))
|
if $1 == nil {
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenNodePosition($2, $10))
|
||||||
|
} else {
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewNodeListNodePosition($1, $10))
|
||||||
|
}
|
||||||
|
|
||||||
// save comments
|
// save comments
|
||||||
yylex.(*Parser).comments.AddFromToken($$, $2, comment.FunctionToken)
|
yylex.(*Parser).comments.AddFromToken($$, $2, comment.FunctionToken)
|
||||||
@ -2130,8 +2133,27 @@ absolute_trait_method_reference:
|
|||||||
;
|
;
|
||||||
|
|
||||||
method_body:
|
method_body:
|
||||||
';' /* abstract method */ { $$ = &nodesWithEndToken{nil, $1} }
|
';' /* abstract method */
|
||||||
| '{' inner_statement_list '}' { $$ = &nodesWithEndToken{$2, $3} }
|
{
|
||||||
|
$$ = stmt.NewNop()
|
||||||
|
|
||||||
|
// save position
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokenPosition($1))
|
||||||
|
|
||||||
|
// save comments
|
||||||
|
yylex.(*Parser).comments.AddFromToken($$, $1, comment.SemiColonToken)
|
||||||
|
}
|
||||||
|
| '{' inner_statement_list '}'
|
||||||
|
{
|
||||||
|
$$ = stmt.NewStmtList($2)
|
||||||
|
|
||||||
|
// save position
|
||||||
|
yylex.(*Parser).positions.AddPosition($$, yylex.(*Parser).positionBuilder.NewTokensPosition($1, $3))
|
||||||
|
|
||||||
|
// save comments
|
||||||
|
yylex.(*Parser).comments.AddFromToken($$, $1, comment.OpenCurlyBracesToken)
|
||||||
|
yylex.(*Parser).comments.AddFromToken($$, $3, comment.CloseCurlyBracesToken)
|
||||||
|
}
|
||||||
;
|
;
|
||||||
|
|
||||||
variable_modifiers:
|
variable_modifiers:
|
||||||
@ -4223,11 +4245,6 @@ type foreachVariable struct {
|
|||||||
byRef bool
|
byRef bool
|
||||||
}
|
}
|
||||||
|
|
||||||
type nodesWithEndToken struct {
|
|
||||||
nodes []node.Node
|
|
||||||
endToken *scanner.Token
|
|
||||||
}
|
|
||||||
|
|
||||||
type boolWithToken struct {
|
type boolWithToken struct {
|
||||||
value bool
|
value bool
|
||||||
token *scanner.Token
|
token *scanner.Token
|
||||||
|
@ -549,7 +549,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
Params: expectedParams,
|
Params: expectedParams,
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -866,7 +868,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
PhpDocComment: "",
|
PhpDocComment: "",
|
||||||
MethodName: &node.Identifier{Value: "bar"},
|
MethodName: &node.Identifier{Value: "bar"},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -881,7 +885,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
&node.Identifier{Value: "public"},
|
&node.Identifier{Value: "public"},
|
||||||
&node.Identifier{Value: "static"},
|
&node.Identifier{Value: "static"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -901,7 +907,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
&name.NamePart{Value: "void"},
|
&name.NamePart{Value: "void"},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2966,7 +2974,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
MethodName: &node.Identifier{Value: "class"},
|
MethodName: &node.Identifier{Value: "class"},
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3072,6 +3082,7 @@ func TestPhp7(t *testing.T) {
|
|||||||
&node.Identifier{Value: "protected"},
|
&node.Identifier{Value: "protected"},
|
||||||
&node.Identifier{Value: "static"},
|
&node.Identifier{Value: "static"},
|
||||||
},
|
},
|
||||||
|
Stmt: &stmt.Nop{},
|
||||||
},
|
},
|
||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
MethodName: &node.Identifier{Value: "baz"},
|
MethodName: &node.Identifier{Value: "baz"},
|
||||||
@ -3079,7 +3090,9 @@ func TestPhp7(t *testing.T) {
|
|||||||
&node.Identifier{Value: "final"},
|
&node.Identifier{Value: "final"},
|
||||||
&node.Identifier{Value: "private"},
|
&node.Identifier{Value: "private"},
|
||||||
},
|
},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -1517,13 +1517,18 @@ func (p *Printer) printStmtClassMethod(n node.Node) {
|
|||||||
p.Print(nn.ReturnType)
|
p.Print(nn.ReturnType)
|
||||||
}
|
}
|
||||||
|
|
||||||
io.WriteString(p.w, "\n")
|
switch s := nn.Stmt.(type) {
|
||||||
p.printIndent()
|
case *stmt.StmtList:
|
||||||
io.WriteString(p.w, "{\n")
|
io.WriteString(p.w, "\n")
|
||||||
p.printNodes(nn.Stmts)
|
p.printIndent()
|
||||||
io.WriteString(p.w, "\n")
|
io.WriteString(p.w, "{\n")
|
||||||
p.printIndent()
|
p.printNodes(s.Stmts)
|
||||||
io.WriteString(p.w, "}")
|
io.WriteString(p.w, "\n")
|
||||||
|
p.printIndent()
|
||||||
|
io.WriteString(p.w, "}")
|
||||||
|
default:
|
||||||
|
p.Print(s)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (p *Printer) printStmtClass(n node.Node) {
|
func (p *Printer) printStmtClass(n node.Node) {
|
||||||
|
@ -44,10 +44,12 @@ func TestPrintFile(t *testing.T) {
|
|||||||
&stmt.ClassMethod{
|
&stmt.ClassMethod{
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
MethodName: &node.Identifier{Value: "greet"},
|
MethodName: &node.Identifier{Value: "greet"},
|
||||||
Stmts: []node.Node{
|
Stmt: &stmt.StmtList{
|
||||||
&stmt.Echo{
|
Stmts: []node.Node{
|
||||||
Exprs: []node.Node{
|
&stmt.Echo{
|
||||||
&scalar.String{Value: "'Hello world'"},
|
Exprs: []node.Node{
|
||||||
|
&scalar.String{Value: "'Hello world'"},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -2453,8 +2455,10 @@ func TestPrintStmtClassMethod(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}},
|
ReturnType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "void"}}},
|
||||||
Stmts: []node.Node{
|
Stmt: &stmt.StmtList{
|
||||||
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
Stmts: []node.Node{
|
||||||
|
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -3387,8 +3391,10 @@ func TestPrintInterface(t *testing.T) {
|
|||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Params: []node.Node{},
|
Params: []node.Node{},
|
||||||
Stmts: []node.Node{
|
Stmt: &stmt.StmtList{
|
||||||
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
Stmts: []node.Node{
|
||||||
|
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -3833,8 +3839,10 @@ func TestPrintTrait(t *testing.T) {
|
|||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
MethodName: &node.Identifier{Value: "foo"},
|
MethodName: &node.Identifier{Value: "foo"},
|
||||||
Params: []node.Node{},
|
Params: []node.Node{},
|
||||||
Stmts: []node.Node{
|
Stmt: &stmt.StmtList{
|
||||||
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
Stmts: []node.Node{
|
||||||
|
&stmt.Expression{Expr: &expr.Variable{VarName: &node.Identifier{Value: "a"}}},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -63,8 +63,8 @@ func ExampleDumper() {
|
|||||||
//| "Stmts":
|
//| "Stmts":
|
||||||
//| [*stmt.ClassMethod]
|
//| [*stmt.ClassMethod]
|
||||||
//| "Position": Pos{Line: 5-9 Pos: 45-134};
|
//| "Position": Pos{Line: 5-9 Pos: 45-134};
|
||||||
//| "PhpDocComment": ;
|
|
||||||
//| "ReturnsRef": false;
|
//| "ReturnsRef": false;
|
||||||
|
//| "PhpDocComment": ;
|
||||||
//| "MethodName":
|
//| "MethodName":
|
||||||
//| [*node.Identifier]
|
//| [*node.Identifier]
|
||||||
//| "Position": Pos{Line: 5-5 Pos: 61-72};
|
//| "Position": Pos{Line: 5-5 Pos: 61-72};
|
||||||
@ -104,16 +104,19 @@ func ExampleDumper() {
|
|||||||
//| [*name.NamePart]
|
//| [*name.NamePart]
|
||||||
//| "Position": Pos{Line: 5-5 Pos: 86-89};
|
//| "Position": Pos{Line: 5-5 Pos: 86-89};
|
||||||
//| "Value": null;
|
//| "Value": null;
|
||||||
//| "Stmts":
|
//| "Stmt":
|
||||||
//| [*stmt.Expression]
|
//| [*stmt.StmtList]
|
||||||
//| "Position": Pos{Line: 8-8 Pos: 124-128};
|
//| "Position": Pos{Line: 6-9 Pos: 96-134};
|
||||||
//| "Expr":
|
//| "Stmts":
|
||||||
//| [*expr.Variable]
|
//| [*stmt.Expression]
|
||||||
//| "Position": Pos{Line: 8-8 Pos: 124-127};
|
//| "Position": Pos{Line: 8-8 Pos: 124-128};
|
||||||
//| "Comments":
|
//| "Expr":
|
||||||
//| "// some comment\n" before "VariableToken"
|
//| [*expr.Variable]
|
||||||
//| "VarName":
|
|
||||||
//| [*node.Identifier]
|
|
||||||
//| "Position": Pos{Line: 8-8 Pos: 124-127};
|
//| "Position": Pos{Line: 8-8 Pos: 124-127};
|
||||||
//| "Value": var;
|
//| "Comments":
|
||||||
|
//| "// some comment\n" before "VariableToken"
|
||||||
|
//| "VarName":
|
||||||
|
//| [*node.Identifier]
|
||||||
|
//| "Position": Pos{Line: 8-8 Pos: 124-127};
|
||||||
|
//| "Value": var;
|
||||||
}
|
}
|
||||||
|
@ -544,7 +544,9 @@ func TestResolveMethodName(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
ReturnType: &node.Nullable{Expr: nameBC},
|
ReturnType: &node.Nullable{Expr: nameBC},
|
||||||
Stmts: []node.Node{},
|
Stmt: &stmt.StmtList{
|
||||||
|
Stmts: []node.Node{},
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
expected := map[node.Node]string{
|
expected := map[node.Node]string{
|
||||||
|
Loading…
Reference in New Issue
Block a user