Skip to content

Commit 8cf9362

Browse files
committed
Fixed parsing of negative number literals in macros.
1 parent bf1043c commit 8cf9362

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

crates/mbe/src/subtree_source.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
33
use parser::{Token, TokenSource};
44
use std::cell::{Cell, Ref, RefCell};
5-
use syntax::{lex_single_syntax_kind, SmolStr, SyntaxKind, SyntaxKind::*, T};
5+
use syntax::{tokenize, SmolStr, SyntaxKind, SyntaxKind::*, T};
66
use tt::buffer::{Cursor, TokenBuffer};
77

88
#[derive(Debug, Clone, Eq, PartialEq)]
@@ -155,10 +155,17 @@ fn convert_delim(d: Option<tt::DelimiterKind>, closing: bool) -> TtToken {
155155
}
156156

157157
fn convert_literal(l: &tt::Literal) -> TtToken {
158-
let kind = lex_single_syntax_kind(&l.text)
159-
.map(|(kind, _error)| kind)
160-
.filter(|kind| kind.is_literal())
161-
.unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
158+
let mut kinds = tokenize(&l.text).0.into_iter().map(|token| token.kind);
159+
160+
let kind = match kinds.next() {
161+
Some(kind) if kind.is_literal() => Some(kind),
162+
Some(SyntaxKind::MINUS) => match kinds.next() {
163+
Some(kind) if kind.is_literal() => Some(kind),
164+
_ => None,
165+
},
166+
_ => None,
167+
}
168+
.unwrap_or_else(|| panic!("Fail to convert given literal {:#?}", &l));
162169

163170
TtToken { kind, is_joint_to_next: false, text: l.text.clone() }
164171
}

0 commit comments

Comments
 (0)