@@ -122,9 +122,9 @@ func (t *tokens[U]) AST() *node[U] {
122
122
node *node[U]
123
123
down *element
124
124
}
125
- tokens := t.Tokens()
125
+ tokenSlice := t.Tokens()
126
126
var stack *element
127
- for _, token := range tokens {
127
+ for _, token := range tokenSlice {
128
128
if token.begin == token.end {
129
129
continue
130
130
}
@@ -216,28 +216,28 @@ func translatePositions(buffer []rune, positions []int) textPositionMap {
216
216
217
217
type parseError[U Uint] struct {
218
218
p *{{.StructName}}[U]
219
- max token[U]
219
+ maxToken token[U]
220
220
}
221
221
222
222
func (e *parseError[U]) Error() string {
223
- tokens , err := []token[U]{e.max }, "\n"
224
- positions, p := make([]int, 2 * len(tokens )), 0
225
- for _, token := range tokens {
226
- positions[p], p = int(token .begin), p + 1
227
- positions[p], p = int(token .end), p + 1
223
+ tokenSlice , err := []token[U]{e.maxToken }, "\n"
224
+ positions, p := make([]int, 2* len(tokenSlice )), 0
225
+ for _, t := range tokenSlice {
226
+ positions[p], p = int(t .begin), p+ 1
227
+ positions[p], p = int(t .end), p+ 1
228
228
}
229
229
translations := translatePositions(e.p.buffer, positions)
230
230
format := "parse error near %v (line %v symbol %v - line %v symbol %v):\n%v\n"
231
231
if e.p.Pretty {
232
232
format = "parse error near \x1B[34m%v\x1B[m (line %v symbol %v - line %v symbol %v):\n%v\n"
233
233
}
234
- for _, token := range tokens {
235
- begin, end := int(token .begin), int(token .end)
234
+ for _, t := range tokenSlice {
235
+ begin, end := int(t .begin), int(t .end)
236
236
err += fmt.Sprintf(format,
237
- rul3s[token .pegRule],
238
- translations[begin].line, translations[begin].symbol,
239
- translations[end].line, translations[end].symbol,
240
- strconv.Quote(string(e.p.buffer[begin:end])))
237
+ rul3s[t .pegRule],
238
+ translations[begin].line, translations[begin].symbol,
239
+ translations[end].line, translations[end].symbol,
240
+ strconv.Quote(string(e.p.buffer[begin:end])))
241
241
}
242
242
243
243
return err
@@ -265,11 +265,11 @@ func (p *{{.StructName}}[_]) SprintSyntaxTree() string {
265
265
{{if .HasActions}}
266
266
func (p *{{.StructName}}[_]) Execute() {
267
267
buffer, _buffer, text, begin, end := p.Buffer, p.buffer, "", 0, 0
268
- for _, token := range p.Tokens() {
269
- switch (token .pegRule) {
268
+ for _, t := range p.Tokens() {
269
+ switch t .pegRule {
270
270
{{if .HasPush}}
271
271
case rulePegText:
272
- begin, end = int(token .begin), int(token .end)
272
+ begin, end = int(t .begin), int(t .end)
273
273
text = string(_buffer[begin:end])
274
274
{{end}}
275
275
{{range .Actions}}case ruleAction{{.GetID}}:
@@ -317,11 +317,11 @@ type memoKey[U Uint] struct {
317
317
318
318
func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) error {
319
319
var (
320
- max token[U]
320
+ maxToken token[U]
321
321
position, tokenIndex U
322
- buffer []rune
322
+ buffer []rune
323
323
{{if .Ast -}}
324
- memoization map[memoKey[U]]memo[U]
324
+ memoization map[memoKey[U]]memo[U]
325
325
{{end -}}
326
326
{{if not .Ast -}}
327
327
{{if .HasPush -}}
@@ -336,7 +336,7 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
336
336
}
337
337
}
338
338
p.reset = func() {
339
- max = token[U]{}
339
+ maxToken = token[U]{}
340
340
position, tokenIndex = 0, 0
341
341
{{if .Ast -}}
342
342
memoization = make(map[memoKey[U]]memo[U])
@@ -369,16 +369,16 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
369
369
{{end -}}
370
370
return nil
371
371
}
372
- return &parseError[U]{p, max }
372
+ return &parseError[U]{p, maxToken }
373
373
}
374
374
375
375
add := func(rule pegRule, begin U) {
376
376
{{if .Ast -}}
377
377
tree.Add(rule, begin, position, tokenIndex)
378
378
{{end -}}
379
379
tokenIndex++
380
- if begin != position && position > max .end {
381
- max = token[U]{rule, begin, position}
380
+ if begin != position && position > maxToken .end {
381
+ maxToken = token[U]{rule, begin, position}
382
382
}
383
383
}
384
384
@@ -405,8 +405,8 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
405
405
tree.tree = append(tree.tree[:tokenIndex], m.Partial...)
406
406
tokenIndex += U(len(m.Partial))
407
407
position = m.Partial[len(m.Partial)-1].end
408
- if tree.tree[tokenIndex-1].begin != position && position > max .end {
409
- max = tree.tree[tokenIndex-1]
408
+ if tree.tree[tokenIndex-1].begin != position && position > maxToken .end {
409
+ maxToken = tree.tree[tokenIndex-1]
410
410
}
411
411
return true
412
412
}
0 commit comments