Skip to content

Render alternatives in PEG-safe order - #12

Open
levitte wants to merge 1 commit into
Nadrieril:mainfrom
levitte:peg-safe-alternative-order
Open

Render alternatives in PEG-safe order#12
levitte wants to merge 1 commit into
Nadrieril:mainfrom
levitte:peg-safe-alternative-order

Conversation

@levitte

@levitte levitte commented Aug 10, 2026

Copy link
Copy Markdown
Contributor

Fixes #11.

Render each alternation stable-sorted: can't-fail alternatives last (pest_derive rejects them elsewhere), string literals longest-first (avoids prefix shadowing). Everything else keeps written order. Doing it at render time fixes both written and =/-merged alternations at once.

Limitation: longest-first applies only to alternatives that are string literals, not ones that merely start alike.

Limitation: only alternatives that *are* string literals benefit from
longest-first ordering; prefix shadowing between alternatives that
merely *start* the same way (e.g. two concatenations sharing a leading
rulename) is not detected.

Fixes: Nadrieril#11
Assisted-by: Pi:moonshot/kimi-k3
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.

Rendered alternative order is not PEG-safe (empty alternative first, prefixes shadowed)

1 participant