syntax: don't parse numeric literals in the lexer
This removes a bunch of token types. Tokens now store the original, unaltered numeric literal (that is still checked for correctness), which is parsed into an actual number later, as needed, when creating the AST. This can change how syntax extensions work, but otherwise poses no visible changes. [breaking-change]
This commit is contained in:
@@ -619,7 +619,7 @@ pub enum Mac_ {
|
||||
MacInvocTT(Path, Vec<TokenTree> , SyntaxContext), // new macro-invocation
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub enum StrStyle {
|
||||
CookedStr,
|
||||
RawStr(uint)
|
||||
@@ -627,7 +627,7 @@ pub enum StrStyle {
|
||||
|
||||
pub type Lit = Spanned<Lit_>;
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash, Show)]
|
||||
pub enum Lit_ {
|
||||
LitStr(InternedString, StrStyle),
|
||||
LitBinary(Rc<Vec<u8> >),
|
||||
@@ -697,6 +697,16 @@ impl fmt::Show for IntTy {
|
||||
}
|
||||
}
|
||||
|
||||
impl IntTy {
|
||||
pub fn suffix_len(&self) -> uint {
|
||||
match *self {
|
||||
TyI => 1,
|
||||
TyI8 => 2,
|
||||
TyI16 | TyI32 | TyI64 => 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub enum UintTy {
|
||||
TyU,
|
||||
@@ -706,6 +716,16 @@ pub enum UintTy {
|
||||
TyU64,
|
||||
}
|
||||
|
||||
impl UintTy {
|
||||
pub fn suffix_len(&self) -> uint {
|
||||
match *self {
|
||||
TyU => 1,
|
||||
TyU8 => 2,
|
||||
TyU16 | TyU32 | TyU64 => 3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Show for UintTy {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", ast_util::uint_ty_to_string(*self, None))
|
||||
@@ -724,6 +744,14 @@ impl fmt::Show for FloatTy {
|
||||
}
|
||||
}
|
||||
|
||||
impl FloatTy {
|
||||
pub fn suffix_len(&self) -> uint {
|
||||
match *self {
|
||||
TyF32 | TyF64 => 3, // add F128 handling here
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// NB PartialEq method appears below.
|
||||
#[deriving(Clone, PartialEq, Eq, Encodable, Decodable, Hash)]
|
||||
pub struct Ty {
|
||||
|
||||
Reference in New Issue
Block a user