foundry_common/comments/
comment.rs
1use solar_parse::{
4 ast::{CommentKind, Span},
5 interface::BytePos,
6};
7
8#[derive(Clone, Copy, PartialEq, Debug)]
9pub enum CommentStyle {
10 Isolated,
12 Trailing,
14 Mixed,
16 BlankLine,
18}
19
20#[derive(Clone, Debug)]
21pub struct Comment {
22 pub lines: Vec<String>,
23 pub span: Span,
24 pub style: CommentStyle,
25 pub is_doc: bool,
26 pub kind: CommentKind,
27}
28
29impl Comment {
30 pub fn pos(&self) -> BytePos {
31 self.span.lo()
32 }
33
34 pub fn prefix(&self) -> Option<&'static str> {
35 if self.lines.is_empty() {
36 return None;
37 }
38 Some(match (self.kind, self.is_doc) {
39 (CommentKind::Line, false) => "//",
40 (CommentKind::Line, true) => "///",
41 (CommentKind::Block, false) => "/*",
42 (CommentKind::Block, true) => "/**",
43 })
44 }
45
46 pub fn suffix(&self) -> Option<&'static str> {
47 if self.lines.is_empty() {
48 return None;
49 }
50 match self.kind {
51 CommentKind::Line => None,
52 CommentKind::Block => Some("*/"),
53 }
54 }
55}