1. Juancarlo Añez
  2. grako

Commits

Juancarlo Añez  committed 2ff6aa9

FailedCut must trickle all the way up the runtime rule calls to allow for errors to be reported as closes as possible to their source.

  • Participants
  • Parent commits cad60d1
  • Branches default

Comments (0)

Files changed (3)

File grako/contexts.py

View file
  • Ignore whitespace
         self._state = None
         self._lookahead = 0
 
+    def _clear_cache(self):
+        self._memoization_cache = dict()
+
     def _reset(self, text=None,
               filename=None,
               semantics=None,
             yield None
         except OptionSucceeded:
             pass
-        except FailedCut as e:
-            raise e.nested
 
     @contextmanager
     def _optional(self):

File grako/grammars.py

View file
  • Ignore whitespace
                          FailedToken,
                          FailedPattern,
                          FailedRef,
+                         FailedCut,
                          FailedSemantics,
                          GrammarError)
 
             ctx = ModelContext(self.rules, trace=trace, **kwargs)
         ctx._reset(text=text, semantics=semantics, **kwargs)
         start_rule = ctx._find_rule(start) if start else self.rules[0]
-        with ctx._choice():
-            return start_rule.parse(ctx)
+        try:
+            with ctx._choice():
+                return start_rule.parse(ctx)
+        except FailedCut as e:
+            raise e.nested
+        finally:
+            ctx._clear_cache()
 
     def codegen(self):
         return self.render()

File grako/parsing.py

View file
  • Ignore whitespace
 import functools
 from .contexts import ParseContext, ParseInfo
 from .exceptions import (FailedParse,
+                         FailedCut,
                          FailedToken,
                          FailedPattern,
                          FailedRef,
             result = rule()
             self.ast[rule_name] = result
             return result
+        except FailedCut as e:
+            raise e.nested
         finally:
-            self._memoization_cache = dict()
+            self._clear_cache()
 
     @classmethod
     def rule_list(cls):