Skip to content

Commit

Permalink
add fn comment
Browse files Browse the repository at this point in the history
  • Loading branch information
DaniPopes committed Dec 4, 2024
1 parent db504c6 commit a6ca2a9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 11 additions & 0 deletions crates/ast/src/token.rs
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,17 @@ impl Token {
}
}

/// Returns the comment if the kind is [`TokenKind::Comment`], and whether it's a doc-comment.
#[inline]
pub const fn comment(&self) -> Option<(bool, DocComment)> {
match self.kind {
TokenKind::Comment(is_doc, kind, symbol) => {
Some((is_doc, DocComment { span: self.span, kind, symbol }))
}
_ => None,
}
}

/// Returns the comment if the kind is [`TokenKind::Comment`].
///
/// Does not check that `is_doc` is `true`.
Expand Down
6 changes: 3 additions & 3 deletions crates/parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -741,11 +741,11 @@ impl<'sess, 'ast> Parser<'sess, 'ast> {

debug_assert!(next.is_comment_or_doc());
self.prev_token = std::mem::replace(&mut self.token, next);
while let Some(doc) = self.token.doc() {
if !self.token.is_comment() {
while let Some((is_doc, doc)) = self.token.comment() {
if is_doc {
self.docs.push(doc);
}
// Don't set `previon_token` on purpose.
// Don't set `prev_token` on purpose.
self.token = self.next_token();
}

Expand Down

0 comments on commit a6ca2a9

Please sign in to comment.