squawk_syntax/ast/
token_ext.rs1use crate::ast::{self, AstToken};
2
3impl ast::Whitespace {
4 pub fn spans_multiple_lines(&self) -> bool {
5 let text = self.text();
6 text.find('\n')
7 .is_some_and(|idx| text[idx + 1..].contains('\n'))
8 }
9}
10
11impl ast::Comment {
12 pub fn kind(&self) -> CommentKind {
13 CommentKind::from_text(self.text())
14 }
15}
16
17#[derive(Debug, PartialEq, Eq, Clone, Copy)]
18pub enum CommentKind {
19 Line,
20 Block,
21}
22
23impl CommentKind {
24 const BY_PREFIX: [(&'static str, CommentKind); 3] = [
25 ("/**/", CommentKind::Block),
26 ("/*", CommentKind::Block),
27 ("--", CommentKind::Line),
28 ];
29 pub(crate) fn from_text(text: &str) -> CommentKind {
30 let &(_prefix, kind) = CommentKind::BY_PREFIX
31 .iter()
32 .find(|&(prefix, _kind)| text.starts_with(prefix))
33 .unwrap();
34 kind
35 }
36
37 pub fn is_line(self) -> bool {
38 self == CommentKind::Line
39 }
40
41 pub fn is_block(self) -> bool {
42 self == CommentKind::Block
43 }
44}