aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-02-23 12:43:45 +0000
committerAleksey Kladov <[email protected]>2019-02-23 13:55:18 +0000
commit83d6be6cecb19659e289eba63f12ac33dceb3b56 (patch)
treee66750729579dfeba7c2257a65fd29b343b4e403
parent71b8a874e7931e2213e3864e1eae90ceb2551fc2 (diff)
keep-text
-rw-r--r--crates/ra_mbe/src/syntax_bridge.rs27
1 files changed, 17 insertions, 10 deletions
diff --git a/crates/ra_mbe/src/syntax_bridge.rs b/crates/ra_mbe/src/syntax_bridge.rs
index 7a4ba9e93..24a043175 100644
--- a/crates/ra_mbe/src/syntax_bridge.rs
+++ b/crates/ra_mbe/src/syntax_bridge.rs
@@ -98,7 +98,7 @@ struct TtTokenSource {
98struct Tok { 98struct Tok {
99 kind: SyntaxKind, 99 kind: SyntaxKind,
100 is_joint_to_next: bool, 100 is_joint_to_next: bool,
101 text: Option<SmolStr>, 101 text: SmolStr,
102} 102}
103 103
104impl TtTokenSource { 104impl TtTokenSource {
@@ -123,27 +123,34 @@ impl TtTokenSource {
123 tt::Leaf::Literal(l) => Tok { 123 tt::Leaf::Literal(l) => Tok {
124 kind: SyntaxKind::INT_NUMBER, // FIXME 124 kind: SyntaxKind::INT_NUMBER, // FIXME
125 is_joint_to_next: false, 125 is_joint_to_next: false,
126 text: Some(l.text.clone()), 126 text: l.text.clone(),
127 }, 127 },
128 tt::Leaf::Punct(p) => Tok { 128 tt::Leaf::Punct(p) => Tok {
129 kind: SyntaxKind::from_char(p.char).unwrap(), 129 kind: SyntaxKind::from_char(p.char).unwrap(),
130 is_joint_to_next: p.spacing == tt::Spacing::Joint, 130 is_joint_to_next: p.spacing == tt::Spacing::Joint,
131 text: None, 131 text: {
132 let mut buf = [0u8; 4];
133 let s: &str = p.char.encode_utf8(&mut buf);
134 SmolStr::new(s)
135 },
132 }, 136 },
133 tt::Leaf::Ident(ident) => { 137 tt::Leaf::Ident(ident) => {
134 Tok { kind: IDENT, is_joint_to_next: false, text: Some(ident.text.clone()) } 138 Tok { kind: IDENT, is_joint_to_next: false, text: ident.text.clone() }
135 } 139 }
136 }; 140 };
137 self.tokens.push(tok) 141 self.tokens.push(tok)
138 } 142 }
139 fn push_delim(&mut self, d: tt::Delimiter, closing: bool) { 143 fn push_delim(&mut self, d: tt::Delimiter, closing: bool) {
140 let kinds = match d { 144 let (kinds, texts) = match d {
141 tt::Delimiter::Parenthesis => [L_PAREN, R_PAREN], 145 tt::Delimiter::Parenthesis => ([L_PAREN, R_PAREN], "()"),
142 tt::Delimiter::Brace => [L_CURLY, R_CURLY], 146 tt::Delimiter::Brace => ([L_CURLY, R_CURLY], "{}"),
143 tt::Delimiter::Bracket => [L_BRACK, R_BRACK], 147 tt::Delimiter::Bracket => ([L_BRACK, R_BRACK], "[]"),
144 tt::Delimiter::None => return, 148 tt::Delimiter::None => return,
145 }; 149 };
146 let tok = Tok { kind: kinds[closing as usize], is_joint_to_next: false, text: None }; 150 let idx = closing as usize;
151 let kind = kinds[idx];
152 let text = &texts[idx..texts.len() - (1 - idx)];
153 let tok = Tok { kind, is_joint_to_next: false, text: SmolStr::new(text) };
147 self.tokens.push(tok) 154 self.tokens.push(tok)
148 } 155 }
149} 156}
@@ -156,6 +163,6 @@ impl TokenSource for TtTokenSource {
156 self.tokens[pos].is_joint_to_next 163 self.tokens[pos].is_joint_to_next
157 } 164 }
158 fn is_keyword(&self, pos: usize, kw: &str) -> bool { 165 fn is_keyword(&self, pos: usize, kw: &str) -> bool {
159 self.tokens[pos].text.as_ref().map(|it| it.as_str()) == Some(kw) 166 self.tokens[pos].text == *kw
160 } 167 }
161} 168}