Add String() method to parser.Tree

This commit is contained in:
2023-09-18 00:24:13 -04:00
parent 6df77d35fc
commit eb73b388d6

View File

@@ -1,6 +1,8 @@
package parser
import "io"
import "os"
import "fmt"
import "github.com/alecthomas/participle/v2"
var parser = participle.MustBuild[Tree] (
@@ -42,6 +44,14 @@ var parser = participle.MustBuild[Tree] (
type Tree struct {
Declarations []TopLevel `parser:" @@* "`
}
func (this *Tree) String () string {
out := ""
for index, declaration := range this.Declarations {
if index > 0 { out += "\n" }
out += fmt.Sprint(declaration)
}
return out
}
// Parse parses the contents of the given io.Reader into the tree.
func (this *Tree) Parse (name string, file io.Reader) error {