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
use crate::token::Token;
use crate::util::encdec::ToText;

/// Start and end of blocks, signalled e.g. by indentation.
#[derive(Debug, Default, PartialEq, Eq, Hash, Clone)]
pub struct StartBlockToken {}

#[derive(Debug, Default, PartialEq, Eq, Hash, Clone)]
pub struct EndBlockToken {
    is_dedent: bool,
    is_end_keyword: bool,
}

impl StartBlockToken {
    pub fn new() -> Self {
        StartBlockToken {}
    }
}

impl EndBlockToken {
    pub fn new(is_dedent: bool, is_end_keyword: bool) -> Self {
        assert!(is_dedent || is_end_keyword);
        EndBlockToken { is_dedent, is_end_keyword }
    }
}

impl ToText for StartBlockToken {
    // TODO: needs context information to render indents
    fn to_text(&self) -> String {
        " { ".to_owned()
    }
}

impl ToText for EndBlockToken {
    // TODO: needs context information to render indents
    fn to_text(&self) -> String {
        " } ".to_owned()
    }
}

impl Token for StartBlockToken {}

impl Token for EndBlockToken {}