diff options
author | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
---|---|---|
committer | Seivan Heidari <[email protected]> | 2019-12-23 14:35:31 +0000 |
commit | b21d9337d9200e2cfdc90b386591c72c302dc03e (patch) | |
tree | f81f5c08f821115cee26fa4d3ceaae88c7807fd5 /crates/ra_tt/src | |
parent | 18a0937585b836ec5ed054b9ae48e0156ab6d9ef (diff) | |
parent | ce07a2daa9e53aa86a769f8641b14c2878444fbc (diff) |
Merge branch 'master' into feature/themes
Diffstat (limited to 'crates/ra_tt/src')
-rw-r--r-- | crates/ra_tt/src/lib.rs | 43 |
1 files changed, 27 insertions, 16 deletions
diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 20c251ff4..10f424aae 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs | |||
@@ -33,14 +33,14 @@ impl TokenId { | |||
33 | } | 33 | } |
34 | } | 34 | } |
35 | 35 | ||
36 | #[derive(Debug, Clone, PartialEq, Eq)] | 36 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
37 | pub enum TokenTree { | 37 | pub enum TokenTree { |
38 | Leaf(Leaf), | 38 | Leaf(Leaf), |
39 | Subtree(Subtree), | 39 | Subtree(Subtree), |
40 | } | 40 | } |
41 | impl_froms!(TokenTree: Leaf, Subtree); | 41 | impl_froms!(TokenTree: Leaf, Subtree); |
42 | 42 | ||
43 | #[derive(Debug, Clone, PartialEq, Eq)] | 43 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
44 | pub enum Leaf { | 44 | pub enum Leaf { |
45 | Literal(Literal), | 45 | Literal(Literal), |
46 | Punct(Punct), | 46 | Punct(Punct), |
@@ -48,38 +48,45 @@ pub enum Leaf { | |||
48 | } | 48 | } |
49 | impl_froms!(Leaf: Literal, Punct, Ident); | 49 | impl_froms!(Leaf: Literal, Punct, Ident); |
50 | 50 | ||
51 | #[derive(Debug, Clone, PartialEq, Eq)] | 51 | #[derive(Debug, Clone, PartialEq, Eq, Hash, Default)] |
52 | pub struct Subtree { | 52 | pub struct Subtree { |
53 | pub delimiter: Delimiter, | 53 | pub delimiter: Option<Delimiter>, |
54 | pub token_trees: Vec<TokenTree>, | 54 | pub token_trees: Vec<TokenTree>, |
55 | } | 55 | } |
56 | 56 | ||
57 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] | 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, |
62 | None, | ||
63 | } | 68 | } |
64 | 69 | ||
65 | #[derive(Debug, Clone, PartialEq, Eq)] | 70 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
66 | pub struct Literal { | 71 | pub struct Literal { |
67 | pub text: SmolStr, | 72 | pub text: SmolStr, |
73 | pub id: TokenId, | ||
68 | } | 74 | } |
69 | 75 | ||
70 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 76 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
71 | pub struct Punct { | 77 | pub struct Punct { |
72 | pub char: char, | 78 | pub char: char, |
73 | pub spacing: Spacing, | 79 | pub spacing: Spacing, |
80 | pub id: TokenId, | ||
74 | } | 81 | } |
75 | 82 | ||
76 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] | 83 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
77 | pub enum Spacing { | 84 | pub enum Spacing { |
78 | Alone, | 85 | Alone, |
79 | Joint, | 86 | Joint, |
80 | } | 87 | } |
81 | 88 | ||
82 | #[derive(Debug, Clone, PartialEq, Eq)] | 89 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
83 | pub struct Ident { | 90 | pub struct Ident { |
84 | pub text: SmolStr, | 91 | pub text: SmolStr, |
85 | pub id: TokenId, | 92 | pub id: TokenId, |
@@ -96,11 +103,11 @@ impl fmt::Display for TokenTree { | |||
96 | 103 | ||
97 | impl fmt::Display for Subtree { | 104 | impl fmt::Display for Subtree { |
98 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { | 105 | fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { |
99 | let (l, r) = match self.delimiter { | 106 | let (l, r) = match self.delimiter_kind() { |
100 | Delimiter::Parenthesis => ("(", ")"), | 107 | Some(DelimiterKind::Parenthesis) => ("(", ")"), |
101 | Delimiter::Brace => ("{", "}"), | 108 | Some(DelimiterKind::Brace) => ("{", "}"), |
102 | Delimiter::Bracket => ("[", "]"), | 109 | Some(DelimiterKind::Bracket) => ("[", "]"), |
103 | Delimiter::None => ("", ""), | 110 | None => ("", ""), |
104 | }; | 111 | }; |
105 | f.write_str(l)?; | 112 | f.write_str(l)?; |
106 | let mut needs_space = false; | 113 | let mut needs_space = false; |
@@ -164,6 +171,10 @@ impl Subtree { | |||
164 | 171 | ||
165 | self.token_trees.len() + children_count | 172 | self.token_trees.len() + children_count |
166 | } | 173 | } |
174 | |||
175 | pub fn delimiter_kind(&self) -> Option<DelimiterKind> { | ||
176 | self.delimiter.map(|it| it.kind) | ||
177 | } | ||
167 | } | 178 | } |
168 | 179 | ||
169 | pub mod buffer; | 180 | pub mod buffer; |