Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions detail.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlread

import (
"errors"
"strings"
)

type InsertDetailParser struct {
Expand Down Expand Up @@ -82,7 +83,7 @@ func stringValue(c LexItem) (string, error) {
d := v[0]
m := len(v) - 2

s := ""
var s strings.Builder
i := 0
for {
i++
Expand Down Expand Up @@ -125,22 +126,22 @@ func stringValue(c LexItem) (string, error) {
}

i++
s += string(x)
s.WriteString(string(x))
continue
}

if v[i] == d {
if i+1 < m && v[i+1] == d {
i++
s += string(d)
s.WriteString(string(d))
continue
} else {
return "", errorInvalidString
}
}

s += string(v[i])
s.WriteString(string(v[i]))
}

return s, nil
return s.String(), nil
}
4 changes: 1 addition & 3 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
module github.com/donatj/sqlread

go 1.24

toolchain go1.24.4
go 1.26

Comment on lines 1 to 4
require (
github.com/avvmoto/buf-readerat v0.0.0-20171115124131-a17c8cb89270
Expand Down
13 changes: 7 additions & 6 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package sqlread
import (
"fmt"
"slices"
"strings"
)

// Parser is a state based SQL Parser that reads LexItems on a channel
Expand Down Expand Up @@ -47,12 +48,12 @@ func (p *Parser) Run(start parseState) error {
}

func (p *Parser) errorUnexpectedLex(f LexItem, e ...lexItemType) {
s := ""
var s strings.Builder
for _, ei := range e {
s += "'" + ei.String() + "' "
s.WriteString("'" + ei.String() + "' ")
}

p.err = fmt.Errorf("found '%s'; expected %s at byte: %d", f.Type.String(), s, f.Pos)
p.err = fmt.Errorf("found '%s'; expected %s at byte: %d", f.Type.String(), s.String(), f.Pos)
}

func (p *Parser) errorUnexpectedEOF() {
Expand All @@ -63,12 +64,12 @@ func (p *Parser) errorUnexpectedEOF() {
// It includes the last position scanned to help with debugging
// lastPos is the position of the last valid scanned item
func (p *Parser) errorUnexpectedEOFExpectedLexItemType(lastPos int64, e ...lexItemType) {
s := ""
var s strings.Builder
for _, ei := range e {
s += "'" + ei.String() + "' "
s.WriteString("'" + ei.String() + "' ")
}

p.err = fmt.Errorf("unexpected eof; expected %s starting at byte: %d", s, lastPos+1)
p.err = fmt.Errorf("unexpected eof; expected %s starting at byte: %d", s.String(), lastPos+1)
}

func isOfAny(c LexItem, l ...lexItemType) bool {
Expand Down
17 changes: 3 additions & 14 deletions scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package sqlread

import (
"io"
"slices"
"strings"
"unicode/utf8"
)
Expand Down Expand Up @@ -158,13 +159,7 @@ func (l *lexer) accept(bs []byte) (c int) {
for {
n := l.next()

found := false
for _, b := range bs {
if b == n {
found = true
break
}
}
found := slices.Contains(bs, n)

if !found {
l.rewind()
Expand Down Expand Up @@ -281,11 +276,5 @@ func (l *lexer) emit(t lexItemType) LexItem {
}

func in(b byte, bs []byte) bool {
for _, bb := range bs {
if b == bb {
return true
}
}

return false
return slices.Contains(bs, b)
}