From 8cf93629840aa0130abae003d1436040f1852144 Mon Sep 17 00:00:00 2001 From: Tim Date: Tue, 6 Oct 2020 22:10:55 +0200 Subject: Fixed parsing of negative number literals in macros. --- crates/mbe/src/subtree_source.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'crates/mbe') diff --git a/crates/mbe/src/subtree_source.rs b/crates/mbe/src/subtree_source.rs index 41461b315..8941da0f1 100644 --- a/crates/mbe/src/subtree_source.rs +++ b/crates/mbe/src/subtree_source.rs @@ -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, 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() } } -- cgit v1.2.3