Skip to content

Commit 4223b2e

Browse files
committed
Minor wins in joinErrors and considerError.
1 parent 1e080fa commit 4223b2e

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

ometa/runtime.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,19 +122,24 @@ def joinErrors(errors, presorted=False):
122122
"""
123123
Return the error from the branch that matched the most of the input.
124124
"""
125+
if len(errors) == 1:
126+
return errors[0]
127+
125128
if not presorted:
126129
errors.sort(reverse=True, key=operator.itemgetter(0))
127130

128131
results = set()
129132
pos = errors[0].position
130133
trail = None
131134
for err in errors:
132-
if pos == err.position:
133-
e, trail = err.error, (err.trail or trail)
134-
if e is not None:
135-
results.update(e)
136-
else:
135+
if pos != err.position:
137136
break
137+
138+
trail = err.trail or trail
139+
e = err.error
140+
if e:
141+
results.update(e)
142+
138143
return ParseError(errors[0].input, pos, list(results) or None, trail)
139144

140145

@@ -383,9 +388,11 @@ def __init__(self, input, globals=None, name='<string>', tree=False,
383388

384389
def considerError(self, error, typ=None):
385390
if error:
386-
if error[0] > self.currentError[0]:
391+
newPos = error.position
392+
curPos = self.currentError.position
393+
if newPos > curPos:
387394
self.currentError = error
388-
elif error[0] == self.currentError[0]:
395+
elif newPos == curPos:
389396
self.currentError = joinErrors([error, self.currentError], presorted=True)
390397

391398

0 commit comments

Comments
 (0)