<commit_before>package printing

import (
	"fmt"
	"strings"

	"stephensearles.com/php/ast"
)

type Walker struct {
	tabLevel int
	ast.DefaultWalker
}

func (w *Walker) Walk(node ast.Node) {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			fmt.Printf("%T - %+v\n", node, node)
			panic(r)
		}
	}()
	fmt.Printf("%s(%T)%s\n", strings.Repeat("\t", w.tabLevel), node, node.String())
	switch children := node.Children(); children {
	case nil:
	default:
		w.tabLevel += 1
		for _, child := range children {
			if child != nil {
				w.Walk(child)
			}
		}
		w.tabLevel -= 1
	}
}
<commit_msg>Allowing the printing module to be configured with any writer<commit_after>package printing

import (
	"fmt"
	"io"
	"os"
	"strings"

	"stephensearles.com/php/ast"
)

type Walker struct {
	tabLevel int
	ast.DefaultWalker
	W io.Writer
}

func NewWalker(w io.Writer) *Walker {
	return &Walker{W: os.Stdout}
}

func (w *Walker) Walk(node ast.Node) {
	defer func() {
		if r := recover(); r != nil {
			fmt.Println(r)
			fmt.Printf("%T - %+v\n", node, node)
			panic(r)
		}
	}()
	fmt.Fprintf(w.W, "%s(%T)%s\n", strings.Repeat("\t", w.tabLevel), node, node.String())
	switch children := node.Children(); children {
	case nil:
	default:
		w.tabLevel += 1
		for _, child := range children {
			if child != nil {
				w.Walk(child)
			}
		}
		w.tabLevel -= 1
	}
}

{'fraction_non_alphanumeric': 0.17551622418879056, 'fraction_numerical': 0.0029498525073746312, 'mean_word_length': 3.1753846153846155, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7559923', 'n_tokens_mistral': 589, 'n_tokens_neox': 540, 'n_words': 129}