aboutsummaryrefslogtreecommitdiff
path: root/crates/mbe/src/subtree_source.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/mbe/src/subtree_source.rs')
-rw-r--r--crates/mbe/src/subtree_source.rs22
1 files changed, 10 insertions, 12 deletions
diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs
index 226dc3bec..396ce8b16 100644
--- a/crates/mbe/src/subtree_source.rs
+++ b/crates/mbe/src/subtree_source.rs
@@ -2,7 +2,7 @@
2 2
3use parser::{Token, TokenSource}; 3use parser::{Token, TokenSource};
4use std::cell::{Cell, Ref, RefCell}; 4use std::cell::{Cell, Ref, RefCell};
5use syntax::{tokenize, SmolStr, SyntaxKind, SyntaxKind::*, T}; 5use syntax::{lex_single_syntax_kind, SmolStr, SyntaxKind, SyntaxKind::*, T};
6use tt::buffer::{Cursor, TokenBuffer}; 6use tt::buffer::{Cursor, TokenBuffer};
7 7
8#[derive(Debug, Clone, Eq, PartialEq)] 8#[derive(Debug, Clone, Eq, PartialEq)]
@@ -155,17 +155,15 @@ fn convert_delim(d: Option<tt::DelimiterKind>, closing: bool) -> TtToken {
155} 155}
156 156
157fn convert_literal(l: &tt::Literal) -> TtToken { 157fn convert_literal(l: &tt::Literal) -> TtToken {
158 let mut kinds = tokenize(&l.text).0.into_iter().map(|token| token.kind); 158 let is_negated = l.text.starts_with('-');
159 159 let inner_text = &l.text[if is_negated { 1 } else { 0 }..];
160 let kind = match kinds.next() { 160
161 Some(kind) if kind.is_literal() => Some(kind), 161 let kind = lex_single_syntax_kind(inner_text)
162 Some(SyntaxKind::MINUS) => match kinds.next() { 162 .map(|(kind, _error)| kind)
163 Some(kind) if kind.is_literal() => Some(kind), 163 .filter(|kind| {
164 _ => None, 164 kind.is_literal() && (!is_negated || matches!(kind, FLOAT_NUMBER | INT_NUMBER))
165 }, 165 })
166 _ => None, 166 .unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
167 }
168 .unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
169 167
170 TtToken { kind, is_joint_to_next: false, text: l.text.clone() } 168 TtToken { kind, is_joint_to_next: false, text: l.text.clone() }
171} 169}