You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
antlr4-rust-gen accepts several authored target-code surfaces but silently
omits them from generated Rust:
parser-rule catch [...] { ... };
parser-rule finally { ... };
grammar/scoped @header { ... };
grammar/scoped @...::definitions { ... }.
This happens in both --actions embedded and --actions templates. --require-full-semantics still exits successfully, and semantics.json
contains no entry explaining that the authored code was discarded.
The direct grammar frontend already retains these constructs:
generated rule lifecycle sections currently expose only setup, body, success, and recovery
(renderer).
This violates the fail-loud semantic contract established by #9 and #35:
authored target code must either execute, be routed through a documented hook,
or fail generation with a source-positioned diagnostic.
the catch, finally, @header, and @definitions bodies are absent;
semantics.json reports no affected coordinate or source section.
The same omission occurs with --actions templates.
Goal
Make every authored target-code surface accountable.
The first correctness step is to reject unsupported source sections with a
precise diagnostic. Implementing a section may then replace that diagnostic,
but silent omission must not remain an accepted disposition.
Inventory
Inventory grammar-level/scoped named actions and rule exception groups after
import resolution and grammar transforms.
Give each source-owned section a deterministic disposition such as embedded, translated, hooked, synthetic, or unsupported.
Extend semantics.json, or a companion deterministic manifest section, so
strict semantic auditing covers constructs which do not have ATN
action/predicate coordinates.
Make --require-full-semantics reject every unsupported authored section.
Embedded Rust support
Emit supported @header sections at a stable module position before imports
or other generated declarations.
Emit supported @definitions sections at a documented module/impl position
matching their scope.
Define duplicate/scoped-section behavior for combined, parser, lexer, and
imported grammars.
Translate token aliases and other generated names using the same structural
machinery as @members, rather than textual special cases.
Rule exception lifecycle
Preserve ANTLR ordering between the rule body, @after, catch, finally,
default recovery, context finalization, and listener events.
@after must remain success-only.
finally must execute exactly once on every path for which ANTLR executes it,
including recoverable and propagated failures.
A grammar catch clause must not accidentally run during speculative
prediction or generated-path retries.
Ordinary and left-recursive rules must share one lifecycle contract.
If catch/finally support requires a new generated-rule macro section or runtime
helper, update the generated-code API revision and compatibility surfaces
required by AGENTS.md.
Acceptance criteria
No authored named action, catch clause, or finally clause can disappear
without an explicit disposition.
Unsupported source sections fail generation with source path, line,
column, section kind, and remediation guidance.
Summary
antlr4-rust-genaccepts several authored target-code surfaces but silentlyomits them from generated Rust:
catch [...] { ... };finally { ... };@header { ... };@...::definitions { ... }.This happens in both
--actions embeddedand--actions templates.--require-full-semanticsstill exits successfully, andsemantics.jsoncontains no entry explaining that the authored code was discarded.
The direct grammar frontend already retains these constructs:
parser_rulerecordscatchesandfinally_action;The production render path, however, only materializes rule
@init/@afterand grammar
@members:structural_embedded_model;build_embedded_parser_data;setup,body,success, andrecovery(renderer).
This violates the fail-loud semantic contract established by #9 and #35:
authored target code must either execute, be routed through a documented hook,
or fail generation with a source-positioned diagnostic.
Reproduction
finallycatchnamed file/module sections
Run each with:
Observed on
main@5caa7d3e:@membersmethod is present;catch,finally,@header, and@definitionsbodies are absent;semantics.jsonreports no affected coordinate or source section.The same omission occurs with
--actions templates.Goal
Make every authored target-code surface accountable.
The first correctness step is to reject unsupported source sections with a
precise diagnostic. Implementing a section may then replace that diagnostic,
but silent omission must not remain an accepted disposition.
Inventory
import resolution and grammar transforms.
embedded,translated,hooked,synthetic, orunsupported.semantics.json, or a companion deterministic manifest section, sostrict semantic auditing covers constructs which do not have ATN
action/predicate coordinates.
--require-full-semanticsreject every unsupported authored section.Embedded Rust support
@headersections at a stable module position before importsor other generated declarations.
@definitionssections at a documented module/impl positionmatching their scope.
imported grammars.
machinery as
@members, rather than textual special cases.Rule exception lifecycle
@after,catch,finally,default recovery, context finalization, and listener events.
@aftermust remain success-only.finallymust execute exactly once on every path for which ANTLR executes it,including recoverable and propagated failures.
prediction or generated-path retries.
If catch/finally support requires a new generated-rule macro section or runtime
helper, update the generated-code API revision and compatibility surfaces
required by
AGENTS.md.Acceptance criteria
without an explicit disposition.
column, section kind, and remediation guidance.
--require-full-semanticsrejects unsupported non-ATN target-codesections.
@headerand@definitionsbodies appear exactlyonce at documented generated positions.
error, and ordering semantics.
left-recursive rules, success, recoverable error, fatal error, and
duplicate scoped sections.
observable.
Related
Non-goals
into Rust.
codegen paths.