Fixed parsing of negative number literals in macros.
This commit is contained in:
parent
bf1043cac2
commit
8cf9362984
1 changed files with 12 additions and 5 deletions
|
@ -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() }
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue