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

Fix how negative literals are handled to be in line with Rust #132

Merged
merged 2 commits into from
Oct 2, 2020

Conversation

udoprog
Copy link
Collaborator

@udoprog udoprog commented Oct 2, 2020

Literals are resolved internally to num::BigInt, so they have no size limitation at compile time. Only at the point that they are treated as something, like a tuple index (usize) or a literal number (i64).

This fixes parsing so that it is in line with Rust. This has been an outstanding issue with the quote! macro, in that -10 would be treated as - 10 (note the space), which wouldn't parse. Now it does parse.

This has the nice side effect that the rune! macro can mostly just consume a token stream from Rust now, since Rune mostly accepts the same stringified tokens as Rust. So many test cases now look like this:

assert_eq! {
    rune!(bool => fn main() { false || false || {return true; false} || false }),
    true,
};

Note: this currently "cheats" by calling stringify!, but could just as well use quote! internally.

The exception is the ones dealing with string templates, since they are whitespace sensitive and have no corollary in Rust. For these we maintain the rune_s! test macro that works like rune! did before:

assert_eq! {
    rune_s! { String => r#"
        fn main() {
            let name = "John Doe";
            `Hello {name}, I am {1 - 10} years old!`
        }
    "#},
    "Hello John Doe, I am -9 years old!",
};

This also changes a bunch of the plumbing for ast::Pat, since these used to rely on literals parsing in a different manner. Of note is that they also parse attributes now.

@udoprog udoprog added the enhancement New feature or request label Oct 2, 2020
@udoprog udoprog merged commit cd8fe23 into master Oct 2, 2020
@udoprog udoprog deleted the unary-expr branch October 2, 2020 16:35
@udoprog udoprog added the changelog Issue has been added to the changelog label Oct 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog Issue has been added to the changelog enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant