print node

This commit is contained in:
z7zmey 2017-12-18 19:03:39 +02:00
parent b5dc115ff1
commit a73b9a9478
3 changed files with 31 additions and 2 deletions

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

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

@ -4215,7 +4215,7 @@ yydefault:
yyDollar = yyS[yypt-2 : yypt+1]
//line parser/parser.y:893
{
yyVAL.node = node.NewSimpleNode("Print").Append(yyDollar[2].node)
yyVAL.node = expr.NewPrint(yyDollar[2].node)
}
case 363:
yyDollar = yyS[yypt-1 : yypt+1]

View File

@ -890,7 +890,7 @@ expr_without_variable:
| '@' expr { $$ = node.NewSimpleNode("Silence").Append($2); }
| scalar { $$ = $1; }
| '`' backticks_expr '`' { $$ = node.NewNodeExprShellExec($1, $2, $3) }
| T_PRINT expr { $$ = node.NewSimpleNode("Print").Append($2); }
| T_PRINT expr { $$ = expr.NewPrint($2) }
| T_YIELD { $$ = node.NewSimpleNode("Yield"); }
| T_YIELD expr { $$ = node.NewSimpleNode("Yield").Append($2); }
| T_YIELD expr T_DOUBLE_ARROW expr { $$ = node.NewSimpleNode("Yield").Append($2).Append($4); }