<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk/walk.go
diff options
context:
space:
mode:
Diffstat (limited to 'walk/walk.go')
-rw-r--r--walk/walk.go31
1 files changed, 31 insertions, 0 deletions
diff --git a/walk/walk.go b/walk/walk.go
index 64f16ac..cc17245 100644
--- a/walk/walk.go
+++ b/walk/walk.go
@@ -5,10 +5,41 @@ import (
"encoding/json"
"fmt"
"strings"
+ "math"
)
+// int or string
type PathSegment interface {}
type Path []PathSegment
+func (path Path) ToWalkValues() []WalkValue {
+ var values []WalkValue
+ for _, segment := range path {
+ switch s := segment.(type) {
+ case int:
+ values = append(values, ValueNumber(s))
+ case string:
+ values = append(values, ValueString(s))
+ default:
+ panic("Invalid PathSegment")
+ }
+ }
+ return values
+}
+
+func PathFromWalkValues(values []WalkValue) Path {
+ var segments []PathSegment
+ for _, value := range values {
+ switch v := value.(type) {
+ case ValueNumber:
+ segments = append(segments, int(math.Round(float64(v))))
+ case ValueString:
+ segments = append(segments, string(v))
+ default:
+ panic("Invalid value in path")
+ }
+ }
+ return segments
+}
type TerminalValue int
const (