static_var node

This commit is contained in:
vadim 2017-12-09 11:49:26 +02:00
parent 8cb363d5aa
commit 120db3332b
3 changed files with 36 additions and 4 deletions

32
node/stmt/static_var.go Normal file
View 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+" ")
}
}

View File

@ -3452,13 +3452,13 @@ yydefault:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]
//line parser/parser.y:661 //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: case 237:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:662 //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: case 238:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]

View File

@ -658,8 +658,8 @@ static_var_list:
; ;
static_var: static_var:
T_VARIABLE { $$ = node.NewSimpleNode("StaticVariable").Attribute("Name", $1.String()); } T_VARIABLE { $$ = stmt.NewStaticVar($1, nil) }
| T_VARIABLE '=' expr { $$ = node.NewSimpleNode("StaticVariable").Attribute("Name", $1.String()).Append(node.NewSimpleNode("expr").Append($3)); } | T_VARIABLE '=' expr { $$ = stmt.NewStaticVar($1, $3) }
; ;
class_statement_list: class_statement_list: