Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

0e+10 is invalid whereas 00e+10 is valid #40408

Closed
qnighy opened this issue Mar 10, 2017 · 4 comments
Closed

0e+10 is invalid whereas 00e+10 is valid #40408

qnighy opened this issue Mar 10, 2017 · 4 comments

Comments

@qnighy
Copy link
Contributor

qnighy commented Mar 10, 2017

I found this line in the lexer prevents 0e+10 to be parsed as a float, whereas 00e+10 is allowed anyway. Is this a bug or an intended behavior?

This is a code I tested on Rust Playground:

fn main() {
  // OK
  println!("{}", 0);
  // OK
  println!("{}", 00e+10);
  // Parse Error
  println!("{}", 0e+10);
}

It seems natural that both of them are banned or both of them are allowed.

@nagisa
Copy link
Member

nagisa commented Mar 10, 2017

It is a bug.

@nagisa
Copy link
Member

nagisa commented Mar 10, 2017

IIRC at least.

@nagisa
Copy link
Member

nagisa commented Mar 11, 2017

This is the relevant section in the reference: https://doc.rust-lang.org/reference.html#floating-point-literals

It says:

A floating-point literal has one of two forms:

  • A decimal literal followed by a period character U+002E (.). This is optionally followed by another decimal literal, with an optional exponent.
  • A single decimal literal followed by an exponent.

and

A decimal literal starts with a decimal digit and continues with any mixture of decimal digits and underscores.

i.e.

LIT_DECIMAL := DEC_DIGIT (DEC_DIGIT | "_")+
EXPONENT := /* snip */
LIT_FLOAT_FORM1 := LIT_DECIMAL "." [LIT_DECIMAL [EXPONENT]]
LIT_FLOAT_FORM2 := LIT_DECIMAL EXPONENT
LIT_FLOAT := LIT_FLOAT_FORM1 | LIT_FLOAT_FORM2

so all forms should parse.

topecongiro added a commit to topecongiro/rust that referenced this issue Mar 18, 2017
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 18, 2017
… r=nagisa

Parse 0e+10 as a valid floating-point literal

Fixes issue rust-lang#40408.
arielb1 pushed a commit to arielb1/rust that referenced this issue Mar 19, 2017
… r=nagisa

Parse 0e+10 as a valid floating-point literal

Fixes issue rust-lang#40408.
frewsxcv added a commit to frewsxcv/rust that referenced this issue Mar 19, 2017
… r=nagisa

Parse 0e+10 as a valid floating-point literal

Fixes issue rust-lang#40408.
@qnighy
Copy link
Contributor Author

qnighy commented Apr 28, 2017

I'm going to close this issue, because #40589 fixed it.

@qnighy qnighy closed this as completed Apr 28, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants