First request after an edit −19 % (§63.2, N1 of the 0.52.0 review): the flush split on the timing line (rebuild{lex parse defines analyze external lines publish documents}) named lex 29 + parse 26 of a 100 ms flush and no second lint or analysis; the lexer's two phases fused (the intermediate Vec<RawTok> gone), Parser::skip for the 178 bump() sites that discarded the token, a first-byte test in front of the operator table (tokenize 27.8 → 11.6 ms). Pinmux first menu after didChange 109 → 88 ms paired; every other row within noise; RSS not up. Token stream, diagnostics, AST and symbols digested over 4 807 files: 0 differ (re-derived by QA against a rebuilt 1b8723c); five gap fuzzers at their pins; corpus and opentitan byte-identical. Lead: an orphan trailing comment leads the next token instead of vanishing (unreachable, kept as a rule). QA: 16 attack tests, the flat-groups guard the harness relies on.
ci / checks (push) Successful in 1m16s
ci / corpus (push) Successful in 34s

Co-Authored-By: Claude Fable 5.1 <[email protected]>
This commit is contained in:
lucioandClaude Fable 5.1 committed 2026-09-12 03:11:59 -07:00
1 parent 1b8723ca1f
commit c82978c3db
30 files changed
+1513 -260

No files matched your search

+280 -62
View File
@@ -403,8 +403,14 @@ impl<'a> RawLexer<'a> {
});
}
// Operators, longest match first.
// Operators, longest match first. The first-byte test is not a second
// way of matching — `starts_with` still decides — it is what keeps a
// `;` from being compared against all 42 spellings: one byte compare
// rejects every operator that cannot start here (TODO §63.2).
for op in OPERATORS {
if op.as_bytes()[0] != c {
continue;
}
if self.starts_with(op) {
for _ in 0..op.len() {
self.bump();
@@ -918,80 +924,111 @@ fn is_line_directive(word: &str) -> bool {
)
}
/// What the attachment phase carries from one raw token to the next.
#[derive(Default)]
struct Attaching {
/// Comments waiting for the real token they lead.
pending: Vec<Comment>,
/// Whether a blank line was seen since the last pending comment.
pending_blank: bool,
}
/// Tokenize source text, attaching comments and blank-line info to tokens.
///
/// The two phases are **fused**: each raw token is attached as it is lexed,
/// rather than collected into a `Vec<RawTok>` the attachment loop then walks.
/// Attachment only ever reads the raw token in hand and the token last pushed,
/// so the fusion is a pure reordering — it drops a second whole-file vector
/// (a 40 267-line file's worth of it is ~22 MB of allocation, growth copying
/// and teardown), which is why the first request after an edit pays less for
/// the same tokens (TODO §63.2).
pub fn tokenize(source: &str) -> Result<Vec<Token>, LexError> {
let mut raw_lexer = RawLexer::new(source.as_bytes());
let mut raws: Vec<RawTok> = Vec::new();
let mut tokens: Vec<Token> = Vec::with_capacity(estimated_tokens(source.len()));
let mut state = Attaching::default();
loop {
let tok = raw_lexer.next_raw()?;
let is_eof = tok.kind == RawKind::Real(TokenKind::Eof);
raws.push(tok);
let raw = raw_lexer.next_raw()?;
let is_eof = raw.kind == RawKind::Real(TokenKind::Eof);
attach(raw, &mut tokens, &mut state);
if is_eof {
break;
}
}
Ok(tokens)
}
// Attachment phase.
let mut tokens: Vec<Token> = Vec::new();
let mut pending: Vec<Comment> = Vec::new();
let mut pending_blank = false;
/// How many tokens a source of `bytes` bytes is guessed to hold.
///
/// Only to spare the growing vector its early doublings; a wrong guess costs
/// nothing but the growth it would have paid anyway. Six bytes a token is the
/// measured average over the corpus and over opentitan's generated register
/// files alike, and the guess is capped so a pathological file (one enormous
/// string literal) cannot reserve more than it could ever need.
fn estimated_tokens(bytes: usize) -> usize {
(bytes / 6).min(1 << 20)
}
for raw in raws {
match raw.kind {
RawKind::LineComment | RawKind::BlockComment => {
let same_line_as_prev =
raw.newlines_before == 0 && !tokens.is_empty() && pending.is_empty();
let comment = Comment {
text: raw.text,
blank_before: raw.newlines_before > 1 || pending_blank,
line: raw.line,
col: raw.col,
span: raw.span,
};
if same_line_as_prev {
// Trailing comment for the previous real token.
let prev = tokens.last_mut().unwrap();
match &mut prev.trailing {
Some(existing) => {
// Two comments on one line become one node, so its
// span has to cover both — the merge normalizes
// the gap between them to a single space, which is
// why a merged comment is the one comment whose
// text can differ from `source[span]`.
existing.text.push(' ');
existing.text.push_str(&comment.text);
existing.span = TextRange::new(existing.span.start, comment.span.end);
}
None => prev.trailing = Some(comment),
}
} else {
pending.push(comment);
pending_blank = false;
}
}
RawKind::Real(kind) => {
let blank_before = if pending.is_empty() {
raw.newlines_before > 1
} else {
// Comments already carry their own blank flags; the token
// is blank-separated only if there was a blank line
// between the last comment and the token itself.
raw.newlines_before > 1
};
tokens.push(Token {
kind,
text: raw.text,
line: raw.line,
col: raw.col,
span: raw.span,
leading: std::mem::take(&mut pending),
trailing: None,
blank_before,
});
/// Fold one raw token into the token stream: a comment onto its neighbour,
/// a real token onto the end with whatever comments were waiting for it.
fn attach(raw: RawTok, tokens: &mut Vec<Token>, state: &mut Attaching) {
match raw.kind {
RawKind::LineComment | RawKind::BlockComment => {
let same_line_as_prev =
raw.newlines_before == 0 && !tokens.is_empty() && state.pending.is_empty();
let comment = Comment {
text: raw.text,
blank_before: raw.newlines_before > 1 || state.pending_blank,
line: raw.line,
col: raw.col,
span: raw.span,
};
// A comment that finds no token to trail — unreachable while
// `same_line_as_prev` requires one, kept as a rule rather than a
// hope — leads the next token instead of vanishing (invariant 3).
let orphan =
if same_line_as_prev { attach_trailing(tokens, comment) } else { Some(comment) };
if let Some(comment) = orphan {
state.pending.push(comment);
state.pending_blank = false;
}
}
RawKind::Real(kind) => {
// Comments already carry their own blank flags; the token is
// blank-separated only if there was a blank line between the last
// comment and the token itself — which is the same test either
// way, so `pending` does not enter into it.
let blank_before = raw.newlines_before > 1;
tokens.push(Token {
kind,
text: raw.text,
line: raw.line,
col: raw.col,
span: raw.span,
leading: std::mem::take(&mut state.pending),
trailing: None,
blank_before,
});
}
}
Ok(tokens)
}
/// Hang a comment off the token before it, merging with one already there.
/// Handed back untouched when there is no token before it.
fn attach_trailing(tokens: &mut [Token], comment: Comment) -> Option<Comment> {
let Some(prev) = tokens.last_mut() else { return Some(comment) };
match &mut prev.trailing {
Some(existing) => {
// Two comments on one line become one node, so its span has to
// cover both — the merge normalizes the gap between them to a
// single space, which is why a merged comment is the one comment
// whose text can differ from `source[span]`.
existing.text.push(' ');
existing.text.push_str(&comment.text);
existing.span = TextRange::new(existing.span.start, comment.span.end);
}
None => prev.trailing = Some(comment),
}
None
}
#[cfg(test)]
@@ -1510,4 +1547,185 @@ mod tests {
assert!(texts.contains(&"!=="));
assert!(texts.contains(&"<="));
}
// ------------------------------------------------------------------
// TODO §63.2 QA: the fused attach phase, attacked
//
// These cover the shapes the two-phase code (a `Vec<RawTok>` fully
// built, then walked) could tell apart from the fused one-pass code
// (each raw token attached as it is produced) if the fusion were not a
// pure reordering: a comment with no token before it at all, comments
// that never see a "previous token" until much later, EOF immediately
// after a trailing comment, and so on. Every one of these was also
// cross-checked, file for file, against `tokenize` built from 1b8723c
// (the pre-fusion tree) with a throwaway digest tool in the QA
// scratchpad — token-for-token identical, hash and manual `Debug`
// inspection alike; the assertions below pin that result durably.
// ------------------------------------------------------------------
#[test]
fn a_comment_as_the_very_first_thing_in_the_file_is_the_first_token_s_leading() {
let toks = tokenize("// only thing before the module\nmodule m;\nendmodule").unwrap();
assert_eq!(toks[0].leading.len(), 1);
assert_eq!(toks[0].leading[0].text, "// only thing before the module");
assert!(!toks[0].leading[0].blank_before);
}
#[test]
fn two_comments_on_the_first_line_before_any_token_both_lead_it() {
// Two *separate* comments here means two lines, each its own line
// comment (a line comment always runs to end of line, so "two
// comments on one line" before any token is only possible with
// block comments — covered by `two_block_comments_on_one_line_merge`
// below).
let toks = tokenize("// one\n// two\nmodule m;\nendmodule").unwrap();
assert_eq!(toks[0].leading.len(), 2);
assert_eq!(toks[0].leading[0].text, "// one");
assert_eq!(toks[0].leading[1].text, "// two");
assert!(!toks[0].leading[1].blank_before);
}
#[test]
fn a_trailing_comment_after_the_last_real_token_reaches_eof() {
let toks = tokenize("module m;\nendmodule // trailing at eof\n").unwrap();
let end = toks.iter().find(|t| t.is_kw("endmodule")).unwrap();
let trailing = end.trailing.as_ref().expect("trailing comment on endmodule");
assert_eq!(trailing.text, "// trailing at eof");
assert_eq!(toks.last().unwrap().kind, TokenKind::Eof);
}
#[test]
fn two_block_comments_on_one_line_merge_into_one_trailing_comment() {
let toks = tokenize("wire w; /* one */ /* two */\nendmodule").unwrap();
let semi = toks.iter().find(|t| t.is_sym(";")).unwrap();
let trailing = semi.trailing.as_ref().expect("merged trailing comment");
assert_eq!(trailing.text, "/* one */ /* two */");
}
#[test]
fn a_blank_line_between_a_comment_and_its_token_marks_both() {
let toks = tokenize("// lead\n\nmodule m;\nendmodule").unwrap();
assert_eq!(toks[0].leading.len(), 1);
// The comment itself is not blank-separated from what came before it
// (nothing did); the blank line sits between the comment and the
// token, so the *token* carries the flag.
assert!(!toks[0].leading[0].blank_before);
assert!(toks[0].blank_before);
}
#[test]
fn crlf_line_endings_lex_like_lf_with_the_same_comment_attachment() {
let toks = tokenize("module m; // c\r\nendmodule\r\n").unwrap();
let semi = toks.iter().find(|t| t.is_sym(";")).unwrap();
assert_eq!(semi.trailing.as_ref().unwrap().text, "// c");
let end = toks.iter().find(|t| t.is_kw("endmodule")).unwrap();
assert_eq!(end.line, 2);
}
#[test]
fn a_block_comment_spanning_lines_still_leads_a_same_line_token() {
let toks = tokenize("/* block\n spanning\n lines */ module m;\nendmodule").unwrap();
assert_eq!(toks[0].leading.len(), 1);
assert!(toks[0].leading[0].text.starts_with("/* block"));
assert!(toks[0].leading[0].text.ends_with("lines */"));
// The module keyword itself sits on the block comment's last line.
assert_eq!(toks[0].line, 3);
}
#[test]
fn a_comment_between_a_macro_invocation_and_its_arguments_trails_the_macro() {
let toks = tokenize("module m;\n`MYMACRO /*c*/ (a, b);\nendmodule").unwrap();
let mac = toks.iter().find(|t| t.text == "`MYMACRO").unwrap();
assert_eq!(mac.trailing.as_ref().unwrap().text, "/*c*/");
// The macro call's parenthesized arguments are unaffected — still
// ordinary tokens right after, comment or not.
let open_paren_idx = toks.iter().position(|t| t.is_sym("(")).unwrap();
assert_eq!(toks[open_paren_idx + 1].text, "a");
}
#[test]
fn a_file_that_is_only_comments_attaches_them_all_to_the_synthetic_eof() {
let toks = tokenize("// only a comment, nothing else\n").unwrap();
assert_eq!(toks.len(), 1);
assert_eq!(toks[0].kind, TokenKind::Eof);
assert_eq!(toks[0].leading.len(), 1);
assert_eq!(toks[0].leading[0].text, "// only a comment, nothing else");
}
#[test]
fn an_empty_file_lexes_to_a_lone_eof_with_no_comments() {
let toks = tokenize("").unwrap();
assert_eq!(toks.len(), 1);
assert_eq!(toks[0].kind, TokenKind::Eof);
assert!(toks[0].leading.is_empty());
}
// ------------------------------------------------------------------
// TODO §63.2 QA: the operator table's first-byte test
// ------------------------------------------------------------------
#[test]
fn every_operator_s_first_byte_is_a_single_ascii_byte() {
// `op.as_bytes()[0] != c` compares one byte of `c: u8` against the
// table entry's first *byte*. If any entry's first character were
// multi-byte UTF-8, its first byte alone would not identify it and
// the guard could reject a spelling it should have let through. Every
// entry here is pure ASCII punctuation, so the byte comparison is the
// whole character.
for op in OPERATORS {
let first = op.chars().next().expect("no empty operator spellings");
assert!(first.is_ascii(), "{op:?} does not start with an ASCII byte");
assert_eq!(
op.as_bytes()[0],
first as u8,
"{op:?}'s first byte does not match its first char"
);
}
}
#[test]
fn the_operator_table_has_no_duplicate_or_empty_entries() {
// A duplicate wastes a comparison; an empty entry would make
// `op.as_bytes()[0]` panic before ever reaching `starts_with`.
for op in OPERATORS {
assert!(!op.is_empty());
}
let mut sorted = OPERATORS.to_vec();
sorted.sort_unstable();
sorted.dedup();
assert_eq!(sorted.len(), OPERATORS.len(), "OPERATORS has a duplicate entry");
}
#[test]
fn every_operator_followed_by_every_other_operator_still_lexes_without_a_gap() {
// The first-byte test must not change *which* entry `starts_with`
// picks — only how many entries are tried before it does. Lexing
// every `op1 op2` concatenation (no space) and requiring the token
// stream to account for every byte with no lex error is the
// regression gate: a wrong short-circuit would either misplace the
// split point or leave a byte unconsumed. Cross-checked pair for
// pair against `tokenize` built from 1b8723c (pre-first-byte-test)
// in the QA scratchpad: 1 764 pairs, 0 differ.
for &op1 in OPERATORS {
for &op2 in OPERATORS {
let src = format!("{op1}{op2} ;");
let toks = tokenize(&src)
.unwrap_or_else(|e| panic!("lexing {op1:?} followed by {op2:?} failed: {e}"));
// Everything up to the space must be Symbol tokens whose
// texts concatenate back to exactly op1 followed by op2,
// with no gap and no overlap.
let mut consumed = String::new();
let mut i = 0;
while toks[i].kind == TokenKind::Symbol && toks[i].text != ";" {
consumed.push_str(&toks[i].text);
i += 1;
}
assert_eq!(
consumed,
format!("{op1}{op2}"),
"{op1:?} followed by {op2:?} did not round-trip"
);
}
}
}
}
+17 -17
View File
@@ -53,11 +53,11 @@ impl<'a> Parser<'a> {
let start = self.here();
let col = self.cur().col;
if self.cur().kind == TokenKind::Ident && self.nth(1).is_sym(":") {
self.bump();
self.bump();
self.skip();
self.skip();
}
// `assert` / `assume` / `cover` / `restrict`.
self.bump();
self.skip();
self.expect_kw("property")?;
self.expect_sym("(")?;
self.skip_balanced("(", ")")?;
@@ -132,22 +132,22 @@ impl<'a> Parser<'a> {
at_stmt_start = false;
let t = self.cur();
if t.is_sym("(") {
self.bump();
self.skip();
self.skip_balanced("(", ")")?;
} else if t.is_sym("[") {
self.bump();
self.skip();
self.skip_balanced("[", "]")?;
} else if t.is_sym("{") {
self.bump();
self.skip();
self.skip_balanced("{", "}")?;
} else if (t.is_kw("disable") || t.is_kw("wait")) && self.nth(1).is_kw("fork") {
// `disable fork` / `wait fork` name the enclosing block; they
// do not open one.
self.bump();
self.bump();
self.skip();
self.skip();
} else if BLOCK_OPENERS.iter().any(|k| t.is_kw(k)) {
depth += 1;
self.bump();
self.skip();
} else if BLOCK_CLOSERS.iter().any(|k| t.is_kw(k)) {
if depth == 0 {
// A closer with nothing open: the action statement is
@@ -156,7 +156,7 @@ impl<'a> Parser<'a> {
return self.error("expected `;`");
}
depth -= 1;
self.bump();
self.skip();
if depth == 0 {
self.parse_label()?;
if !self.eat_kw("else") {
@@ -167,7 +167,7 @@ impl<'a> Parser<'a> {
} else if depth == 0 && self.eat_sym(";") {
return Ok(());
} else {
self.bump();
self.skip();
}
}
}
@@ -199,9 +199,9 @@ impl<'a> Parser<'a> {
let start = self.here();
let col = self.cur().col;
let end_kw = if self.cur().is_kw("sequence") { "endsequence" } else { "endproperty" };
self.bump();
self.skip();
while !self.at_eof() && !self.cur().is_kw(end_kw) {
self.bump();
self.skip();
}
self.expect_closer(end_kw)?;
self.parse_label()?;
@@ -220,7 +220,7 @@ impl<'a> Parser<'a> {
fn parse_default_disable(&mut self) -> PResult<RawText> {
let start = self.here();
let col = self.cur().col;
self.bump(); // default
self.skip(); // default
self.expect_kw("disable")?;
self.expect_kw("iff")?;
self.skip_to_semi()?;
@@ -252,7 +252,7 @@ impl<'a> Parser<'a> {
fn parse_prop_seq_decl_inner(&mut self) -> PResult<PropSeqDecl> {
let kw = self.cur().text.clone();
let end_kw = if kw == "sequence" { "endsequence" } else { "endproperty" };
self.bump();
self.skip();
let before_name = self.take_gap();
let name = self.expect_name()?;
let before_args = self.take_before_open("(");
@@ -407,7 +407,7 @@ impl<'a> Parser<'a> {
let mut action = ActionBlock::default();
if self.cur().is_sym(";") {
action.before = self.take_gap();
self.bump();
self.skip();
return Ok(action);
}
if !self.cur().is_kw("else") {
@@ -415,7 +415,7 @@ impl<'a> Parser<'a> {
}
if self.cur().is_kw("else") {
action.before_else = self.take_gap();
self.bump();
self.skip();
action.after_else = self.take_gap();
action.fail = Some(Box::new(self.parse_stmt()?));
}
+12 -12
View File
@@ -94,7 +94,7 @@ impl<'a> Parser<'a> {
let mut after_hash = Vec::new();
let mut param_directives = Vec::new();
if self.cur().is_sym("#") {
self.bump();
self.skip();
after_hash = self.take_gap();
self.expect_sym("(")?;
let mark = self.diags_mark();
@@ -305,7 +305,7 @@ impl<'a> Parser<'a> {
return self.parse_constraint_foreach();
}
if self.cur().is_kw("unique") && self.nth(1).is_sym("{") {
self.bump();
self.skip();
let comments = self.take_gap();
let items = self.parse_constraint_expr_set()?;
return Ok(ConstraintItemKind::Unique { items, comments });
@@ -314,9 +314,9 @@ impl<'a> Parser<'a> {
// `soft` is matched by text, for the reason `parse_constraint_expr`
// gives.
if self.cur().is_kw("disable") && word_at(self.nth(1), "soft") {
self.bump();
self.skip();
let before = self.take_gap();
self.bump();
self.skip();
let after = self.take_gap();
let expr = self.parse_expr()?;
return Ok(ConstraintItemKind::DisableSoft {
@@ -341,7 +341,7 @@ impl<'a> Parser<'a> {
let soft = self.at_soft_constraint();
let mut after_soft = Vec::new();
if soft {
self.bump();
self.skip();
after_soft = self.take_gap();
}
let mark = self.pending_trailing.len();
@@ -374,7 +374,7 @@ impl<'a> Parser<'a> {
}
if !soft && self.cur().is_sym("->") {
let before = self.take_around(mark);
self.bump();
self.skip();
let after = self.take_around(mark);
let set = self.parse_constraint_set()?;
return Ok(ConstraintItemKind::Implication {
@@ -403,7 +403,7 @@ impl<'a> Parser<'a> {
let mut els = None;
if self.cur().is_kw("else") {
else_comments = self.take_dangling();
self.bump();
self.skip();
// The gap after `else` is this item's when the set it introduces
// opens with a token of its own — a `{`, or the `if` of a chain.
// A set written on the next line leaves it to that item's own
@@ -458,13 +458,13 @@ impl<'a> Parser<'a> {
}
fn parse_solve_before(&mut self) -> PResult<ConstraintItemKind> {
self.bump(); // solve
self.skip(); // solve
let solve = self.parse_solve_operands()?;
if !word_at(self.cur(), "before") {
return self.error("expected `before`");
}
let before_comments = self.take_gap();
self.bump();
self.skip();
let before = self.parse_solve_operands()?;
Ok(ConstraintItemKind::SolveBefore { solve, before_comments, before })
}
@@ -526,7 +526,7 @@ impl<'a> Parser<'a> {
expr: Expr,
before: Vec<Comment>,
) -> PResult<Expr> {
self.bump(); // dist
self.skip(); // dist
let after = self.take_gap();
self.expect_sym("{")?;
let mut weights: Vec<DistItem> = Vec::new();
@@ -539,8 +539,8 @@ impl<'a> Parser<'a> {
let mut op_comments = BinaryComments::default();
if let Some(spelling) = self.dist_weight_op() {
op_comments.before = self.take_gap();
self.bump();
self.bump();
self.skip();
self.skip();
op_comments.after = self.take_gap();
op = Some(spelling.to_string());
weight = Some(self.parse_ternary()?);
+22 -22
View File
@@ -56,7 +56,7 @@ impl<'a> Parser<'a> {
self.take_member_prefix();
self.expect_kw("covergroup")?;
while !self.at_eof() && !self.cur().is_kw("endgroup") {
self.bump();
self.skip();
}
self.expect_closer("endgroup")?;
self.parse_label()?;
@@ -139,7 +139,7 @@ impl<'a> Parser<'a> {
fn parse_coverage_event(&mut self) -> PResult<Option<CoverageEvent>> {
if self.cur().is_kw("with") {
let before_with = self.take_gap();
self.bump();
self.skip();
let after_with = self.take_gap();
self.expect_kw("function")?;
let after_function = self.take_gap();
@@ -147,7 +147,7 @@ impl<'a> Parser<'a> {
return self.error("expected `sample`");
}
let name = Name { text: self.cur().text.clone(), span: self.cur().span };
self.bump();
self.skip();
let before_args = self.take_before_open("(");
let has_parens = self.cur().is_sym("(");
let args = self.parse_tf_ports(false)?.args;
@@ -163,7 +163,7 @@ impl<'a> Parser<'a> {
}
if self.cur().is_sym("@") {
let before = self.take_gap();
self.bump();
self.skip();
let sens = self.parse_sens_list()?;
return Ok(Some(CoverageEvent::Clocking { before, sens }));
}
@@ -206,9 +206,9 @@ impl<'a> Parser<'a> {
&& (word_at(self.nth(2), "coverpoint") || word_at(self.nth(2), "cross"))
{
let name = Name { text: self.cur().text.clone(), span: self.cur().span };
self.bump();
self.skip();
let before = self.take_gap();
self.bump(); // :
self.skip(); // :
let after = self.take_gap();
Some(CoverLabel { name, comments: Box::new(BinaryComments { before, after }) })
} else {
@@ -224,7 +224,7 @@ impl<'a> Parser<'a> {
}
fn parse_coverpoint(&mut self, label: Option<CoverLabel>) -> PResult<CoverpointDecl> {
self.bump(); // coverpoint
self.skip(); // coverpoint
let after_kw = self.take_gap();
let expr = self.parse_expr()?;
let iff = self.parse_cover_iff()?;
@@ -234,7 +234,7 @@ impl<'a> Parser<'a> {
}
fn parse_cross(&mut self, label: Option<CoverLabel>) -> PResult<CrossDecl> {
self.bump(); // cross
self.skip(); // cross
let after_kw = self.take_gap();
let mut items: Vec<ExprItem> = Vec::new();
loop {
@@ -265,7 +265,7 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let before_kw = self.take_gap();
self.bump();
self.skip();
let after_kw = self.take_gap();
self.expect_sym("(")?;
let after_open = self.take_gap();
@@ -356,13 +356,13 @@ impl<'a> Parser<'a> {
let wildcard = word_at(self.cur(), "wildcard") && bin_kind_at(self.nth(1)).is_some();
let mut after_wildcard = Vec::new();
if wildcard {
self.bump();
self.skip();
after_wildcard = self.take_gap();
}
let Some(kind) = bin_kind_at(self.cur()) else {
return self.error("expected `bins`, `ignore_bins` or `illegal_bins`");
};
self.bump();
self.skip();
let before_name = self.take_gap();
let name = self.expect_name()?;
let array = self.parse_bin_array()?;
@@ -392,7 +392,7 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let before = self.take_gap();
self.bump();
self.skip();
let inner_before = self.take_gap();
let size = if self.cur().is_sym("]") { None } else { Some(self.parse_expr()?) };
let inner_after = self.gap_before("]");
@@ -412,12 +412,12 @@ impl<'a> Parser<'a> {
/// `bins b = (1'b1[*5]);` wrong.
fn parse_bin_spec(&mut self, in_cross: bool) -> PResult<BinSpec> {
if self.cur().is_kw("default") {
self.bump();
self.skip();
// `sequence` really is a lexer keyword (a `sequence ... endsequence`
// declaration), so this one is not matched by text.
if self.cur().is_kw("sequence") {
let comments = self.take_gap();
self.bump();
self.skip();
return Ok(BinSpec::DefaultSequence { comments });
}
return Ok(BinSpec::Default);
@@ -446,7 +446,7 @@ impl<'a> Parser<'a> {
break;
}
let before = self.take_gap();
self.bump();
self.skip();
let after = self.take_gap();
arrow = BinaryComments { before, after };
}
@@ -494,7 +494,7 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let before = self.take_gap();
self.bump(); // [
self.skip(); // [
let after_open = self.take_gap();
let op = self.bump().text;
let inner_before = self.take_gap();
@@ -503,7 +503,7 @@ impl<'a> Parser<'a> {
let mut hi = None;
if self.cur().is_sym(":") {
colon.before = self.take_gap();
self.bump();
self.skip();
colon.after = self.take_gap();
hi = Some(self.parse_expr()?);
}
@@ -541,13 +541,13 @@ impl<'a> Parser<'a> {
fn parse_select_primary(&mut self) -> PResult<SelectExpr> {
if self.cur().is_sym("!") {
self.bump();
self.skip();
let comments = self.take_gap();
let expr = self.parse_select_primary()?;
return Ok(SelectExpr::Not { comments, expr: Box::new(expr) });
}
if self.cur().is_sym("(") {
self.bump();
self.skip();
let before = self.take_gap();
let expr = self.parse_select_expr()?;
let after = self.gap_before(")");
@@ -577,7 +577,7 @@ impl<'a> Parser<'a> {
}
fn parse_binsof(&mut self) -> PResult<BinsofSel> {
self.bump(); // binsof
self.skip(); // binsof
let after_kw = self.take_gap();
self.expect_sym("(")?;
let after_open = self.take_gap();
@@ -589,7 +589,7 @@ impl<'a> Parser<'a> {
let mut intersect = None;
if word_at(self.cur(), "intersect") {
before_intersect = self.take_gap();
self.bump();
self.skip();
after_intersect = self.take_gap();
intersect = Some(self.parse_constraint_expr_set()?);
}
@@ -610,7 +610,7 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let before_kw = self.take_gap();
self.bump();
self.skip();
let after_kw = self.take_gap();
self.expect_sym("(")?;
let after_open = self.take_gap();
+27 -2
View File
@@ -63,6 +63,31 @@ impl<'a> Parser<'a> {
t
}
/// Consume the current token without building a copy of it.
///
/// Exactly [`Parser::bump`] for the caller that throws the token away —
/// the same comment plumbing, the same cursor step, the same `self.tokens`
/// left untouched — minus the clone. `bump` copies the token's `text`
/// (a `String`, so an allocation) and its comment buckets for a value most
/// callers drop on the next line; on a 40 267-line generated file that is
/// one allocate-and-free per token consumed (TODO §63.2).
pub(super) fn skip(&mut self) {
let token = &self.tokens[self.pos];
// Cloned rather than moved out, because `bump` moved them out of its
// *copy*: the stream keeps its comments either way, which is what the
// rewind of a speculative parse relies on.
let (mut leading, trailing) = (token.leading.clone(), token.trailing.clone());
if self.pos + 1 < self.tokens.len() {
self.pos += 1;
}
if !leading.is_empty() {
self.pending_leading.append(&mut leading);
}
if let Some(trailing) = trailing {
self.pending_trailing.push(trailing);
}
}
/// Open one level of nesting, refusing to recurse past
/// [`MAX_NESTING_DEPTH`]. Callers that succeed must pair this with
/// [`Parser::leave`] on every path out, including the error paths.
@@ -199,7 +224,7 @@ impl<'a> Parser<'a> {
pub(super) fn eat_sym(&mut self, sym: &str) -> bool {
if self.cur().is_sym(sym) {
self.bump();
self.skip();
true
} else {
false
@@ -208,7 +233,7 @@ impl<'a> Parser<'a> {
pub(super) fn eat_kw(&mut self, kw: &str) -> bool {
if self.cur().is_kw(kw) {
self.bump();
self.skip();
true
} else {
false
+7 -7
View File
@@ -39,7 +39,7 @@ impl<'a> Parser<'a> {
// this function with the `virtual` already taken into
// `DataDecl::qualifiers`, so this only fires for the other positions.)
if self.cur().is_kw("virtual") {
self.bump();
self.skip();
ty.virt =
Some(if self.eat_kw("interface") { VirtualKw::Interface } else { VirtualKw::Bare });
// `virtual spi_if.tb sif` — a modport-qualified virtual interface
@@ -97,12 +97,12 @@ impl<'a> Parser<'a> {
// comment inside the brackets could attach.
let mut comments =
SegmentComments { before_open: self.take_gap(), ..Default::default() };
self.bump();
self.skip();
comments.after_open = self.take_gap();
let kind = if self.cur().is_sym("]") {
// `[]` — a dynamic array.
comments.before_close = std::mem::take(&mut comments.after_open);
self.bump();
self.skip();
dims.push(Dim {
kind: DimKind::Dynamic,
comments: Box::new(comments),
@@ -111,7 +111,7 @@ impl<'a> Parser<'a> {
continue;
} else if self.cur().is_sym("*") && self.nth(1).is_sym("]") {
// `[*]` — a wildcard-keyed associative array.
self.bump();
self.skip();
DimKind::Wildcard
} else {
let a = self.parse_expr()?;
@@ -303,7 +303,7 @@ impl<'a> Parser<'a> {
// `wire /* c */ #5 w;`. Taken only here — when the read does not
// happen the gap belongs to whatever comes next.
let before_hash = self.take_gap();
self.bump();
self.skip();
let after_hash = self.take_gap();
Ok(Some(NetDelay { before_hash, after_hash, expr: self.parse_delay_value()?, after_type }))
}
@@ -392,7 +392,7 @@ impl<'a> Parser<'a> {
let mut eq_comments = BinaryComments::default();
let value = if self.cur().is_sym("=") {
eq_comments.before = self.take_gap();
self.bump();
self.skip();
eq_comments.after = self.take_gap();
Some(self.parse_expr()?)
} else {
@@ -436,7 +436,7 @@ impl<'a> Parser<'a> {
// grammar of their own and are still a clean parse error.
let tagged = word_at(self.cur(), "tagged");
if tagged {
self.bump();
self.skip();
header_comments.after_tagged = self.take_gap();
}
let packed = self.eat_kw("packed");
+2 -2
View File
@@ -347,8 +347,8 @@ impl<'a> Parser<'a> {
let raw = if self.at_spaced_macro_call() {
let start = self.here();
let col = self.cur().col;
self.bump(); // `NAME
self.bump(); // (
self.skip(); // `NAME
self.skip(); // (
self.skip_balanced("(", ")")?;
// Verbatim, space included: the argument text is preprocessor
// input lucisv does not model, and closing the gap would make the
+8 -8
View File
@@ -64,7 +64,7 @@ impl<'a> Parser<'a> {
// Each of the four gaps inside a `? :` can hold comments; kept
// apart so none of them drifts across the `?` or the `:`.
let before_question = self.take_around(mark);
self.bump();
self.skip();
let after_question = self.take_around(mark);
let then = self.parse_expr()?;
let before_colon = self.take_around(mark);
@@ -144,7 +144,7 @@ impl<'a> Parser<'a> {
// The word is an operator like any other, and keeps the
// comments written on either side of it the same way.
let before = self.take_around(mark);
self.bump();
self.skip();
let after = self.take_around(mark);
let comments = Box::new(BinaryComments { before, after });
// `x inside `MACRO` — the macro expands to the `{...}` set,
@@ -324,7 +324,7 @@ impl<'a> Parser<'a> {
let base = Box::new(base);
if self.cur().is_sym(".") || self.cur().is_sym("::") {
let scoped = self.cur().is_sym("::");
self.bump();
self.skip();
comments.after_open = self.take_gap();
let name = self.expect_ident()?;
let comments = Box::new(comments);
@@ -415,7 +415,7 @@ impl<'a> Parser<'a> {
before_open: self.take_before_open("("),
..CallComments::default()
};
self.bump();
self.skip();
let mut args = Vec::new();
if !self.cur().is_sym(")") {
let arg_start = self.here();
@@ -462,14 +462,14 @@ impl<'a> Parser<'a> {
},
);
} else if self.nth(1).is_sym("[") {
self.bump(); // with
self.skip(); // with
let range = self.parse_stream_range(comments)?;
expr = self.expr_at(
start,
ExprKind::StreamWith { base: Box::new(expr), range: Box::new(range) },
);
} else {
self.bump(); // with
self.skip(); // with
comments.after_kw = self.take_before_open("(");
// `( expression )` — an ordinary parenthesized primary,
// which is what IEEE 1800 §7.12 spells here.
@@ -511,9 +511,9 @@ impl<'a> Parser<'a> {
},
);
} else {
self.bump(); // '
self.skip(); // '
comments.after_tick = self.take_gap();
self.bump(); // (
self.skip(); // (
comments.after_open = self.take_gap();
let inner = self.parse_expr()?;
comments.before_close = self.gap_before(")");
+11 -11
View File
@@ -24,7 +24,7 @@ impl<'a> Parser<'a> {
let mut after_hash = Vec::new();
let mut after_delay = Vec::new();
let delay = if self.cur().is_sym("#") {
self.bump();
self.skip();
after_hash = self.take_gap();
let delay = self.parse_delay_value()?;
// The gap between the delay and the first left-hand side is the
@@ -82,7 +82,7 @@ impl<'a> Parser<'a> {
}
let mut comments =
Box::new(DriveStrengthComments { before_open: self.take_gap(), ..Default::default() });
self.bump(); // (
self.skip(); // (
comments.after_open = self.take_gap();
let first = self.bump().text;
// The gap after the first strength ends either at the `,` or at the
@@ -121,7 +121,7 @@ impl<'a> Parser<'a> {
// What is written just inside the `(` belongs to the first value; the
// gap before each `,` and the gap after it belong to the values either
// side of it.
self.bump();
self.skip();
let mut leading = self.take_gap();
let mut out: Vec<DelayValue> = Vec::new();
loop {
@@ -242,7 +242,7 @@ impl<'a> Parser<'a> {
/// `bind <target> [: <inst>, ...] <module> [#(...)] <name> (...);`
pub(super) fn parse_bind(&mut self) -> PResult<BindDirective> {
self.bump(); // `bind`
self.skip(); // `bind`
// The target is a bare string, so a comment written before it has no
// node to attach to: harvest it here, where source order is still
// known, rather than letting it drift onto the instance below.
@@ -250,7 +250,7 @@ impl<'a> Parser<'a> {
let start = self.here();
let mut target = vec![self.parse_path_segment()?];
while self.cur().is_sym(".") {
self.bump();
self.skip();
target.push(self.parse_path_segment()?);
}
let target_span = self.span_from(start);
@@ -278,7 +278,7 @@ impl<'a> Parser<'a> {
let start = self.here();
let mut text = self.expect_ident()?;
while self.cur().is_sym(".") {
self.bump();
self.skip();
let segment = self.expect_ident()?;
Self::push_path_segment(&mut text, &segment);
}
@@ -301,7 +301,7 @@ impl<'a> Parser<'a> {
let module_start = self.here();
let mut module = self.expect_ident()?;
while self.cur().is_sym("::") {
self.bump();
self.skip();
let segment = self.expect_ident()?;
Self::push_scope_segment(&mut module, &segment);
}
@@ -312,7 +312,7 @@ impl<'a> Parser<'a> {
let mut after_hash = Vec::new();
let mut param_directives = Vec::new();
if self.cur().is_sym("#") {
self.bump();
self.skip();
after_hash = self.take_gap();
self.expect_sym("(")?;
let mut list = Vec::new();
@@ -571,7 +571,7 @@ impl<'a> Parser<'a> {
// `.name(/* unused */)`: the comments were written inside
// these parens and are printed back inside them.
let inside = self.take_around(mark);
self.bump();
self.skip();
Some(self.expr_at(paren_start, ExprKind::Empty(inside)))
} else {
after_open = self.take_gap();
@@ -684,7 +684,7 @@ impl<'a> Parser<'a> {
let start = self.here();
let col = self.cur().col;
while self.pos < end_pos && !self.at_eof() {
self.bump();
self.skip();
}
let raw = self.verbatim_since(start, col);
self.expr_at(start, ExprKind::Verbatim(raw))
@@ -699,7 +699,7 @@ impl<'a> Parser<'a> {
let before_hash = self.take_before_open("#");
let mut after_hash = Vec::new();
let delay = if self.cur().is_sym("#") {
self.bump();
self.skip();
after_hash = self.take_gap();
self.parse_delay_values()?
} else {
+11 -11
View File
@@ -155,7 +155,7 @@ impl<'a> Parser<'a> {
// `TokenKind` match below because punctuation is matched by text
// everywhere in this file. See `ItemKind::Empty`.
if self.cur().is_sym(";") {
self.bump();
self.skip();
return Ok(ItemKind::Empty);
}
let t = self.cur();
@@ -209,7 +209,7 @@ impl<'a> Parser<'a> {
"modport" => self.parse_modport().map(ItemKind::Modport),
"clocking" => self.parse_clocking(false).map(ItemKind::Clocking),
"default" if self.nth(1).is_kw("clocking") => {
self.bump();
self.skip();
self.parse_clocking(true).map(ItemKind::Clocking)
}
"default" if self.nth(1).is_kw("disable") => self.parse_default_disable_item(),
@@ -243,7 +243,7 @@ impl<'a> Parser<'a> {
Ok(ItemKind::PortDecl(d))
}
"genvar" => {
self.bump();
self.skip();
let mut names = vec![self.expect_name()?];
while self.eat_sym(",") {
names.push(self.expect_name()?);
@@ -258,15 +258,15 @@ impl<'a> Parser<'a> {
Ok(ItemKind::Always { kw, stmt })
}
"initial" => {
self.bump();
self.skip();
Ok(ItemKind::Initial(self.parse_stmt()?))
}
"final" => {
self.bump();
self.skip();
Ok(ItemKind::Final(self.parse_stmt()?))
}
"generate" => {
self.bump();
self.skip();
let mut items = Vec::new();
while !self.at_body_end("endgenerate") {
items.push(self.item_or_recover()?);
@@ -339,7 +339,7 @@ impl<'a> Parser<'a> {
}
}
"defparam" => {
self.bump();
self.skip();
let mut pairs = Vec::new();
loop {
let lhs = self.parse_expr()?;
@@ -492,7 +492,7 @@ impl<'a> Parser<'a> {
loop {
let star = self.cur().span;
let pkg = if allow_star_pkg && self.cur().is_sym("*") {
self.bump();
self.skip();
Name { text: "*".to_string(), span: star }
} else {
self.expect_name()?
@@ -578,7 +578,7 @@ impl<'a> Parser<'a> {
}
let span = self.cur().span;
let name = Name { text: self.bump().text, span };
self.bump();
self.skip();
Some(name)
}
@@ -603,7 +603,7 @@ impl<'a> Parser<'a> {
let then = self.parse_gen_block()?;
let els = if self.cur().is_kw("else") {
let meta = self.take_meta();
self.bump();
self.skip();
if self.cur().is_kw("if") {
Some(Box::new(GenElse::If(meta, Box::new(self.parse_gen_if()?))))
} else {
@@ -688,7 +688,7 @@ impl<'a> Parser<'a> {
// The gap between whatever came before and the `begin` belongs to
// the block — nothing else was written where it could attach.
let before_kw = self.take_gap();
self.bump();
self.skip();
let before_colon = self.gap_before(":");
let mut after_colon = Vec::new();
let label_name = if self.eat_sym(":") {
+18 -18
View File
@@ -22,7 +22,7 @@ impl<'a> Parser<'a> {
let kw = self.cur().text.clone();
match kw.as_str() {
"begin" => {
self.bump();
self.skip();
let (label_comments, label_name) = self.parse_label_with()?;
let (label, label_span) = split_label(label_name);
let mut stmts = Vec::new();
@@ -45,7 +45,7 @@ impl<'a> Parser<'a> {
})
}
"fork" => {
self.bump();
self.skip();
let (label_comments, label_name) = self.parse_label_with()?;
let (label, label_span) = split_label(label_name);
let mut stmts = Vec::new();
@@ -88,7 +88,7 @@ impl<'a> Parser<'a> {
"case" | "casex" | "casez" => self.parse_case_stmt(None),
"for" => self.parse_for_stmt(),
"while" => {
self.bump();
self.skip();
self.expect_sym("(")?;
let cond = self.cond_or_recover()?;
let recovered = cond.is_error();
@@ -96,7 +96,7 @@ impl<'a> Parser<'a> {
Ok(StmtKind::While { cond, body: Box::new(self.body_after_recovery(recovered)?) })
}
"do" => {
self.bump();
self.skip();
let body = Box::new(self.parse_stmt()?);
self.expect_kw("while")?;
let mut comments =
@@ -110,7 +110,7 @@ impl<'a> Parser<'a> {
Ok(StmtKind::DoWhile { body, cond, comments: Box::new(comments) })
}
"repeat" => {
self.bump();
self.skip();
self.expect_sym("(")?;
let count = self.cond_or_recover()?;
let recovered = count.is_error();
@@ -118,11 +118,11 @@ impl<'a> Parser<'a> {
Ok(StmtKind::Repeat { count, body: Box::new(self.body_after_recovery(recovered)?) })
}
"forever" => {
self.bump();
self.skip();
Ok(StmtKind::Forever { body: Box::new(self.parse_stmt()?) })
}
"foreach" => {
self.bump();
self.skip();
let mut comments =
HeaderComments { after_kw: self.take_gap(), ..Default::default() };
self.expect_sym("(")?;
@@ -141,41 +141,41 @@ impl<'a> Parser<'a> {
})
}
"randcase" => {
self.bump();
self.skip();
let (items, dangling) = self.parse_case_body()?;
Ok(StmtKind::RandCase { items, dangling })
}
"return" => {
self.bump();
self.skip();
let after_kw = self.take_gap();
let expr = if self.cur().is_sym(";") { None } else { Some(self.parse_expr()?) };
self.expect_stmt_semi()?;
Ok(StmtKind::Return { after_kw, expr })
}
"break" => {
self.bump();
self.skip();
self.expect_stmt_semi()?;
Ok(StmtKind::Break)
}
"continue" => {
self.bump();
self.skip();
self.expect_stmt_semi()?;
Ok(StmtKind::Continue)
}
"disable" => {
self.bump();
self.skip();
// `disable fork;` kills every process the enclosing `fork`
// started; `fork` is a keyword, not a block name.
if self.cur().is_kw("fork") {
let name_span = self.cur().span;
self.bump();
self.skip();
self.expect_stmt_semi()?;
return Ok(StmtKind::Disable { name: "fork".to_string(), name_span });
}
let start = self.here();
let mut name = self.expect_ident()?;
while self.cur().is_sym(".") {
self.bump();
self.skip();
name.push('.');
name.push_str(&self.expect_ident()?);
}
@@ -184,11 +184,11 @@ impl<'a> Parser<'a> {
Ok(StmtKind::Disable { name, name_span })
}
"wait" => {
self.bump();
self.skip();
// `wait fork;` waits for the enclosing `fork`'s children
// (IEEE 1800 §9.6.1); `fork` is a keyword, not a condition.
if self.cur().is_kw("fork") {
self.bump();
self.skip();
self.expect_stmt_semi()?;
return Ok(StmtKind::WaitFork);
}
@@ -217,7 +217,7 @@ impl<'a> Parser<'a> {
Ok(StmtKind::Assert { kw, cond, then, els })
}
"force" => {
self.bump();
self.skip();
let lhs = self.parse_unary()?;
self.expect_sym("=")?;
let rhs = self.parse_expr()?;
@@ -290,7 +290,7 @@ impl<'a> Parser<'a> {
/// is parsed as usual. The init entries read before the failure are kept
/// — they are what declares the loop variable the body uses.
fn parse_for_stmt(&mut self) -> PResult<StmtKind> {
self.bump();
self.skip();
let mut comments = ForComments { after_kw: self.take_gap(), ..Default::default() };
self.expect_sym("(")?;
comments.after_open = self.take_gap();
+2 -2
View File
@@ -431,7 +431,7 @@ impl<'a> Parser<'a> {
let mut scope: Vec<ScopeSeg> = Vec::new();
while self.cur().is_sym("::") {
let before_sep = self.take_gap();
self.bump();
self.skip();
let after_sep = self.take_gap();
let next = self.expect_name()?;
scope.push(ScopeSeg { name, before_sep, after_sep });
@@ -474,7 +474,7 @@ impl<'a> Parser<'a> {
let start = self.here();
let mut name = self.expect_ident()?;
while self.cur().is_sym("::") {
self.bump();
self.skip();
let segment = self.expect_ident()?;
Self::push_scope_segment(&mut name, &segment);
}
+5 -5
View File
@@ -327,7 +327,7 @@ impl<'a> Parser<'a> {
return Ok(None);
}
let before_dir = self.take_gap();
self.bump();
self.skip();
let after_dir = self.take_gap();
Ok(Some(ClockingDefault { before_dir, after_dir, skew: self.parse_clocking_skew()? }))
}
@@ -387,7 +387,7 @@ impl<'a> Parser<'a> {
if !self.cur().is_sym("#") {
return Ok(out);
}
self.bump();
self.skip();
out.after_hash = self.take_gap();
self.expect_sym("(")?;
let mark = self.diags_mark();
@@ -438,7 +438,7 @@ impl<'a> Parser<'a> {
return Ok((Box::default(), None));
}
let before = self.take_gap();
self.bump();
self.skip();
let after = self.take_gap();
let value = parse(self)?;
Ok((Box::new(BinaryComments { before, after }), Some(value)))
@@ -507,7 +507,7 @@ impl<'a> Parser<'a> {
if !self.cur().is_sym("(") {
return Ok((PortList::None, Vec::new(), Vec::new()));
}
self.bump();
self.skip();
let mark = self.diags_mark();
// Directives before the first port. Harvested here rather than in the
// loop below because both the ANSI/non-ANSI decision and the
@@ -517,7 +517,7 @@ impl<'a> Parser<'a> {
if self.cur().is_sym(")") {
// `module m (/* c */);` — the comments stay between the parens.
let dangling = self.take_dangling();
self.bump();
self.skip();
return Ok((PortList::Empty, dangling, directives));
}
let ansi = {
+13 -13
View File
@@ -31,7 +31,7 @@ impl<'a> Parser<'a> {
}
TokenKind::Ident | TokenKind::SystemIdent => {
if self.at_shallow_copy() {
self.bump(); // new
self.skip(); // new
let src = self.parse_postfix()?;
return Ok(self.expr_at(start, ExprKind::New(Box::new(src))));
}
@@ -53,9 +53,9 @@ impl<'a> Parser<'a> {
let ty = self.expr_at(ty_start, ExprKind::Ident(ty_text));
let mut comments =
CastComments { before_tick: self.take_gap(), ..Default::default() };
self.bump(); // '
self.skip(); // '
comments.after_tick = self.take_gap();
self.bump(); // (
self.skip(); // (
comments.after_open = self.take_gap();
let inner = self.parse_expr()?;
comments.before_close = self.gap_before(")");
@@ -85,14 +85,14 @@ impl<'a> Parser<'a> {
// work through the existing expression grammar, and lucisv
// checks legality nowhere else either.
"$" => {
self.bump();
self.skip();
Ok(self.expr_at(start, ExprKind::Ident("$".to_string())))
}
"(" => {
// Comments written just inside the parens stay there;
// anything else would move them across a token.
let mut before = self.take_trailing_here();
self.bump();
self.skip();
before.append(&mut self.take_leading_here());
let mark = self.pending_trailing.len();
let inner_start = self.here();
@@ -106,7 +106,7 @@ impl<'a> Parser<'a> {
))
}
"{" => {
self.bump();
self.skip();
if self.cur().is_sym("<<") || self.cur().is_sym(">>") {
return self.parse_stream_concat(start);
}
@@ -114,13 +114,13 @@ impl<'a> Parser<'a> {
// `{}` — the empty queue/dynamic-array literal
// (`q = {};`). Illegal as a Verilog concatenation,
// but lucisv is not a legality checker.
self.bump();
self.skip();
return Ok(self.expr_at(start, ExprKind::Concat(Vec::new())));
}
let first = self.parse_expr_item()?;
if self.cur().is_sym("{") {
// Replication {N{a, b}}
self.bump();
self.skip();
let inner_first = self.parse_expr_item()?;
let inner = self.parse_expr_list(inner_first, "}")?;
self.expect_sym("}")?;
@@ -241,7 +241,7 @@ impl<'a> Parser<'a> {
/// (`ty'{...}`) keeps the type outside the pattern's span, in the `Cast`
/// node that wraps it.
pub(super) fn parse_assign_pattern(&mut self, start: u32) -> PResult<Expr> {
self.bump(); // '{
self.skip(); // '{
if self.at_assign_pattern_repl() {
return self.parse_assign_pattern_repl(start);
}
@@ -251,7 +251,7 @@ impl<'a> Parser<'a> {
let item_start = self.here();
let mut meta = self.take_meta();
let key_or_val = if self.cur().is_kw("default") {
self.bump();
self.skip();
self.expr_at(item_start, ExprKind::Ident("default".to_string()))
} else {
self.parse_expr_or_type()?
@@ -352,7 +352,7 @@ impl<'a> Parser<'a> {
/// the `.` and the next token is an identifier.
pub(super) fn parse_named_arg(&mut self) -> PResult<Expr> {
let start = self.here();
self.bump(); // .
self.skip(); // .
let after_dot = self.take_gap();
let Name { text: name, span: name_span } = self.expect_name()?;
let before_open = self.take_before_open("(");
@@ -365,7 +365,7 @@ impl<'a> Parser<'a> {
// between the parens, exactly as an empty connection does. The
// span covers the `( )` pair.
let comments = self.take_around(mark);
self.bump();
self.skip();
(self.expr_at(paren_start, ExprKind::Empty(comments)), Vec::new())
} else {
after_open = self.take_gap();
@@ -403,7 +403,7 @@ impl<'a> Parser<'a> {
pub(super) fn parse_value_range(&mut self) -> PResult<Expr> {
let start = self.here();
let mut comments = SegmentComments { before_open: self.take_gap(), ..Default::default() };
self.bump(); // [
self.skip(); // [
comments.after_open = self.take_gap();
let lo = self.parse_expr()?;
comments.before_op = self.gap_before(":");
@@ -52,7 +52,7 @@ impl<'a> Parser<'a> {
// The gap in front of the `|` belongs to the alternative it opens,
// so it prints on the bar's own side of the previous one.
let before_bar = self.take_gap();
self.bump();
self.skip();
alternatives.push(self.parse_alternative(before_bar)?);
}
let span = self.span_from(start);
@@ -107,8 +107,8 @@ impl<'a> Parser<'a> {
let mut weight = None;
if self.at_weight_op() {
before_weight = self.take_gap();
self.bump(); // :
self.bump(); // =
self.skip(); // :
self.skip(); // =
weight = Some(self.parse_weight()?);
}
Ok(Alternative { before_bar, after_bar, items, before_weight, weight })
@@ -170,7 +170,7 @@ impl<'a> Parser<'a> {
return self.parse_rs_if();
}
if t.is_kw("repeat") {
self.bump();
self.skip();
let after_kw = self.take_before_open("(");
self.expect_sym("(")?;
let count = self.parse_expr()?;
@@ -240,7 +240,7 @@ impl<'a> Parser<'a> {
// A `default` arm may write no `:` at all (§18.17.4).
let has_colon = self.cur().is_sym(":");
if has_colon {
self.bump();
self.skip();
} else if !is_default {
return self.error("expected `:` in a randsequence case arm");
}
@@ -271,7 +271,7 @@ impl<'a> Parser<'a> {
let after_rand = self.take_gap();
self.expect_kw("join")?;
let weight = if self.cur().is_sym("(") {
self.bump();
self.skip();
let e = self.parse_expr()?;
self.expect_sym(")")?;
Some(e)
@@ -292,7 +292,7 @@ impl<'a> Parser<'a> {
let has_parens = self.cur().is_sym("(");
let mut args = Vec::new();
if has_parens {
self.bump();
self.skip();
if !self.cur().is_sym(")") {
let first = self.parse_expr_item()?;
args = self.parse_expr_list(first, ")")?;
+4 -4
View File
@@ -102,7 +102,7 @@ impl<'a> Parser<'a> {
/// error node.
pub(super) fn expect_closer(&mut self, kw: &str) -> PResult<()> {
if self.cur().is_kw(kw) {
self.bump();
self.skip();
return Ok(());
}
if self.tolerant {
@@ -150,7 +150,7 @@ impl<'a> Parser<'a> {
return;
}
if t.is_sym(";") {
self.bump();
self.skip();
return;
}
}
@@ -159,7 +159,7 @@ impl<'a> Parser<'a> {
} else if open > 0 && (t.is_sym(")") || t.is_sym("]") || t.is_sym("}")) {
open -= 1;
}
self.bump();
self.skip();
}
}
@@ -171,7 +171,7 @@ impl<'a> Parser<'a> {
if self.pos == start_pos {
// The failed construct consumed nothing, so skipping might not
// either; take one token to guarantee the enclosing loop advances.
self.bump();
self.skip();
}
self.skip_to_sync();
// Comments inside the skipped range are part of the raw text below.
@@ -227,7 +227,7 @@ impl<'a> Parser<'a> {
if self.pos == start_pos && !self.cur().is_sym(")") {
// The header consumed nothing and the skip below may not either;
// take one token so the statement cannot be re-read forever.
self.bump();
self.skip();
}
self.skip_inside_brackets(true);
// As in `recover`: comments inside the skipped range are bytes of the
@@ -247,7 +247,7 @@ impl<'a> Parser<'a> {
// Nothing was consumed and nothing below will be: the list loop
// neither ends here nor eats a separator, so take one token to
// guarantee it advances.
self.bump();
self.skip();
} else if self.at_open_bracket() {
// The element gave up standing *on* a bracket, which is therefore
// one it opened and never closed — the `(` of a half-typed
@@ -258,7 +258,7 @@ impl<'a> Parser<'a> {
// the body would be swallowed looking for a `)` that was never
// written. Taken here, the skip starts inside it at the list's own
// level and stops at the next line as it does everywhere else.
self.bump();
self.skip();
}
self.skip_inside_brackets(false);
let _ = self.take_dangling();
@@ -310,7 +310,7 @@ impl<'a> Parser<'a> {
} else if closes {
open -= 1;
}
self.bump();
self.skip();
}
}
+1 -1
View File
@@ -274,7 +274,7 @@ impl<'a> Parser<'a> {
// already moved — are dropped by `verbatim_since`.
self.pos = mark.pos;
while self.pos < end_pos && !self.at_eof() {
self.bump();
self.skip();
}
self.verbatim_since(start, col)
}
+12 -12
View File
@@ -125,11 +125,11 @@ impl<'a> Parser<'a> {
return Ok(StmtKind::Directive(self.take_raw_text()));
}
if t.is_sym(";") {
self.bump();
self.skip();
return Ok(StmtKind::Null);
}
if t.is_sym("#") {
self.bump();
self.skip();
let after_hash = self.take_gap();
let delay = self.parse_delay_value()?;
let stmt = if self.eat_stmt_semi() { None } else { Some(Box::new(self.parse_stmt()?)) };
@@ -139,7 +139,7 @@ impl<'a> Parser<'a> {
});
}
if t.is_sym("@") {
self.bump();
self.skip();
let sens = self.parse_sens_list()?;
let stmt = if self.eat_stmt_semi() { None } else { Some(Box::new(self.parse_stmt()?)) };
return Ok(StmtKind::Timing { control: TimingControl::Event(sens), stmt });
@@ -204,7 +204,7 @@ impl<'a> Parser<'a> {
// keyword's left; the then-branch has already taken its own
// trailing comment.
else_comments = self.take_dangling();
self.bump();
self.skip();
Some(Box::new(self.parse_stmt()?))
} else {
None
@@ -306,7 +306,7 @@ impl<'a> Parser<'a> {
if let Some(last) = vars.last_mut() {
last.after = self.take_gap();
}
self.bump();
self.skip();
vars.push(self.parse_foreach_var()?);
}
}
@@ -343,7 +343,7 @@ impl<'a> Parser<'a> {
if self.cur().kind == TokenKind::Symbol && (ASSIGN_OPS.contains(&op.as_str()) || op == "<=")
{
let before = self.take_around(mark);
self.bump();
self.skip();
let after = self.take_gap();
let rhs = self.parse_expr()?;
Ok(ForStep::Assign(SimpleAssign {
@@ -377,16 +377,16 @@ impl<'a> Parser<'a> {
// it (`x[6:0] /* opcode */ = v;`); left in the pending buffers
// they would be lost and the safety net would refuse the file.
let op_comments = self.take_around(mark);
self.bump();
self.skip();
let rhs_comments = self.take_around(mark);
let timing = if self.cur().is_sym("#") {
self.bump();
self.skip();
Some(TimingControl::Delay {
after_hash: self.take_gap(),
expr: self.parse_delay_value()?,
})
} else if self.cur().is_sym("@") {
self.bump();
self.skip();
Some(TimingControl::Event(self.parse_sens_list()?))
} else {
None
@@ -430,7 +430,7 @@ impl<'a> Parser<'a> {
if self.cur().is_sym("*") {
// `@*` without parens — the gap after the `@` is the `*`'s own
// `before` slot, which the formatter prints in the same place.
self.bump();
self.skip();
return Ok(SensList::Star { before: after_at, after: Vec::new() });
}
if self.cur().kind == TokenKind::Ident {
@@ -449,10 +449,10 @@ impl<'a> Parser<'a> {
// to whatever node comes next.
let mut before = after_at;
before.append(&mut self.take_trailing_here());
self.bump(); // (
self.skip(); // (
before.append(&mut self.take_leading_here());
let mut after = self.take_trailing_here();
self.bump(); // *
self.skip(); // *
after.append(&mut self.take_leading_here());
self.expect_sym(")")?;
return Ok(SensList::Star { before, after });
+8 -8
View File
@@ -218,7 +218,7 @@ impl<'a> Parser<'a> {
self.link()?;
let before = self.take_around(mark);
for _ in 0..tokens {
self.bump();
self.skip();
}
let after = self.take_around(mark);
let rhs = self.parse_prop_expr(Self::right_operand_prec(prec, right))?;
@@ -316,7 +316,7 @@ impl<'a> Parser<'a> {
let mut count = None;
let mut after_count = Vec::new();
if counted && self.cur().is_sym("[") {
self.bump();
self.skip();
let after_open = self.take_gap();
count = Some(Box::new(SvaRange { after_open, ..self.parse_sva_bounds()? }));
after_count = self.take_gap();
@@ -367,7 +367,7 @@ impl<'a> Parser<'a> {
let mut els = None;
if self.cur().is_kw("else") {
before_else = self.take_gap();
self.bump();
self.skip();
after_else = self.take_gap();
els = Some(self.parse_prop_expr(0)?);
}
@@ -421,7 +421,7 @@ impl<'a> Parser<'a> {
let mut labels = Vec::new();
let is_default = self.cur().is_kw("default");
if is_default {
self.bump();
self.skip();
} else {
loop {
labels.push(self.parse_expr_item()?);
@@ -463,7 +463,7 @@ impl<'a> Parser<'a> {
while self.at_repeat_bracket() {
self.link()?;
let before_open = self.take_gap();
self.bump(); // [
self.skip(); // [
let after_open = self.take_gap();
// `[+]` writes no operator of its own: its `+` is the bound.
let (op, after_op) = if self.cur().is_sym("+") {
@@ -493,7 +493,7 @@ impl<'a> Parser<'a> {
range.lo = Some(self.parse_expr()?);
if self.cur().is_sym(":") {
range.before_colon = self.take_gap();
self.bump();
self.skip();
range.after_colon = self.take_gap();
range.hi = Some(self.parse_expr()?);
}
@@ -509,7 +509,7 @@ impl<'a> Parser<'a> {
self.expect_sym("##")?;
let after_hash = self.take_gap();
if self.cur().is_sym("[") {
self.bump();
self.skip();
let after_open = self.take_gap();
let range = Box::new(SvaRange { after_open, ..self.parse_sva_bounds()? });
return Ok(CycleDelay { after_hash, expr: None, range: Some(range) });
@@ -707,7 +707,7 @@ impl<'a> Parser<'a> {
let mut items = Vec::new();
while self.cur().is_sym(",") {
let before_comma = self.take_gap();
self.bump();
self.skip();
let start = self.here();
let meta = self.take_meta();
let lhs = self.parse_expr()?;
+5 -5
View File
@@ -227,12 +227,12 @@ impl<'a> Parser<'a> {
if !self.cur().is_sym("(") {
return Ok(TfPorts::default());
}
self.bump();
self.skip();
if self.cur().is_sym(")") {
// Only what was written *inside* the empty `()`, as an empty
// argument list of a call keeps.
let dangling = self.take_gap();
self.bump();
self.skip();
return Ok(TfPorts { args, dangling });
}
let mark = self.diags_mark();
@@ -272,9 +272,9 @@ impl<'a> Parser<'a> {
// `ibex/vendor/lowrisc_ip/dv/sv/dv_utils/dv_utils_pkg.sv:104`.
// Two keywords, so the gap between them is a slot of its own —
// no other direction has an inside.
self.bump();
self.skip();
after_const = self.take_gap();
self.bump();
self.skip();
Some("const ref".to_string())
} else if t.is_kw("input") || t.is_kw("output") || t.is_kw("inout") || t.is_kw("ref") {
Some(self.bump().text)
@@ -298,7 +298,7 @@ impl<'a> Parser<'a> {
let mut eq_comments = BinaryComments::default();
let default = if self.cur().is_sym("=") {
eq_comments.before = self.take_gap();
self.bump();
self.skip();
eq_comments.after = self.take_gap();
Some(self.parse_expr()?)
} else {
+7 -7
View File
@@ -38,7 +38,7 @@ impl<'a> Parser<'a> {
} else if t.is_kw(&open) {
depth += 1;
}
self.bump();
self.skip();
}
self.expect_closer(close)?;
self.parse_label()?;
@@ -52,7 +52,7 @@ impl<'a> Parser<'a> {
pub(super) fn parse_opaque_line(&mut self) -> PResult<RawText> {
let start = self.here();
let col = self.cur().col;
self.bump();
self.skip();
self.skip_to_semi()?;
Ok(self.verbatim_since(start, col))
}
@@ -94,7 +94,7 @@ impl<'a> Parser<'a> {
/// than as a nested assignment. How many there are, and whether they are
/// legal lvalues, is a checker's business.
pub(super) fn parse_alias(&mut self) -> PResult<ItemKind> {
self.bump(); // alias
self.skip(); // alias
let mut nets = vec![self.parse_expr()?];
while self.eat_sym("=") {
nets.push(self.parse_expr()?);
@@ -154,7 +154,7 @@ impl<'a> Parser<'a> {
pub(super) fn parse_expect_statement(&mut self) -> PResult<RawText> {
let start = self.here();
let col = self.cur().col;
self.bump(); // expect
self.skip(); // expect
self.expect_sym("(")?;
self.skip_balanced("(", ")")?;
self.skip_action_block()?;
@@ -176,7 +176,7 @@ impl<'a> Parser<'a> {
} else if t.is_sym(close) {
depth -= 1;
}
self.bump();
self.skip();
}
Ok(())
}
@@ -215,12 +215,12 @@ impl<'a> Parser<'a> {
"[" => ("[", "]"),
_ => ("{", "}"),
};
self.bump();
self.skip();
self.skip_balanced(open, close)?;
} else if self.eat_sym(";") {
return Ok(());
} else {
self.bump();
self.skip();
}
}
}