<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/walk/walk.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 12:16:39 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 12:16:39 +0100
commitac153f2b90b966baaf132a487514ae2194a64dd5 (patch)
tree39f63785de58ce4f6d8055847d5f0efa54d9499b /walk/walk.go
parent7d53110f2773ba758dea2f5c00483d879d378870 (diff)
downloadstred-go-ac153f2b90b966baaf132a487514ae2194a64dd5.tar
Removes lots of old atom based code from walk
Diffstat (limited to 'walk/walk.go')
-rw-r--r--walk/walk.go152
1 files changed, 0 insertions, 152 deletions
diff --git a/walk/walk.go b/walk/walk.go
index 65fac6e..aca6a8c 100644
--- a/walk/walk.go
+++ b/walk/walk.go
@@ -2,7 +2,6 @@ package walk
import (
"fmt"
- "math"
"strings"
"unicode/utf8"
)
@@ -221,40 +220,6 @@ func (_ MapEndTerminal) edible() {}
func (_ MapEndTerminal) atom() {}
func (_ MapEndTerminal) terminal() {}
-// int or string
-type PathSegment interface {}
-
-type Path []PathSegment
-func (path Path) ToWalkValues() []ValueOLD {
- var values []ValueOLD
- 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 []ValueOLD) 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 WalkItem struct {
Value ValueList
Path ValueList
@@ -277,120 +242,3 @@ func (item WalkItem) Debug() string {
}
return builder.String()
}
-
-func ConcatData(first []AtomOLD, second []AtomOLD) []AtomOLD {
- res := make([]AtomOLD, 0, len(first) + len(second))
- res = append(res, first...)
- res = append(res, second...)
- return res
-}
-
-func Atomise(in []ValueOLD) (out []AtomOLD) {
- numAtoms := 0
- for _, value := range in {
- switch v := value.(type) {
- case ValueTerminal, ValueNull, ValueBool, ValueNumber:
- numAtoms++
- case ValueString:
- numAtoms += utf8.RuneCountInString(string(v)) + 2
- default:
- panic("Invalid WalkValue")
- }
- }
- out = make([]AtomOLD, 0, numAtoms)
- for _, value := range in {
- out = value.Atomise(out)
- }
- return out
-}
-
-type CompoundError int
-
-const (
- CompoundRuneOutsideString CompoundError = iota
- CompoundUnknownAtom
- CompoundMissingEnd
- CompoundInvalidStringAtom
-)
-
-func (err CompoundError) Error() string {
- switch err {
- case CompoundRuneOutsideString:
- return "Compound Error: Rune Outside String"
- case CompoundUnknownAtom:
- return "Compound Error: Unknown Atom"
- case CompoundMissingEnd:
- return "Compound Error: Missing End"
- case CompoundInvalidStringAtom:
- return "Compound Error: Invalid String Atom"
- default:
- panic("Invalid CompoundError")
- }
-}
-
-type CompoundResult struct {
- value ValueOLD
- error error
-}
-
-func Compound(in []AtomOLD) (out []ValueOLD, error error) {
- numValues := 0
- i := 0
- inString := false
- for _, atom := range in {
- switch atom.Typ {
- case AtomNull, AtomBool, AtomNumber, AtomTerminal:
- if !inString {
- numValues++
- }
- case AtomStringTerminal:
- if inString {
- numValues++
- }
- inString = !inString
- }
- }
- i = 0
- out = make([]ValueOLD, 0, numValues)
- for {
- if i >= len(in) {
- break
- }
- atom := in[i]
- i++
- switch atom.Typ {
- case AtomNull:
- out = append(out, ValueNull{})
- continue
- case AtomBool:
- out = append(out, ValueBool(atom.data != 0))
- continue
- case AtomNumber:
- out = append(out, ValueNumber(math.Float64frombits(atom.data)))
- continue
- case AtomTerminal:
- out = append(out, ValueTerminal(atom.data))
- continue
- case AtomStringRune:
- return nil, CompoundRuneOutsideString
- case AtomStringTerminal:
- default:
- return nil, CompoundUnknownAtom
- }
- // Handle string start
- var builder strings.Builder
- for {
- if i >= len(in) {
- return nil, CompoundMissingEnd
- }
- atom := in[i]
- i++
- if atom.Typ == AtomStringTerminal {
- break
- }
- builder.WriteString(atom.String())
- }
- out = append(out, ValueString(builder.String()))
- }
- return out, nil
-}