instance_of node

This commit is contained in:
z7zmey 2017-12-17 23:08:17 +02:00
parent 9095d3fef7
commit aa520300c0
3 changed files with 38 additions and 2 deletions

36
node/expr/instance_of.go Normal file
View File

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

View File

@ -4105,7 +4105,7 @@ yydefault:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]
//line parser/parser.y:866 //line parser/parser.y:866
{ {
yyVAL.node = node.NewSimpleNode("InstanceOf").Append(yyDollar[1].node).Append(yyDollar[3].node) yyVAL.node = expr.NewInstanceOf(yyDollar[1].node, yyDollar[3].node)
} }
case 345: case 345:
yyDollar = yyS[yypt-3 : yypt+1] yyDollar = yyS[yypt-3 : yypt+1]

View File

@ -863,7 +863,7 @@ expr_without_variable:
| expr '>' expr { $$ = binary_op.NewGreater($1, $3) } | expr '>' expr { $$ = binary_op.NewGreater($1, $3) }
| expr T_IS_GREATER_OR_EQUAL expr { $$ = binary_op.NewGreaterOrEqual($1, $3) } | expr T_IS_GREATER_OR_EQUAL expr { $$ = binary_op.NewGreaterOrEqual($1, $3) }
| expr T_SPACESHIP expr { $$ = binary_op.NewSpaceship($1, $3) } | expr T_SPACESHIP expr { $$ = binary_op.NewSpaceship($1, $3) }
| expr T_INSTANCEOF class_name_reference { $$ = node.NewSimpleNode("InstanceOf").Append($1).Append($3) } | expr T_INSTANCEOF class_name_reference { $$ = expr.NewInstanceOf($1, $3) }
| '(' expr ')' { $$ = $2; } | '(' expr ')' { $$ = $2; }
| new_expr { $$ = $1; } | new_expr { $$ = $1; }
| expr '?' expr ':' expr { $$ = node.NewSimpleNode("Ternary").Append($1).Append($3).Append($5); } | expr '?' expr ':' expr { $$ = node.NewSimpleNode("Ternary").Append($1).Append($3).Append($5); }