Add comments-round: close the comment-attachment gaps

Meta.trailing is now Option<Comment> (line/col/span — delivers the
format-fences handshake; same-line fences stay deliberately inert),
and Meta::before_sep keeps a comment on its element's side of the
separator across every list kind, including the closing-bracket
buckets. take_before_sep is a no-op unless the cursor is on the
separator, which is why all 299 pre-existing cases stayed
byte-identical. Also fixes: EnumType::dangling comments parsed but
never printed (a latent invariant-#3 violation), the double-blank
between leading comments (six corpus files became fixed points), and
five documented expression refusals (replication interior,
compact-bracket operator position, assign-value, concat brace,
header imports via HeaderImport).

Reproducible acceptance metrics (HEAD-worktree control): line-
position comment injection refusals 2.3% -> 0.4%; exhaustive gap
probe 90 -> 22 refused; delimiter-position 61% -> 36%. Remaining
parked positions documented. verify.rs byte-identical; +7 rejection
tests; corpus 0 verification errors, 0 crashes, parse 468/820.

229 workspace tests, clippy silent. Dev: Opus agent; QA: Sonnet
agent (sabotage-verified pins, independent probes); review in
docs/features/comments-round/README.md.

Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5 committed 2026-08-19 06:11:53 -07:00
1 parent 0ba29d4635
commit 982e37063b
9 files changed
+1318 -146

No files matched your search

+40 -9
View File
@@ -16,7 +16,17 @@ use crate::token::Comment;
#[derive(Debug, Clone, Default)]
pub struct Meta {
pub leading: Vec<Comment>,
pub trailing: Option<String>,
/// The comment written *after* the node and the separator that closes it
/// (`,` or `;`), on the same line. Several are merged into one, joined by
/// a space; the merged value keeps the first one's position and spans
/// from the first byte of the first to the last byte of the last.
pub trailing: Option<Comment>,
/// Comments written *between* the node and the separator that follows it
/// (`element /* c */,`). They print on the node's side of the separator,
/// which is where the source put them — printing them after it moves a
/// comment across a token and the safety net rejects the output. Empty
/// for a node no separator follows.
pub before_sep: Vec<Comment>,
pub blank_before: bool,
/// Attribute instances `(* ... *)` that preceded the node, verbatim.
pub attrs: Vec<RawText>,
@@ -119,11 +129,10 @@ pub enum ItemKind {
pub struct Module {
pub kw: String,
pub name: String,
/// One entry per `import` statement written in the header, each holding
/// that statement's comma-separated paths. A header may write several
/// (`module m import a::*; import b::t; (...)`), and merging them into one
/// statement would replace a `;` with a `,`.
pub imports: Vec<Vec<String>>,
/// One entry per `import` statement written in the header. A header may
/// write several (`module m import a::*; import b::t; (...)`), and merging
/// them into one statement would replace a `;` with a `,`.
pub imports: Vec<HeaderImport>,
/// `None` when the header wrote no `#( ... )` at all; an empty `Some` is a
/// written-but-empty `#()`, which must be printed back.
pub param_ports: Option<Vec<ParamPort>>,
@@ -137,6 +146,16 @@ pub struct Module {
pub end_label: Option<String>,
}
/// One `import` statement in a module header, with the comments written
/// around it. A header import is not an [`Item`], so it needs its own place
/// to keep them.
#[derive(Debug)]
pub struct HeaderImport {
pub meta: Meta,
/// The comma-separated paths of this one statement.
pub paths: Vec<String>,
}
#[derive(Debug)]
pub enum PortList {
/// No port list at all: `module m;`
@@ -331,6 +350,10 @@ pub enum SensList {
#[derive(Debug)]
pub struct SensItem {
/// Comments written around this item: `leading` before it (after the `(`
/// or the separator), `before_sep` between it and the separator that
/// follows — or the closing `)` for the last item.
pub meta: Meta,
/// The separator written before this item; `None` on the first item.
pub sep: Option<SensSep>,
pub edge: Option<String>,
@@ -390,6 +413,10 @@ pub struct Connection {
/// `None` for `.name` (implicit) and `.*`; `Some` for `.name(expr)`.
/// An explicitly empty connection `.name()` is `Some(Expr::Empty)`.
pub expr: Option<Expr>,
/// Comments written between the value and the connection's own `)`
/// (`.data_i (x /* verilator lint_off */)`). Printed back inside the
/// parens: after them they would sit in the enclosing list instead.
pub close_comments: Vec<Comment>,
/// Code extent of the connection.
pub span: TextRange,
}
@@ -406,7 +433,7 @@ pub struct GateInstantiation {
pub struct GateInstance {
pub meta: Meta,
pub name: Option<String>,
pub args: Vec<Expr>,
pub args: Vec<ExprItem>,
/// Code extent of the gate instance.
pub span: TextRange,
}
@@ -422,7 +449,9 @@ pub struct GenIf {
#[derive(Debug)]
pub enum GenElse {
If(Meta, GenIf),
/// `else if`: boxed because a `Meta` plus a whole `GenIf` inline makes
/// this variant several times the size of `Block`.
If(Meta, Box<GenIf>),
Block(GenBlock),
}
@@ -726,7 +755,9 @@ pub enum ExprKind {
Concat(Vec<ExprItem>),
Repl {
count: Box<Expr>,
inner: Vec<Expr>,
/// Elements carry their comments the way a concatenation's do, so a
/// comment inside a replication stays inside it.
inner: Vec<ExprItem>,
},
Paren {
inner: Box<Expr>,