Repository navigation
Fix token filtering when reusing repetition helpers - #1678
vera-rubin wants to merge 2 commits into
Conversation
Include keep_all_tokens in repetition cache keys so pinned and ordinary rules don't share helpers with incompatible token filtering. Cover recursive and large ranged repetitions in both rule orders.
|
It fixes the reported bug, but it breaks some LALR grammars that load fine on master, and it leaves the underlying cache-key flaw in place.
The same happens with a named terminal (NAME+) in the shared prefix, which is a realistic shape.
The new test's ~50 cases sit exactly on REPEAT_BREAK_THRESHOLD, so they would stop exercising the helper path if that constant were raised; 60 or 100, as other tests use, avoids this. |
Terminals compare by name only, so equal expressions can still differ in which tokens they filter out: through keep_all_tokens, or because an anonymous string resolves to a named terminal. Add each terminal's effective filter_out to the cache key instead of keep_all_tokens itself. Rules that filter the repeated expression the same way share a helper again, so a pinned rule and an ordinary rule with a common repeated prefix no longer collide in LALR. Move the test sizes off REPEAT_BREAK_THRESHOLD.
|
Thanks for the review. I pushed a follow-up commit. The cache key no longer includes keep_all_tokens. It now records, for each terminal in the repeated expression, whether the current rule filters it out. Rules that filter it the same way share the helper as on master, so your Tests: sizes are 60 now, plus two new tests, one for your regression grammar ( One limit: if two rules really filter a shared repeated prefix differently (e.g. |
When ordinary and pinned rules repeat the same terminal, the first rule's filtering setting is reused for both. This prints
[]instead of[Token('_A', 'a')], although pinned rules should keep all their terminals:We include
keep_all_tokensin cache keys for repetition helpers so each rule keeps its own filtering behavior. The regression covers both definition orders for+,*, and large ranged repetitions, and the full test suite passes.— ChipLab