Skip to content

feat: support antlr4rust recog predicate receiver - #249

Merged
tinovyatkin merged 2 commits into
mainfrom
codex/issue-241-recog-predicates
Jul 29, 2026
Merged

feat: support antlr4rust recog predicate receiver#249
tinovyatkin merged 2 commits into
mainfrom
codex/issue-241-recog-predicates

Conversation

@tinovyatkin

@tinovyatkin tinovyatkin commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • add an optional receiver = "..." alias to individual semantic [[helper]] patterns without embedding target-specific names in generic codegen
  • support antlr4rust recog.helper() predicates by declaring receiver = "recog" in migration pattern metadata
  • snapshot the full manifest record and generated typed-hook adapter, and prove the hook runs during parsing

Root cause

The generic helper-call parser recognizes bare calls plus the established this. and self. forms. Semantic pattern metadata could describe a helper's kind, name, arguments, return type, and lowering, but not an additional receiver spelling, so an antlr4rust predicate such as recog.IsOk() could not match its declared helper.

This change keeps codegen grammar-agnostic: nonstandard receiver spellings are accepted only when the matching helper pattern explicitly declares one. Unconfigured dotted calls remain unsupported.

Validation

  • cargo test --locked --features codegen --bin antlr4-rust-gen (823 passed)
  • cargo test --locked --features codegen --test antlr4_rust_gen_cli (43 passed)
  • cargo clippy --locked --all-targets --all-features -- -D warnings
  • cargo fmt --check --all
  • commit hooks: cargo check --all-targets --all-features --locked, strict clippy, formatting, and rumdl

Fixes #241

Normalize the antlr4rust `recog.` recognizer receiver alongside bare, `this.`, and `self.` semantic helper calls. This keeps migrated predicates wired to declared typed hooks instead of falling back or failing strict generation.

Cover strict manifest routing, generated dispatch, compilation, and execution, and document the migration convention.

Fixes #241
@coderabbitai

coderabbitai Bot commented Jul 29, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The generator now recognizes recog. semantic helper calls, routes them through typed parser hooks, and verifies the behavior with unit and end-to-end tests. README documentation lists the supported receiver forms and lexer semantic-hook routing.

Changes

recog semantic hook support

Layer / File(s) Summary
Receiver parsing and unit coverage
src/bin/antlr4-rust-gen.rs
Semantic helper parsing accepts recog. and tests it alongside bare, this., and self. calls.
Typed-hook generation and documentation
tests/antlr4_rust_gen_cli.rs, README.md
The regression test verifies manifest output, generated typed-hook dispatch, and successful parsing; documentation describes the supported forms and routing.อ่าน

Estimated code review effort: 2 (Simple) | ~15 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The code and tests implement recog. helper parsing, typed-hook routing, manifest handling, and strict-generation success.
Out of Scope Changes check ✅ Passed The README update and added tests stay aligned with the recog. predicate support work and do not introduce unrelated scope.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding support for the antlr4rust recog predicate receiver.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch codex/issue-241-recog-predicates

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

Copy/Paste Detection

Found 2 duplication(s) across 2 changed Rust file(s) (threshold: 100 tokens).

Show duplications

Found a 22 line (132 tokens) duplication in the following files:

  • Starting at line 1996 of tests/antlr4_rust_gen_cli.rs
  • Starting at line 2232 of tests/antlr4_rust_gen_cli.rs
        "parser grammar Delegate;\ndelegated: {isTypeName()}? ID;\n",
    )
    .expect("delegate grammar should be writable");
    fs::write(&tokens, "lexer grammar Tokens;\nID: [a-z]+;\n")
        .expect("token grammar should be writable");

    let output = run_antlr4_rust_gen(&[
        root.as_os_str(),
        tokens.as_os_str(),
        OsStr::new("-I"),
        temp.path().as_os_str(),
        OsStr::new("--out-dir"),
        out.as_os_str(),
    ]);
    assert!(
        output.status.success(),
        "stdout: {}\nstderr: {}",
        utf8(&output.stdout),
        utf8(&output.stderr)
    );
    let parser = fs::read_to_string(out.join("root.rs")).expect("parser should be emitted");
    assert!(parser.contains("pub trait RootHooks"), "{parser}");
```rust

---

Found a 17 line (102 tokens) duplication in the following files:
* Starting at line 3243 of tests/antlr4_rust_gen_cli.rs
* Starting at line 3310 of tests/antlr4_rust_gen_cli.rs

```rust
        dir.join("L.g4").as_os_str(),
        OsStr::new("--sem-patterns"),
        dir.join("patterns.toml").as_os_str(),
        OsStr::new("--sem-unknown"),
        OsStr::new("error"),
        OsStr::new("--require-full-semantics"),
        OsStr::new("--out-dir"),
        out.as_os_str(),
    ]);
    assert!(
        output.status.success(),
        "stdout: {}\nstderr: {}",
        utf8(&output.stdout),
        utf8(&output.stderr)
    );

    let lexer = fs::read_to_string(out.join("l.rs")).expect("lexer should be emitted");

@claude

claude Bot commented Jul 29, 2026

Copy link
Copy Markdown

Claude Code is working…

I'll analyze this and get back to you.

View job run

@github-actions

github-actions Bot commented Jul 29, 2026

Copy link
Copy Markdown

📊 Source Code Metrics (this PR vs main)

File Cyclomatic Cognitive Functions LLOC MI
src/bin/antlr4-rust-gen.rs 2706 (main: 2693) 🔴 1739 (main: 1730) 🔴 576 (main: 575) 🔴 4703 (main: 4691) 🔴 0 ⚪

Generated by mehen v1.7.0 — the code quality watcher.

@codecov

codecov Bot commented Jul 29, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.73418% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/bin/antlr4-rust-gen.rs 98.73% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 50c0fa515e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/bin/antlr4-rust-gen.rs Outdated
body = body
.strip_prefix("this.")
.or_else(|| body.strip_prefix("self."))
.or_else(|| body.strip_prefix("recog."))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Move antlr4rust receiver handling out of generic codegen

For any non-antlr4rust grammar containing recog.foo() and a matching [[helper]] declaration, this unconditional normalization now changes the expression from unsupported semantics into a typed hook. That embeds an antlr4rust-specific source-language convention in the generic helper parser; make accepted receiver aliases pattern- or metadata-driven instead, leaving the recog convention in language-specific configuration, documentation, and tests.

AGENTS.md reference: AGENTS.md:L5-L9

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Addressed in 754b2c60c. The generic parser no longer contains recog; [[helper]] now has an optional metadata-driven receiver alias, and only the antlr4rust migration pattern declares receiver = "recog". Unit coverage confirms an unconfigured dotted receiver remains unmatched. Full generator tests, CLI integration tests, and strict clippy pass.

Comment thread tests/antlr4_rust_gen_cli.rs Outdated
Comment thread tests/antlr4_rust_gen_cli.rs
Declare nonstandard receiver spellings on individual [[helper]] entries instead of normalizing them in the grammar-agnostic helper parser. This supports antlr4rust's recog convention through receiver = "recog" without changing other grammars.

Snapshot the full manifest record and generated adapter, and prove the typed hook runs during parsing.
@tinovyatkin tinovyatkin changed the title [codex] Support antlr4rust recog predicate receiver feat: support antlr4rust recog predicate receiver Jul 29, 2026
@tinovyatkin
tinovyatkin merged commit 45c56f4 into main Jul 29, 2026
16 of 17 checks passed
@tinovyatkin
tinovyatkin deleted the codex/issue-241-recog-predicates branch July 29, 2026 13:30
@ophiarch ophiarch Bot mentioned this pull request Jul 29, 2026
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.

codegen: recog. semantic predicates are not recognized as helper hooks

1 participant