class_const_fetch node

This commit is contained in:
z7zmey 2017-12-16 22:14:26 +02:00
parent ae759c26c7
commit cf084b5893
3 changed files with 37 additions and 4 deletions

View File

@ -0,0 +1,33 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/token"
)
type ClassConstFetch struct {
node.SimpleNode
class node.Node
name token.Token
}
func NewClassConstFetch(class node.Node, name token.Token) node.Node {
return ClassConstFetch{
node.SimpleNode{Name: "ClassConstFetch", Attributes: make(map[string]string)},
class,
name,
}
}
func (n ClassConstFetch) Print(out io.Writer, indent string) {
fmt.Fprintf(out, "\n%v%v [- -]", indent, n.Name)
fmt.Fprintf(out, "\n%vname: %q", indent+" ", n.name)
if n.class != nil {
fmt.Fprintf(out, "\n%vclass:", indent+" ")
n.class.Print(out, indent+" ")
}
}

View File

@ -4522,13 +4522,13 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:993 //line parser/parser.y:993
{ {
yyVAL.node = node.NewSimpleNode("Const").Append(yyDollar[1].node).Attribute("value", yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, yyDollar[3].token)
} }
case 413: case 413:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:995 //line parser/parser.y:995
{ {
yyVAL.node = node.NewSimpleNode("Const").Append(yyDollar[1].node).Attribute("value", yyDollar[3].token.Value) yyVAL.node = expr.NewClassConstFetch(yyDollar[1].node, yyDollar[3].token)
} }
case 414: case 414:
yyDollar = yyS[yypt-1 : yypt+1] yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -990,9 +990,9 @@ scalar:
constant: constant:
name { $$ = node.NewSimpleNode("Const").Append($1) } name { $$ = node.NewSimpleNode("Const").Append($1) }
| class_name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = node.NewSimpleNode("Const").Append($1).Attribute("value", $3.Value) } | class_name T_PAAMAYIM_NEKUDOTAYIM identifier { $$ = expr.NewClassConstFetch($1, $3) }
| variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier | variable_class_name T_PAAMAYIM_NEKUDOTAYIM identifier
{ $$ = node.NewSimpleNode("Const").Append($1).Attribute("value", $3.Value) } { $$ = expr.NewClassConstFetch($1, $3) }
; ;
expr: expr: