Skip to content

Commit f851c43

Browse files
authored
Rename variables to avoid shadowing (#169)
1 parent d29dd7a commit f851c43

File tree

2 files changed

+48
-48
lines changed

2 files changed

+48
-48
lines changed

Diff for: peg.peg.go

+22-22
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: tree/peg.go

+26-26
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,9 @@ func (t *tokens[U]) AST() *node[U] {
122122
node *node[U]
123123
down *element
124124
}
125-
tokens := t.Tokens()
125+
tokenSlice := t.Tokens()
126126
var stack *element
127-
for _, token := range tokens {
127+
for _, token := range tokenSlice {
128128
if token.begin == token.end {
129129
continue
130130
}
@@ -216,28 +216,28 @@ func translatePositions(buffer []rune, positions []int) textPositionMap {
216216
217217
type parseError[U Uint] struct {
218218
p *{{.StructName}}[U]
219-
max token[U]
219+
maxToken token[U]
220220
}
221221
222222
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
228228
}
229229
translations := translatePositions(e.p.buffer, positions)
230230
format := "parse error near %v (line %v symbol %v - line %v symbol %v):\n%v\n"
231231
if e.p.Pretty {
232232
format = "parse error near \x1B[34m%v\x1B[m (line %v symbol %v - line %v symbol %v):\n%v\n"
233233
}
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)
236236
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])))
241241
}
242242
243243
return err
@@ -265,11 +265,11 @@ func (p *{{.StructName}}[_]) SprintSyntaxTree() string {
265265
{{if .HasActions}}
266266
func (p *{{.StructName}}[_]) Execute() {
267267
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 {
270270
{{if .HasPush}}
271271
case rulePegText:
272-
begin, end = int(token.begin), int(token.end)
272+
begin, end = int(t.begin), int(t.end)
273273
text = string(_buffer[begin:end])
274274
{{end}}
275275
{{range .Actions}}case ruleAction{{.GetID}}:
@@ -317,11 +317,11 @@ type memoKey[U Uint] struct {
317317
318318
func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) error {
319319
var (
320-
max token[U]
320+
maxToken token[U]
321321
position, tokenIndex U
322-
buffer []rune
322+
buffer []rune
323323
{{if .Ast -}}
324-
memoization map[memoKey[U]]memo[U]
324+
memoization map[memoKey[U]]memo[U]
325325
{{end -}}
326326
{{if not .Ast -}}
327327
{{if .HasPush -}}
@@ -336,7 +336,7 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
336336
}
337337
}
338338
p.reset = func() {
339-
max = token[U]{}
339+
maxToken = token[U]{}
340340
position, tokenIndex = 0, 0
341341
{{if .Ast -}}
342342
memoization = make(map[memoKey[U]]memo[U])
@@ -369,16 +369,16 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
369369
{{end -}}
370370
return nil
371371
}
372-
return &parseError[U]{p, max}
372+
return &parseError[U]{p, maxToken}
373373
}
374374
375375
add := func(rule pegRule, begin U) {
376376
{{if .Ast -}}
377377
tree.Add(rule, begin, position, tokenIndex)
378378
{{end -}}
379379
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}
382382
}
383383
}
384384
@@ -405,8 +405,8 @@ func (p *{{.StructName}}[U]) Init(options ...func(*{{.StructName}}[U]) error) er
405405
tree.tree = append(tree.tree[:tokenIndex], m.Partial...)
406406
tokenIndex += U(len(m.Partial))
407407
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]
410410
}
411411
return true
412412
}

0 commit comments

Comments
 (0)