diff options
| author | Lindsey Kuper <lindsey@rockstargirl.org> | 2012-06-11 16:31:03 -0700 |
|---|---|---|
| committer | Lindsey Kuper <lindsey@rockstargirl.org> | 2012-06-11 16:34:56 -0700 |
| commit | 8467279faccc3837cddf854e30eafb3a086c3c9e (patch) | |
| tree | 6980e71b1a286ecd2a093a96205bbe8971cb450d /src/libsyntax/parse | |
| parent | baf58a764b4cc5ffc3de7bf43b549a4cc59a57a4 (diff) | |
| download | rust-8467279faccc3837cddf854e30eafb3a086c3c9e.tar.gz rust-8467279faccc3837cddf854e30eafb3a086c3c9e.zip | |
Add a new AST node for unsuffixed integer types.
Diffstat (limited to 'src/libsyntax/parse')
| -rw-r--r-- | src/libsyntax/parse/classify.rs | 9 | ||||
| -rw-r--r-- | src/libsyntax/parse/lexer.rs | 5 | ||||
| -rw-r--r-- | src/libsyntax/parse/parser.rs | 7 | ||||
| -rw-r--r-- | src/libsyntax/parse/token.rs | 6 |
4 files changed, 22 insertions, 5 deletions
diff --git a/src/libsyntax/parse/classify.rs b/src/libsyntax/parse/classify.rs index 471fe15788d..aff0334a946 100644 --- a/src/libsyntax/parse/classify.rs +++ b/src/libsyntax/parse/classify.rs @@ -51,7 +51,14 @@ fn need_parens(expr: @ast::expr, outer_prec: uint) -> bool { fn ends_in_lit_int(ex: @ast::expr) -> bool { alt ex.node { - ast::expr_lit(@{node: ast::lit_int(_, ast::ty_i), _}) { true } + ast::expr_lit(node) { + alt node { + @{node: ast::lit_int(_, ast::ty_i), _} | + @{node: ast::lit_int_unsuffixed(_, ast::ty_i), _} + { true } + _ { false } + } + } ast::expr_binary(_, _, sub) | ast::expr_unary(_, sub) | ast::expr_move(_, sub) | ast::expr_copy(sub) | ast::expr_assign(_, sub) | diff --git a/src/libsyntax/parse/lexer.rs b/src/libsyntax/parse/lexer.rs index c93680b40a0..115a9957c28 100644 --- a/src/libsyntax/parse/lexer.rs +++ b/src/libsyntax/parse/lexer.rs @@ -282,7 +282,10 @@ fn scan_number(c: char, rdr: reader) -> token::token { rdr.fatal("no valid digits found for number"); } let parsed = option::get(u64::from_str_radix(num_str, base as u64)); - ret token::LIT_INT(parsed as i64, ast::ty_i); + + #debug["lexing %s as an unsuffixed integer literal", + num_str]; + ret token::LIT_INT_UNSUFFIXED(parsed as i64, ast::ty_i); } } diff --git a/src/libsyntax/parse/parser.rs b/src/libsyntax/parse/parser.rs index 75dae09fd0d..7e6fb726f67 100644 --- a/src/libsyntax/parse/parser.rs +++ b/src/libsyntax/parse/parser.rs @@ -507,7 +507,7 @@ class parser { let lo = self.span.lo; self.bump(); alt copy self.token { - token::LIT_INT(num, ty_i) { + token::LIT_INT_UNSUFFIXED(num, _) { self.bump(); some(mac_var(num as uint)) } @@ -519,7 +519,7 @@ class parser { some(mac_aq(mk_sp(lo,hi), e)) } _ { - self.fatal("expected `(` or integer literal"); + self.fatal("expected `(` or unsuffixed integer literal"); } } } @@ -540,7 +540,7 @@ class parser { token::UNDERSCORE { self.bump(); some(vstore_fixed(none)) } - token::LIT_INT(i, ty_i) if i >= 0i64 { + token::LIT_INT_UNSUFFIXED(i, _) if i >= 0i64 { self.bump(); some(vstore_fixed(some(i as uint))) } token::BINOP(token::AND) { @@ -559,6 +559,7 @@ class parser { alt tok { token::LIT_INT(i, it) { lit_int(i, it) } token::LIT_UINT(u, ut) { lit_uint(u, ut) } + token::LIT_INT_UNSUFFIXED(i, it) { lit_int_unsuffixed(i, it) } token::LIT_FLOAT(s, ft) { lit_float(self.get_str(s), ft) } token::LIT_STR(s) { lit_str(self.get_str(s)) } token::LPAREN { self.expect(token::RPAREN); lit_nil } diff --git a/src/libsyntax/parse/token.rs b/src/libsyntax/parse/token.rs index ca11dfa1f9b..989699ab247 100644 --- a/src/libsyntax/parse/token.rs +++ b/src/libsyntax/parse/token.rs @@ -58,6 +58,7 @@ enum token { /* Literals */ LIT_INT(i64, ast::int_ty), LIT_UINT(u64, ast::uint_ty), + LIT_INT_UNSUFFIXED(i64, ast::int_ty), LIT_FLOAT(str_num, ast::float_ty), LIT_STR(str_num), @@ -132,6 +133,9 @@ fn to_str(in: interner<@str>, t: token) -> str { LIT_UINT(u, t) { ret uint::to_str(u as uint, 10u) + ast_util::uint_ty_to_str(t); } + LIT_INT_UNSUFFIXED(i, t) { + ret int::to_str(i as int, 10u) + ast_util::int_ty_to_str(t); + } LIT_FLOAT(s, t) { ret *interner::get(in, s) + ast_util::float_ty_to_str(t); @@ -161,6 +165,7 @@ pure fn can_begin_expr(t: token) -> bool { TILDE { true } LIT_INT(_, _) { true } LIT_UINT(_, _) { true } + LIT_INT_UNSUFFIXED(_, _) { true } LIT_FLOAT(_, _) { true } LIT_STR(_) { true } POUND { true } @@ -178,6 +183,7 @@ fn is_lit(t: token::token) -> bool { ret alt t { token::LIT_INT(_, _) { true } token::LIT_UINT(_, _) { true } + token::LIT_INT_UNSUFFIXED(_, _) { true } token::LIT_FLOAT(_, _) { true } token::LIT_STR(_) { true } _ { false } |
