diff options
Diffstat (limited to 'crates/ra_tt/src/lib.rs')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index e7bfd5fd2..10f424aae 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -55,7 +55,13 @@ pub struct Subtree { | |||
55 | } | 55 | } |
56 | 56 | ||
57 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 57 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
58 | pub enum Delimiter { | 58 | pub struct Delimiter { |
59 | pub id: TokenId, | ||
60 | pub kind: DelimiterKind, | ||
61 | } | ||
62 | |||
63 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | ||
64 | pub enum DelimiterKind { | ||
59 | Parenthesis, | 65 | Parenthesis, |
60 | Brace, | 66 | Brace, |
61 | Bracket, | 67 | Bracket, |
@@ -64,12 +70,14 @@ pub enum Delimiter { | |||
64 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 70 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
65 | pub struct Literal { | 71 | pub struct Literal { |
66 | pub text: SmolStr, | 72 | pub text: SmolStr, |
73 | pub id: TokenId, | ||
67 | } | 74 | } |
68 | 75 | ||
69 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 76 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
70 | pub struct Punct { | 77 | pub struct Punct { |
71 | pub char: char, | 78 | pub char: char, |
72 | pub spacing: Spacing, | 79 | pub spacing: Spacing, |
80 | pub id: TokenId, | ||
73 | } | 81 | } |
74 | 82 | ||
75 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 83 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -95,10 +103,10 @@ impl fmt::Display for TokenTree { | |||
95 | 103 | ||
96 | impl fmt::Display for Subtree { | 104 | impl fmt::Display for Subtree { |
97 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 105 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
98 | let (l, r) = match self.delimiter { | 106 | let (l, r) = match self.delimiter_kind() { |
99 | Some(Delimiter::Parenthesis) => ("(", ")"), | 107 | Some(DelimiterKind::Parenthesis) => ("(", ")"), |
100 | Some(Delimiter::Brace) => ("{", "}"), | 108 | Some(DelimiterKind::Brace) => ("{", "}"), |
101 | Some(Delimiter::Bracket) => ("[", "]"), | 109 | Some(DelimiterKind::Bracket) => ("[", "]"), |
102 | None => ("", ""), | 110 | None => ("", ""), |
103 | }; | 111 | }; |
104 | f.write_str(l)?; | 112 | f.write_str(l)?; |
@@ -163,6 +171,10 @@ impl Subtree { | |||
163 | 171 | ||
164 | self.token_trees.len() + children_count | 172 | self.token_trees.len() + children_count |
165 | } | 173 | } |
174 | |||
175 | pub fn delimiter_kind(&self) -> Option<DelimiterKind> { | ||
176 | self.delimiter.map(|it| it.kind) | ||
177 | } | ||
166 | } | 178 | } |
167 | 179 | ||
168 | pub mod buffer; | 180 | pub mod buffer; |