-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Feature request: allow digit separator after 0b or 0x #12680
Comments
This is a language request, not a compiler request. The compiler is behaving per its specification. |
/cc @khyperia FYI |
I implemented this a while back, so I figured I'd chime in with what I know. While I'm not sure where the exact spec is hiding (it likely is equivalent to the compiler), this is what the compiler does: Any "string of digits" (e.g. 0-9 for decimals, plus fullwidth for VB) in any literal (decimal, hex, binary, float, double) can contain any number of underscores at any place between the first and last digit (i.e. cannot start nor end with an underscore). There are additional cases that might be interesting to consider when discussing the choice of if
Additionally, Note that if any rules is changed, we would also want to update VB, as well as possibly F# - I helped out a PR implementing digit separators in F#, and they ended up following the same rules. Edit from half a year later (2017-02-11): Don't know what I was thinking with |
So the compiler will have to wait until it knows whether |
I think the proposed grammar was |
I'm closing this and letting the LDM decide before doing any work. See dotnet/csharplang#65 |
Note: I'd be very wary about allowing a prefix of |
@CyrusNajmabadi The meaning of prefix here are is, are those define by the language specification.
If the prefix is missing then it possible for the character sequence to match a identifier (possibly legal) if the underscore separator is first. Though this is unlikely as the prefix is required in this context of digit separators. |
This was previously requested in a comment on #216 (and I independently viewed that thread precisely to see if it was already valid).
With VS15 Preview 3, we have:
Valid:
Not valid:
I find the latter more readable than the former. While I can see the reason why digit separators before just digits isn't valid (e.g.
_1
, which is a valid identifier), the leading0x
or0b
already prevents the token from being an identifier.// cc @zippec
The text was updated successfully, but these errors were encountered: