assign_ref node
This commit is contained in:
parent
3ec45dc334
commit
2c6664bdc9
@ -1,30 +1,19 @@
|
|||||||
package assign_op
|
package assign_op
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
"io"
|
|
||||||
|
|
||||||
"github.com/z7zmey/php-parser/node"
|
"github.com/z7zmey/php-parser/node"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Assign struct {
|
type Assign struct {
|
||||||
AssignOp
|
AssignOp
|
||||||
byRef bool
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAssign(variable node.Node, expression node.Node, byRef bool) node.Node {
|
func NewAssign(variable node.Node, expression node.Node) node.Node {
|
||||||
return Assign{
|
return Assign{
|
||||||
AssignOp{
|
AssignOp{
|
||||||
node.SimpleNode{Name: "AssignAssign", Attributes: make(map[string]string)},
|
node.SimpleNode{Name: "Assign", Attributes: make(map[string]string)},
|
||||||
variable,
|
variable,
|
||||||
expression,
|
expression,
|
||||||
},
|
},
|
||||||
byRef,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (n Assign) Print(out io.Writer, indent string) {
|
|
||||||
n.AssignOp.Print(out, indent)
|
|
||||||
|
|
||||||
fmt.Fprintf(out, "\n%vbyRef: %t", indent+" ", n.byRef)
|
|
||||||
}
|
|
||||||
|
@ -13,14 +13,6 @@ type AssignOp struct {
|
|||||||
expression node.Node
|
expression node.Node
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewAssignOp(variable node.Node, expression node.Node) node.Node {
|
|
||||||
return AssignOp{
|
|
||||||
node.SimpleNode{Name: "AssignOp", Attributes: make(map[string]string)},
|
|
||||||
variable,
|
|
||||||
expression,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (n AssignOp) Print(out io.Writer, indent string) {
|
func (n AssignOp) Print(out io.Writer, indent string) {
|
||||||
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
|
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
|
||||||
|
|
||||||
@ -28,7 +20,7 @@ func (n AssignOp) Print(out io.Writer, indent string) {
|
|||||||
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
|
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
|
||||||
n.variable.Print(out, indent+" ")
|
n.variable.Print(out, indent+" ")
|
||||||
}
|
}
|
||||||
|
|
||||||
if n.expression != nil {
|
if n.expression != nil {
|
||||||
fmt.Fprintf(out, "\n%vexpression:", indent+" ")
|
fmt.Fprintf(out, "\n%vexpression:", indent+" ")
|
||||||
n.expression.Print(out, indent+" ")
|
n.expression.Print(out, indent+" ")
|
||||||
|
19
node/expr/assign_op/assign_ref.go
Normal file
19
node/expr/assign_op/assign_ref.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package assign_op
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AssignRef struct {
|
||||||
|
AssignOp
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewAssignRef(variable node.Node, expression node.Node) node.Node {
|
||||||
|
return AssignRef{
|
||||||
|
AssignOp{
|
||||||
|
node.SimpleNode{Name: "AssignRef", Attributes: make(map[string]string)},
|
||||||
|
variable,
|
||||||
|
expression,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
@ -3800,26 +3800,26 @@ yydefault:
|
|||||||
//line parser/parser.y:817
|
//line parser/parser.y:817
|
||||||
{
|
{
|
||||||
list := expr.NewList(yyDollar[3].list)
|
list := expr.NewList(yyDollar[3].list)
|
||||||
yyVAL.node = assign_op.NewAssign(list, yyDollar[6].node, false)
|
yyVAL.node = assign_op.NewAssign(list, yyDollar[6].node)
|
||||||
}
|
}
|
||||||
case 294:
|
case 294:
|
||||||
yyDollar = yyS[yypt-5 : yypt+1]
|
yyDollar = yyS[yypt-5 : yypt+1]
|
||||||
//line parser/parser.y:822
|
//line parser/parser.y:822
|
||||||
{
|
{
|
||||||
shortList := expr.NewShortList(yyDollar[2].list)
|
shortList := expr.NewShortList(yyDollar[2].list)
|
||||||
yyVAL.node = assign_op.NewAssign(shortList, yyDollar[5].node, false)
|
yyVAL.node = assign_op.NewAssign(shortList, yyDollar[5].node)
|
||||||
}
|
}
|
||||||
case 295:
|
case 295:
|
||||||
yyDollar = yyS[yypt-3 : yypt+1]
|
yyDollar = yyS[yypt-3 : yypt+1]
|
||||||
//line parser/parser.y:826
|
//line parser/parser.y:826
|
||||||
{
|
{
|
||||||
yyVAL.node = assign_op.NewAssign(yyDollar[1].node, yyDollar[3].node, false)
|
yyVAL.node = assign_op.NewAssign(yyDollar[1].node, yyDollar[3].node)
|
||||||
}
|
}
|
||||||
case 296:
|
case 296:
|
||||||
yyDollar = yyS[yypt-4 : yypt+1]
|
yyDollar = yyS[yypt-4 : yypt+1]
|
||||||
//line parser/parser.y:827
|
//line parser/parser.y:827
|
||||||
{
|
{
|
||||||
yyVAL.node = assign_op.NewAssign(yyDollar[1].node, yyDollar[4].node, true)
|
yyVAL.node = assign_op.NewAssignRef(yyDollar[1].node, yyDollar[4].node)
|
||||||
}
|
}
|
||||||
case 297:
|
case 297:
|
||||||
yyDollar = yyS[yypt-2 : yypt+1]
|
yyDollar = yyS[yypt-2 : yypt+1]
|
||||||
|
@ -816,15 +816,15 @@ expr_without_variable:
|
|||||||
T_LIST '(' array_pair_list ')' '=' expr
|
T_LIST '(' array_pair_list ')' '=' expr
|
||||||
{
|
{
|
||||||
list := expr.NewList($3)
|
list := expr.NewList($3)
|
||||||
$$ = assign_op.NewAssign(list, $6, false)
|
$$ = assign_op.NewAssign(list, $6)
|
||||||
}
|
}
|
||||||
| '[' array_pair_list ']' '=' expr
|
| '[' array_pair_list ']' '=' expr
|
||||||
{
|
{
|
||||||
shortList := expr.NewShortList($2)
|
shortList := expr.NewShortList($2)
|
||||||
$$ = assign_op.NewAssign(shortList, $5, false)
|
$$ = assign_op.NewAssign(shortList, $5)
|
||||||
}
|
}
|
||||||
| variable '=' expr { $$ = assign_op.NewAssign($1, $3, false) }
|
| variable '=' expr { $$ = assign_op.NewAssign($1, $3) }
|
||||||
| variable '=' '&' expr { $$ = assign_op.NewAssign($1, $4, true) }
|
| variable '=' '&' expr { $$ = assign_op.NewAssignRef($1, $4) }
|
||||||
| T_CLONE expr { $$ = expr.NewClone($2) }
|
| T_CLONE expr { $$ = expr.NewClone($2) }
|
||||||
| variable T_PLUS_EQUAL expr { $$ = assign_op.NewPlus($1, $3) }
|
| variable T_PLUS_EQUAL expr { $$ = assign_op.NewPlus($1, $3) }
|
||||||
| variable T_MINUS_EQUAL expr { $$ = assign_op.NewMinus($1, $3) }
|
| variable T_MINUS_EQUAL expr { $$ = assign_op.NewMinus($1, $3) }
|
||||||
|
Loading…
Reference in New Issue
Block a user