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

Parse error handling floats with leading DOT #225

Open
idavis opened this issue Aug 30, 2024 · 0 comments
Open

Parse error handling floats with leading DOT #225

idavis opened this issue Aug 30, 2024 · 0 comments

Comments

@idavis
Copy link

idavis commented Aug 30, 2024

Floats with leading DOT fail to parse. Example values that fail parsing:

  • .1234_5678
  • .1e3
  • .1e-3
  • `.1e+3

From the spec:

fragment FloatLiteralExponent: [eE] (PLUS | MINUS)? DecimalIntegerLiteral;
FloatLiteral:
    // 1_123e-3, 123e+4 or 123E5 (needs the exponent or it's just an integer)
    DecimalIntegerLiteral FloatLiteralExponent
    // .1234_5678 or .1e3 (no digits before the dot)
    | DOT DecimalIntegerLiteral FloatLiteralExponent?
    // 123.456, 123. or 145.32e+1_00
    | DecimalIntegerLiteral DOT DecimalIntegerLiteral? FloatLiteralExponent?;

Example test:

#[test]
fn test_spec_types_float_leading_dot() {
    fn parse_source_string(code: &str) -> oq3_source_file::SourceString {
        oq3_source_file::parse_source_string(code, None, None::<&[&std::path::Path]>)
    }
    let code = r#"
   float my_machine_float = .1e3;
"#;
    let source_string = parse_source_string(code);

    if source_string.any_parse_errors() {
        source_string.print_syntax_errors();
        panic!("Errors found");
    }
}

Example output:

Error: atom_expr: expected expression
   ╭─[no file:2:29]
 2 │   float my_machine_float = .1e3;
   │                            ╰ Near this point
Error: expected SEMICOLON
   ╭─[no file:2:30]
 2 │   float my_machine_float = .1e3;
   │                             ╰ Near this point
test test_spec_types_float_leading_dot ... FAILED
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

1 participant