trait_use_alias node

This commit is contained in:
vadim 2017-12-09 12:58:35 +02:00
parent ef11d0ab38
commit f4a0a56b14
3 changed files with 51 additions and 8 deletions

View File

@ -0,0 +1,43 @@
package stmt
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type TraitUseAlias struct {
node.SimpleNode
ref node.Node
modifier node.Node
alias token.TokenInterface
}
func NewTraitUseAlias(ref node.Node, modifier node.Node, alias token.TokenInterface) node.Node {
return TraitUseAlias{
node.SimpleNode{Name: "TraitUseAlias", Attributes: make(map[string]string)},
ref,
modifier,
alias,
}
}
func (n TraitUseAlias) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
if n.alias != nil {
fmt.Fprintf(out, "\n%valias: %q", indent+" ", n.alias.GetValue())
}
if n.ref != nil {
fmt.Fprintf(out, "\n%vmethod", indent+" ")
n.ref.Print(out, indent+" ")
}
if n.modifier != nil {
fmt.Fprintf(out, "\n%vmodifier:", indent+" ")
n.modifier.Print(out, indent+" ")
}
}

View File

@ -3560,25 +3560,25 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:708
{
yyVAL.node = yyDollar[1].node.Append(node.NewSimpleNode("as").Attribute("value", yyDollar[3].token.String()))
yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, nil, yyDollar[3].token)
}
case 255:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:710
{
yyVAL.node = yyDollar[1].node.Append(node.NewSimpleNode("as").Append(node.NewSimpleNode("reservedNonModifiers")))
yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, nil, yyDollar[3].token)
}
case 256:
yyDollar = yyS[yypt-4 : yypt+1]
//line parser/parser.y:712
{
yyVAL.node = yyDollar[1].node.Append(yyDollar[3].node).Attribute("as", yyDollar[4].token.Value)
yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, yyDollar[4].token)
}
case 257:
yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:713
{
yyVAL.node = yyDollar[1].node.Append(yyDollar[3].node)
yyVAL.node = stmt.NewTraitUseAlias(yyDollar[1].node, yyDollar[3].node, nil)
}
case 258:
yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -705,12 +705,12 @@ trait_precedence:
;
trait_alias:
trait_method_reference T_AS T_STRING { $$ = $1.Append(node.NewSimpleNode("as").Attribute("value", $3.String())); }
trait_method_reference T_AS T_STRING { $$ = stmt.NewTraitUseAlias($1, nil, $3) }
| trait_method_reference T_AS reserved_non_modifiers
{ $$ = $1.Append(node.NewSimpleNode("as").Append(node.NewSimpleNode("reservedNonModifiers"))); }
{ $$ = stmt.NewTraitUseAlias($1, nil, $3) }
| trait_method_reference T_AS member_modifier identifier
{ $$ = $1.Append($3).Attribute("as", $4.Value); }
| trait_method_reference T_AS member_modifier { $$ = $1.Append($3); }
{ $$ = stmt.NewTraitUseAlias($1, $3, $4) }
| trait_method_reference T_AS member_modifier { $$ = stmt.NewTraitUseAlias($1, $3, nil) }
;
trait_method_reference: