teo_parser/ast/
operators.rs1
2use crate::{declare_node, impl_node_defaults};
3use crate::ast::span::Span;
4use crate::format::Writer;
5use crate::traits::write::Write;
6
7declare_node!(Operator, content: String);
8
9impl Operator {
10
11 pub(crate) fn new(content: &str, span: Span, path: Vec<usize>) -> Self {
12 Self {
13 span,
14 path,
15 content: content.to_owned()
16 }
17 }
18
19 pub fn content(&self) -> &str {
20 self.content.as_str()
21 }
22}
23
24impl_node_defaults!(Operator);
25
26impl Write for Operator {
27
28 fn write<'a>(&'a self, writer: &mut Writer<'a>) {
29 writer.write_content(self, self.content());
30 }
31
32 fn prefer_whitespace_before(&self) -> bool {
33 match self.content() {
34 "!" | "?" | ".." | "..." => false,
35 _ => true,
36 }
37 }
38
39 fn prefer_whitespace_after(&self) -> bool {
40 match self.content() {
41 "!" | "?" | ".." | "..." => false,
42 _ => true,
43 }
44 }
45
46 fn prefer_always_no_whitespace_before(&self) -> bool {
47 match self.content() {
48 "!" | "?" | ".." | "..." => true,
49 _ => false,
50 }
51 }
52}