php-parser/printer/printer.go

2904 lines
62 KiB
Go
Raw Normal View History

package printer
import (
"io"
2018-04-05 21:39:04 +00:00
"strings"
"github.com/z7zmey/php-parser/meta"
"github.com/z7zmey/php-parser/node/stmt"
"github.com/z7zmey/php-parser/node"
"github.com/z7zmey/php-parser/node/expr"
"github.com/z7zmey/php-parser/node/expr/assign"
"github.com/z7zmey/php-parser/node/expr/binary"
"github.com/z7zmey/php-parser/node/expr/cast"
"github.com/z7zmey/php-parser/node/name"
"github.com/z7zmey/php-parser/node/scalar"
)
2018-04-02 20:57:22 +00:00
type Printer struct {
w io.Writer
}
2018-04-02 20:57:22 +00:00
// NewPrinter - Constructor for Printer
func NewPrinter(w io.Writer) *Printer {
2018-04-02 20:57:22 +00:00
return &Printer{
w: w,
2018-04-02 20:57:22 +00:00
}
}
func (p *Printer) Print(n node.Node) {
p.printNode(n)
}
func (p *Printer) joinPrint(glue string, nn []node.Node) {
for k, n := range nn {
if k > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, glue)
}
2018-04-02 20:57:22 +00:00
p.Print(n)
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodes(nn []node.Node) {
for _, n := range nn {
2018-04-02 20:57:22 +00:00
p.Print(n)
}
2018-04-03 16:20:55 +00:00
}
func (p *Printer) printMeta(n node.Node, tn meta.TokenName) {
if n == nil {
return
}
for _, m := range n.GetMeta() {
if m.GetTokenName() == tn {
io.WriteString(p.w, m.String())
}
2018-04-03 16:20:55 +00:00
}
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNode(n node.Node) {
switch n.(type) {
// node
2018-05-02 09:14:24 +00:00
case *node.Root:
p.printNodeRoot(n)
case *node.Identifier:
2018-04-02 20:57:22 +00:00
p.printNodeIdentifier(n)
case *node.Parameter:
2018-04-02 20:57:22 +00:00
p.printNodeParameter(n)
case *node.Nullable:
2018-04-02 20:57:22 +00:00
p.printNodeNullable(n)
case *node.Argument:
2018-04-02 20:57:22 +00:00
p.printNodeArgument(n)
2018-04-05 08:59:29 +00:00
// name
case *name.NamePart:
2018-04-02 20:57:22 +00:00
p.printNameNamePart(n)
case *name.Name:
2018-04-02 20:57:22 +00:00
p.printNameName(n)
case *name.FullyQualified:
2018-04-02 20:57:22 +00:00
p.printNameFullyQualified(n)
case *name.Relative:
2018-04-02 20:57:22 +00:00
p.printNameRelative(n)
2018-04-05 08:59:29 +00:00
// scalar
case *scalar.Lnumber:
2018-04-02 20:57:22 +00:00
p.printScalarLNumber(n)
case *scalar.Dnumber:
2018-04-02 20:57:22 +00:00
p.printScalarDNumber(n)
case *scalar.String:
2018-04-02 20:57:22 +00:00
p.printScalarString(n)
case *scalar.EncapsedStringPart:
2018-04-02 20:57:22 +00:00
p.printScalarEncapsedStringPart(n)
case *scalar.Encapsed:
2018-04-02 20:57:22 +00:00
p.printScalarEncapsed(n)
2018-04-05 21:39:04 +00:00
case *scalar.Heredoc:
p.printScalarHeredoc(n)
case *scalar.MagicConstant:
2018-04-02 20:57:22 +00:00
p.printScalarMagicConstant(n)
2018-04-05 08:59:29 +00:00
// assign
case *assign.Assign:
2018-04-02 20:57:22 +00:00
p.printAssign(n)
2018-04-05 09:03:32 +00:00
case *assign.Reference:
p.printReference(n)
case *assign.BitwiseAnd:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseAnd(n)
case *assign.BitwiseOr:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseOr(n)
case *assign.BitwiseXor:
2018-04-02 20:57:22 +00:00
p.printAssignBitwiseXor(n)
case *assign.Concat:
2018-04-02 20:57:22 +00:00
p.printAssignConcat(n)
case *assign.Div:
2018-04-02 20:57:22 +00:00
p.printAssignDiv(n)
case *assign.Minus:
2018-04-02 20:57:22 +00:00
p.printAssignMinus(n)
case *assign.Mod:
2018-04-02 20:57:22 +00:00
p.printAssignMod(n)
case *assign.Mul:
2018-04-02 20:57:22 +00:00
p.printAssignMul(n)
case *assign.Plus:
2018-04-02 20:57:22 +00:00
p.printAssignPlus(n)
case *assign.Pow:
2018-04-02 20:57:22 +00:00
p.printAssignPow(n)
case *assign.ShiftLeft:
2018-04-02 20:57:22 +00:00
p.printAssignShiftLeft(n)
case *assign.ShiftRight:
2018-04-02 20:57:22 +00:00
p.printAssignShiftRight(n)
2018-04-05 08:59:29 +00:00
// binary
case *binary.BitwiseAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseAnd(n)
case *binary.BitwiseOr:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseOr(n)
case *binary.BitwiseXor:
2018-04-02 20:57:22 +00:00
p.printBinaryBitwiseXor(n)
case *binary.BooleanAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryBooleanAnd(n)
case *binary.BooleanOr:
2018-04-02 20:57:22 +00:00
p.printBinaryBooleanOr(n)
case *binary.Coalesce:
2018-04-02 20:57:22 +00:00
p.printBinaryCoalesce(n)
case *binary.Concat:
2018-04-02 20:57:22 +00:00
p.printBinaryConcat(n)
case *binary.Div:
2018-04-02 20:57:22 +00:00
p.printBinaryDiv(n)
case *binary.Equal:
2018-04-02 20:57:22 +00:00
p.printBinaryEqual(n)
case *binary.GreaterOrEqual:
2018-04-02 20:57:22 +00:00
p.printBinaryGreaterOrEqual(n)
case *binary.Greater:
2018-04-02 20:57:22 +00:00
p.printBinaryGreater(n)
case *binary.Identical:
2018-04-02 20:57:22 +00:00
p.printBinaryIdentical(n)
case *binary.LogicalAnd:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalAnd(n)
case *binary.LogicalOr:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalOr(n)
case *binary.LogicalXor:
2018-04-02 20:57:22 +00:00
p.printBinaryLogicalXor(n)
case *binary.Minus:
2018-04-02 20:57:22 +00:00
p.printBinaryMinus(n)
case *binary.Mod:
2018-04-02 20:57:22 +00:00
p.printBinaryMod(n)
case *binary.Mul:
2018-04-02 20:57:22 +00:00
p.printBinaryMul(n)
case *binary.NotEqual:
2018-04-02 20:57:22 +00:00
p.printBinaryNotEqual(n)
case *binary.NotIdentical:
2018-04-02 20:57:22 +00:00
p.printBinaryNotIdentical(n)
case *binary.Plus:
2018-04-02 20:57:22 +00:00
p.printBinaryPlus(n)
case *binary.Pow:
2018-04-02 20:57:22 +00:00
p.printBinaryPow(n)
case *binary.ShiftLeft:
2018-04-02 20:57:22 +00:00
p.printBinaryShiftLeft(n)
case *binary.ShiftRight:
2018-04-02 20:57:22 +00:00
p.printBinaryShiftRight(n)
case *binary.SmallerOrEqual:
2018-04-02 20:57:22 +00:00
p.printBinarySmallerOrEqual(n)
case *binary.Smaller:
2018-04-02 20:57:22 +00:00
p.printBinarySmaller(n)
case *binary.Spaceship:
2018-04-02 20:57:22 +00:00
p.printBinarySpaceship(n)
2018-04-05 08:59:29 +00:00
// cast
case *cast.Array:
p.printArray(n)
case *cast.Bool:
p.printBool(n)
case *cast.Double:
p.printDouble(n)
case *cast.Int:
p.printInt(n)
case *cast.Object:
p.printObject(n)
case *cast.String:
p.printString(n)
case *cast.Unset:
p.printUnset(n)
// expr
case *expr.ArrayDimFetch:
2018-04-02 20:57:22 +00:00
p.printExprArrayDimFetch(n)
case *expr.ArrayItem:
2018-04-02 20:57:22 +00:00
p.printExprArrayItem(n)
case *expr.Array:
2018-04-02 20:57:22 +00:00
p.printExprArray(n)
case *expr.BitwiseNot:
2018-04-02 20:57:22 +00:00
p.printExprBitwiseNot(n)
case *expr.BooleanNot:
2018-04-02 20:57:22 +00:00
p.printExprBooleanNot(n)
case *expr.ClassConstFetch:
2018-04-02 20:57:22 +00:00
p.printExprClassConstFetch(n)
case *expr.Clone:
2018-04-02 20:57:22 +00:00
p.printExprClone(n)
case *expr.ClosureUse:
2018-04-02 20:57:22 +00:00
p.printExprClosureUse(n)
case *expr.Closure:
2018-04-02 20:57:22 +00:00
p.printExprClosure(n)
case *expr.ConstFetch:
2018-04-02 20:57:22 +00:00
p.printExprConstFetch(n)
case *expr.Die:
2018-04-02 20:57:22 +00:00
p.printExprDie(n)
case *expr.Empty:
2018-04-02 20:57:22 +00:00
p.printExprEmpty(n)
case *expr.ErrorSuppress:
2018-04-02 20:57:22 +00:00
p.printExprErrorSuppress(n)
case *expr.Eval:
2018-04-02 20:57:22 +00:00
p.printExprEval(n)
case *expr.Exit:
2018-04-02 20:57:22 +00:00
p.printExprExit(n)
case *expr.FunctionCall:
2018-04-02 20:57:22 +00:00
p.printExprFunctionCall(n)
case *expr.Include:
2018-04-02 20:57:22 +00:00
p.printExprInclude(n)
case *expr.IncludeOnce:
2018-04-02 20:57:22 +00:00
p.printExprIncludeOnce(n)
case *expr.InstanceOf:
2018-04-02 20:57:22 +00:00
p.printExprInstanceOf(n)
case *expr.Isset:
2018-04-02 20:57:22 +00:00
p.printExprIsset(n)
case *expr.List:
2018-04-02 20:57:22 +00:00
p.printExprList(n)
case *expr.MethodCall:
2018-04-02 20:57:22 +00:00
p.printExprMethodCall(n)
case *expr.New:
2018-04-02 20:57:22 +00:00
p.printExprNew(n)
case *expr.PostDec:
2018-04-02 20:57:22 +00:00
p.printExprPostDec(n)
case *expr.PostInc:
2018-04-02 20:57:22 +00:00
p.printExprPostInc(n)
case *expr.PreDec:
2018-04-02 20:57:22 +00:00
p.printExprPreDec(n)
case *expr.PreInc:
2018-04-02 20:57:22 +00:00
p.printExprPreInc(n)
case *expr.Print:
2018-04-02 20:57:22 +00:00
p.printExprPrint(n)
case *expr.PropertyFetch:
2018-04-02 20:57:22 +00:00
p.printExprPropertyFetch(n)
case *expr.Reference:
p.printExprReference(n)
case *expr.Require:
2018-04-02 20:57:22 +00:00
p.printExprRequire(n)
case *expr.RequireOnce:
2018-04-02 20:57:22 +00:00
p.printExprRequireOnce(n)
case *expr.ShellExec:
2018-04-02 20:57:22 +00:00
p.printExprShellExec(n)
case *expr.ShortArray:
2018-04-02 20:57:22 +00:00
p.printExprShortArray(n)
case *expr.ShortList:
2018-04-02 20:57:22 +00:00
p.printExprShortList(n)
case *expr.StaticCall:
2018-04-02 20:57:22 +00:00
p.printExprStaticCall(n)
case *expr.StaticPropertyFetch:
2018-04-02 20:57:22 +00:00
p.printExprStaticPropertyFetch(n)
case *expr.Ternary:
2018-04-02 20:57:22 +00:00
p.printExprTernary(n)
case *expr.UnaryMinus:
2018-04-02 20:57:22 +00:00
p.printExprUnaryMinus(n)
case *expr.UnaryPlus:
2018-04-02 20:57:22 +00:00
p.printExprUnaryPlus(n)
case *expr.Variable:
2018-04-02 20:57:22 +00:00
p.printExprVariable(n)
case *expr.YieldFrom:
2018-04-02 20:57:22 +00:00
p.printExprYieldFrom(n)
case *expr.Yield:
2018-04-02 20:57:22 +00:00
p.printExprYield(n)
2018-04-05 08:59:29 +00:00
// stmt
case *stmt.AltElseIf:
2018-04-02 20:57:22 +00:00
p.printStmtAltElseIf(n)
case *stmt.AltElse:
2018-04-02 20:57:22 +00:00
p.printStmtAltElse(n)
case *stmt.AltFor:
2018-04-02 20:57:22 +00:00
p.printStmtAltFor(n)
case *stmt.AltForeach:
2018-04-02 20:57:22 +00:00
p.printStmtAltForeach(n)
case *stmt.AltIf:
2018-04-02 20:57:22 +00:00
p.printStmtAltIf(n)
case *stmt.AltSwitch:
2018-04-02 20:57:22 +00:00
p.printStmtAltSwitch(n)
case *stmt.AltWhile:
2018-04-02 20:57:22 +00:00
p.printStmtAltWhile(n)
case *stmt.Break:
2018-04-02 20:57:22 +00:00
p.printStmtBreak(n)
case *stmt.Case:
2018-04-02 20:57:22 +00:00
p.printStmtCase(n)
case *stmt.Catch:
2018-04-02 20:57:22 +00:00
p.printStmtCatch(n)
case *stmt.ClassMethod:
2018-04-02 20:57:22 +00:00
p.printStmtClassMethod(n)
2018-03-20 18:06:56 +00:00
case *stmt.Class:
2018-04-02 20:57:22 +00:00
p.printStmtClass(n)
2018-03-20 18:37:55 +00:00
case *stmt.ClassConstList:
2018-04-02 20:57:22 +00:00
p.printStmtClassConstList(n)
case *stmt.Constant:
2018-04-02 20:57:22 +00:00
p.printStmtConstant(n)
2018-03-20 18:37:55 +00:00
case *stmt.Continue:
2018-04-02 20:57:22 +00:00
p.printStmtContinue(n)
2018-03-28 20:44:02 +00:00
case *stmt.Declare:
2018-04-02 20:57:22 +00:00
p.printStmtDeclare(n)
2018-03-28 21:04:09 +00:00
case *stmt.Default:
2018-04-02 20:57:22 +00:00
p.printStmtDefault(n)
2018-03-28 21:04:09 +00:00
case *stmt.Do:
2018-04-02 20:57:22 +00:00
p.printStmtDo(n)
case *stmt.Echo:
2018-04-02 20:57:22 +00:00
p.printStmtEcho(n)
case *stmt.ElseIf:
2018-04-02 20:57:22 +00:00
p.printStmtElseif(n)
case *stmt.Else:
2018-04-02 20:57:22 +00:00
p.printStmtElse(n)
2018-03-31 11:17:05 +00:00
case *stmt.Expression:
2018-04-02 20:57:22 +00:00
p.printStmtExpression(n)
2018-03-31 11:17:05 +00:00
case *stmt.Finally:
2018-04-02 20:57:22 +00:00
p.printStmtFinally(n)
case *stmt.For:
2018-04-02 20:57:22 +00:00
p.printStmtFor(n)
case *stmt.Foreach:
2018-04-02 20:57:22 +00:00
p.printStmtForeach(n)
case *stmt.Function:
2018-04-02 20:57:22 +00:00
p.printStmtFunction(n)
case *stmt.Global:
2018-04-02 20:57:22 +00:00
p.printStmtGlobal(n)
case *stmt.Goto:
2018-04-02 20:57:22 +00:00
p.printStmtGoto(n)
case *stmt.GroupUse:
2018-04-02 20:57:22 +00:00
p.printStmtGroupUse(n)
case *stmt.HaltCompiler:
2018-04-02 20:57:22 +00:00
p.printStmtHaltCompiler(n)
2018-04-01 14:07:07 +00:00
case *stmt.If:
2018-04-02 20:57:22 +00:00
p.printStmtIf(n)
2018-04-01 14:07:07 +00:00
case *stmt.InlineHtml:
2018-04-02 20:57:22 +00:00
p.printStmtInlineHTML(n)
case *stmt.Interface:
2018-04-02 20:57:22 +00:00
p.printStmtInterface(n)
case *stmt.Label:
2018-04-02 20:57:22 +00:00
p.printStmtLabel(n)
case *stmt.Namespace:
2018-04-02 20:57:22 +00:00
p.printStmtNamespace(n)
case *stmt.Nop:
2018-04-02 20:57:22 +00:00
p.printStmtNop(n)
case *stmt.PropertyList:
2018-04-02 20:57:22 +00:00
p.printStmtPropertyList(n)
case *stmt.Property:
2018-04-02 20:57:22 +00:00
p.printStmtProperty(n)
case *stmt.Return:
2018-04-02 20:57:22 +00:00
p.printStmtReturn(n)
case *stmt.StaticVar:
2018-04-02 20:57:22 +00:00
p.printStmtStaticVar(n)
case *stmt.Static:
2018-04-02 20:57:22 +00:00
p.printStmtStatic(n)
case *stmt.StmtList:
2018-04-02 20:57:22 +00:00
p.printStmtStmtList(n)
case *stmt.Switch:
2018-04-02 20:57:22 +00:00
p.printStmtSwitch(n)
case *stmt.Throw:
2018-04-02 20:57:22 +00:00
p.printStmtThrow(n)
case *stmt.TraitMethodRef:
2018-04-02 20:57:22 +00:00
p.printStmtTraitMethodRef(n)
case *stmt.TraitUseAlias:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUseAlias(n)
case *stmt.TraitUsePrecedence:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUsePrecedence(n)
case *stmt.TraitUse:
2018-04-02 20:57:22 +00:00
p.printStmtTraitUse(n)
case *stmt.Trait:
2018-04-02 20:57:22 +00:00
p.printStmtTrait(n)
case *stmt.Try:
2018-04-02 20:57:22 +00:00
p.printStmtTry(n)
case *stmt.Unset:
2018-04-02 20:57:22 +00:00
p.printStmtUnset(n)
case *stmt.UseList:
2018-04-02 20:57:22 +00:00
p.printStmtUseList(n)
case *stmt.Use:
2018-04-02 20:57:22 +00:00
p.printStmtUse(n)
case *stmt.While:
2018-04-02 20:57:22 +00:00
p.printStmtWhile(n)
}
}
// node
2018-05-02 09:14:24 +00:00
func (p *Printer) printNodeRoot(n node.Node) {
nn := n.(*node.Root)
p.printMeta(nn, meta.NodeStart)
2018-05-02 09:14:24 +00:00
var stmts []node.Node
if len(nn.Stmts) > 0 {
firstStmt := nn.Stmts[0]
stmts = nn.Stmts[1:]
2018-05-02 09:14:24 +00:00
switch fs := firstStmt.(type) {
case *stmt.InlineHtml:
io.WriteString(p.w, fs.Value)
io.WriteString(p.w, "<?php")
2018-05-02 09:14:24 +00:00
default:
io.WriteString(p.w, "<?php")
2018-05-02 09:14:24 +00:00
p.Print(fs)
}
}
p.printNodes(stmts)
p.printMeta(nn, meta.NodeEnd)
2018-05-02 09:14:24 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeIdentifier(n node.Node) {
nn := n.(*node.Identifier)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IdentifierToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeParameter(n node.Node) {
nn := n.(*node.Parameter)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UnknownToken)
if nn.VariableType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.VariableType)
}
if nn.ByRef {
p.printMeta(nn, meta.AmpersandToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
if nn.Variadic {
p.printMeta(nn, meta.EllipsisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "...")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.DefaultValue != nil {
p.printMeta(nn, meta.EqualToken)
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.DefaultValue)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeNullable(n node.Node) {
nn := n.(*node.Nullable)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.QuestionMarkToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "?")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNodeArgument(n node.Node) {
nn := n.(*node.Argument)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UnknownToken)
if nn.IsReference {
p.printMeta(nn, meta.AmpersandToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
if nn.Variadic {
p.printMeta(nn, meta.EllipsisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "...")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
// name
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameNamePart(n node.Node) {
nn := n.(*name.NamePart)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.StringToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NsSeparatorToken)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameName(n node.Node) {
nn := n.(*name.Name)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.StringToken)
for k, part := range nn.Parts {
if k > 0 {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
}
2018-04-02 20:57:22 +00:00
p.Print(part)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameFullyQualified(n node.Node) {
nn := n.(*name.FullyQualified)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.NsSeparatorToken)
for _, part := range nn.Parts {
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
p.Print(part)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printNameRelative(n node.Node) {
nn := n.(*name.Relative)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.NamespaceToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "namespace")
for k, part := range nn.Parts {
if k == 0 {
p.printMeta(nn, meta.NsSeparatorToken)
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\\")
p.Print(part)
}
p.printMeta(nn, meta.NodeEnd)
}
// scalar
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarLNumber(n node.Node) {
nn := n.(*scalar.Lnumber)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.LnumberToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarDNumber(n node.Node) {
nn := n.(*scalar.Dnumber)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DnumberToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarString(n node.Node) {
nn := n.(*scalar.String)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ConstantEncapsedStringToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarEncapsedStringPart(n node.Node) {
nn := n.(*scalar.EncapsedStringPart)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.EncapsedAndWhitespaceToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarEncapsed(n node.Node) {
nn := n.(*scalar.Encapsed)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DoubleQuoteToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\"")
for _, part := range nn.Parts {
switch part.(type) {
case *scalar.EncapsedStringPart:
p.Print(part)
default:
io.WriteString(p.w, "{")
p.Print(part)
2018-07-09 19:04:18 +00:00
p.printMeta(nn, meta.CloseCurlyBracesToken)
io.WriteString(p.w, "}")
}
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "\"")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 21:39:04 +00:00
func (p *Printer) printScalarHeredoc(n node.Node) {
nn := n.(*scalar.Heredoc)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.StartHeredocToken)
2018-04-05 21:39:04 +00:00
io.WriteString(p.w, "<<<")
io.WriteString(p.w, nn.Label)
io.WriteString(p.w, "\n")
for _, part := range nn.Parts {
switch part.(type) {
case *scalar.EncapsedStringPart:
p.Print(part)
default:
io.WriteString(p.w, "{")
p.Print(part)
2018-07-09 19:04:18 +00:00
p.printMeta(nn, meta.CloseCurlyBracesToken)
io.WriteString(p.w, "}")
}
2018-04-05 21:39:04 +00:00
}
io.WriteString(p.w, strings.Trim(nn.Label, "\"'"))
p.printMeta(nn, meta.NodeEnd)
2018-04-05 21:39:04 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printScalarMagicConstant(n node.Node) {
nn := n.(*scalar.MagicConstant)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.MagicConstantToken)
io.WriteString(p.w, nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
// Assign
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssign(n node.Node) {
nn := n.(*assign.Assign)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.EqualToken)
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 09:03:32 +00:00
func (p *Printer) printReference(n node.Node) {
nn := n.(*assign.Reference)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.EqualToken)
io.WriteString(p.w, "=")
p.printMeta(nn, meta.AmpersandToken)
io.WriteString(p.w, "&")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseAnd(n node.Node) {
nn := n.(*assign.BitwiseAnd)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.AndEqualToken)
io.WriteString(p.w, "&")
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseOr(n node.Node) {
nn := n.(*assign.BitwiseOr)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.OrEqualToken)
io.WriteString(p.w, "|=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignBitwiseXor(n node.Node) {
nn := n.(*assign.BitwiseXor)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.XorEqualToken)
io.WriteString(p.w, "^=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignConcat(n node.Node) {
nn := n.(*assign.Concat)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.ConcatEqualToken)
io.WriteString(p.w, ".=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignDiv(n node.Node) {
nn := n.(*assign.Div)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.DivEqualToken)
io.WriteString(p.w, "/=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMinus(n node.Node) {
nn := n.(*assign.Minus)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.MinusEqualToken)
io.WriteString(p.w, "-=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMod(n node.Node) {
nn := n.(*assign.Mod)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.ModEqualToken)
io.WriteString(p.w, "%=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignMul(n node.Node) {
nn := n.(*assign.Mul)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.MulEqualToken)
io.WriteString(p.w, "*=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignPlus(n node.Node) {
nn := n.(*assign.Plus)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.PlusEqualToken)
io.WriteString(p.w, "+=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignPow(n node.Node) {
nn := n.(*assign.Pow)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.PowEqualToken)
io.WriteString(p.w, "**=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignShiftLeft(n node.Node) {
nn := n.(*assign.ShiftLeft)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.SlEqualToken)
io.WriteString(p.w, "<<=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printAssignShiftRight(n node.Node) {
nn := n.(*assign.ShiftRight)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.SrEqualToken)
io.WriteString(p.w, ">>=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expression)
p.printMeta(nn, meta.NodeEnd)
}
// binary
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseAnd(n node.Node) {
nn := n.(*binary.BitwiseAnd)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.AmpersandToken)
io.WriteString(p.w, "&")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseOr(n node.Node) {
nn := n.(*binary.BitwiseOr)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.VerticalBarToken)
io.WriteString(p.w, "|")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBitwiseXor(n node.Node) {
nn := n.(*binary.BitwiseXor)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.CaretToken)
io.WriteString(p.w, "^")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBooleanAnd(n node.Node) {
nn := n.(*binary.BooleanAnd)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.BooleanAndToken)
io.WriteString(p.w, "&&")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryBooleanOr(n node.Node) {
nn := n.(*binary.BooleanOr)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.BooleanOrToken)
io.WriteString(p.w, "||")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryCoalesce(n node.Node) {
nn := n.(*binary.Coalesce)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.CoalesceToken)
io.WriteString(p.w, "??")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryConcat(n node.Node) {
nn := n.(*binary.Concat)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.DotToken)
io.WriteString(p.w, ".")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryDiv(n node.Node) {
nn := n.(*binary.Div)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.SlashToken)
io.WriteString(p.w, "/")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryEqual(n node.Node) {
nn := n.(*binary.Equal)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsEqualToken)
io.WriteString(p.w, "==")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryGreaterOrEqual(n node.Node) {
nn := n.(*binary.GreaterOrEqual)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsGreaterOrEqualToken)
io.WriteString(p.w, ">=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryGreater(n node.Node) {
nn := n.(*binary.Greater)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.GreaterToken)
io.WriteString(p.w, ">")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryIdentical(n node.Node) {
nn := n.(*binary.Identical)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsIdenticalToken)
io.WriteString(p.w, "===")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalAnd(n node.Node) {
nn := n.(*binary.LogicalAnd)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.LogicalAndToken)
io.WriteString(p.w, "and")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalOr(n node.Node) {
nn := n.(*binary.LogicalOr)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.LogicalOrToken)
io.WriteString(p.w, "or")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryLogicalXor(n node.Node) {
nn := n.(*binary.LogicalXor)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.LogicalXorToken)
io.WriteString(p.w, "xor")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMinus(n node.Node) {
nn := n.(*binary.Minus)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.MinusToken)
io.WriteString(p.w, "-")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMod(n node.Node) {
nn := n.(*binary.Mod)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.PercentToken)
io.WriteString(p.w, "%")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryMul(n node.Node) {
nn := n.(*binary.Mul)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.AsteriskToken)
io.WriteString(p.w, "*")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryNotEqual(n node.Node) {
nn := n.(*binary.NotEqual)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsNotEqualToken)
io.WriteString(p.w, "!=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryNotIdentical(n node.Node) {
nn := n.(*binary.NotIdentical)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsNotIdenticalToken)
io.WriteString(p.w, "!==")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryPlus(n node.Node) {
nn := n.(*binary.Plus)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.PlusToken)
io.WriteString(p.w, "+")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryPow(n node.Node) {
nn := n.(*binary.Pow)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.PowToken)
io.WriteString(p.w, "**")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryShiftLeft(n node.Node) {
nn := n.(*binary.ShiftLeft)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.SlToken)
io.WriteString(p.w, "<<")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinaryShiftRight(n node.Node) {
nn := n.(*binary.ShiftRight)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.SrToken)
io.WriteString(p.w, ">>")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySmallerOrEqual(n node.Node) {
nn := n.(*binary.SmallerOrEqual)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.IsSmallerOrEqualToken)
io.WriteString(p.w, "<=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySmaller(n node.Node) {
nn := n.(*binary.Smaller)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.LessToken)
io.WriteString(p.w, "<")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printBinarySpaceship(n node.Node) {
nn := n.(*binary.Spaceship)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Left)
p.printMeta(nn, meta.SpaceshipToken)
io.WriteString(p.w, "<=>")
2018-04-02 20:57:22 +00:00
p.Print(nn.Right)
p.printMeta(nn, meta.NodeEnd)
}
// cast
2018-04-05 08:59:29 +00:00
func (p *Printer) printArray(n node.Node) {
nn := n.(*cast.Array)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ArrayCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(array)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printBool(n node.Node) {
nn := n.(*cast.Bool)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.BoolCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(bool)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printDouble(n node.Node) {
nn := n.(*cast.Double)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DoubleCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(float)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printInt(n node.Node) {
nn := n.(*cast.Int)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IntCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(int)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printObject(n node.Node) {
nn := n.(*cast.Object)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ObjectCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(object)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printString(n node.Node) {
nn := n.(*cast.String)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.StringCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(string)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-05 08:59:29 +00:00
func (p *Printer) printUnset(n node.Node) {
nn := n.(*cast.Unset)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UnsetCastToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(unset)")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
// expr
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArrayDimFetch(n node.Node) {
nn := n.(*expr.ArrayDimFetch)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.OpenSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "[")
p.Print(nn.Dim)
p.printMeta(nn, meta.CloseSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "]")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArrayItem(n node.Node) {
nn := n.(*expr.ArrayItem)
p.printMeta(nn, meta.NodeStart)
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
p.printMeta(nn, meta.DoubleArrowToken)
io.WriteString(p.w, "=>")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Val)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprArray(n node.Node) {
nn := n.(*expr.Array)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ArrayToken)
io.WriteString(p.w, "array")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Items)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprBitwiseNot(n node.Node) {
nn := n.(*expr.BitwiseNot)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.TildeToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "~")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprBooleanNot(n node.Node) {
nn := n.(*expr.BooleanNot)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ExclamationMarkToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "!")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClassConstFetch(n node.Node) {
nn := n.(*expr.ClassConstFetch)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
p.printMeta(nn, meta.PaamayimNekudotayimToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "::")
p.Print(nn.ConstantName)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClone(n node.Node) {
nn := n.(*expr.Clone)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.CloneToken)
io.WriteString(p.w, "clone")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClosureUse(n node.Node) {
nn := n.(*expr.ClosureUse)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UseToken)
io.WriteString(p.w, "use")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Uses)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprClosure(n node.Node) {
nn := n.(*expr.Closure)
p.printMeta(nn, meta.NodeStart)
if nn.Static {
p.printMeta(nn, meta.StaticToken)
io.WriteString(p.w, "static")
}
p.printMeta(nn, meta.FunctionToken)
io.WriteString(p.w, "function")
if nn.ReturnsRef {
p.printMeta(nn, meta.AmpersandToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
p.printMeta(nn, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Params)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
if nn.ClosureUse != nil {
p.Print(nn.ClosureUse)
}
if nn.ReturnType != nil {
p.printMeta(nn.ReturnType, meta.ColonToken)
io.WriteString(p.w, ":")
2018-04-02 20:57:22 +00:00
p.Print(nn.ReturnType)
}
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprConstFetch(n node.Node) {
nn := n.(*expr.ConstFetch)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Constant)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprDie(n node.Node) {
nn := n.(*expr.Die)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ExitToken)
io.WriteString(p.w, "die")
p.printMeta(nn.Expr, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn.Expr, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprEmpty(n node.Node) {
nn := n.(*expr.Empty)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.EmptyToken)
io.WriteString(p.w, "empty")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprErrorSuppress(n node.Node) {
nn := n.(*expr.ErrorSuppress)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.AtToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "@")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprEval(n node.Node) {
nn := n.(*expr.Eval)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.EvalToken)
io.WriteString(p.w, "eval")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprExit(n node.Node) {
nn := n.(*expr.Exit)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ExitToken)
io.WriteString(p.w, "exit")
p.printMeta(nn.Expr, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn.Expr, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprFunctionCall(n node.Node) {
nn := n.(*expr.FunctionCall)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Function)
p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprInclude(n node.Node) {
nn := n.(*expr.Include)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IncludeToken)
io.WriteString(p.w, "include")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprIncludeOnce(n node.Node) {
nn := n.(*expr.IncludeOnce)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IncludeOnceToken)
io.WriteString(p.w, "include_once")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprInstanceOf(n node.Node) {
nn := n.(*expr.InstanceOf)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.InstanceofToken)
io.WriteString(p.w, "instanceof")
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprIsset(n node.Node) {
nn := n.(*expr.Isset)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IssetToken)
io.WriteString(p.w, "isset")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Variables)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprList(n node.Node) {
nn := n.(*expr.List)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ListToken)
io.WriteString(p.w, "list")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Items)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprMethodCall(n node.Node) {
nn := n.(*expr.MethodCall)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.ObjectOperatorToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "->")
p.Print(nn.Method)
p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprNew(n node.Node) {
nn := n.(*expr.New)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.NewToken)
io.WriteString(p.w, "new")
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
2018-04-29 16:58:49 +00:00
if nn.ArgumentList != nil {
p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPostDec(n node.Node) {
nn := n.(*expr.PostDec)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.DecToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "--")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPostInc(n node.Node) {
nn := n.(*expr.PostInc)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.IncToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "++")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPreDec(n node.Node) {
nn := n.(*expr.PreDec)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DecToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "--")
p.Print(nn.Variable)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPreInc(n node.Node) {
nn := n.(*expr.PreInc)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IncToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "++")
p.Print(nn.Variable)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPrint(n node.Node) {
nn := n.(*expr.Print)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.PrintToken)
io.WriteString(p.w, "print")
p.printMeta(nn.Expr, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn.Expr, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprPropertyFetch(n node.Node) {
nn := n.(*expr.PropertyFetch)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.ObjectOperatorToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "->")
p.Print(nn.Property)
p.printMeta(nn, meta.NodeEnd)
}
func (p *Printer) printExprReference(n node.Node) {
nn := n.(*expr.Reference)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.AmpersandToken)
io.WriteString(p.w, "&")
p.Print(nn.Variable)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprRequire(n node.Node) {
nn := n.(*expr.Require)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.RequireToken)
io.WriteString(p.w, "require")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprRequireOnce(n node.Node) {
nn := n.(*expr.RequireOnce)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.RequireOnceToken)
io.WriteString(p.w, "require_once")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShellExec(n node.Node) {
nn := n.(*expr.ShellExec)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.BackquoteToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "`")
for _, part := range nn.Parts {
switch part.(type) {
case *scalar.EncapsedStringPart:
p.Print(part)
default:
io.WriteString(p.w, "{")
p.Print(part)
2018-07-09 19:04:18 +00:00
p.printMeta(nn, meta.CloseCurlyBracesToken)
io.WriteString(p.w, "}")
}
}
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "`")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShortArray(n node.Node) {
nn := n.(*expr.ShortArray)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.OpenSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "[")
p.joinPrint(",", nn.Items)
p.printMeta(nn, meta.CloseSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "]")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprShortList(n node.Node) {
nn := n.(*expr.ShortList)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.OpenSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "[")
p.joinPrint(",", nn.Items)
p.printMeta(nn, meta.CloseSquareBracket)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "]")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprStaticCall(n node.Node) {
nn := n.(*expr.StaticCall)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
p.printMeta(nn, meta.PaamayimNekudotayimToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "::")
p.Print(nn.Call)
p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprStaticPropertyFetch(n node.Node) {
nn := n.(*expr.StaticPropertyFetch)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Class)
p.printMeta(nn, meta.PaamayimNekudotayimToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "::")
p.Print(nn.Property)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprTernary(n node.Node) {
nn := n.(*expr.Ternary)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Condition)
p.printMeta(nn, meta.QuestionMarkToken)
io.WriteString(p.w, "?")
if nn.IfTrue != nil {
p.Print(nn.IfTrue)
}
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
p.Print(nn.IfFalse)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprUnaryMinus(n node.Node) {
nn := n.(*expr.UnaryMinus)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.MinusToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "-")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprUnaryPlus(n node.Node) {
nn := n.(*expr.UnaryPlus)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.PlusToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "+")
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprVariable(n node.Node) {
nn := n.(*expr.Variable)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.VariableToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "$")
p.Print(nn.VarName)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprYieldFrom(n node.Node) {
nn := n.(*expr.YieldFrom)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.YieldFromToken)
io.WriteString(p.w, "yield from")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printExprYield(n node.Node) {
nn := n.(*expr.Yield)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.YieldToken)
io.WriteString(p.w, "yield")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
p.printMeta(nn, meta.DoubleArrowToken)
io.WriteString(p.w, "=>")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Value)
p.printMeta(nn, meta.NodeEnd)
}
// smtm
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltElseIf(n node.Node) {
nn := n.(*stmt.AltElseIf)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ElseifToken)
io.WriteString(p.w, "elseif")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 {
2018-04-02 20:57:22 +00:00
p.printNodes(s)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltElse(n node.Node) {
nn := n.(*stmt.AltElse)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ElseToken)
io.WriteString(p.w, "else")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
if s := nn.Stmt.(*stmt.StmtList).Stmts; len(s) > 0 {
2018-04-02 20:57:22 +00:00
p.printNodes(s)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltFor(n node.Node) {
nn := n.(*stmt.AltFor)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ForToken)
io.WriteString(p.w, "for")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Init)
p.printMeta(nn, meta.ForInitSemicolonToken)
io.WriteString(p.w, ";")
p.joinPrint(",", nn.Cond)
p.printMeta(nn, meta.ForCondSemicolonToken)
io.WriteString(p.w, ";")
p.joinPrint(",", nn.Loop)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
p.printMeta(nn, meta.EndforToken)
io.WriteString(p.w, "endfor")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltForeach(n node.Node) {
nn := n.(*stmt.AltForeach)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ForeachToken)
io.WriteString(p.w, "foreach")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.AsToken)
io.WriteString(p.w, "as")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
p.printMeta(nn, meta.DoubleArrowToken)
io.WriteString(p.w, "=>")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
p.printMeta(nn, meta.EndforeachToken)
io.WriteString(p.w, "endforeach")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltIf(n node.Node) {
nn := n.(*stmt.AltIf)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.IfToken)
io.WriteString(p.w, "if")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
for _, elseif := range nn.ElseIf {
2018-04-02 20:57:22 +00:00
p.Print(elseif)
}
if nn.Else != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Else)
}
p.printMeta(nn, meta.EndifToken)
io.WriteString(p.w, "endif")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltSwitch(n node.Node) {
nn := n.(*stmt.AltSwitch)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.SwitchToken)
io.WriteString(p.w, "switch")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
p.printMeta(nn, meta.SwitchSemicolonToken)
io.WriteString(p.w, ";")
2018-04-29 20:10:56 +00:00
s := nn.CaseList.Cases
2018-04-02 20:57:22 +00:00
p.printNodes(s)
p.printMeta(nn, meta.EndswitchToken)
io.WriteString(p.w, "endswitch")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtAltWhile(n node.Node) {
nn := n.(*stmt.AltWhile)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.WhileToken)
io.WriteString(p.w, "while")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.ColonToken)
io.WriteString(p.w, ":")
s := nn.Stmt.(*stmt.StmtList)
2018-04-02 20:57:22 +00:00
p.printNodes(s.Stmts)
p.printMeta(nn, meta.EndwhileToken)
io.WriteString(p.w, "endwhile")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtBreak(n node.Node) {
nn := n.(*stmt.Break)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.BreakToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "break")
if nn.Expr != nil {
p.printMeta(nn.Expr, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn.Expr, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
}
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtCase(n node.Node) {
nn := n.(*stmt.Case)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.CaseToken)
io.WriteString(p.w, "case")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CaseSeparatorToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ":")
if len(nn.Stmts) > 0 {
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtCatch(n node.Node) {
nn := n.(*stmt.Catch)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.CatchToken)
io.WriteString(p.w, "catch")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint("|", nn.Types)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClassMethod(n node.Node) {
nn := n.(*stmt.ClassMethod)
p.printMeta(nn, meta.NodeStart)
if nn.Modifiers != nil {
p.joinPrint("", nn.Modifiers)
}
p.printMeta(nn, meta.FunctionToken)
io.WriteString(p.w, "function")
if nn.ReturnsRef {
p.printMeta(nn, meta.AmpersandToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.MethodName)
p.printMeta(nn, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Params)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
if nn.ReturnType != nil {
p.printMeta(nn.ReturnType, meta.ColonToken)
io.WriteString(p.w, ":")
2018-04-02 20:57:22 +00:00
p.Print(nn.ReturnType)
}
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClass(n node.Node) {
2018-03-20 18:06:56 +00:00
nn := n.(*stmt.Class)
p.printMeta(nn, meta.NodeStart)
2018-03-20 18:06:56 +00:00
if nn.Modifiers != nil {
p.joinPrint("", nn.Modifiers)
2018-03-20 18:06:56 +00:00
}
p.printMeta(nn, meta.ClassToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "class")
2018-03-20 18:06:56 +00:00
if nn.ClassName != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.ClassName)
2018-03-20 18:06:56 +00:00
}
2018-04-29 16:58:49 +00:00
if nn.ArgumentList != nil {
p.printMeta(nn.ArgumentList, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.ArgumentList.Arguments)
p.printMeta(nn.ArgumentList, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
2018-03-20 18:06:56 +00:00
}
if nn.Extends != nil {
p.printMeta(nn.Extends, meta.ExtendsToken)
io.WriteString(p.w, "extends")
p.Print(nn.Extends.ClassName)
2018-03-20 18:06:56 +00:00
}
if nn.Implements != nil {
p.printMeta(nn.Implements, meta.ImplementsToken)
io.WriteString(p.w, "implements")
p.joinPrint(",", nn.Implements.InterfaceNames)
2018-03-20 18:06:56 +00:00
}
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
2018-03-20 18:06:56 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtClassConstList(n node.Node) {
2018-03-20 18:37:55 +00:00
nn := n.(*stmt.ClassConstList)
p.printMeta(nn, meta.NodeStart)
2018-03-20 18:37:55 +00:00
if nn.Modifiers != nil {
p.joinPrint("", nn.Modifiers)
2018-03-20 18:37:55 +00:00
}
p.printMeta(nn, meta.ConstToken)
io.WriteString(p.w, "const")
2018-03-20 18:37:55 +00:00
p.joinPrint(",", nn.Consts)
2018-03-20 18:37:55 +00:00
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtConstant(n node.Node) {
nn := n.(*stmt.Constant)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.ConstantName)
p.printMeta(nn, meta.EqualToken)
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtContinue(n node.Node) {
2018-03-20 18:37:55 +00:00
nn := n.(*stmt.Continue)
p.printMeta(nn, meta.NodeStart)
2018-03-20 18:37:55 +00:00
p.printMeta(nn, meta.ContinueToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "continue")
2018-03-20 18:37:55 +00:00
if nn.Expr != nil {
p.printMeta(nn.Expr, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn.Expr, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
2018-03-20 18:37:55 +00:00
}
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
2018-03-20 18:37:55 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDeclare(n node.Node) {
2018-03-28 20:44:02 +00:00
nn := n.(*stmt.Declare)
p.printMeta(nn, meta.NodeStart)
2018-03-28 20:44:02 +00:00
p.printMeta(nn, meta.DeclareToken)
io.WriteString(p.w, "declare")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Consts)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
2018-03-31 10:50:35 +00:00
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
2018-03-28 20:44:02 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDefault(n node.Node) {
2018-03-28 21:04:09 +00:00
nn := n.(*stmt.Default)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DefaultToken)
io.WriteString(p.w, "default")
p.printMeta(nn, meta.CaseSeparatorToken)
io.WriteString(p.w, ":")
if len(nn.Stmts) > 0 {
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
}
p.printMeta(nn, meta.NodeEnd)
2018-03-28 21:04:09 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtDo(n node.Node) {
2018-03-28 21:04:09 +00:00
nn := n.(*stmt.Do)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.DoToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "do")
2018-03-28 21:04:09 +00:00
p.Print(nn.Stmt)
p.printMeta(nn, meta.WhileToken)
io.WriteString(p.w, "while")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
2018-03-28 21:04:09 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtEcho(n node.Node) {
nn := n.(*stmt.Echo)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.EchoToken)
io.WriteString(p.w, "echo")
p.joinPrint(",", nn.Exprs)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtElseif(n node.Node) {
nn := n.(*stmt.ElseIf)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ElseifToken)
io.WriteString(p.w, "elseif")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtElse(n node.Node) {
nn := n.(*stmt.Else)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ElseToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "else")
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtExpression(n node.Node) {
nn := n.(*stmt.Expression)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-03-28 20:44:02 +00:00
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFinally(n node.Node) {
2018-03-31 11:17:05 +00:00
nn := n.(*stmt.Finally)
p.printMeta(nn, meta.NodeStart)
2018-03-31 11:17:05 +00:00
p.printMeta(nn, meta.FinallyToken)
io.WriteString(p.w, "finally")
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
2018-03-31 11:17:05 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFor(n node.Node) {
nn := n.(*stmt.For)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ForToken)
io.WriteString(p.w, "for")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Init)
p.printMeta(nn, meta.ForInitSemicolonToken)
io.WriteString(p.w, ";")
p.joinPrint(",", nn.Cond)
p.printMeta(nn, meta.ForCondSemicolonToken)
io.WriteString(p.w, ";")
p.joinPrint(",", nn.Loop)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtForeach(n node.Node) {
nn := n.(*stmt.Foreach)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ForeachToken)
io.WriteString(p.w, "foreach")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.AsToken)
io.WriteString(p.w, "as")
if nn.Key != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Key)
p.printMeta(nn, meta.DoubleArrowToken)
io.WriteString(p.w, "=>")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtFunction(n node.Node) {
nn := n.(*stmt.Function)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.FunctionToken)
io.WriteString(p.w, "function")
if nn.ReturnsRef {
p.printMeta(nn, meta.AmpersandToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "&")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.FunctionName)
p.printMeta(nn, meta.OpenParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Params)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
if nn.ReturnType != nil {
p.printMeta(nn.ReturnType, meta.ColonToken)
io.WriteString(p.w, ":")
2018-04-02 20:57:22 +00:00
p.Print(nn.ReturnType)
}
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGlobal(n node.Node) {
nn := n.(*stmt.Global)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.GlobalToken)
io.WriteString(p.w, "global")
p.joinPrint(",", nn.Vars)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGoto(n node.Node) {
nn := n.(*stmt.Goto)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.GotoToken)
io.WriteString(p.w, "goto")
2018-04-02 20:57:22 +00:00
p.Print(nn.Label)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtGroupUse(n node.Node) {
nn := n.(*stmt.GroupUse)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UseToken)
io.WriteString(p.w, "use")
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Prefix)
p.printMeta(nn, meta.NsSeparatorToken)
io.WriteString(p.w, "\\")
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
p.joinPrint(",", nn.UseList)
p.printMeta(nn, meta.CloseCurlyBracesToken)
io.WriteString(p.w, "}")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtHaltCompiler(n node.Node) {
nn := n.(*stmt.HaltCompiler)
p.printMeta(nn, meta.NodeStart)
p.printMeta(n, meta.HaltCompilerToken)
io.WriteString(p.w, "__halt_compiler")
p.printMeta(n, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.printMeta(n, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(n, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtIf(n node.Node) {
2018-04-01 14:07:07 +00:00
nn := n.(*stmt.If)
p.printMeta(nn, meta.NodeStart)
2018-04-01 14:07:07 +00:00
p.printMeta(n, meta.IfToken)
io.WriteString(p.w, "if")
p.printMeta(n, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(n, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
2018-04-01 14:07:07 +00:00
p.Print(nn.Stmt)
2018-04-01 14:07:07 +00:00
if nn.ElseIf != nil {
2018-04-02 20:57:22 +00:00
p.printNodes(nn.ElseIf)
2018-04-01 14:07:07 +00:00
}
if nn.Else != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Else)
2018-04-01 14:07:07 +00:00
}
p.printMeta(nn, meta.NodeEnd)
2018-04-01 14:07:07 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtInlineHTML(n node.Node) {
2018-04-01 14:07:07 +00:00
nn := n.(*stmt.InlineHtml)
p.printMeta(nn, meta.NodeStart)
2018-04-01 14:07:07 +00:00
p.printMeta(n, meta.InlineHTMLToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "?>")
io.WriteString(p.w, nn.Value)
io.WriteString(p.w, "<?php")
p.printMeta(nn, meta.NodeEnd)
2018-04-01 14:07:07 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtInterface(n node.Node) {
nn := n.(*stmt.Interface)
p.printMeta(nn, meta.NodeStart)
p.printMeta(n, meta.InterfaceToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "interface")
if nn.InterfaceName != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.InterfaceName)
}
if nn.Extends != nil {
p.printMeta(nn.Extends, meta.ExtendsToken)
io.WriteString(p.w, "extends")
p.joinPrint(",", nn.Extends.InterfaceNames)
}
p.printMeta(n, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(n, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtLabel(n node.Node) {
nn := n.(*stmt.Label)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.LabelName)
p.printMeta(n, meta.ColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ":")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtNamespace(n node.Node) {
nn := n.(*stmt.Namespace)
p.printMeta(nn, meta.NodeStart)
p.printMeta(n, meta.NamespaceToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, "namespace")
if nn.NamespaceName != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.NamespaceName)
}
if nn.Stmts != nil {
p.printMeta(n, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(n, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
} else {
p.printMeta(n, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtNop(n node.Node) {
p.printMeta(n, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
2018-03-31 11:17:05 +00:00
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtPropertyList(n node.Node) {
nn := n.(*stmt.PropertyList)
p.printMeta(nn, meta.NodeStart)
p.joinPrint("", nn.Modifiers)
p.joinPrint(",", nn.Properties)
p.printMeta(n, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
2018-03-31 11:17:05 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtProperty(n node.Node) {
nn := n.(*stmt.Property)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.Expr != nil {
p.printMeta(n, meta.EqualToken)
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtReturn(n node.Node) {
nn := n.(*stmt.Return)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ReturnToken)
io.WriteString(p.w, "return")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
2018-03-28 20:44:02 +00:00
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStaticVar(n node.Node) {
nn := n.(*stmt.StaticVar)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Variable)
if nn.Expr != nil {
p.printMeta(nn, meta.EqualToken)
io.WriteString(p.w, "=")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStatic(n node.Node) {
nn := n.(*stmt.Static)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.StaticToken)
io.WriteString(p.w, "static")
p.joinPrint(",", nn.Vars)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtStmtList(n node.Node) {
nn := n.(*stmt.StmtList)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtSwitch(n node.Node) {
nn := n.(*stmt.Switch)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.SwitchToken)
io.WriteString(p.w, "switch")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.printMeta(nn.CaseList, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-29 20:10:56 +00:00
p.printNodes(nn.CaseList.Cases)
p.printMeta(nn.CaseList, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtThrow(n node.Node) {
nn := n.(*stmt.Throw)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.ThrowToken)
io.WriteString(p.w, "throw")
2018-04-02 20:57:22 +00:00
p.Print(nn.Expr)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitMethodRef(n node.Node) {
nn := n.(*stmt.TraitMethodRef)
p.printMeta(nn, meta.NodeStart)
if nn.Trait != nil {
p.Print(nn.Trait)
p.printMeta(nn, meta.PaamayimNekudotayimToken)
io.WriteString(p.w, "::")
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Method)
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUseAlias(n node.Node) {
nn := n.(*stmt.TraitUseAlias)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Ref)
p.printMeta(nn, meta.AsToken)
io.WriteString(p.w, "as")
if nn.Modifier != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Modifier)
}
if nn.Alias != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Alias)
}
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUsePrecedence(n node.Node) {
nn := n.(*stmt.TraitUsePrecedence)
p.printMeta(nn, meta.NodeStart)
2018-04-02 20:57:22 +00:00
p.Print(nn.Ref)
p.printMeta(nn, meta.InsteadofToken)
io.WriteString(p.w, "insteadof")
p.joinPrint(",", nn.Insteadof)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTraitUse(n node.Node) {
nn := n.(*stmt.TraitUse)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UseToken)
io.WriteString(p.w, "use")
p.joinPrint(",", nn.Traits)
if adaptationList, ok := nn.TraitAdaptationList.(*stmt.TraitAdaptationList); ok {
p.printMeta(adaptationList, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
p.printNodes(adaptationList.Adaptations)
p.printMeta(adaptationList, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
} else {
p.printMeta(nn.TraitAdaptationList, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTrait(n node.Node) {
nn := n.(*stmt.Trait)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.TraitToken)
io.WriteString(p.w, "trait")
2018-04-02 20:57:22 +00:00
p.Print(nn.TraitName)
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtTry(n node.Node) {
nn := n.(*stmt.Try)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.TryToken)
io.WriteString(p.w, "try")
p.printMeta(nn, meta.OpenCurlyBracesToken)
io.WriteString(p.w, "{")
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Stmts)
p.printMeta(nn, meta.CloseCurlyBracesToken)
2018-04-03 16:20:55 +00:00
io.WriteString(p.w, "}")
if nn.Catches != nil {
2018-04-02 20:57:22 +00:00
p.printNodes(nn.Catches)
}
if nn.Finally != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.Finally)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUnset(n node.Node) {
nn := n.(*stmt.Unset)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UnsetToken)
io.WriteString(p.w, "unset")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
p.joinPrint(",", nn.Vars)
p.printMeta(nn, meta.CloseParenthesisToken)
io.WriteString(p.w, ")")
p.printMeta(nn, meta.SemiColonToken)
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUseList(n node.Node) {
nn := n.(*stmt.UseList)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.UseToken)
io.WriteString(p.w, "use")
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
}
p.joinPrint(",", nn.Uses)
p.printMeta(nn, meta.SemiColonToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ";")
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtUse(n node.Node) {
nn := n.(*stmt.Use)
p.printMeta(nn, meta.NodeStart)
if nn.UseType != nil {
2018-04-02 20:57:22 +00:00
p.Print(nn.UseType)
}
2018-04-02 20:57:22 +00:00
p.Print(nn.Use)
if nn.Alias != nil {
p.printMeta(nn, meta.AsToken)
io.WriteString(p.w, "as")
2018-04-02 20:57:22 +00:00
p.Print(nn.Alias)
}
p.printMeta(nn, meta.NodeEnd)
}
2018-04-02 20:57:22 +00:00
func (p *Printer) printStmtWhile(n node.Node) {
nn := n.(*stmt.While)
p.printMeta(nn, meta.NodeStart)
p.printMeta(nn, meta.WhileToken)
io.WriteString(p.w, "while")
p.printMeta(nn, meta.OpenParenthesisToken)
io.WriteString(p.w, "(")
2018-04-02 20:57:22 +00:00
p.Print(nn.Cond)
p.printMeta(nn, meta.CloseParenthesisToken)
2018-04-02 20:57:22 +00:00
io.WriteString(p.w, ")")
p.Print(nn.Stmt)
p.printMeta(nn, meta.NodeEnd)
}