1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

use crate::{declare_node, impl_node_defaults};
use crate::ast::span::Span;
use crate::format::Writer;
use crate::traits::write::Write;

declare_node!(Operator, content: String);

impl Operator {

    pub(crate) fn new(content: &str, span: Span, path: Vec<usize>) -> Self {
        Self {
            span,
            path,
            content: content.to_owned()
        }
    }

    pub fn content(&self) -> &str {
        self.content.as_str()
    }
}

impl_node_defaults!(Operator);

impl Write for Operator {

    fn write<'a>(&'a self, writer: &mut Writer<'a>) {
        writer.write_content(self, self.content());
    }

    fn prefer_whitespace_before(&self) -> bool {
        match self.content() {
            "!" | "?" | ".." | "..." => false,
            _ => true,
        }
    }

    fn prefer_whitespace_after(&self) -> bool {
        match self.content() {
            "!" | "?" | ".." | "..." => false,
            _ => true,
        }
    }

    fn prefer_always_no_whitespace_before(&self) -> bool {
        match self.content() {
            "!" | "?" | ".." | "..." => true,
            _ => false,
        }
    }
}