diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-26 08:57:32 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-26 08:57:32 +0000 |
commit | 9ba3b1d97e8fd2a2e3c4bb08fe350c8dd5f9733e (patch) | |
tree | 9969939626ef40adb02631d919795bb40cc30e69 /walk/walk.go | |
parent | a2636b27fdadb2b7951fa35fe301e8e6b41fc28a (diff) | |
download | stred-go-9ba3b1d97e8fd2a2e3c4bb08fe350c8dd5f9733e.tar |
Converts subex output back into WalkValues and prints for easier debugging
Diffstat (limited to 'walk/walk.go')
-rw-r--r-- | walk/walk.go | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/walk/walk.go b/walk/walk.go index 1df7a6e..30bfb29 100644 --- a/walk/walk.go +++ b/walk/walk.go @@ -19,19 +19,47 @@ const ( func (value TerminalValue) Pieces(out chan<- Datum) { out<-value } +func (value TerminalValue) String() string { + switch value { + case ArrayBegin: + return "[" + case ArrayEnd: + return "]" + case MapBegin: + return "{" + case MapEnd: + return "}" + default: + panic("Unknown TerminalValue") + } +} type ValueNull struct {} func (value ValueNull) Pieces(out chan<- Datum) { out<-value } +func (value ValueNull) String() string { + return "null" +} type ValueBool bool func (value ValueBool) Pieces(out chan<- Datum) { out<-value } +func (value ValueBool) String() string { + if value { + return "true" + } else { + return "false" + } +} type ValueNumber float64 func (value ValueNumber) Pieces(out chan<- Datum) { out<-value } +func (value ValueNumber) String() string { + v := float64(value) + return fmt.Sprintf("%f", v) +} type StartString struct {} type EndString struct {} @@ -43,11 +71,15 @@ func (value ValueString) Pieces(out chan<- Datum) { } out<-EndString{} } +func (value ValueString) String() string { + return fmt.Sprintf("\"%s\"", string(value)) +} type Datum interface {} type WalkValue interface { Pieces(out chan<- Datum) + String() string } type WalkItem struct { |