static_var node
This commit is contained in:
parent
8cb363d5aa
commit
120db3332b
32
node/stmt/static_var.go
Normal file
32
node/stmt/static_var.go
Normal file
@ -0,0 +1,32 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type StaticVar struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
expr node.Node
|
||||
}
|
||||
|
||||
func NewStaticVar(token token.Token, expr node.Node) node.Node {
|
||||
return StaticVar{
|
||||
node.SimpleNode{Name: "StaticVar", Attributes: make(map[string]string)},
|
||||
token,
|
||||
expr,
|
||||
}
|
||||
}
|
||||
|
||||
func (n StaticVar) Print(out io.Writer, indent string) {
|
||||
fmt.Fprintf(out, "\n%v%v [%d %d] %q", indent, n.Name, n.token.StartLine, n.token.EndLine, n.token.Value)
|
||||
|
||||
if n.expr != nil {
|
||||
fmt.Fprintf(out, "\n%vexpr:", indent+" ")
|
||||
n.expr.Print(out, indent+" ")
|
||||
}
|
||||
}
|
@ -3452,13 +3452,13 @@ yydefault:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
//line parser/parser.y:661
|
||||
{
|
||||
yyVAL.node = node.NewSimpleNode("StaticVariable").Attribute("Name", yyDollar[1].token.String())
|
||||
yyVAL.node = stmt.NewStaticVar(yyDollar[1].token, nil)
|
||||
}
|
||||
case 237:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
//line parser/parser.y:662
|
||||
{
|
||||
yyVAL.node = node.NewSimpleNode("StaticVariable").Attribute("Name", yyDollar[1].token.String()).Append(node.NewSimpleNode("expr").Append(yyDollar[3].node))
|
||||
yyVAL.node = stmt.NewStaticVar(yyDollar[1].token, yyDollar[3].node)
|
||||
}
|
||||
case 238:
|
||||
yyDollar = yyS[yypt-2 : yypt+1]
|
||||
|
@ -658,8 +658,8 @@ static_var_list:
|
||||
;
|
||||
|
||||
static_var:
|
||||
T_VARIABLE { $$ = node.NewSimpleNode("StaticVariable").Attribute("Name", $1.String()); }
|
||||
| T_VARIABLE '=' expr { $$ = node.NewSimpleNode("StaticVariable").Attribute("Name", $1.String()).Append(node.NewSimpleNode("expr").Append($3)); }
|
||||
T_VARIABLE { $$ = stmt.NewStaticVar($1, nil) }
|
||||
| T_VARIABLE '=' expr { $$ = stmt.NewStaticVar($1, $3) }
|
||||
;
|
||||
|
||||
class_statement_list:
|
||||
|
Loading…
Reference in New Issue
Block a user