Escaped identifiers: the terminating space, written once at fifty sites
coverage_gaps H3. An escaped identifier ends at whitespace (IEEE 1800 5.6.1) and the lexer stops the token before it; the formatter emitted every name bare or through a format! splice, so \my-signal; re-lexed as one token and the safety net refused the whole file - netlists and generated RTL could not be formatted at all. One choke point (format::named / name_doc, predicate ends_escaped because parser-joined composites like a.\b end inside an escaped name) now terminates the name; the space is unconditional and the printer's trailing trim removes it before a break, so doc.rs and printer.rs are untouched. verify.rs untouched; eight masked-corruption attack pairs; corpus byte-identical by construction (every corpus backslash is inside a string or a comment). Ran in its own worktree in parallel with member completion. Open, filed as topo 2.9-21: a scoped name whose segment is escaped is refused, never corrupted, until the parser keeps segments. docs/features/escaped-identifiers/README.md; TODO.md section 19. Co-Authored-By: Claude Fable 5 <[email protected]>
This commit is contained in:
1 parent
df85fd3b54
commit
7d637323a5
6 files changed
+966
-89
No files matched your search
@@ -1030,6 +1030,29 @@ mod tests {
|
||||
assert_eq!((err.line, err.col), (1, 15));
|
||||
}
|
||||
|
||||
/// IEEE 1800-2017 §5.6.1: an escaped identifier runs from its `\` to the
|
||||
/// next whitespace character, which is *not* part of the token. Everything
|
||||
/// downstream depends on this split — the formatter has to write that
|
||||
/// terminator back itself, because the token it is handed does not carry
|
||||
/// it (see `docs/features/escaped-identifiers/README.md`).
|
||||
#[test]
|
||||
fn an_escaped_identifier_ends_before_its_terminating_whitespace() {
|
||||
let toks = kinds("wire \\my-signal ;");
|
||||
assert_eq!(toks[1], (TokenKind::Ident, "\\my-signal".to_string()));
|
||||
assert_eq!(toks[2], (TokenKind::Symbol, ";".to_string()));
|
||||
// Any whitespace ends it, and punctuation ends nothing: `\a;` is one
|
||||
// identifier that has swallowed the semicolon.
|
||||
let texts: Vec<String> = kinds("\\a\tb \\c\n\\d ;").into_iter().map(|(_, t)| t).collect();
|
||||
assert_eq!(texts, ["\\a", "b", "\\c", "\\d", ";", ""]);
|
||||
assert_eq!(kinds("wire \\a;")[1], (TokenKind::Ident, "\\a;".to_string()));
|
||||
// A name may end the file: there is nothing left to terminate it.
|
||||
assert_eq!(kinds("wire \\a")[1], (TokenKind::Ident, "\\a".to_string()));
|
||||
// The span stops with the text, so `src[span] == text`.
|
||||
let toks = tokenize("wire \\my-signal ;").unwrap();
|
||||
let span = toks[1].span;
|
||||
assert_eq!(&"wire \\my-signal ;"[span.start as usize..span.end as usize], "\\my-signal");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn operators() {
|
||||
let toks = kinds("a <<< b === c !== d <= e");
|
||||
|
||||
Reference in new issue
Block a user