boilerplate_parser/
block.rs1use super::*;
2
3#[derive(Clone, Copy, Debug, PartialEq)]
4pub enum Block {
5 Code,
6 CodeLine,
7 Interpolation,
8 InterpolationLine,
9}
10
11impl Block {
12 pub(crate) fn close_delimiter(self) -> &'static str {
13 match self {
14 Self::Code => "%}",
15 Self::CodeLine | Self::InterpolationLine => "\n",
16 Self::Interpolation => "}}",
17 }
18 }
19
20 pub(crate) fn from_rest(rest: &str) -> Option<Self> {
21 [
22 Self::Code,
23 Self::CodeLine,
24 Self::Interpolation,
25 Self::InterpolationLine,
26 ]
27 .into_iter()
28 .find(|block| rest.starts_with(block.open_delimiter()))
29 }
30
31 pub(crate) fn is_line(self) -> bool {
32 match self {
33 Self::Code | Self::Interpolation => false,
34 Self::CodeLine | Self::InterpolationLine => true,
35 }
36 }
37
38 pub(crate) fn open_delimiter(self) -> &'static str {
39 match self {
40 Self::Code => "{%",
41 Self::CodeLine => "%%",
42 Self::Interpolation => "{{",
43 Self::InterpolationLine => "$$",
44 }
45 }
46
47 pub(crate) fn token(self, contents: &str, closed: bool) -> Token {
48 match self {
49 Self::Code => Token::Code { contents },
50 Self::CodeLine => Token::CodeLine { contents, closed },
51 Self::Interpolation => Token::Interpolation { contents },
52 Self::InterpolationLine => Token::InterpolationLine { contents, closed },
53 }
54 }
55}