Skip to content

Conversation

jbdutton
Copy link
Contributor

@jbdutton jbdutton commented Aug 8, 2023

Allow one or more underscores at the start of a variable name, like so:

fn main() {
    let _a = 0;
    _a = 42;
    _a
}

This changes the lexer to allow underscores at the start of an identifier, and only emits ask::Kind::Underscore if it's strictly _.

Interestingly, this seems to match the behavior in Rust. They both treat more than one underscore as a valid identifier. So this would work in both Rust and Rune:

fn main() {
    let ___ = 0;
    ___ = 42;
    ___
}

(Assuming you mark ___ as mut in Rust.)

Personally, I find this behavior odd. But maybe matching the Rust compiler behavior is best?

Fixes #435.

@jbdutton jbdutton marked this pull request as ready for review August 8, 2023 16:04
@udoprog udoprog added the enhancement New feature or request label Aug 8, 2023
@udoprog
Copy link
Collaborator

udoprog commented Aug 8, 2023

Short and sweet. Thank you!

The msrv error is not your fault, it's an upstream dependency I'll have to deal with once I bake a new release.

@udoprog udoprog merged commit ffb6cfe into rune-rs:main Aug 8, 2023
@jbdutton jbdutton deleted the underscores branch August 8, 2023 16:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow variable names starting with an underscore _
2 participants