Add node.go

This commit is contained in:
rwxrob 2022-03-04 21:22:06 -05:00
parent 78a8a6fb65
commit 3307393f1a
No known key found for this signature in database
GPG Key ID: 2B9111F33082AE77

31
scan/node.go Normal file
View File

@ -0,0 +1,31 @@
package scan
import (
"encoding/json"
"fmt"
"log"
)
// Node structs are for use with bonzai/scan.R and compliment those from
// bonzai/tree. They are simply lighter and optimized for quick parsing
// during the scan process with scan.R.Parse and the z.P Expect
// expression.
type Node struct {
T string `json:",omitempty"` // type
V string `json:",omitempty"` // type
U []*Node `json:",omitempty"` // type
}
// ---------------------------- PrintAsJSON ---------------------------
// JSON implements PrintAsJSON multi-line, 2-space indent JSON output.
func (s *Node) JSON() string { b, _ := json.Marshal(s); return string(b) }
// String implements PrintAsJSON and fmt.Stringer interface as JSON.
func (s Node) String() string { return s.JSON() }
// Print implements PrintAsJSON.
func (s *Node) Print() { fmt.Println(s.JSON()) }
// Log implements PrintAsJSON.
func (s Node) Log() { log.Print(s.JSON()) }