Stop lexing -1 as a single token
And remove the hack that made 1-1 work given that other hack. Issue #954
This commit is contained in:
parent
64ce092c27
commit
7655b3c0c6
@ -175,17 +175,6 @@ fn scan_exponent(rdr: reader) -> option::t<str> {
|
||||
} else { ret none::<str>; }
|
||||
}
|
||||
|
||||
fn scan_dec_digits_with_prefix(rdr: reader) -> str {
|
||||
let negative = false;
|
||||
if rdr.curr() == '-' {
|
||||
negative = true;
|
||||
rdr.bump();
|
||||
}
|
||||
let digits = scan_dec_digits(rdr);
|
||||
if negative { str::unshift_char(digits, '-'); }
|
||||
ret digits;
|
||||
}
|
||||
|
||||
fn scan_dec_digits(rdr: reader) -> str {
|
||||
let c = rdr.curr();
|
||||
let rslt: str = "";
|
||||
@ -220,7 +209,7 @@ fn scan_number(c: char, rdr: reader) -> token::token {
|
||||
c = rdr.curr();
|
||||
}
|
||||
} else {
|
||||
num_str = scan_dec_digits_with_prefix(rdr);
|
||||
num_str = scan_dec_digits(rdr);
|
||||
accum_int = std::int::from_str(num_str);
|
||||
}
|
||||
c = rdr.curr();
|
||||
@ -346,7 +335,7 @@ fn next_token_inner(rdr: reader) -> token::token {
|
||||
ret token::IDENT(interner::intern::<str>(*rdr.get_interner(),
|
||||
accum_str), is_mod_name);
|
||||
}
|
||||
if is_dec_digit(c) || (c == '-' && is_dec_digit(rdr.next())) {
|
||||
if is_dec_digit(c) {
|
||||
ret scan_number(c, rdr);
|
||||
}
|
||||
fn binop(rdr: reader, op: token::binop) -> token::token {
|
||||
@ -743,42 +732,6 @@ fn gather_comments_and_literals(cm: codemap::codemap, path: str,
|
||||
ret {cmnts: comments, lits: literals};
|
||||
}
|
||||
|
||||
// This is a stopgap fix. We will have to do better eventually (issue #954)
|
||||
fn maybe_untangle_minus_from_lit(r: reader, t: token::token)
|
||||
-> option::t<token::token> {
|
||||
fn check_str(r: reader, i: uint) -> option::t<uint> {
|
||||
let it = r.get_interner(), s = interner::get(*it, i);
|
||||
if s[0] == '-' as u8 {
|
||||
some(interner::intern(*it, str::slice(s, 1u, str::byte_len(s))))
|
||||
} else { none }
|
||||
}
|
||||
alt t {
|
||||
token::LIT_INT(v) {
|
||||
if v < 0 { ret some(token::LIT_INT(-v)); }
|
||||
}
|
||||
token::LIT_UINT(v) {
|
||||
if v > 0x7fffffffu { ret some(token::LIT_UINT(-(v as int) as uint)); }
|
||||
}
|
||||
token::LIT_MACH_INT(m, v) {
|
||||
if v < 0 { ret some(token::LIT_MACH_INT(m, -v)); }
|
||||
}
|
||||
token::LIT_FLOAT(s) {
|
||||
alt check_str(r, s) {
|
||||
some(s) { ret some(token::LIT_FLOAT(s)); }
|
||||
_ {}
|
||||
}
|
||||
}
|
||||
token::LIT_MACH_FLOAT(m, s) {
|
||||
alt check_str(r, s) {
|
||||
some(s) { ret some(token::LIT_MACH_FLOAT(m, s)); }
|
||||
_ {}
|
||||
}
|
||||
}
|
||||
_ {}
|
||||
}
|
||||
none
|
||||
}
|
||||
|
||||
//
|
||||
// Local Variables:
|
||||
// mode: rust
|
||||
|
@ -1180,24 +1180,12 @@ fn parse_more_binops(p: parser, lhs: @ast::expr, min_prec: int) ->
|
||||
@ast::expr {
|
||||
if !expr_has_value(lhs) { ret lhs; }
|
||||
let peeked = p.peek();
|
||||
let lit_after = alt lexer::maybe_untangle_minus_from_lit(p.get_reader(),
|
||||
peeked) {
|
||||
some(tok) {
|
||||
peeked = token::BINOP(token::MINUS);
|
||||
let lit = @{node: lit_from_token(p, tok), span: p.get_span()};
|
||||
some(mk_expr(p, p.get_lo_pos(), p.get_hi_pos(), ast::expr_lit(lit)))
|
||||
}
|
||||
none. { none }
|
||||
};
|
||||
if peeked == token::BINOP(token::OR) &&
|
||||
p.get_restriction() == RESTRICT_NO_BAR_OP { ret lhs; }
|
||||
for cur: op_spec in *p.get_prec_table() {
|
||||
if cur.prec > min_prec && cur.tok == peeked {
|
||||
p.bump();
|
||||
let expr = alt lit_after {
|
||||
some(ex) { ex }
|
||||
_ { parse_prefix_expr(p) }
|
||||
};
|
||||
let expr = parse_prefix_expr(p);
|
||||
let rhs = parse_more_binops(p, expr, cur.prec);
|
||||
let bin = mk_expr(p, lhs.span.lo, rhs.span.hi,
|
||||
ast::expr_binary(cur.op, lhs, rhs));
|
||||
|
Loading…
Reference in New Issue
Block a user