Skip to content

Add opt-in memoized left-recursion support for marked rules - #30

Draft
tomtau with Copilot wants to merge 4 commits into
masterfrom
copilot/add-memoization-support
Draft

Add opt-in memoized left-recursion support for marked rules#30
tomtau with Copilot wants to merge 4 commits into
masterfrom
copilot/add-memoization-support

Conversation

Copilot AI commented Apr 30, 2026

Copy link
Copy Markdown
Contributor

This adds an opt-in path for PEG rules that need memoization-backed left recursion. Marked rules can now grow through direct or mutual left-recursive expansions without rewriting the grammar into a non-left-recursive form.

  • Grammar syntax

    • Add a recursive rule modifier after =
    • Support @ as the documented marker, with % kept as an equivalent alias
    • Parse recursive and silent modifiers independently so they can be combined
  • Meta parser plumbing

    • Extend ParseRule with a recursive flag
    • Thread the flag through grammar parsing and error naming
    • Keep unmarked rules on the existing behavior path
  • Generated parser behavior

    • Emit recursive-aware wrappers only for rules explicitly marked recursive
    • Leave non-recursive generated rules unchanged to avoid widening trait bounds or altering existing parse behavior
  • Runtime memoization

    • Add per-rule/per-position memoization in the typed tracker for marked recursive rules
    • Use iterative growth to reuse the best known result and stop when no further input is consumed
    • Apply the same strategy to both full parse and check-only paths
  • Coverage and docs

    • Add focused tests for direct and mutual left recursion
    • Document the new marker syntax in derive docs

Example:

expr = @ { expr - "+" - num | num }
num = ('0'..'9')+

call    = @ { primary - args }
primary = @ { call | ident }
ident   = ('a'..'z')+
args    = "(" - ")"

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • gist.github.com
    • Triggering command: /home/REDACTED/work/_temp/ghcca-node/node/bin/node /home/REDACTED/work/_temp/ghcca-node/node/bin/node --enable-source-maps /home/REDACTED/work/_temp/copilot-developer-action-main/dist/index.js (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI linked an issue Apr 30, 2026 that may be closed by this pull request
Copilot AI and others added 3 commits April 30, 2026 00:51
Agent-Logs-Url: https://github.com/pest-parser/pest3/sessions/e539c623-60cd-4bc3-8134-8199e01dad9b

Co-authored-by: tomtau <2410580+tomtau@users.noreply.github.com>
Agent-Logs-Url: https://github.com/pest-parser/pest3/sessions/e539c623-60cd-4bc3-8134-8199e01dad9b

Co-authored-by: tomtau <2410580+tomtau@users.noreply.github.com>
Agent-Logs-Url: https://github.com/pest-parser/pest3/sessions/e539c623-60cd-4bc3-8134-8199e01dad9b

Co-authored-by: tomtau <2410580+tomtau@users.noreply.github.com>
Copilot AI changed the title [WIP] Add memoization and left-recursion support Add opt-in memoized left-recursion support for marked rules Apr 30, 2026
Copilot AI requested a review from tomtau April 30, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

memoization and left-recursion support

2 participants