-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Accept underscore as numeric literal separator #6989
Accept underscore as numeric literal separator #6989
Conversation
b8556e2
to
dd1231d
Compare
0295fd9
to
6c0cef5
Compare
Marking as WIP until the status of this change (SIP? Micro-SIP?) is clear. |
@adriaanm @SethTisue Probably a syntax change can't land in 2.13.1? "It's just syntax." |
6c0cef5
to
e69c40a
Compare
There is a precedent: trailing commas landed in 2.12.2. |
right, we don't guarantee forward source compat, only forward binary compat |
Wow, I thought "It's just syntax" was just a saying. I'm going to start using trailing commas everywhere now. Or everywhere except 0.13 builds, I guess. |
What's next here? I'd personally prefer supporting only one of the two separators. |
+1 to Lukas' comment. I'm in favour of |
e69c40a
to
d4d5735
Compare
There was a long discussion elsewhere in which Ichoran expressed a personal preference for Here is the commit rebased and slightly cleaner. The warnings were pushed to the linked PR. It should be easy for someone else to push a tweak once the committee makes up its mind. |
Our approach here is usually to copy Java, which means just having underscore: https://docs.oracle.com/javase/8/docs/technotes/guides/language/underscores-literals.html |
Does Java accept a leading zero? |
@soronpo Java supports octal syntax. |
Why is this good? |
this is ready for merge, right? I'm certainly in favor of the change. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this looks ready to go (post-squash), except that it should include a spec update
as always, our compass is WWGD? |
58aa62e
to
f8d704d
Compare
/cc @olafurpg fyi, small syntax change. We should also think about what this means for round-tripping (normalisation during lexing means we can't print the original source based on the AST.). I'm not saying this has to block the PR, but it's worth documenting. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks great! In Scalameta we already store the original syntax in tokens so the underscores won't be lost during a pretty-printing roundtrip. I recommend to add some position tests (esp. with -Yrangepos
) to ensure compiler trees are able recover the original syntax.
The separator character is underscore as in Java. They may be mixed arbitrarily in a numeric literal, but only in the interior: the literal, and each part of double, must begin and end with a digit. Add spec for underscore numeric separator. Test literal positions. Verifying visually that literals with underscores are the correct length.
04de9d0
to
c359188
Compare
@SethTisue One, two, three, four, what's the syntax we adore? Numeric underscore! Fully baked squash pie. This is the rare PR with no thumbs pointed netherward. Even when the mob was all pitchforky about single quote as separator, they dared not jinx it, such was their faith and enthusiasm. |
Hmmmm 🥧 |
🎉 |
Nice! Particularly well done for not restricting it to groupings of 3, which wouldn't be very nice towards some numbering systems like https://en.wikipedia.org/wiki/Indian_numbering_system |
000123
,000_123
,000'123
,3_14e-0_2
.