Skip to content

Commit 6eaf4a6

Browse files
committed
minor error message fix, minor internal tweaks
1 parent 70d1e01 commit 6eaf4a6

File tree

9 files changed

+72
-66
lines changed

9 files changed

+72
-66
lines changed

readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ func Example_composition() {
100100

101101
## Changelog
102102

103+
### v0.7.4
104+
105+
Minor fix for reporting types in error messages. Some internal tweaks.
106+
103107
### v0.7.3
104108

105109
Added `UpsertConflictVoid`, `UpsertConflict`.

sqlb_dict.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ shortcut.
1010
type List []any
1111

1212
// Implement part of the `ArgDict` interface.
13-
func (self List) IsEmpty() bool { return self.Len() == 0 }
13+
func (self List) IsEmpty() bool { return self.Len() <= 0 }
1414

1515
// Implement part of the `ArgDict` interface.
1616
func (self List) Len() int { return len(self) }
@@ -43,7 +43,7 @@ the `DictQ` shortcut.
4343
type Dict map[string]any
4444

4545
// Implement part of the `ArgDict` interface.
46-
func (self Dict) IsEmpty() bool { return self.Len() == 0 }
46+
func (self Dict) IsEmpty() bool { return self.Len() <= 0 }
4747

4848
// Implement part of the `ArgDict` interface.
4949
func (self Dict) Len() int { return len(self) }

sqlb_expr.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (self Identifier) AppendExpr(text []byte, args []any) ([]byte, []any) {
7070
// Implement the `AppenderTo` interface, sometimes allowing more efficient text
7171
// encoding.
7272
func (self Identifier) AppendTo(text []byte) []byte {
73-
if len(self) == 0 {
73+
if len(self) <= 0 {
7474
return text
7575
}
7676
for ind, val := range self {
@@ -114,7 +114,7 @@ func (self Path) AppendExpr(text []byte, args []any) ([]byte, []any) {
114114
// Implement the `AppenderTo` interface, sometimes allowing more efficient text
115115
// encoding.
116116
func (self Path) AppendTo(text []byte) []byte {
117-
if len(self) == 0 {
117+
if len(self) <= 0 {
118118
return text
119119
}
120120

@@ -165,7 +165,7 @@ func (self PseudoPath) AppendExpr(text []byte, args []any) ([]byte, []any) {
165165
// Implement the `AppenderTo` interface, sometimes allowing more efficient text
166166
// encoding.
167167
func (self PseudoPath) AppendTo(text []byte) []byte {
168-
if len(self) == 0 {
168+
if len(self) <= 0 {
169169
return text
170170
}
171171

@@ -215,7 +215,7 @@ func (self AliasedPath) AppendExpr(text []byte, args []any) ([]byte, []any) {
215215
// Implement the `AppenderTo` interface, sometimes allowing more efficient text
216216
// encoding.
217217
func (self AliasedPath) AppendTo(text []byte) []byte {
218-
if len(self) == 0 {
218+
if len(self) <= 0 {
219219
return text
220220
}
221221

@@ -259,7 +259,7 @@ func (self Table) AppendExpr(text []byte, args []any) ([]byte, []any) {
259259
// Implement the `AppenderTo` interface, sometimes allowing more efficient text
260260
// encoding.
261261
func (self Table) AppendTo(text []byte) []byte {
262-
if len(self) == 0 {
262+
if len(self) <= 0 {
263263
return text
264264
}
265265
text = appendMaybeSpaced(text, `table`)
@@ -536,7 +536,7 @@ func (self *Seq) appendEmpty(bui *Bui) {
536536
func (self Seq) appendSlice(bui *Bui, src any) {
537537
val := valueOf(src)
538538

539-
if val.Len() == 0 {
539+
if val.Len() <= 0 {
540540
self.appendEmpty(bui)
541541
return
542542
}
@@ -625,7 +625,7 @@ type Ands []any
625625

626626
// Implement the `Expr` interface, making this a sub-expression.
627627
func (self Ands) AppendExpr(text []byte, args []any) ([]byte, []any) {
628-
if len(self) == 0 {
628+
if len(self) <= 0 {
629629
return And{}.AppendExpr(text, args)
630630
}
631631
return And{[]any(self)}.AppendExpr(text, args)
@@ -643,7 +643,7 @@ type Ors []any
643643

644644
// Implement the `Expr` interface, making this a sub-expression.
645645
func (self Ors) AppendExpr(text []byte, args []any) ([]byte, []any) {
646-
if len(self) == 0 {
646+
if len(self) <= 0 {
647647
return Or{}.AppendExpr(text, args)
648648
}
649649
return Or{[]any(self)}.AppendExpr(text, args)
@@ -885,7 +885,7 @@ type StructsInsert[A any] []A
885885

886886
// Implement the `Expr` interface, making this a sub-expression.
887887
func (self StructsInsert[A]) AppendExpr(text []byte, args []any) ([]byte, []any) {
888-
if len(self) == 0 {
888+
if len(self) <= 0 {
889889
return text, args
890890
}
891891

sqlb_jel.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ falling back on "true" if empty.
159159
func (self Jel) AppendExpr(text []byte, args []any) ([]byte, []any) {
160160
bui := Bui{text, args}
161161

162-
if len(self.Text) == 0 {
162+
if len(self.Text) <= 0 {
163163
bui.Str(`true`)
164164
} else {
165165
self.decode(&bui, stringToBytesUnsafe(self.Text))

sqlb_misc.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ func TypeCols(typ r.Type) string {
3636

3737
/*
3838
Returns the output of `ColsDeep` for the given type, but takes `reflect.Type` as
39-
input, rather than a type-carrying `any`. Used internally by
40-
`ColsDeep`. The result is cached and reused. Subsequent calls for the same type
41-
are nearly free.
39+
input, rather than a type-carrying `any`. Used internally by `ColsDeep`. The
40+
result is cached and reused. Subsequent calls for the same type are nearly
41+
free.
4242
*/
4343
func TypeColsDeep(typ r.Type) string {
4444
return colsDeepCache.Get(typeElem(typ))
@@ -54,15 +54,15 @@ func Preparse(val string) Prep { return prepCache.Get(val) }
5454

5555
// Shortcut for `StrQ{text, List(args)}`.
5656
func ListQ(text string, args ...any) StrQ {
57-
if len(args) == 0 {
57+
if len(args) <= 0 {
5858
return StrQ{text, nil}
5959
}
6060
return StrQ{text, List(args)}
6161
}
6262

6363
// Shortcut for `StrQ{text, Dict(args)}`.
6464
func DictQ(text string, args map[string]any) StrQ {
65-
if len(args) == 0 {
65+
if len(args) <= 0 {
6666
return StrQ{text, nil}
6767
}
6868
return StrQ{text, Dict(args)}

sqlb_ord.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ func (self Ords) RowNumberOver() RowNumberOver {
8888
}
8989

9090
// Returns true if there are no non-nil items.
91-
func (self Ords) IsEmpty() bool { return self.Len() == 0 }
91+
func (self Ords) IsEmpty() bool { return self.Len() <= 0 }
9292

9393
// Returns the amount of non-nil items.
9494
func (self Ords) Len() (count int) {
@@ -205,7 +205,7 @@ func (self Ord) AppendTo(text []byte) []byte {
205205
func (self Ord) String() string { return AppenderString(&self) }
206206

207207
// True if the path is empty.
208-
func (self Ord) IsEmpty() bool { return len(self.Path) == 0 }
208+
func (self Ord) IsEmpty() bool { return len(self.Path) <= 0 }
209209

210210
// Same as `Ord{Path: path, Dir: DirAsc}` but more syntactically convenient
211211
// and uses less memory.

sqlb_tokenizer.go

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ func (self *Tokenizer) nextToken() Token {
9595
if self.maybeNamedParam(); self.cursor > mid {
9696
return self.choose(start, mid, TokenTypeNamedParam)
9797
}
98-
self.char()
98+
self.skipChar()
9999
}
100100

101101
if self.cursor > start {
@@ -128,7 +128,7 @@ func (self *Tokenizer) setNext(val Token) {
128128

129129
func (self *Tokenizer) maybeWhitespace() {
130130
for self.more() && charsetWhitespace.has(self.headByte()) {
131-
self.scan(1)
131+
self.skipBytes(1)
132132
}
133133
}
134134

@@ -145,10 +145,10 @@ func (self *Tokenizer) maybeQuotedGrave() {
145145
}
146146

147147
func (self *Tokenizer) maybeCommentLine() {
148-
if !self.scannedString(commentLinePrefix) {
148+
if !self.skippedString(commentLinePrefix) {
149149
return
150150
}
151-
for self.more() && !self.scannedNewline() && self.scannedChar() {
151+
for self.more() && !self.skippedNewline() && self.skippedChar() {
152152
}
153153
}
154154

@@ -163,85 +163,85 @@ func (self *Tokenizer) maybeDoubleColon() {
163163

164164
func (self *Tokenizer) maybeOrdinalParam() {
165165
start := self.cursor
166-
if !self.scannedByte(ordinalParamPrefix) {
166+
if !self.skippedByte(ordinalParamPrefix) {
167167
return
168168
}
169-
if !self.scannedDigits() {
169+
if !self.skippedDigits() {
170170
self.cursor = start
171171
}
172172
}
173173

174174
func (self *Tokenizer) maybeNamedParam() {
175175
start := self.cursor
176-
if !self.scannedByte(namedParamPrefix) {
176+
if !self.skippedByte(namedParamPrefix) {
177177
return
178178
}
179-
if !self.scannedIdent() {
179+
if !self.skippedIdent() {
180180
self.cursor = start
181181
}
182182
}
183183

184184
func (self *Tokenizer) maybeString(val string) {
185-
_ = self.scannedString(val)
185+
_ = self.skippedString(val)
186186
}
187187

188-
func (self *Tokenizer) scannedNewline() bool {
188+
func (self *Tokenizer) skippedNewline() bool {
189189
start := self.cursor
190190
self.maybeNewline()
191191
return self.cursor > start
192192
}
193193

194194
func (self *Tokenizer) maybeNewline() {
195-
self.scan(leadingNewlineSize(self.rest()))
195+
self.skipBytes(leadingNewlineSize(self.rest()))
196196
}
197197

198-
func (self *Tokenizer) scannedChar() bool {
198+
func (self *Tokenizer) skippedChar() bool {
199199
start := self.cursor
200-
self.char()
200+
self.skipChar()
201201
return self.cursor > start
202202
}
203203

204-
func (self *Tokenizer) char() {
204+
func (self *Tokenizer) skipChar() {
205205
_, size := utf8.DecodeRuneInString(self.rest())
206-
self.scan(size)
206+
self.skipBytes(size)
207207
}
208208

209-
func (self *Tokenizer) scannedDigits() bool {
209+
func (self *Tokenizer) skippedDigits() bool {
210210
start := self.cursor
211-
self.maybeDigits()
211+
self.maybeSkipDigits()
212212
return self.cursor > start
213213
}
214214

215-
func (self *Tokenizer) maybeDigits() {
215+
func (self *Tokenizer) maybeSkipDigits() {
216216
for self.more() && charsetDigitDec.has(self.headByte()) {
217-
self.scan(1)
217+
self.skipBytes(1)
218218
}
219219
}
220220

221-
func (self *Tokenizer) scannedIdent() bool {
221+
func (self *Tokenizer) skippedIdent() bool {
222222
start := self.cursor
223223
self.maybeIdent()
224224
return self.cursor > start
225225
}
226226

227227
func (self *Tokenizer) maybeIdent() {
228-
if !self.scannedByteIn(charsetIdentStart) {
228+
if !self.skippedByteFromCharset(charsetIdentStart) {
229229
return
230230
}
231-
for self.more() && self.scannedByteIn(charsetIdent) {
231+
for self.more() && self.skippedByteFromCharset(charsetIdent) {
232232
}
233233
}
234234

235235
func (self *Tokenizer) maybeStringBetween(prefix, suffix string) {
236-
if !self.scannedString(prefix) {
236+
if !self.skippedString(prefix) {
237237
return
238238
}
239239

240240
for self.more() {
241-
if self.scannedString(suffix) {
241+
if self.skippedString(suffix) {
242242
return
243243
}
244-
self.char()
244+
self.skipChar()
245245
}
246246

247247
panic(ErrUnexpectedEOF{Err{
@@ -251,15 +251,15 @@ func (self *Tokenizer) maybeStringBetween(prefix, suffix string) {
251251
}
252252

253253
func (self *Tokenizer) maybeStringBetweenBytes(prefix, suffix byte) {
254-
if !self.scannedByte(prefix) {
254+
if !self.skippedByte(prefix) {
255255
return
256256
}
257257

258258
for self.more() {
259-
if self.scannedByte(suffix) {
259+
if self.skippedByte(suffix) {
260260
return
261261
}
262-
self.char()
262+
self.skipChar()
263263
}
264264

265265
panic(ErrUnexpectedEOF{Err{
@@ -268,7 +268,7 @@ func (self *Tokenizer) maybeStringBetweenBytes(prefix, suffix byte) {
268268
}})
269269
}
270270

271-
func (self *Tokenizer) scan(val int) {
271+
func (self *Tokenizer) skipBytes(val int) {
272272
self.cursor += val
273273
}
274274

@@ -288,33 +288,30 @@ func (self *Tokenizer) headByte() byte {
288288
return self.Source[self.cursor]
289289
}
290290

291-
func (self *Tokenizer) scannedByte(val byte) bool {
291+
func (self *Tokenizer) skippedByte(val byte) bool {
292292
if self.headByte() == val {
293-
self.scan(1)
293+
self.skipBytes(1)
294294
return true
295295
}
296296
return false
297297
}
298298

299-
func (self *Tokenizer) scannedByteIn(val *charset) bool {
299+
func (self *Tokenizer) skippedByteFromCharset(val *charset) bool {
300300
if val.has(self.headByte()) {
301-
self.scan(1)
301+
self.skipBytes(1)
302302
return true
303303
}
304304
return false
305305
}
306306

307-
func (self *Tokenizer) scannedString(val string) bool {
307+
func (self *Tokenizer) skippedString(val string) bool {
308308
if strings.HasPrefix(self.rest(), val) {
309-
self.scan(len(val))
309+
self.skipBytes(len(val))
310310
return true
311311
}
312312
return false
313313
}
314314

315-
// Part of `Token`.
316-
type TokenType byte
317-
318315
const (
319316
TokenTypeInvalid TokenType = iota
320317
TokenTypeText
@@ -329,6 +326,9 @@ const (
329326
TokenTypeNamedParam
330327
)
331328

329+
// Part of `Token`.
330+
type TokenType byte
331+
332332
// Represents an arbitrary chunk of SQL text parsed by `Tokenizer`.
333333
type Token struct {
334334
Text string

0 commit comments

Comments
 (0)