closure_use node
This commit is contained in:
parent
84aefef316
commit
2703c00374
32
node/expr/closure_use.go
Normal file
32
node/expr/closure_use.go
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
package expr
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io"
|
||||||
|
|
||||||
|
"github.com/z7zmey/php-parser/node"
|
||||||
|
)
|
||||||
|
|
||||||
|
type ClusureUse struct {
|
||||||
|
node.SimpleNode
|
||||||
|
variable node.Node
|
||||||
|
byRef bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewClusureUse(variable node.Node, byRef bool) node.Node {
|
||||||
|
return ClusureUse{
|
||||||
|
node.SimpleNode{Name: "ClusureUse", Attributes: make(map[string]string)},
|
||||||
|
variable,
|
||||||
|
byRef,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (n ClusureUse) Print(out io.Writer, indent string) {
|
||||||
|
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
|
||||||
|
fmt.Fprintf(out, "\n%vby ref: %t", indent+" ", n.byRef)
|
||||||
|
|
||||||
|
if n.variable != nil {
|
||||||
|
fmt.Fprintf(out, "\n%vvariable:", indent+" ")
|
||||||
|
n.variable.Print(out, indent+" ")
|
||||||
|
}
|
||||||
|
}
|
@ -4290,13 +4290,13 @@ yydefault:
|
|||||||
yyDollar = yyS[yypt-1 : yypt+1]
|
yyDollar = yyS[yypt-1 : yypt+1]
|
||||||
//line parser/parser.y:914
|
//line parser/parser.y:914
|
||||||
{
|
{
|
||||||
yyVAL.node = node.NewSimpleNode("Variable").Attribute("value", yyDollar[1].token.String())
|
yyVAL.node = expr.NewClusureUse(expr.NewVariable(yyDollar[1].token), false)
|
||||||
}
|
}
|
||||||
case 376:
|
case 376:
|
||||||
yyDollar = yyS[yypt-2 : yypt+1]
|
yyDollar = yyS[yypt-2 : yypt+1]
|
||||||
//line parser/parser.y:915
|
//line parser/parser.y:915
|
||||||
{
|
{
|
||||||
yyVAL.node = node.NewSimpleNode("Variable").Attribute("value", yyDollar[2].token.String()).Attribute("ref", "true")
|
yyVAL.node = expr.NewClusureUse(expr.NewVariable(yyDollar[2].token), true)
|
||||||
}
|
}
|
||||||
case 377:
|
case 377:
|
||||||
yyDollar = yyS[yypt-2 : yypt+1]
|
yyDollar = yyS[yypt-2 : yypt+1]
|
||||||
|
@ -911,8 +911,8 @@ lexical_var_list:
|
|||||||
;
|
;
|
||||||
|
|
||||||
lexical_var:
|
lexical_var:
|
||||||
T_VARIABLE { $$ = node.NewSimpleNode("Variable").Attribute("value", $1.String()) }
|
T_VARIABLE { $$ = expr.NewClusureUse(expr.NewVariable($1), false) }
|
||||||
| '&' T_VARIABLE { $$ = node.NewSimpleNode("Variable").Attribute("value", $2.String()).Attribute("ref", "true") }
|
| '&' T_VARIABLE { $$ = expr.NewClusureUse(expr.NewVariable($2), true) }
|
||||||
;
|
;
|
||||||
|
|
||||||
function_call:
|
function_call:
|
||||||
|
Loading…
Reference in New Issue
Block a user