Skip to content

Commit 13c0d57

Browse files
committed
Shave a bit of time off considerError by mutating (gross).
1 parent 74260d7 commit 13c0d57

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

ometa/runtime.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,15 @@ def __eq__(self, other):
2727
return (self.position, self.error) == (other.position, other.error)
2828

2929

30+
def mergeWith(self, other):
31+
"""
32+
Merges in another error's error and trail.
33+
"""
34+
self.error = list(set(self.error + other.error))
35+
self.args = (self.position, self.error)
36+
self.trail = other.trail or self.trail or []
37+
38+
3039
def formatReason(self):
3140
if not self.error:
3241
return "Syntax error"
@@ -392,13 +401,7 @@ def considerError(self, error, typ=None):
392401
if newPos > curPos:
393402
self.currentError = error
394403
elif newPos == curPos:
395-
# Same logic as joinErrors, inlined and special-cased for two
396-
# errors at the same position
397-
self.currentError = ParseError(
398-
self.currentError.input,
399-
curPos,
400-
list(set(self.currentError.error + error.error)),
401-
error.trail or self.currentError.trail or None)
404+
self.currentError.mergeWith(error)
402405

403406

404407
def _trace(self, src, span, inputPos):

0 commit comments

Comments
 (0)