-
Notifications
You must be signed in to change notification settings - Fork 743
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
Update C# lexer: new keywords and numeric literal syntax improvements #1660
Conversation
* `and` (pattern matching in C# 9) * `init` (records in C# 9) * `unmanaged` (new type constraint in C# 7) * `nint` (native sized integers in C# 9) * `nuint` (native sized integers in C# 9) * `not` (pattern matching in C# 9) * `notnull` (nullable reference types in C# 8) * `#nullable` (nullable reference types in C# 8) * `or` (pattern matching in C# 9) * `record` (records in C# 9) * `with` (records in C# 9) * `when` (exception filters in C# 6, pattern matching in C# 7)
* add C# 7 binary literals, e.g. `0b0010` * add C# 7 digit separators in all numeric literals, e.g. `123_567_890` * add missing `M` type suffix designating `decimal` * make the exponent sign optional
0eefbf3
to
4fcb7cb
Compare
[0-9](?:[_0-9]*[0-9])? | ||
([.][0-9](?:[_0-9]*[0-9])?)? # decimal | ||
(e[+-]?[0-9](?:[_0-9]*[0-9])?)? # exponent | ||
[fldum]? # type |
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.
@jneen I'm curious on your thoughts here. I always recall you saying that a lexer doesn't necessarily have to be syntactically correct. In the case of this regex is there any reason we shouldn't accept the extended regex here for correctness? Or could we, for instance, collapse some of this and says an _
at the beginning or end is OK, although syntactically incorrect for C#?
[_0-9]
([.][_0-9]*)? # decimal
(e[+-][_0-9]+)? # exponent
[fldum]? # type
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.
Thanks for your contribution, @stakx. I'm extending one question to Jeanine, but otherwise things look good. Let's wait a bit to hear back and if we don't, I'm good with it as-is.
This PR is probably out of date, given that it was opened almost 17 months ago, and there are two new versions of the C# language. Is there still any interest in this at all? |
@stakx Sorry for the delay on this PR 🙏🏼 . We are still interested in getting this merge. Any thoughts on whether this is still relevant given the new versions 10 and 11? We can always iterate on future PR. |
@tancnle, yes, this should still be relevant, even now that there are newer language versions. Those add a few more new contextual keywords (e.g. |
Thank you for your response @stakx. In that case, I am fine with this MR being merged 👍🏼 🚀 |
Those happened in C# language versions 6 through 9. I've mostly tested these additions visually (using
rackup
). Tests (rake
) all pass. Here's a quick summary with links to official documentation:Added keywords
and
(pattern matching in C# 9)init
(init only setters and records in C# 9)unmanaged
(new generic type constraint in C# 7)nint
(native sized integers in C# 9)nuint
(native sized integers in C# 9)not
(pattern matching in C# 9)notnull
(nullable reference types in C# 8)#nullable
(nullable reference types in C# 8)or
(pattern matching in C# 9)record
(records in C# 9)with
(records in C# 9)when
(exception filters in C# 6, pattern matching in C# 7)Numeric literal improvements (documentation)
0b0010
123_567_890
M
type suffix designatingdecimal