From 8cf10efe3b5a1bcc70bc6e5590ee63fd5eb00c5b Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 19 Jul 2023 11:57:59 +0100 Subject: Huge refactor to a more value based system, doing away with terminals. Also introduces unit testing --- json_tokens/read.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'json_tokens/read.go') 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 } -- cgit v1.2.3