From 5eafa07470a3e761944ff5af00dbcd794dfa09da Mon Sep 17 00:00:00 2001 From: Max Fischer Date: Fri, 30 Jul 2021 14:51:33 +0200 Subject: Add support for LR parsing * first draft of LR parsing * removed debug output * cache is owned and cleared by ParserElement * bounded recursion must be enabled explicitly * packrat rejects recursion * basic LR unit test * tests for associativity and nesting * added math example * fixed test typo * unittest for empty and non-peg clauses * LR-Forward can match Empty * fixed test typos * added base case to unittest * memo cache only provides copies * flattened Forward parse method * added high-level description of algorithm * expanded docstring * added tests for repetition rules * renamed bounded to left recursion * naive test for existing suite * explicitly testing tests for LR compatibility * LR memo no longer mixes action/no-action results * simplified replacement logic * adjusted example with ambiguous failure case * LR memo content is always returned as copy * draft for peeking recursion * memo update consistent for all actions * fixed a bug for non-string token identifiers * action wins against no-action * cleanup * properly setting names in tests * memoization can be turned off * testing memo switches * typos * flattened recursion memo * left recursion memo size may be limited * adjusted docs for recursion cache --- pyparsing/testing.py | 3 +++ 1 file changed, 3 insertions(+) (limited to 'pyparsing/testing.py') diff --git a/pyparsing/testing.py b/pyparsing/testing.py index 393f37b..43f23ab 100644 --- a/pyparsing/testing.py +++ b/pyparsing/testing.py @@ -20,6 +20,7 @@ class pyparsing_test: """ Context manager to be used when writing unit tests that modify pyparsing config values: - packrat parsing + - bounded recursion parsing - default whitespace characters. - default keyword characters - literal string auto-conversion class @@ -61,6 +62,7 @@ class pyparsing_test: else: self._save_context["packrat_cache_size"] = None self._save_context["packrat_parse"] = ParserElement._parse + self._save_context["recursion_enabled"] = ParserElement._left_recursion_enabled self._save_context["__diag__"] = { name: getattr(__diag__, name) for name in __diag__._all_names @@ -97,6 +99,7 @@ class pyparsing_test: ParserElement.enablePackrat(self._save_context["packrat_cache_size"]) else: ParserElement._parse = self._save_context["packrat_parse"] + ParserElement._left_recursion_enabled = self._save_context["recursion_enabled"] __compat__.collect_all_And_tokens = self._save_context["__compat__"] -- cgit v1.2.1