class const node
This commit is contained in:
parent
01f7e3fe63
commit
3a5590d7bc
43
node/stmt/class_const.go
Normal file
43
node/stmt/class_const.go
Normal file
@ -0,0 +1,43 @@
|
||||
package stmt
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"io"
|
||||
|
||||
"github.com/z7zmey/php-parser/node"
|
||||
"github.com/z7zmey/php-parser/token"
|
||||
)
|
||||
|
||||
type ClassConst struct {
|
||||
node.SimpleNode
|
||||
token token.Token
|
||||
modifiers []node.Node
|
||||
consts []node.Node
|
||||
}
|
||||
|
||||
func NewClassConst(token token.Token, modifiers []node.Node, consts []node.Node) node.Node {
|
||||
return ClassConst{
|
||||
node.SimpleNode{Name: "ClassConst", Attributes: make(map[string]string)},
|
||||
token,
|
||||
modifiers,
|
||||
consts,
|
||||
}
|
||||
}
|
||||
|
||||
func (n ClassConst) 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.modifiers != nil {
|
||||
fmt.Fprintf(out, "\n%vmotifiers:", indent+" ")
|
||||
for _, nn := range n.modifiers {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
|
||||
if n.consts != nil {
|
||||
fmt.Fprintf(out, "\n%vconsts:", indent+" ")
|
||||
for _, nn := range n.consts {
|
||||
nn.Print(out, indent+" ")
|
||||
}
|
||||
}
|
||||
}
|
@ -3492,7 +3492,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-4 : yypt+1]
|
||||
//line parser/parser.y:685
|
||||
{
|
||||
yyVAL.node = yyDollar[3].node.Append(yyDollar[1].node)
|
||||
yyVAL.node = stmt.NewClassConst(yyDollar[2].token, yyDollar[1].node.(node.SimpleNode).Children, yyDollar[3].node.(node.SimpleNode).Children)
|
||||
}
|
||||
case 242:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
@ -3642,7 +3642,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-0 : yypt+1]
|
||||
//line parser/parser.y:755
|
||||
{
|
||||
yyVAL.node = node.NewSimpleNode("PublicMemberModifier")
|
||||
yyVAL.node = node.NewSimpleNode("MemberModifiers").Append(node.NewSimpleNode("PublicMemberModifier"))
|
||||
}
|
||||
case 266:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
@ -3654,7 +3654,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-1 : yypt+1]
|
||||
//line parser/parser.y:760
|
||||
{
|
||||
yyVAL.node = yyDollar[1].node
|
||||
yyVAL.node = node.NewSimpleNode("MemberModifiers").Append(yyDollar[1].node)
|
||||
}
|
||||
case 268:
|
||||
yyDollar = yyS[yypt-2 : yypt+1]
|
||||
@ -3738,7 +3738,7 @@ yydefault:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
//line parser/parser.y:789
|
||||
{
|
||||
yyVAL.node = node.NewSimpleNode("Const").Append(yyDollar[3].node)
|
||||
yyVAL.node = node.NewSimpleNode("Const").Append(yyDollar[1].node).Append(yyDollar[3].node)
|
||||
}
|
||||
case 282:
|
||||
yyDollar = yyS[yypt-3 : yypt+1]
|
||||
|
@ -682,7 +682,7 @@ class_statement_list:
|
||||
|
||||
class_statement:
|
||||
variable_modifiers property_list ';' { $$ = $2.Append($1) }
|
||||
| method_modifiers T_CONST class_const_list ';' { $$ = $3.Append($1); }
|
||||
| method_modifiers T_CONST class_const_list ';' { $$ = stmt.NewClassConst($2, $1.(node.SimpleNode).Children, $3.(node.SimpleNode).Children); }
|
||||
| T_USE name_list trait_adaptations { $$ = node.NewSimpleNode("Use").Append($2).Append($3); }
|
||||
| method_modifiers T_FUNCTION returns_ref identifier '(' parameter_list ')'
|
||||
return_type method_body
|
||||
@ -752,12 +752,12 @@ variable_modifiers:
|
||||
;
|
||||
|
||||
method_modifiers:
|
||||
/* empty */ { $$ = node.NewSimpleNode("PublicMemberModifier"); }
|
||||
/* empty */ { $$ = node.NewSimpleNode("MemberModifiers").Append(node.NewSimpleNode("PublicMemberModifier")); }
|
||||
| non_empty_member_modifiers { $$ = $1; }
|
||||
;
|
||||
|
||||
non_empty_member_modifiers:
|
||||
member_modifier { $$ = $1; }
|
||||
member_modifier { $$ = node.NewSimpleNode("MemberModifiers").Append($1); }
|
||||
| non_empty_member_modifiers member_modifier { $$ = $1.Append($2) }
|
||||
;
|
||||
|
||||
@ -786,7 +786,7 @@ class_const_list:
|
||||
;
|
||||
|
||||
class_const_decl:
|
||||
identifier '=' expr { $$ = node.NewSimpleNode("Const").Append($3) }
|
||||
identifier '=' expr { $$ = node.NewSimpleNode("Const").Append($1).Append($3) }
|
||||
;
|
||||
|
||||
const_decl:
|
||||
|
Loading…
Reference in New Issue
Block a user