Add String() method to parser.Tree
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user