mirror of
https://github.com/rwxrob/bonzai
synced 2024-11-16 21:25:44 +00:00
Add node.go
This commit is contained in:
parent
78a8a6fb65
commit
3307393f1a
31
scan/node.go
Normal file
31
scan/node.go
Normal 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()) }
|
Loading…
Reference in New Issue
Block a user