feat: support antlr4rust recog predicate receiver - #249
Conversation
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
📝 WalkthroughWalkthroughThe generator now recognizes Changesrecog semantic hook support
Estimated code review effort: 2 (Simple) | ~15 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
Copy/Paste DetectionFound 2 duplication(s) across 2 changed Rust file(s) (threshold: 100 tokens). Show duplicationsFound a 22 line (132 tokens) duplication in the following files:
"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"); |
|
I'll analyze this and get back to you. |
📊 Source Code Metrics (this PR vs
|
| 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 Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
💡 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".
| body = body | ||
| .strip_prefix("this.") | ||
| .or_else(|| body.strip_prefix("self.")) | ||
| .or_else(|| body.strip_prefix("recog.")) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
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.
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.

Summary
receiver = "..."alias to individual semantic[[helper]]patterns without embedding target-specific names in generic codegenrecog.helper()predicates by declaringreceiver = "recog"in migration pattern metadataRoot cause
The generic helper-call parser recognizes bare calls plus the established
this.andself.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 asrecog.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 warningscargo fmt --check --allcargo check --all-targets --all-features --locked, strict clippy, formatting, andrumdlFixes #241