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 { if err != nil {
t.Errorf("Parse(%q) returns bad parse tree: %v", tc.src, err) t.Errorf("Parse(%q) returns bad parse tree: %v", tc.src, err)
fmt.Fprintf(os.Stderr, "Parse tree of %q:\n", tc.src) fmt.Fprintf(os.Stderr, "Parse tree of %q:\n", tc.src)
PPrintParseTreeTo(bn, os.Stderr) PPrintParseTree(bn, os.Stderr)
} }
err = checkAST(bn, tc.ast) err = checkAST(bn, tc.ast)
if err != nil { if err != nil {
t.Errorf("Parse(%q) returns bad AST: %v", tc.src, err) t.Errorf("Parse(%q) returns bad AST: %v", tc.src, err)
fmt.Fprintf(os.Stderr, "AST of %q:\n", tc.src) 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 package parse
import ( import (
"bytes"
"fmt" "fmt"
"io" "io"
"reflect" "reflect"
@ -14,16 +13,9 @@ const (
indentInc = 2 indentInc = 2
) )
// PPrintAST pretty-prints the AST part of a Node. // PPrintAST pretty-prints the AST part of a Node to a Writer.
func PPrintAST(n Node) string { func PPrintAST(n Node, w io.Writer) {
var b bytes.Buffer pprintAST(n, w, 0, "")
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, "")
} }
type field struct { 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. // PPrintParseTree pretty-prints the parse tree part of a Node to a Writer.
func PPrintParseTree(n Node) string { func PPrintParseTree(n Node, w io.Writer) {
var b bytes.Buffer pprintParseTree(n, w, 0)
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)
} }
func pprintParseTree(n Node, wr io.Writer, indent int) { func pprintParseTree(n Node, wr io.Writer, indent int) {

View File

@ -1,6 +1,7 @@
package parse package parse
import ( import (
"strings"
"testing" "testing"
"github.com/elves/elvish/tt" "github.com/elves/elvish/tt"
@ -25,7 +26,11 @@ var pprintASTTests = tt.Table{
} }
func TestPPrintAST(t *testing.T) { 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{ var pprintParseTreeTests = tt.Table{
@ -51,7 +56,11 @@ var pprintParseTreeTests = tt.Table{
} }
func TestPprintParseTree(t *testing.T) { 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 { func mustParse(src string) Node {