pretty printer: print Continue
This commit is contained in:
parent
cbc46cb612
commit
685b7b25bd
@ -290,15 +290,17 @@ func getPrintFuncByNode(n node.Node) func(o io.Writer, n node.Node) {
|
|||||||
return printStmtCase
|
return printStmtCase
|
||||||
case *stmt.Catch:
|
case *stmt.Catch:
|
||||||
return printStmtCatch
|
return printStmtCatch
|
||||||
case *stmt.ClassConstList:
|
|
||||||
return printStmtClassConstList
|
|
||||||
case *stmt.ClassMethod:
|
case *stmt.ClassMethod:
|
||||||
return printStmtClassMethod
|
return printStmtClassMethod
|
||||||
case *stmt.Class:
|
case *stmt.Class:
|
||||||
return printStmtClass
|
return printStmtClass
|
||||||
|
case *stmt.ClassConstList:
|
||||||
|
return printStmtClassConstList
|
||||||
case *stmt.Constant:
|
case *stmt.Constant:
|
||||||
return printStmtConstant
|
return printStmtConstant
|
||||||
|
case *stmt.Continue:
|
||||||
|
return printStmtContinue
|
||||||
|
|
||||||
case *stmt.StmtList:
|
case *stmt.StmtList:
|
||||||
return printStmtStmtList
|
return printStmtStmtList
|
||||||
case *stmt.Expression:
|
case *stmt.Expression:
|
||||||
@ -1326,20 +1328,6 @@ func printStmtCatch(o io.Writer, n node.Node) {
|
|||||||
io.WriteString(o, "}\n")
|
io.WriteString(o, "}\n")
|
||||||
}
|
}
|
||||||
|
|
||||||
func printStmtClassConstList(o io.Writer, n node.Node) {
|
|
||||||
nn := n.(*stmt.ClassConstList)
|
|
||||||
|
|
||||||
if nn.Modifiers != nil {
|
|
||||||
joinPrint(" ", o, nn.Modifiers)
|
|
||||||
io.WriteString(o, " ")
|
|
||||||
}
|
|
||||||
io.WriteString(o, "const ")
|
|
||||||
|
|
||||||
joinPrint(", ", o, nn.Consts)
|
|
||||||
|
|
||||||
io.WriteString(o, ";\n")
|
|
||||||
}
|
|
||||||
|
|
||||||
func printStmtClassMethod(o io.Writer, n node.Node) {
|
func printStmtClassMethod(o io.Writer, n node.Node) {
|
||||||
nn := n.(*stmt.ClassMethod)
|
nn := n.(*stmt.ClassMethod)
|
||||||
|
|
||||||
@ -1403,6 +1391,20 @@ func printStmtClass(o io.Writer, n node.Node) {
|
|||||||
io.WriteString(o, "}\n") // TODO: handle indentation
|
io.WriteString(o, "}\n") // TODO: handle indentation
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printStmtClassConstList(o io.Writer, n node.Node) {
|
||||||
|
nn := n.(*stmt.ClassConstList)
|
||||||
|
|
||||||
|
if nn.Modifiers != nil {
|
||||||
|
joinPrint(" ", o, nn.Modifiers)
|
||||||
|
io.WriteString(o, " ")
|
||||||
|
}
|
||||||
|
io.WriteString(o, "const ")
|
||||||
|
|
||||||
|
joinPrint(", ", o, nn.Consts)
|
||||||
|
|
||||||
|
io.WriteString(o, ";\n")
|
||||||
|
}
|
||||||
|
|
||||||
func printStmtConstant(o io.Writer, n node.Node) {
|
func printStmtConstant(o io.Writer, n node.Node) {
|
||||||
nn := n.(*stmt.Constant)
|
nn := n.(*stmt.Constant)
|
||||||
|
|
||||||
@ -1411,6 +1413,18 @@ func printStmtConstant(o io.Writer, n node.Node) {
|
|||||||
Print(o, nn.Expr)
|
Print(o, nn.Expr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func printStmtContinue(o io.Writer, n node.Node) {
|
||||||
|
nn := n.(*stmt.Continue)
|
||||||
|
|
||||||
|
io.WriteString(o, "continue")
|
||||||
|
if nn.Expr != nil {
|
||||||
|
io.WriteString(o, " ")
|
||||||
|
Print(o, nn.Expr)
|
||||||
|
}
|
||||||
|
|
||||||
|
io.WriteString(o, ";\n")
|
||||||
|
}
|
||||||
|
|
||||||
func printStmtStmtList(o io.Writer, n node.Node) {
|
func printStmtStmtList(o io.Writer, n node.Node) {
|
||||||
nn := n.(*stmt.StmtList)
|
nn := n.(*stmt.StmtList)
|
||||||
|
|
||||||
|
@ -2087,31 +2087,6 @@ $a;
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestPrintStmtClassConstList(t *testing.T) {
|
|
||||||
o := bytes.NewBufferString("")
|
|
||||||
|
|
||||||
printer.Print(o, &stmt.ClassConstList{
|
|
||||||
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
|
||||||
Consts: []node.Node{
|
|
||||||
&stmt.Constant{
|
|
||||||
ConstantName: &node.Identifier{Value: "FOO"},
|
|
||||||
Expr: &scalar.String{Value: "a"},
|
|
||||||
},
|
|
||||||
&stmt.Constant{
|
|
||||||
ConstantName: &node.Identifier{Value: "BAR"},
|
|
||||||
Expr: &scalar.String{Value: "b"},
|
|
||||||
},
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
expected := "public const FOO = 'a', BAR = 'b';\n"
|
|
||||||
actual := o.String()
|
|
||||||
|
|
||||||
if expected != actual {
|
|
||||||
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func TestPrintStmtClassMethod(t *testing.T) {
|
func TestPrintStmtClassMethod(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
@ -2228,6 +2203,31 @@ public const FOO = 'bar';
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintStmtClassConstList(t *testing.T) {
|
||||||
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
printer.Print(o, &stmt.ClassConstList{
|
||||||
|
Modifiers: []node.Node{&node.Identifier{Value: "public"}},
|
||||||
|
Consts: []node.Node{
|
||||||
|
&stmt.Constant{
|
||||||
|
ConstantName: &node.Identifier{Value: "FOO"},
|
||||||
|
Expr: &scalar.String{Value: "a"},
|
||||||
|
},
|
||||||
|
&stmt.Constant{
|
||||||
|
ConstantName: &node.Identifier{Value: "BAR"},
|
||||||
|
Expr: &scalar.String{Value: "b"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
expected := "public const FOO = 'a', BAR = 'b';\n"
|
||||||
|
actual := o.String()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrintStmtConstant(t *testing.T) {
|
func TestPrintStmtConstant(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
@ -2244,6 +2244,21 @@ func TestPrintStmtConstant(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPrintStmtContinue(t *testing.T) {
|
||||||
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
printer.Print(o, &stmt.Continue{
|
||||||
|
Expr: &scalar.Lnumber{Value: "1"},
|
||||||
|
})
|
||||||
|
|
||||||
|
expected := "continue 1;\n"
|
||||||
|
actual := o.String()
|
||||||
|
|
||||||
|
if expected != actual {
|
||||||
|
t.Errorf("\nexpected: %s\ngot: %s\n", expected, actual)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPrintStmtList(t *testing.T) {
|
func TestPrintStmtList(t *testing.T) {
|
||||||
o := bytes.NewBufferString("")
|
o := bytes.NewBufferString("")
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user