expression node

This commit is contained in:
vadim 2017-12-07 12:44:04 +02:00
parent 36709bdfae
commit 21e158284f
3 changed files with 31 additions and 2 deletions

29
node/stmt/expression.go Normal file
View File

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

@ -2886,7 +2886,7 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1] yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:382 //line parser/parser.y:382
{ {
yyVAL.node = yyDollar[1].node yyVAL.node = stmt.NewExpression(yyDollar[1].node)
} }
case 144: case 144:
yyDollar = yyS[yypt-6 : yypt+1] yyDollar = yyS[yypt-6 : yypt+1]

View File

@ -379,7 +379,7 @@ statement:
| T_STATIC static_var_list ';' { $$ = $2; } | T_STATIC static_var_list ';' { $$ = $2; }
| T_ECHO echo_expr_list ';' { $$ = stmt.NewEcho($1, $2) } | T_ECHO echo_expr_list ';' { $$ = stmt.NewEcho($1, $2) }
| T_INLINE_HTML { $$ = node.NewSimpleNode("Echo").Append(node.NewSimpleNode("InlineHtml").Attribute("value", $1.String())) } | T_INLINE_HTML { $$ = node.NewSimpleNode("Echo").Append(node.NewSimpleNode("InlineHtml").Attribute("value", $1.String())) }
| expr ';' { $$ = $1; } | expr ';' { $$ = stmt.NewExpression($1); }
| T_UNSET '(' unset_variables possible_comma ')' ';' | T_UNSET '(' unset_variables possible_comma ')' ';'
{ $$ = node.NewSimpleNode("Unset").Append($3); } { $$ = node.NewSimpleNode("Unset").Append($3); }
| T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement | T_FOREACH '(' expr T_AS foreach_variable ')' foreach_statement