Hi!
I'm trying to read the compiler code (mostly because I'm curious) and right
now I'm trying to understand the handling of negative integer/float
literals.
In token.rs we have:
pub enum Lit {
...
Integer(ast::Name),
Float(ast::Name),
...
}
So at this stage these literals are still just (interned) strings. In lexer/
mod.rs we can see that the lexer doesn't consume any plus/minus sign, so
the above tokens don't contain them.
In ast.rs we have:
pub enum Expr_ {
...
/// A literal (For example: `1u8`, `"foo"`)
ExprLit(P<Lit>),
...
}
pub enum Lit_ {
...
/// An integer literal (`1u8`)
LitInt(u64, LitIntType),
/// A float literal (`1f64` or `1E10f64`)
LitFloat(InternedString, FloatTy),
/// A float literal without a suffix (`1.0 or 1.0E10`)
LitFloatUnsuffixed(InternedString),
...
}
pub enum Sign {
Minus,
Plus
}
pub enum LitIntType {
SignedIntLit(IntTy, Sign),
UnsignedIntLit(UintTy),
UnsuffixedIntLit(Sign)
}
I'd expect that somewhere in the code we'd construct e.g. an SignedIntLit
with a Minus in it, but I cannot find a single place that does this after
looking for all uses of ast::Minus ast::SignedIntLit, etc.
So my question is, *since the sign isn't lexed together with the literal,
how is it eventually added to the literal that's stored in in e.g.
ast::LitInt?*
-- Johan
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev