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

Update C# lexer: new keywords and numeric literal syntax improvements #1660

Merged
merged 2 commits into from
Jan 4, 2023

Conversation

stakx
Copy link
Contributor

@stakx stakx commented Dec 28, 2020

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

Numeric literal improvements (documentation)

  • 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

 * `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
@stakx stakx force-pushed the update-csharp-lexer branch from 0eefbf3 to 4fcb7cb Compare December 28, 2020 11:25
[0-9](?:[_0-9]*[0-9])?
([.][0-9](?:[_0-9]*[0-9])?)? # decimal
(e[+-]?[0-9](?:[_0-9]*[0-9])?)? # exponent
[fldum]? # type
Copy link
Collaborator

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

Copy link
Collaborator

@dblessing dblessing left a 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.

@stakx
Copy link
Contributor Author

stakx commented May 12, 2022

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?

@tancnle
Copy link
Collaborator

tancnle commented May 12, 2022

@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.

@stakx
Copy link
Contributor Author

stakx commented Jan 4, 2023

@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. file, init, required, scoped), but like you said, those can always be added in another PR.

@tancnle
Copy link
Collaborator

tancnle commented Jan 4, 2023

Thank you for your response @stakx. In that case, I am fine with this MR being merged 👍🏼 🚀

@tancnle tancnle merged commit fb9a3d9 into rouge-ruby:master Jan 4, 2023
@stakx stakx deleted the update-csharp-lexer branch January 4, 2023 18:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants