aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_tt
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-12-18 11:47:50 +0000
committerGitHub <[email protected]>2019-12-18 11:47:50 +0000
commit242f0ae1d8e6766091a6050431c3d417a43a2a3e (patch)
treeb45d7619b97cc6edaf6bcf7d1a42366879bdd703 /crates/ra_tt
parent46ca40ccfced6945e05a25979a2703ad967d2fe0 (diff)
parent41544a40883874553f570e2999bf56d172bd6246 (diff)
Merge #2545
2545: Add Token id to all tt::TokenTree r=matklad a=edwin0cheng This PR try to add token id to all `tt::Leaf` and `tt::Delimiter`. ~~Some tests are failed now because of #2544~~ ~~Still blocked by a test in goto-definition : see https://github.com/rust-analyzer/rust-analyzer/pull/2544#issuecomment-565572553~~ Co-authored-by: Edwin Cheng <[email protected]>
Diffstat (limited to 'crates/ra_tt')
-rw-r--r--crates/ra_tt/src/lib.rs22
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)]
58pub enum Delimiter { 58pub struct Delimiter {
59 pub id: TokenId,
60 pub kind: DelimiterKind,
61}
62
63#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
64pub 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)]
65pub struct Literal { 71pub 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)]
70pub struct Punct { 77pub 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
96impl fmt::Display for Subtree { 104impl 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
168pub mod buffer; 180pub mod buffer;