diff options
Diffstat (limited to 'walk')
| -rw-r--r-- | walk/walk.go | 31 | 
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 ( | 
