clone node

This commit is contained in:
z7zmey 2017-12-16 22:17:31 +02:00
parent cf084b5893
commit df662aaa01
3 changed files with 31 additions and 2 deletions

29
node/expr/clone.go Normal file
View File

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

View File

@ -3822,7 +3822,7 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:819
{
yyVAL.node = node.NewSimpleNode("Clone").Append(yyDollar[2].node)
yyVAL.node = expr.NewClone(yyDollar[2].node)
}
case 298:
yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -816,7 +816,7 @@ expr_without_variable:
| '[' array_pair_list ']' '=' expr { $$ = node.NewSimpleNode("Assign").Append($2).Append($5); }
| variable '=' expr { $$ = assign_op.NewAssign($1, $3, false) }
| variable '=' '&' expr { $$ = assign_op.NewAssign($1, $4, true) }
| T_CLONE expr { $$ = node.NewSimpleNode("Clone").Append($2); }
| T_CLONE expr { $$ = expr.NewClone($2) }
| variable T_PLUS_EQUAL expr { $$ = assign_op.NewPlus($1, $3) }
| variable T_MINUS_EQUAL expr { $$ = assign_op.NewMinus($1, $3) }
| variable T_MUL_EQUAL expr { $$ = assign_op.NewMul($1, $3) }