empty eval include include_once require require_once nodes

This commit is contained in:
z7zmey 2017-12-16 23:25:32 +02:00
parent 52638e6654
commit c6729a06e2
8 changed files with 186 additions and 12 deletions

29
node/expr/empty.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type Empty struct {
node.SimpleNode
expr node.Node
}
func NewEmpty(expression node.Node) node.Node {
return Empty{
node.SimpleNode{Name: "Empty", Attributes: make(map[string]string)},
expression,
}
}
func (n Empty) 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+" ")
}
}

29
node/expr/eval.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type Eval struct {
node.SimpleNode
expr node.Node
}
func NewEval(expression node.Node) node.Node {
return Eval{
node.SimpleNode{Name: "Eval", Attributes: make(map[string]string)},
expression,
}
}
func (n Eval) 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+" ")
}
}

29
node/expr/include.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type Include struct {
node.SimpleNode
expr node.Node
}
func NewInclude(expression node.Node) node.Node {
return Include{
node.SimpleNode{Name: "Include", Attributes: make(map[string]string)},
expression,
}
}
func (n Include) 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+" ")
}
}

29
node/expr/include_once.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type IncludeOnce struct {
node.SimpleNode
expr node.Node
}
func NewIncludeOnce(expression node.Node) node.Node {
return IncludeOnce{
node.SimpleNode{Name: "IncludeOnce", Attributes: make(map[string]string)},
expression,
}
}
func (n IncludeOnce) 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+" ")
}
}

29
node/expr/require.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type Require struct {
node.SimpleNode
expr node.Node
}
func NewRequire(expression node.Node) node.Node {
return Require{
node.SimpleNode{Name: "Require", Attributes: make(map[string]string)},
expression,
}
}
func (n Require) 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+" ")
}
}

29
node/expr/require_once.go Normal file
View File

@ -0,0 +1,29 @@
package expr
import (
"fmt"
"io"
"github.com/z7zmey/php-parser/node"
)
type RequireOnce struct {
node.SimpleNode
expr node.Node
}
func NewRequireOnce(expression node.Node) node.Node {
return RequireOnce{
node.SimpleNode{Name: "RequireOnce", Attributes: make(map[string]string)},
expression,
}
}
func (n RequireOnce) 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+" ")
}
}

View File

@ -4909,37 +4909,37 @@ yydefault:
yyDollar = yyS[yypt-4 : yypt+1]
//line parser/parser.y:1122
{
yyVAL.node = node.NewSimpleNode("Empty").Append(yyDollar[3].node)
yyVAL.node = expr.NewEmpty(yyDollar[3].node)
}
case 479:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:1123
{
yyVAL.node = node.NewSimpleNode("Include").Append(yyDollar[2].node)
yyVAL.node = expr.NewInclude(yyDollar[2].node)
}
case 480:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:1124
{
yyVAL.node = node.NewSimpleNode("IncludeOnce").Append(yyDollar[2].node)
yyVAL.node = expr.NewIncludeOnce(yyDollar[2].node)
}
case 481:
yyDollar = yyS[yypt-4 : yypt+1]
//line parser/parser.y:1125
{
yyVAL.node = node.NewSimpleNode("Eval").Append(yyDollar[3].node)
yyVAL.node = expr.NewEval(yyDollar[3].node)
}
case 482:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:1126
{
yyVAL.node = node.NewSimpleNode("Require").Append(yyDollar[2].node)
yyVAL.node = expr.NewRequire(yyDollar[2].node)
}
case 483:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:1127
{
yyVAL.node = node.NewSimpleNode("RequireOnce").Append(yyDollar[2].node)
yyVAL.node = expr.NewRequireOnce(yyDollar[2].node)
}
case 484:
yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -1119,12 +1119,12 @@ encaps_var_offset:
internal_functions_in_yacc:
T_ISSET '(' isset_variables possible_comma ')' { $$ = $3; }
| T_EMPTY '(' expr ')' { $$ = node.NewSimpleNode("Empty").Append($3); }
| T_INCLUDE expr { $$ = node.NewSimpleNode("Include").Append($2); }
| T_INCLUDE_ONCE expr { $$ = node.NewSimpleNode("IncludeOnce").Append($2); }
| T_EVAL '(' expr ')' { $$ = node.NewSimpleNode("Eval").Append($3); }
| T_REQUIRE expr { $$ = node.NewSimpleNode("Require").Append($2); }
| T_REQUIRE_ONCE expr { $$ = node.NewSimpleNode("RequireOnce").Append($2); }
| T_EMPTY '(' expr ')' { $$ = expr.NewEmpty($3) }
| T_INCLUDE expr { $$ = expr.NewInclude($2) }
| T_INCLUDE_ONCE expr { $$ = expr.NewIncludeOnce($2) }
| T_EVAL '(' expr ')' { $$ = expr.NewEval($3) }
| T_REQUIRE expr { $$ = expr.NewRequire($2) }
| T_REQUIRE_ONCE expr { $$ = expr.NewRequireOnce($2) }
;
isset_variables: