TODO §68.2: an unfinished port connection stays in its own entry, and its errors wait until you pause
Parser (tolerant mode only, parser/recover_list.rs): a lone '.', a
'.name(' left open at its line end and a trailing ',' in a named list are
recovered inside their entry — always a diagnostic, never silent; strict
mode and valid code are unchanged (1 026 inputs old vs new: identical
strict results and trees, byte-identical CLI output; corpus 814/6).
Server (state/port_grace.rs): diagnostics that start inside the entry the
last edit touched, in a named-connection list of an instance, are withheld
for 1.5 s and released by the loop's timeout, an edit elsewhere or a save;
a pulling client that supports it gets workspace/diagnostic/refresh.
A trailing ',' in a named list is now reported in tolerant mode too.
Dev + QA (Opus 5.5); QA failed one gate (lucisv_mcp qa_f1), one fix
round, re-check passed: parser 521, server 1954, mcp 383, formatter 352.
Not yet seen in a running VS Code. docs/features/port-entry-grace; topo
rows for §68.1 and §68.2.
Co-Authored-By: Claude Mythos 5.2 <[email protected]>
This commit is contained in:
1 parent
c1076f9405
commit
14213f6a93
19 files changed
+2396
-25
No files matched your search
@@ -320,12 +320,13 @@ impl<'a> Parser<'a> {
|
||||
if !self.cur().is_sym(")") {
|
||||
loop {
|
||||
let at = self.pos;
|
||||
list.push(self.element_or_recover(|p| p.parse_connection())?);
|
||||
list.push(self.connection_or_recover()?);
|
||||
let recovered = list.last().is_some_and(ListElem::is_error);
|
||||
if let Some(ListElem::Ok(last)) = list.last_mut() {
|
||||
self.take_before_sep(&mut last.meta, ",");
|
||||
}
|
||||
let comma = self.eat_sym(",");
|
||||
self.note_trailing_comma(comma);
|
||||
if let Some(ListElem::Ok(last)) = list.last_mut() {
|
||||
last.comma = comma;
|
||||
if comma && last.meta.trailing.is_none() {
|
||||
@@ -338,7 +339,7 @@ impl<'a> Parser<'a> {
|
||||
// the list, and after a directive only the closing bracket
|
||||
// does — an `` `ifdef`` arm may end without a comma and
|
||||
// still be followed by an `` `else`` arm.
|
||||
if self.list_ends(at, comma, dirs.any, recovered) {
|
||||
if self.connection_list_ends(at, comma, dirs.any, recovered) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -437,12 +438,13 @@ impl<'a> Parser<'a> {
|
||||
let mut conns = Vec::new();
|
||||
loop {
|
||||
let at = self.pos;
|
||||
conns.push(self.element_or_recover(|p| p.parse_connection())?);
|
||||
conns.push(self.connection_or_recover()?);
|
||||
let recovered = conns.last().is_some_and(ListElem::is_error);
|
||||
if let Some(ListElem::Ok(last)) = conns.last_mut() {
|
||||
self.take_before_sep(&mut last.meta, ",");
|
||||
}
|
||||
let comma = self.eat_sym(",");
|
||||
self.note_trailing_comma(comma);
|
||||
if let Some(ListElem::Ok(last)) = conns.last_mut() {
|
||||
last.comma = comma;
|
||||
if comma && last.meta.trailing.is_none() {
|
||||
@@ -450,7 +452,7 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
let dirs = self.take_list_directives(directives, conns.len());
|
||||
if self.list_ends(at, comma, dirs.any, recovered) {
|
||||
if self.connection_list_ends(at, comma, dirs.any, recovered) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -560,8 +562,15 @@ impl<'a> Parser<'a> {
|
||||
// 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() {
|
||||
// else. See `docs/features/small-items-3/README.md`. The same
|
||||
// failure covers a `.NAME(` left open at the end of its line while
|
||||
// the next line goes on with the list (`.po(` ⏎ `.b(y));`): the
|
||||
// entry ends with its line, and the diagnostic is on its `(`
|
||||
// (`docs/features/port-entry-grace/README.md`).
|
||||
if self.tolerant
|
||||
&& self.cur().is_sym("(")
|
||||
&& (self.value_runs_into_next_instance() || self.value_left_open())
|
||||
{
|
||||
return self.error("unclosed `(` in a port or parameter connection");
|
||||
}
|
||||
let mut close_comments = Vec::new();
|
||||
|
||||
@@ -25,6 +25,7 @@
|
||||
//! See `docs/features/header-recovery/README.md`.
|
||||
|
||||
use super::directive::{closes_conditional, continues_conditional, opens_conditional};
|
||||
use super::recover::is_sync_stop;
|
||||
use super::*;
|
||||
|
||||
impl<'a> Parser<'a> {
|
||||
@@ -102,6 +103,176 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
/// One entry of a port or parameter connection list, the unfinished ones
|
||||
/// included (`docs/features/port-entry-grace/README.md`).
|
||||
///
|
||||
/// A `.` with no name after it yet — `.a(x), .` ⏎ `.b(y)` — is the entry
|
||||
/// someone is typing. In tolerant mode it becomes an error element of its
|
||||
/// own, holding just the `.`, with its one diagnostic on the `.`: the
|
||||
/// generic recovery would report the token *after* it, which belongs to
|
||||
/// the next entry, and its skip would swallow a `.b(y)` written on the
|
||||
/// same line. Strict mode, and every other entry, is
|
||||
/// [`Parser::element_or_recover`] over [`Parser::parse_connection`].
|
||||
pub(super) fn connection_or_recover(&mut self) -> PResult<ListElem<Connection>> {
|
||||
if self.tolerant && self.at_lone_dot() {
|
||||
return Ok(ListElem::Error(self.take_lone_dot()));
|
||||
}
|
||||
self.element_or_recover(|p| p.parse_connection())
|
||||
}
|
||||
|
||||
/// True on a `.` that no name can follow: the next token ends the entry
|
||||
/// (`,` `)` `;`), ends the file or an enclosing construct, or — on a later
|
||||
/// line — is a keyword or the `.` of the next entry. A keyword or a `.` on
|
||||
/// the same line (`.input(x)`, `..z (p)`) is left to the generic recovery,
|
||||
/// whose skip takes the whole `.input(x)` / `..z (p)` with it: one error
|
||||
/// element, which is what `lucisv_mcp`'s refusal names (`qa_f1.rs`).
|
||||
fn at_lone_dot(&self) -> bool {
|
||||
if !self.cur().is_sym(".") {
|
||||
return false;
|
||||
}
|
||||
let next = self.nth(1);
|
||||
let later_line = next.line != self.cur().line;
|
||||
next.kind == TokenKind::Eof
|
||||
|| next.is_sym(",")
|
||||
|| next.is_sym(")")
|
||||
|| next.is_sym(";")
|
||||
|| is_sync_stop(next)
|
||||
|| (later_line && (next.kind == TokenKind::Keyword || next.is_sym(".")))
|
||||
}
|
||||
|
||||
/// Record the lone `.` at the cursor and take it as an error element.
|
||||
/// The comments written before it are left pending, so the next entry
|
||||
/// picks them up rather than the error leaf swallowing them.
|
||||
fn take_lone_dot(&mut self) -> RawText {
|
||||
let dot = self.cur();
|
||||
let (span, col) = (dot.span, dot.col);
|
||||
self.diagnostics.push(ParseDiagnostic {
|
||||
message: "expected a name after `.`".to_string(),
|
||||
line: dot.line,
|
||||
col,
|
||||
span,
|
||||
});
|
||||
self.skip();
|
||||
RawText { text: self.slice(span), col, span }
|
||||
}
|
||||
|
||||
/// [`Parser::list_ends`] for a connection list, which reads one shape on.
|
||||
///
|
||||
/// After an entry that had to be recovered, a missing `,` normally ends
|
||||
/// the list — what follows belongs to the enclosing construct. In a
|
||||
/// connection list a `.` there is the next connection instead: the entry
|
||||
/// above was abandoned mid-typing (`.po(` ⏎ `.b(y)`), and the list reads
|
||||
/// on. No second diagnostic: the recovered entry already has one, and it
|
||||
/// is the news. Strict mode never recovers, so this is `list_ends` there.
|
||||
pub(super) fn connection_list_ends(
|
||||
&mut self,
|
||||
start: usize,
|
||||
comma: bool,
|
||||
dirs_any: bool,
|
||||
recovered: bool,
|
||||
) -> bool {
|
||||
let next_entry = self.cur().is_sym(".");
|
||||
if self.tolerant && recovered && !comma && !dirs_any && self.pos != start && next_entry {
|
||||
return false;
|
||||
}
|
||||
self.list_ends(start, comma, dirs_any, recovered)
|
||||
}
|
||||
|
||||
/// In tolerant mode, report a connection list's `,` that only the closing
|
||||
/// `)` follows — `.b(y),)`, the separator typed before the next entry.
|
||||
/// Strict mode fails there on the empty entry; tolerant mode used to end
|
||||
/// the list on the `)` without a word. The diagnostic sits on the `,`.
|
||||
/// Called right after the `,` was consumed, so it is the token behind the
|
||||
/// cursor.
|
||||
pub(super) fn note_trailing_comma(&mut self, comma: bool) {
|
||||
if !(self.tolerant && comma && self.cur().is_sym(")")) {
|
||||
return;
|
||||
}
|
||||
let Some(sep) = self.pos.checked_sub(1).and_then(|i| self.tokens.get(i)) else { return };
|
||||
let diag = ParseDiagnostic {
|
||||
message: "expected a connection after `,`".to_string(),
|
||||
line: sep.line,
|
||||
col: sep.col,
|
||||
span: sep.span,
|
||||
};
|
||||
self.diagnostics.push(diag);
|
||||
}
|
||||
|
||||
/// True when the `(` at the cursor — the one that opens a connection's
|
||||
/// value — was left open mid-typing: still open at the end of its line,
|
||||
/// the next line starting something new (a `.` entry, a `)`, a `;`, a
|
||||
/// keyword, or end of file), **and** the bracket never closes the way a
|
||||
/// value's does.
|
||||
///
|
||||
/// The last clause is what keeps every file the strict parser reads
|
||||
/// untouched: in a valid list a value's matching `)` is followed by a
|
||||
/// `,`, the list's `)`, or a directive, so `.po(top` ⏎ `.sig)` — a legal
|
||||
/// path continued on the next line — is read as written. The line clause
|
||||
/// keeps the pinned ambiguous shape `.D(` ⏎ `u0 (.a(x)));` greedy
|
||||
/// (`docs/features/header-recovery/README.md`): an identifier opening the
|
||||
/// next line is [`Parser::value_runs_into_next_instance`]'s question.
|
||||
/// Tolerant mode only; the walk ends at the first `;` or construct keyword
|
||||
/// outside the value, so it is bounded by the item.
|
||||
pub(super) fn value_left_open(&self) -> bool {
|
||||
let open = self.pos;
|
||||
let line = self.cur().line;
|
||||
let mut depth = 0u32;
|
||||
let mut i = open + 1;
|
||||
while let Some(t) = self.tokens.get(i) {
|
||||
if t.line != line || t.kind == TokenKind::Eof {
|
||||
break;
|
||||
}
|
||||
if is_open_bracket(t) {
|
||||
depth += 1;
|
||||
} else if is_close_bracket(t) {
|
||||
if depth == 0 {
|
||||
return false;
|
||||
}
|
||||
depth -= 1;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
let Some(next) = self.tokens.get(i) else { return false };
|
||||
let starts_new = next.kind == TokenKind::Eof
|
||||
|| next.kind == TokenKind::Keyword
|
||||
|| next.is_sym(".")
|
||||
|| next.is_sym(")")
|
||||
|| next.is_sym(";");
|
||||
starts_new && !self.value_closes(open)
|
||||
}
|
||||
|
||||
/// Whether the bracket at token `open` is closed by a `)` that a valid
|
||||
/// connection list could have written next: anything but a `;`, end of
|
||||
/// file, a construct keyword, a `.` or a plain identifier after it. A
|
||||
/// `;` or construct keyword reached first, outside any bracket the value
|
||||
/// opened, means it is never closed at all.
|
||||
fn value_closes(&self, open: usize) -> bool {
|
||||
let mut depth = 0u32;
|
||||
let mut i = open + 1;
|
||||
while let Some(t) = self.tokens.get(i) {
|
||||
if t.kind == TokenKind::Eof {
|
||||
return false;
|
||||
}
|
||||
if is_open_bracket(t) {
|
||||
depth += 1;
|
||||
} else if is_close_bracket(t) {
|
||||
if depth == 0 {
|
||||
return self.tokens.get(i + 1).is_some_and(|after| !ends_a_value_badly(after));
|
||||
}
|
||||
depth -= 1;
|
||||
} else if depth == 0 && (t.is_sym(";") || is_sync_stop(t)) {
|
||||
return false;
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// True on a token that opens a bracket.
|
||||
fn at_open_bracket(&self) -> bool {
|
||||
is_open_bracket(self.cur())
|
||||
}
|
||||
|
||||
/// True on a `` `ifdef `` / `` `ifndef `` / `` `else `` / `` `elsif `` /
|
||||
/// `` `endif ``: a directive that opens, continues or closes a
|
||||
/// conditional-compilation region.
|
||||
@@ -267,12 +438,6 @@ impl<'a> Parser<'a> {
|
||||
RawText { text: self.slice(span), col, span }
|
||||
}
|
||||
|
||||
/// True on a token that opens a bracket.
|
||||
fn at_open_bracket(&self) -> bool {
|
||||
let t = self.cur();
|
||||
t.is_sym("(") || t.is_sym("[") || t.is_sym("{")
|
||||
}
|
||||
|
||||
/// The extent a recovery covers: from `start` through the last token it
|
||||
/// took, or the empty range at `start` when it took none (the sync point
|
||||
/// was already under the cursor).
|
||||
@@ -340,3 +505,25 @@ impl<'a> Parser<'a> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// True on a `(`, `[` or `{`.
|
||||
fn is_open_bracket(t: &Token) -> bool {
|
||||
t.is_sym("(") || t.is_sym("[") || t.is_sym("{")
|
||||
}
|
||||
|
||||
/// True on a `)`, `]` or `}`.
|
||||
fn is_close_bracket(t: &Token) -> bool {
|
||||
t.is_sym(")") || t.is_sym("]") || t.is_sym("}")
|
||||
}
|
||||
|
||||
/// True on a token no valid connection list writes right after a value's
|
||||
/// closing `)`: the list was never closed (`;`, end of file, a construct
|
||||
/// keyword), or the next connection follows with no `,` (`.`, or a plain
|
||||
/// identifier — a macro invocation is a directive's business and allowed).
|
||||
fn ends_a_value_badly(t: &Token) -> bool {
|
||||
t.kind == TokenKind::Eof
|
||||
|| t.is_sym(";")
|
||||
|| t.is_sym(".")
|
||||
|| is_sync_stop(t)
|
||||
|| (t.kind == TokenKind::Ident && !t.is_macro())
|
||||
}
|
||||
Reference in new issue
Block a user