From aceb9d7fb0809ccf364514d9177342edea144c59 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Thu, 12 Dec 2019 21:47:54 +0800 Subject: Add token ids for all tt::Leaf --- crates/ra_tt/src/lib.rs | 2 ++ 1 file changed, 2 insertions(+) (limited to 'crates/ra_tt') diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index e7bfd5fd2..209ca4048 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -64,12 +64,14 @@ pub enum Delimiter { #[derive(Debug, Clone, PartialEq, Eq, Hash)] pub struct Literal { pub text: SmolStr, + pub id: TokenId, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct Punct { pub char: char, pub spacing: Spacing, + pub id: TokenId, } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -- cgit v1.2.3 From 59295854f892b0a8f42a6fbc80b04d1f1c695828 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Fri, 13 Dec 2019 01:41:44 +0800 Subject: Add token id to delims --- crates/ra_tt/src/lib.rs | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'crates/ra_tt') diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 209ca4048..73d8395a8 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -55,7 +55,13 @@ pub struct Subtree { } #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] -pub enum Delimiter { +pub struct Delimiter { + pub id: TokenId, + pub kind: DelimiterKind, +} + +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +pub enum DelimiterKind { Parenthesis, Brace, Bracket, @@ -97,10 +103,10 @@ impl fmt::Display for TokenTree { impl fmt::Display for Subtree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let (l, r) = match self.delimiter { - Some(Delimiter::Parenthesis) => ("(", ")"), - Some(Delimiter::Brace) => ("{", "}"), - Some(Delimiter::Bracket) => ("[", "]"), + let (l, r) = match self.delimiter.map(|it| it.kind) { + Some(DelimiterKind::Parenthesis) => ("(", ")"), + Some(DelimiterKind::Brace) => ("{", "}"), + Some(DelimiterKind::Bracket) => ("[", "]"), None => ("", ""), }; f.write_str(l)?; -- cgit v1.2.3 From 41544a40883874553f570e2999bf56d172bd6246 Mon Sep 17 00:00:00 2001 From: Edwin Cheng Date: Wed, 18 Dec 2019 11:47:26 +0800 Subject: Refactoring --- crates/ra_tt/src/lib.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'crates/ra_tt') diff --git a/crates/ra_tt/src/lib.rs b/crates/ra_tt/src/lib.rs index 73d8395a8..10f424aae 100644 --- a/crates/ra_tt/src/lib.rs +++ b/crates/ra_tt/src/lib.rs @@ -103,7 +103,7 @@ impl fmt::Display for TokenTree { impl fmt::Display for Subtree { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let (l, r) = match self.delimiter.map(|it| it.kind) { + let (l, r) = match self.delimiter_kind() { Some(DelimiterKind::Parenthesis) => ("(", ")"), Some(DelimiterKind::Brace) => ("{", "}"), Some(DelimiterKind::Bracket) => ("[", "]"), @@ -171,6 +171,10 @@ impl Subtree { self.token_trees.len() + children_count } + + pub fn delimiter_kind(&self) -> Option { + self.delimiter.map(|it| it.kind) + } } pub mod buffer; -- cgit v1.2.3