<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/json_tokens/read.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-07-19 11:57:59 +0100
commit8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b (patch)
tree7a16883c17c2bdcc49b2f9d4f333dfc76c66248f /json_tokens/read.go
parent3c34366bdd5d817a184d6b1c901d03a16b6faa4b (diff)
downloadstred-go-8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b.tar
Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing
Diffstat (limited to 'json_tokens/read.go')
-rw-r--r--json_tokens/read.go16
1 files changed, 8 insertions, 8 deletions
diff --git a/json_tokens/read.go b/json_tokens/read.go
index 95bbb9d..b0acf71 100644
--- a/json_tokens/read.go
+++ b/json_tokens/read.go
@@ -33,11 +33,11 @@ const (
)
type JSONIn struct {
- path []walk.Atom
+ path []walk.AtomOLD
reader *bufio.Reader
structure []JSONInStructure
state JSONInState
- readBuffer []walk.Atom
+ readBuffer []walk.AtomOLD
readIndex int
readBufferCapacity int
actionBuffer []ReadAction
@@ -46,11 +46,11 @@ type JSONIn struct {
func NewJSONIn(reader *bufio.Reader) *JSONIn {
return &JSONIn {
- path: make([]walk.Atom, 0, 256),
+ path: make([]walk.AtomOLD, 0, 256),
reader: reader,
structure: []JSONInStructure{},
state: JSONInValueStart,
- readBuffer: make([]walk.Atom, 0, 256),
+ readBuffer: make([]walk.AtomOLD, 0, 256),
readIndex: 0,
readBufferCapacity: 256,
actionBuffer: make([]ReadAction, 0, 256),
@@ -122,7 +122,7 @@ func (in *JSONIn) require(criterion rune) {
}
// Returns the first full value of a list of atoms and also a boolean to indicate if there isn't a value at the beginning
-func firstValue(atoms []walk.Atom) ([]walk.Atom, bool) {
+func firstValue(atoms []walk.AtomOLD) ([]walk.AtomOLD, bool) {
if len(atoms) == 0 {
return nil, true
}
@@ -141,12 +141,12 @@ func firstValue(atoms []walk.Atom) ([]walk.Atom, bool) {
}
}
-func (in *JSONIn) readValue() []walk.Atom {
+func (in *JSONIn) readValue() []walk.AtomOLD {
try:
value, incomplete := firstValue(in.readBuffer[in.readIndex:])
if incomplete {
if in.readIndex == 0 {
- newReadBuffer := make([]walk.Atom, len(in.readBuffer), in.readBufferCapacity * 2)
+ newReadBuffer := make([]walk.AtomOLD, len(in.readBuffer), in.readBufferCapacity * 2)
in.readBufferCapacity *= 2
copy(newReadBuffer, in.readBuffer)
in.readBuffer = newReadBuffer
@@ -216,7 +216,7 @@ func (in *JSONIn) AssertDone() {
}
}
-func (in *JSONIn) pushReadBuffer(atom walk.Atom) bool {
+func (in *JSONIn) pushReadBuffer(atom walk.AtomOLD) bool {
in.readBuffer = append(in.readBuffer, atom)
return len(in.readBuffer) == in.readBufferCapacity
}