mozilla/rust — Issue #1589: Number grammar
Author: mikesamuel
Created: 2012-01-21 02:55:40+00:00
State: open

http://doc.rust-lang.org/doc/rust.html#number-literals

The number literal grammar in 3.5.3.2 has one probable type and a few surprising consequences that may not be spec errors.

num_lit : nonzero_dec [ dec_digit | '_' ] * num_suffix ?
| '0' [ [ dec_digit | '_' ] + num_suffix ?
| 'b' [ '1' | '0' | '_' ] + int_suffix ?
| 'x' [ hex_digit | '-' ] + int_suffix ? ] ;

0x-0 is a number literal. This is not an ambiguity, but perhaps the '-' should be a '_'.

Nits:

0b_ is a valid binary literal and 0x_ is a valid hex literal which is surprising but not ambiguous.

Hex digits can be mixed case but the letter indicating the base cannot be -- 0xABCD is ok, but 0XABCD is not.