Skip to content

Migrate grammar DSL to operator-only Type‑0 model and add rewrite-rule operators - #175

Draft
TristinPorter with Copilot wants to merge 1 commit into
Devfrom
copilot/update-project-to-type-0-grammar
Draft

Migrate grammar DSL to operator-only Type‑0 model and add rewrite-rule operators#175
TristinPorter with Copilot wants to merge 1 commit into
Devfrom
copilot/update-project-to-type-0-grammar

Conversation

Copilot AI commented May 21, 2026

Copy link
Copy Markdown
Contributor

This updates the internal grammar surface to a Type‑0 rewrite-oriented model: Rule variables + terminal literals + first-declared start rule + operator syntax for productions/rewrite rules. It removes legacy builder/chaining APIs from grammar declaration paths and introduces explicit Empty semantics for ε.

  • Core grammar model (Type‑0)

    • Simplified Rule composition to operator-only grammar construction (+, |).
    • Added Rule.Empty as the canonical ε symbol.
    • Start symbol selection now uses the first declared Rule field in declaration order.
  • Terminal model simplification

    • Replaced TokenSpec hierarchy with a minimal terminal-oriented Token wrapper.
    • Added direct terminal conversions for grammar declarations: char, byte, int (hex-byte range), and byte[].
  • Rewrite system syntax

    • Added rewrite primitives:
      • RewriteProduction (α -> β)
      • RewriteRule (collection of productions)
    • Enabled operator syntax:
      • (alpha) > (beta) to create rewrite productions
      • | to compose multiple productions into one RewriteRule.
  • API cleanup / syntax migration

    • Removed legacy builder-style grammar APIs from the public DSL path (Ref, optional/repetition/list/precedence builder helpers, and chained rewrite methods).
    • Updated in-repo grammar declarations to operator-only forms (no .Ref, .Then, .Or, .To, .Rewrite, .Transform).
  • Usage shape (new DSL)

    public static readonly Rule Expr =
        Number | (Expr + Plus + Expr);
    
    public static readonly RewriteRule R1 =
        (A + B + 'a' + C) > (D + 'b' + 'b' + A)
      | (A + 'x') > (A + 'y')
      | (C + 'z') > Rule.Empty;

Agent-Logs-Url: https://github.com/Tristin-Porter/CDTk/sessions/ac101061-cbc2-481f-8aa4-6773b8d70852

Co-authored-by: TristinPorter <232979486+TristinPorter@users.noreply.github.com>
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.

2 participants