parse: Remove PPrint{AST,ParseTree}.

PPrint{AST,ParseTree}To have been renamed to PPrint{AST,ParseTree}.
This commit is contained in:
Qi Xiao 2018-10-13 00:54:33 +08:00
parent 931200b1ce
commit fe234ca3ce
3 changed files with 19 additions and 25 deletions

View File

@ -245,13 +245,13 @@ func TestParse(t *testing.T) {
if err != nil {
t.Errorf("Parse(%q) returns bad parse tree: %v", tc.src, err)
fmt.Fprintf(os.Stderr, "Parse tree of %q:\n", tc.src)
PPrintParseTreeTo(bn, os.Stderr)
PPrintParseTree(bn, os.Stderr)
}
err = checkAST(bn, tc.ast)
if err != nil {
t.Errorf("Parse(%q) returns bad AST: %v", tc.src, err)
fmt.Fprintf(os.Stderr, "AST of %q:\n", tc.src)
PPrintASTTo(bn, os.Stderr)
PPrintAST(bn, os.Stderr)
}
}
}

View File

@ -1,7 +1,6 @@
package parse
import (
"bytes"
"fmt"
"io"
"reflect"
@ -14,16 +13,9 @@ const (
indentInc = 2
)
// PPrintAST pretty-prints the AST part of a Node.
func PPrintAST(n Node) string {
var b bytes.Buffer
PPrintASTTo(n, &b)
return b.String()
}
// PPrintASTTo pretty-prints the AST part of a Node to a Writer.
func PPrintASTTo(n Node, wr io.Writer) {
pprintAST(n, wr, 0, "")
// PPrintAST pretty-prints the AST part of a Node to a Writer.
func PPrintAST(n Node, w io.Writer) {
pprintAST(n, w, 0, "")
}
type field struct {
@ -114,16 +106,9 @@ func pprintAST(n Node, wr io.Writer, indent int, leading string) {
}
}
// PPrintParseTree pretty-prints the parse tree part of a Node.
func PPrintParseTree(n Node) string {
var b bytes.Buffer
PPrintParseTreeTo(n, &b)
return b.String()
}
// PPrintParseTreeTo pretty-prints the parse tree part of a Node to a Writer.
func PPrintParseTreeTo(n Node, wr io.Writer) {
pprintParseTree(n, wr, 0)
// PPrintParseTree pretty-prints the parse tree part of a Node to a Writer.
func PPrintParseTree(n Node, w io.Writer) {
pprintParseTree(n, w, 0)
}
func pprintParseTree(n Node, wr io.Writer, indent int) {

View File

@ -1,6 +1,7 @@
package parse
import (
"strings"
"testing"
"github.com/elves/elvish/tt"
@ -25,7 +26,11 @@ var pprintASTTests = tt.Table{
}
func TestPPrintAST(t *testing.T) {
tt.Test(t, tt.Fn("PPrintAST", PPrintAST), pprintASTTests)
tt.Test(t, tt.Fn("PPrintAST (to string)", func(n Node) string {
var b strings.Builder
PPrintAST(n, &b)
return b.String()
}), pprintASTTests)
}
var pprintParseTreeTests = tt.Table{
@ -51,7 +56,11 @@ var pprintParseTreeTests = tt.Table{
}
func TestPprintParseTree(t *testing.T) {
tt.Test(t, tt.Fn("PPrintParseTree", PPrintParseTree), pprintParseTreeTests)
tt.Test(t, tt.Fn("PPrintParseTree (to string)", func(n Node) string {
var b strings.Builder
PPrintParseTree(n, &b)
return b.String()
}), pprintParseTreeTests)
}
func mustParse(src string) Node {