]> git.lizzy.rs Git - rust.git/commitdiff
Fixed parsing of negative number literals in macros.
authorTim <tim@glacyr.com>
Tue, 6 Oct 2020 20:10:55 +0000 (22:10 +0200)
committerTim <tim@glacyr.com>
Tue, 6 Oct 2020 20:28:13 +0000 (22:28 +0200)
crates/mbe/src/subtree_source.rs

index 41461b3150ae17c9d91b7cc161cb29202ae05e94..8941da0f1c7d6a834683e0b43f8b6943d2a08afe 100644 (file)
@@ -2,7 +2,7 @@
 
 use parser::{Token, TokenSource};
 use std::cell::{Cell, Ref, RefCell};
-use syntax::{lex_single_syntax_kind, SmolStr, SyntaxKind, SyntaxKind::*, T};
+use syntax::{tokenize, SmolStr, SyntaxKind, SyntaxKind::*, T};
 use tt::buffer::{Cursor, TokenBuffer};
 
 #[derive(Debug, Clone, Eq, PartialEq)]
@@ -155,10 +155,17 @@ fn convert_delim(d: Option<tt::DelimiterKind>, closing: bool) -> TtToken {
 }
 
 fn convert_literal(l: &tt::Literal) -> TtToken {
-    let kind = lex_single_syntax_kind(&l.text)
-        .map(|(kind, _error)| kind)
-        .filter(|kind| kind.is_literal())
-        .unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
+    let mut kinds = tokenize(&l.text).0.into_iter().map(|token| token.kind);
+
+    let kind = match kinds.next() {
+        Some(kind) if kind.is_literal() => Some(kind),
+        Some(SyntaxKind::MINUS) => match kinds.next() {
+            Some(kind) if kind.is_literal() => Some(kind),
+            _ => None,
+        },
+        _ => None,
+    }
+    .unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
 
     TtToken { kind, is_joint_to_next: false, text: l.text.clone() }
 }