fix parsing php5 parameters

This commit is contained in:
z7zmey 2018-02-12 12:09:56 +02:00
parent f0411890e6
commit bf90803ef3
4 changed files with 190 additions and 166 deletions

View File

@ -343,6 +343,6 @@ func TestPhp5ParameterNode(t *testing.T) {
}, },
} }
actual, _, _ := php7.Parse(bytes.NewBufferString(src), "test.php") actual, _, _ := php5.Parse(bytes.NewBufferString(src), "test.php")
assertEqual(t, expected, actual) assertEqual(t, expected, actual)
} }

File diff suppressed because it is too large Load Diff

View File

@ -2751,21 +2751,33 @@ static_scalar_value:
{ $$ = $1 } { $$ = $1 }
| namespace_name | namespace_name
{ {
$$ = name.NewName($1) name := name.NewName($1)
positions.AddPosition($$, positionBuilder.NewNodeListPosition($1)) positions.AddPosition(name, positionBuilder.NewNodeListPosition($1))
comments.AddComments($$, ListGetFirstNodeComments($1)) comments.AddComments(name, ListGetFirstNodeComments($1))
$$ = expr.NewConstFetch(name)
positions.AddPosition($$, positionBuilder.NewNodePosition(name))
comments.AddComments($$, comments[name])
} }
| T_NAMESPACE T_NS_SEPARATOR namespace_name | T_NAMESPACE T_NS_SEPARATOR namespace_name
{ {
$$ = name.NewRelative($3) name := name.NewRelative($3)
positions.AddPosition(name, positionBuilder.NewTokenNodeListPosition($1, $3))
comments.AddComments(name, $1.Comments())
$$ = expr.NewConstFetch(name)
positions.AddPosition($$, positionBuilder.NewTokenNodeListPosition($1, $3)) positions.AddPosition($$, positionBuilder.NewTokenNodeListPosition($1, $3))
comments.AddComments($$, $1.Comments()) comments.AddComments($$, comments[name])
} }
| T_NS_SEPARATOR namespace_name | T_NS_SEPARATOR namespace_name
{ {
$$ = name.NewFullyQualified($2) name := name.NewFullyQualified($2)
positions.AddPosition(name, positionBuilder.NewTokenNodeListPosition($1, $2))
comments.AddComments(name, $1.Comments())
$$ = expr.NewConstFetch(name)
positions.AddPosition($$, positionBuilder.NewTokenNodeListPosition($1, $2)) positions.AddPosition($$, positionBuilder.NewTokenNodeListPosition($1, $2))
comments.AddComments($$, $1.Comments()) comments.AddComments($$, comments[name])
} }
| T_ARRAY '(' static_array_pair_list ')' | T_ARRAY '(' static_array_pair_list ')'
{ {

View File

@ -31,7 +31,7 @@ func assertEqual(t *testing.T, expected interface{}, actual interface{}) {
} }
} }
func TestPhp7(t *testing.T) { func TestPhp5(t *testing.T) {
src := `<? src := `<?
foo($a, ...$b); foo($a, ...$b);
$foo($a, ...$b); $foo($a, ...$b);
@ -317,7 +317,7 @@ CAD;
Variadic: false, Variadic: false,
VariableType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "bar"}}}, VariableType: &name.Name{Parts: []node.Node{&name.NamePart{Value: "bar"}}},
Variable: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}}, Variable: &expr.Variable{VarName: &node.Identifier{Value: "$bar"}},
DefaultValue: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}, DefaultValue: &expr.ConstFetch{Constant: &name.Name{Parts: []node.Node{&name.NamePart{Value: "null"}}}},
}, },
&node.Parameter{ &node.Parameter{
ByRef: true, ByRef: true,