property_fetch static_property_fetch nodes

This commit is contained in:
z7zmey 2017-12-18 19:52:41 +02:00
parent a73b9a9478
commit 40a27c6131
5 changed files with 113 additions and 16 deletions

View File

@ -0,0 +1,36 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type PropertyFetch struct {
node.SimpleNode
variable node.Node
name node.Node
}
func NewPropertyFetch(variable node.Node, name node.Node) node.Node {
return PropertyFetch{
node.SimpleNode{Name: "PropertyFetch", Attributes: make(map[string]string)},
variable,
name,
}
}
func (n PropertyFetch) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.variable != nil {
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
n.variable.Print(out, indent+" ")
}
if n.name != nil {
fmt.Fprintf(out, "\n%vname:", indent+" ")
n.name.Print(out, indent+" ")
}
}

View File

@ -0,0 +1,36 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type StaticPropertyFetch struct {
node.SimpleNode
class node.Node
name node.Node
}
func NewStaticPropertyFetch(class node.Node, name node.Node) node.Node {
return StaticPropertyFetch{
node.SimpleNode{Name: "StaticPropertyFetch", Attributes: make(map[string]string)},
class,
name,
}
}
func (n StaticPropertyFetch) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.class != nil {
fmt.Fprintf(out, "\n%vclass:", indent+" ")
n.class.Print(out, indent+" ")
}
if n.name != nil {
fmt.Fprintf(out, "\n%vname:", indent+" ")
n.name.Print(out, indent+" ")
}
}

25
node/identifier.go Normal file
View File

@ -0,0 +1,25 @@
package node
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/token"
)
type Identifier struct {
SimpleNode
name token.Token
}
func NewIdentifier(name token.Token) Node {
return Identifier{
SimpleNode{Name: "Identifier", Attributes: make(map[string]string)},
name,
}
}
func (n Identifier) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.name.Value)
}

View File

@ -4641,7 +4641,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1036
{
yyVAL.node = node.NewSimpleNode("Property").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 434:
yyDollar = yyS[yypt-1 : yypt+1]
@ -4665,13 +4665,13 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1047
{
yyVAL.node = node.NewSimpleNode("StaticProp").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 438:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1049
{
yyVAL.node = node.NewSimpleNode("StaticProp").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 439:
yyDollar = yyS[yypt-1 : yypt+1]
@ -4695,19 +4695,19 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1056
{
yyVAL.node = node.NewSimpleNode("Property").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 443:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1058
{
yyVAL.node = node.NewSimpleNode("StaticProperty").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 444:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1060
{
yyVAL.node = node.NewSimpleNode("StaticProperty").Append(yyDollar[1].node).Append(yyDollar[3].node)
yyVAL.node = expr.NewStaticPropertyFetch(yyDollar[1].node, yyDollar[3].node)
}
case 445:
yyDollar = yyS[yypt-1 : yypt+1]
@ -4731,7 +4731,7 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1]
//line parser/parser.y:1070
{
yyVAL.node = node.NewSimpleNode("PropertyName").Attribute("value", yyDollar[1].token.String())
yyVAL.node = node.NewIdentifier(yyDollar[1].token)
}
case 449:
yyDollar = yyS[yypt-3 : yypt+1]
@ -4859,7 +4859,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:1126
{
yyVAL.node = node.NewSimpleNode("Variable").Attribute("value", yyDollar[1].token.String()).Append(node.NewSimpleNode("property").Attribute("value", yyDollar[3].token.String()))
yyVAL.node = expr.NewPropertyFetch(expr.NewVariable(yyDollar[1].token), node.NewIdentifier(yyDollar[3].token))
}
case 469:
yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -1033,7 +1033,7 @@ callable_variable:
variable:
callable_variable { $$ = $1; }
| static_member { $$ = $1; }
| dereferencable T_OBJECT_OPERATOR property_name { $$ = node.NewSimpleNode("Property").Append($1).Append($3) }
| dereferencable T_OBJECT_OPERATOR property_name { $$ = expr.NewPropertyFetch($1, $3) }
;
simple_variable:
@ -1044,20 +1044,20 @@ simple_variable:
static_member:
class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = node.NewSimpleNode("StaticProp").Append($1).Append($3) }
{ $$ = expr.NewStaticPropertyFetch($1, $3) }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = node.NewSimpleNode("StaticProp").Append($1).Append($3) }
{ $$ = expr.NewStaticPropertyFetch($1, $3) }
;
new_variable:
simple_variable { $$ = $1 }
| new_variable '[' optional_expr ']' { $$ = expr.NewArrayDimFetch($1, $3) }
| new_variable '{' expr '}' { $$ = expr.NewArrayDimFetch($1, $3) }
| new_variable T_OBJECT_OPERATOR property_name { $$ = node.NewSimpleNode("Property").Append($1).Append($3) }
| new_variable T_OBJECT_OPERATOR property_name { $$ = expr.NewPropertyFetch($1, $3) }
| class_name T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = node.NewSimpleNode("StaticProperty").Append($1).Append($3) }
{ $$ = expr.NewStaticPropertyFetch($1, $3) }
| new_variable T_PAAMAYIM_NEKUDOTAYIM simple_variable
{ $$ = node.NewSimpleNode("StaticProperty").Append($1).Append($3) }
{ $$ = expr.NewStaticPropertyFetch($1, $3) }
;
member_name:
@ -1067,7 +1067,7 @@ member_name:
;
property_name:
T_STRING { $$ = node.NewSimpleNode("PropertyName").Attribute("value", $1.String()) }
T_STRING { $$ = node.NewIdentifier($1) }
| '{' expr '}' { $$ = $2; }
| simple_variable { $$ = $1 }
;
@ -1123,7 +1123,7 @@ encaps_list:
encaps_var:
T_VARIABLE { $$ = node.NewSimpleNode("Variable").Attribute("value", $1.String()) }
| T_VARIABLE '[' encaps_var_offset ']' { $$ = expr.NewArrayDimFetch(expr.NewVariable($1), $3) }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = node.NewSimpleNode("Variable").Attribute("value", $1.String()).Append(node.NewSimpleNode("property").Attribute("value", $3.String())) }
| T_VARIABLE T_OBJECT_OPERATOR T_STRING { $$ = expr.NewPropertyFetch(expr.NewVariable($1), node.NewIdentifier($3)) }
| T_DOLLAR_OPEN_CURLY_BRACES expr '}' { $$ = node.NewSimpleNode("Variable").Append(node.NewSimpleNode("expr").Append($2)) }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '}' { $$ = node.NewSimpleNode("Variable").Attribute("value", $2.String()) }
| T_DOLLAR_OPEN_CURLY_BRACES T_STRING_VARNAME '[' expr ']' '}'