Skip to content

Commit

Permalink
Fix data race in attemptRuleCompletion()
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonathan Gordon committed Feb 13, 2020
1 parent 50a1cd5 commit b818867
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -325,12 +325,14 @@ func (p *seqParser) attemptRuleCompletion(scope frozen.Map, first, input *Scanne
default:
return nil
}
oldSlice := append([]Parser{}, p.parsers...)
defer func() { p.parsers = oldSlice }()
p.parsers = p.parsers[failedIndex+1:]

pclone := *p
pclone.parsers = append([]Parser{}, p.parsers...)

pclone.parsers = pclone.parsers[failedIndex+1:]
var v TreeElement
if p.Parse(scope, NewScanner(input.String()), &v) == nil {
switch child := oldSlice[failedIndex].(type) {
if pclone.Parse(scope, NewScanner(input.String()), &v) == nil {
switch child := p.parsers[failedIndex].(type) {
case *sParser:
ctx := first.Slice(0, strings.Index(first.String(), input.String()))

Expand Down

0 comments on commit b818867

Please sign in to comment.