teo_parser/ast/
punctuations.rs1use crate::{declare_node, impl_node_defaults};
2use crate::ast::span::Span;
3use crate::format::Writer;
4use crate::traits::write::Write;
5
6declare_node!(Punctuation, content: &'static str);
7
8impl Punctuation {
9
10 pub(crate) fn new(content: &'static str, span: Span, path: Vec<usize>) -> Self {
11 Self {
12 span,
13 path,
14 content
15 }
16 }
17
18 pub fn content(&self) -> &str {
19 self.content
20 }
21}
22
23impl_node_defaults!(Punctuation);
24
25impl Write for Punctuation {
26
27 fn write<'a>(&'a self, writer: &mut Writer<'a>) {
28 writer.write_content(self, self.content());
29 }
30
31 fn prefer_whitespace_before(&self) -> bool {
32 match self.content() {
33 "@" | "}" | "{" | "->" => true,
34 _ => false,
35 }
36 }
37
38 fn prefer_whitespace_after(&self) -> bool {
39 match self.content() {
40 "," | ":" | "{" | "->" => true,
41 _ => false,
42 }
43 }
44
45 fn prefer_always_no_whitespace_before(&self) -> bool {
46 match self.content() {
47 "," | ")" | "]" => true,
48 _ => false,
49 }
50 }
51
52 fn is_block_start(&self) -> bool {
53 match self.content() {
54 "(" | "[" | "{" => true,
55 _ => false,
56 }
57 }
58
59 fn is_block_end(&self) -> bool {
60 match self.content() {
61 ")" | "]" | "}" => true,
62 _ => false,
63 }
64 }
65
66 fn is_block_element_delimiter(&self) -> bool {
67 match self.content() {
68 "," => true,
69 _ => false,
70 }
71 }
72}