diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2012-11-07 18:40:34 -0800 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2012-11-12 10:39:08 -0800 |
| commit | fe02814a63bd759f6727c7479fc4aeb04f0be9b4 (patch) | |
| tree | 7b372b7829c23190c1e6f1d187e1b316f9b67a3e /src/libsyntax/parse/token.rs | |
| parent | f05e2da709cca3b20e560eaf2e05d73c0ca5d91b (diff) | |
| download | rust-fe02814a63bd759f6727c7479fc4aeb04f0be9b4.tar.gz rust-fe02814a63bd759f6727c7479fc4aeb04f0be9b4.zip | |
rustc: Implement floating point literal inference. r=nmatsakis
Diffstat (limited to 'src/libsyntax/parse/token.rs')
| -rw-r--r-- | src/libsyntax/parse/token.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index 0d139b101d8..baf963942e2 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -62,6 +62,7 @@ enum Token { LIT_UINT(u64, ast::uint_ty), LIT_INT_UNSUFFIXED(i64), LIT_FLOAT(ast::ident, ast::float_ty), + LIT_FLOAT_UNSUFFIXED(ast::ident), LIT_STR(ast::ident), /* Name components */ @@ -164,6 +165,13 @@ fn to_str(in: @ident_interner, t: Token) -> ~str { } body + ast_util::float_ty_to_str(t) } + LIT_FLOAT_UNSUFFIXED(s) => { + let mut body = *in.get(s); + if body.ends_with(~".") { + body = body + ~"0"; // `10.f` is not a float literal + } + body + } LIT_STR(s) => { ~"\"" + str::escape_default(*in.get(s)) + ~"\"" } /* Name components */ @@ -204,6 +212,7 @@ pure fn can_begin_expr(t: Token) -> bool { LIT_UINT(_, _) => true, LIT_INT_UNSUFFIXED(_) => true, LIT_FLOAT(_, _) => true, + LIT_FLOAT_UNSUFFIXED(_) => true, LIT_STR(_) => true, POUND => true, AT => true, @@ -243,6 +252,7 @@ fn is_lit(t: Token) -> bool { LIT_UINT(_, _) => true, LIT_INT_UNSUFFIXED(_) => true, LIT_FLOAT(_, _) => true, + LIT_FLOAT_UNSUFFIXED(_) => true, LIT_STR(_) => true, _ => false } @@ -684,6 +694,12 @@ impl Token : cmp::Eq { _ => false } } + LIT_FLOAT_UNSUFFIXED(e0a) => { + match (*other) { + LIT_FLOAT_UNSUFFIXED(e0b) => e0a == e0b, + _ => false + } + } LIT_STR(e0a) => { match (*other) { LIT_STR(e0b) => e0a == e0b, |
