summaryrefslogtreecommitdiff
path: root/decode_scan.go
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@datawire.io>2022-08-16 00:15:57 -0600
committerLuke Shumaker <lukeshu@datawire.io>2022-08-16 02:08:39 -0600
commit8c0513a04ff3870f57bde230507aaa8c6b7e6e86 (patch)
tree4e9c8082bb9168c923eee2c6bd17f01e44206f0a /decode_scan.go
parent83ec1924ae051b60f911aa8b53b741c5371faaf8 (diff)
Get borrowed_decode_test.go passing
Diffstat (limited to 'decode_scan.go')
-rw-r--r--decode_scan.go30
1 files changed, 24 insertions, 6 deletions
diff --git a/decode_scan.go b/decode_scan.go
index 3c41df6..fee9ec6 100644
--- a/decode_scan.go
+++ b/decode_scan.go
@@ -34,20 +34,37 @@ type runeTypeScannerImpl struct {
parser Parser
offset int64
- repeat bool
- stuck bool
- rRune rune
- rSize int
- rType RuneType
- rErr error
+ repeat bool
+ stuck bool
+ rRune rune
+ rRuneOK bool
+ rSize int
+ rType RuneType
+ rErr error
}
var _ runeTypeScanner = (*runeTypeScannerImpl)(nil)
func (sc *runeTypeScannerImpl) Reset() {
sc.parser.Reset()
+ unread := sc.stuck && sc.rType == RuneTypeEOF && sc.rRuneOK
sc.stuck = false
sc.repeat = false
+ if unread {
+ // re-figure the rType and rErr
+ var err error
+ sc.rType, err = sc.parser.HandleRune(sc.rRune)
+ if err != nil {
+ sc.rErr = &DecodeSyntaxError{
+ Offset: sc.offset,
+ Err: err,
+ }
+ } else {
+ sc.rErr = nil
+ }
+ // tell it to use that rType and rErr
+ sc.UnreadRune()
+ }
}
func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) {
@@ -62,6 +79,7 @@ func (sc *runeTypeScannerImpl) ReadRuneType() (rune, int, RuneType, error) {
var err error
sc.rRune, sc.rSize, err = sc.inner.ReadRune()
sc.offset += int64(sc.rSize)
+ sc.rRuneOK = err == nil
switch err {
case nil:
sc.rType, err = sc.parser.HandleRune(sc.rRune)