Small items, round 3: a bare begin block recovered as a generate block, the half-typed #( override lookahead, atomic in-place writes
TODO §36 (docs/features/small-items-3). Closes topo §2.9-24 and §2.9-25 and the §1 atomic-writes item. 36.1 `ItemKind::GenBlock(Box<GenBlock>)`: in tolerant mode a `begin … end` at module scope or straight inside a generate region is parsed as an unnamed generate block with a diagnostic at the keyword, so the items inside and after it survive; strict mode is untouched. Consumers walk its items; `module-begin-block`, `v2001-generate-begin` and `mismatched-labels` read the node. The formatter's `gen_block` is split by a pure extraction into `begin_block`. One server test that parsed a 3 000-deep begin nest on libtest's thread now runs on PARSE_STACK_SIZE. 36.2 `Parser::value_runs_into_next_instance`, a tolerant-mode lookahead in `parse_connection`: an unclosed `.NAME(` whose value would swallow the next instance as a call fails the element instead; `recover_element` takes the bracket the element stopped on before skipping so the skip stays at the list's level. The balanced-parens spelling stays greedy. 36.3 `lucisv_core::atomic::write_atomic`: sibling temp file + rename, permissions preserved, symlink target replaced, read-only target refused as `fs::write` refused it; used by format, `check --fix` and the cache. Also: TODO housekeeping (QA lines of §27–§35 ticked as recorded in their QA logs; the §27 P6 line and the sva-bodies README checkbox annotated as delivered by §29), topo §2.9-24/25 struck. Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
1 parent
0757503fd1
commit
a30dda167a
35 files changed
+1421
-83
No files matched your search
@@ -3,6 +3,7 @@
|
||||
//! `bind` directives. Drive strengths and delay values live here because
|
||||
//! these are the only items that write them.
|
||||
|
||||
use super::recover::is_sync_stop;
|
||||
use super::*;
|
||||
|
||||
/// The strength keywords a drive strength is written from (IEEE 1800 §28.11).
|
||||
@@ -504,6 +505,16 @@ impl<'a> Parser<'a> {
|
||||
let before_open = self.take_before_open("(");
|
||||
let mark = self.pending_trailing.len();
|
||||
let paren_start = self.here();
|
||||
// A half-typed `.NAME(` whose value would read as the next
|
||||
// instance: `sub #(.WIDTH(8), .DEPTH(` ⏎ `u0 (.a(x));`. Nothing
|
||||
// inside the list fails — `u0 (.a(x))` is a legal call with named
|
||||
// arguments — so the greedy parse swallows the instance and the
|
||||
// whole instantiation collapses into one error item. Failing the
|
||||
// element here costs the one connection and keeps everything
|
||||
// else. See `docs/features/small-items-3/README.md`.
|
||||
if self.tolerant && self.cur().is_sym("(") && self.value_runs_into_next_instance() {
|
||||
return self.error("unclosed `(` in a port or parameter connection");
|
||||
}
|
||||
let mut close_comments = Vec::new();
|
||||
let mut after_open = Vec::new();
|
||||
let expr = if self.eat_sym("(") {
|
||||
@@ -562,6 +573,58 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// True when the `(` at the cursor — the one that opens a connection's
|
||||
/// value — is never closed **and** something that reads as the next
|
||||
/// instance sits inside it.
|
||||
///
|
||||
/// Tolerant mode only, asked once per named connection before its value
|
||||
/// is parsed. The walk starts just past the `(` at depth zero and ends at
|
||||
/// the first of: a closer that would take the depth below zero (the
|
||||
/// value's own `)` — it closes, so nothing is wrong and the value is
|
||||
/// parsed as written), a `;` or a construct keyword at depth zero, or end
|
||||
/// of file. On a file that parses it therefore stops at the value's `)`
|
||||
/// after a handful of tokens; only a value whose bracket was never closed
|
||||
/// walks as far as the next `;`.
|
||||
///
|
||||
/// The candidate is an identifier that opens its own line and is followed
|
||||
/// by `(` — how an instance is written, and how nothing written *inside*
|
||||
/// a value normally is. Only depth zero is read: a candidate inside a
|
||||
/// deeper unclosed bracket (`.DEPTH(f(g(` ⏎ `u0 (…)`) is not seen, and
|
||||
/// that shape falls back to the coarser item-level recovery, which keeps
|
||||
/// the `endmodule` but loses the instantiation. Deliberate — reading
|
||||
/// deeper would start guessing which of several unclosed brackets the
|
||||
/// user meant to close.
|
||||
fn value_runs_into_next_instance(&self) -> bool {
|
||||
let mut depth = 0u32;
|
||||
let mut candidate = false;
|
||||
let mut i = self.pos + 1;
|
||||
while let Some(t) = self.tokens.get(i) {
|
||||
if t.kind == TokenKind::Eof {
|
||||
break;
|
||||
}
|
||||
if t.is_sym("(") || t.is_sym("[") || t.is_sym("{") {
|
||||
depth += 1;
|
||||
} else if t.is_sym(")") || t.is_sym("]") || t.is_sym("}") {
|
||||
if depth == 0 {
|
||||
return false;
|
||||
}
|
||||
depth -= 1;
|
||||
} else if depth == 0 {
|
||||
if t.is_sym(";") || is_sync_stop(t) {
|
||||
break;
|
||||
}
|
||||
if t.kind == TokenKind::Ident
|
||||
&& self.tokens[i - 1].line != t.line
|
||||
&& self.tokens.get(i + 1).is_some_and(|n| n.is_sym("("))
|
||||
{
|
||||
candidate = true;
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
candidate
|
||||
}
|
||||
|
||||
/// Consume the tokens up to `end_pos` as one verbatim expression.
|
||||
///
|
||||
/// [`Parser::open_conds`] is deliberately left alone: it counts *item*
|
||||
|
||||
Reference in new issue
Block a user