summaryrefslogtreecommitdiff
path: root/decode_scan.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-26 00:07:39 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-26 00:08:56 -0700
commit4148776399cb7ea5e10c74dc465e4e1e682cb399 (patch)
treedaf8a3aa6521d3d56aa986f10c3d23ea1b016f4b /decode_scan.go
parente483afa206686ce748ad270140f99fad9d713aad (diff)
Move the Parser to the internal package
Diffstat (limited to 'decode_scan.go')
-rw-r--r--decode_scan.go44
1 files changed, 23 insertions, 21 deletions
diff --git a/decode_scan.go b/decode_scan.go
index eee61fc..5e33760 100644
--- a/decode_scan.go
+++ b/decode_scan.go
@@ -1,4 +1,4 @@
-// Copyright (C) 2022 Luke Shumaker <lukeshu@lukeshu.com>
+// Copyright (C) 2022-2023 Luke Shumaker <lukeshu@lukeshu.com>
//
// SPDX-License-Identifier: GPL-2.0-or-later
@@ -7,6 +7,8 @@ package lowmemjson
import (
"errors"
"io"
+
+ "git.lukeshu.com/go/lowmemjson/internal"
)
type runeTypeScanner interface {
@@ -17,7 +19,7 @@ type runeTypeScanner interface {
// end of both value and file: (_, 0, RuneTypeEOF, nil)
// end of file in middle of value: (_, 0, RuneTypeError, &DecodeSyntaxError{Offset: offset: Err: io.ErrUnexepctedEOF})
// end of file at start of value: (_, 0, RuneTypeError, &DecodeSyntaxError{Offset: offset: Err: io.EOF})
- ReadRuneType() (rune, int, RuneType, error)
+ ReadRuneType() (rune, int, internal.RuneType, error)
// The returned error is a *DecodeReadError, a *DecodeSyntaxError, io.EOF, or nil.
ReadRune() (rune, int, error)
UnreadRune() error
@@ -32,7 +34,7 @@ type runeTypeScannerImpl struct {
initialized bool
- parser Parser
+ parser internal.Parser
offset int64
repeat bool
@@ -40,7 +42,7 @@ type runeTypeScannerImpl struct {
rRune rune
rRuneOK bool
rSize int
- rType RuneType
+ rType internal.RuneType
rErr error
}
@@ -48,7 +50,7 @@ var _ runeTypeScanner = (*runeTypeScannerImpl)(nil)
func (sc *runeTypeScannerImpl) Reset() {
sc.parser.Reset()
- unread := sc.stuck && sc.rType == RuneTypeEOF && sc.rRuneOK
+ unread := sc.stuck && sc.rType == internal.RuneTypeEOF && sc.rRuneOK
sc.stuck = false
sc.repeat = false
if unread {
@@ -68,7 +70,7 @@ func (sc *runeTypeScannerImpl) Reset() {
}
}
-func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) {
+func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, internal.RuneType, error) {
switch {
case sc.stuck:
// do nothing
@@ -110,16 +112,16 @@ func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) {
}
sc.initialized = true
sc.repeat = false
- sc.stuck = sc.rType == RuneTypeEOF || sc.rType == RuneTypeError
+ sc.stuck = sc.rType == internal.RuneTypeEOF || sc.rType == internal.RuneTypeError
return sc.rRune, sc.rSize, sc.rType, sc.rErr
}
func (sc *runeTypeScannerImpl) ReadRune() (rune, int, error) {
r, s, t, e := sc.ReadRuneType()
switch t {
- case RuneTypeEOF:
+ case internal.RuneTypeEOF:
return 0, 0, io.EOF
- case RuneTypeError:
+ case internal.RuneTypeError:
return 0, 0, e
default:
return r, s, nil
@@ -156,10 +158,10 @@ type noWSRuneTypeScanner struct {
var _ runeTypeScanner = (*noWSRuneTypeScanner)(nil)
-func (sc *noWSRuneTypeScanner) ReadRuneType() (rune, int, RuneType, error) {
+func (sc *noWSRuneTypeScanner) ReadRuneType() (rune, int, internal.RuneType, error) {
again:
r, s, t, e := sc.inner.ReadRuneType()
- if t == RuneTypeSpace {
+ if t == internal.RuneTypeSpace {
goto again
}
return r, s, t, e
@@ -168,9 +170,9 @@ again:
func (sc *noWSRuneTypeScanner) ReadRune() (rune, int, error) {
r, s, t, e := sc.ReadRuneType()
switch t {
- case RuneTypeEOF:
+ case internal.RuneTypeEOF:
return 0, 0, io.EOF
- case RuneTypeError:
+ case internal.RuneTypeError:
return 0, 0, e
default:
return r, s, nil
@@ -186,16 +188,16 @@ func (sc *noWSRuneTypeScanner) InputOffset() int64 { return sc.inner.InputOffset
type elemRuneTypeScanner struct {
inner runeTypeScanner
- parser Parser
+ parser internal.Parser
repeat bool
stuck bool
- rType RuneType
+ rType internal.RuneType
rErr error
}
var _ runeTypeScanner = (*elemRuneTypeScanner)(nil)
-func (sc *elemRuneTypeScanner) ReadRuneType() (rune, int, RuneType, error) {
+func (sc *elemRuneTypeScanner) ReadRuneType() (rune, int, internal.RuneType, error) {
// Read it, run it through the parent's parser.
r, s, t, e := sc.inner.ReadRuneType()
@@ -219,16 +221,16 @@ func (sc *elemRuneTypeScanner) ReadRuneType() (rune, int, RuneType, error) {
sc.rErr = nil
}
}
- sc.stuck = sc.rType == RuneTypeEOF || sc.rType == RuneTypeError
+ sc.stuck = sc.rType == internal.RuneTypeEOF || sc.rType == internal.RuneTypeError
t, e = sc.rType, sc.rErr
}
// Check if we need to truncate the result.
- if t == RuneTypeEOF {
+ if t == internal.RuneTypeEOF {
if s > 0 {
_ = sc.inner.UnreadRune()
}
- return 0, 0, RuneTypeEOF, nil
+ return 0, 0, internal.RuneTypeEOF, nil
}
return r, s, t, e
@@ -237,9 +239,9 @@ func (sc *elemRuneTypeScanner) ReadRuneType() (rune, int, RuneType, error) {
func (sc *elemRuneTypeScanner) ReadRune() (rune, int, error) {
r, s, t, e := sc.ReadRuneType()
switch t {
- case RuneTypeEOF:
+ case internal.RuneTypeEOF:
return 0, 0, io.EOF
- case RuneTypeError:
+ case internal.RuneTypeError:
return 0, 0, e
default:
return r, s, nil