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

enh(csharp) add keywords record and init (C# 9.0) #2660

Merged
merged 5 commits into from Aug 20, 2020

Conversation

Youssef1313
Copy link
Contributor

No description provided.

@joshgoebel
Copy link
Member

joshgoebel commented Aug 19, 2020

Please show examples of how both of these are used... sometimes it's not just as simple as adding them to the keywords list. If record is more of a "class" like in Java then it likely needs far more complex rules.

@Youssef1313
Copy link
Contributor Author

Youssef1313 commented Aug 19, 2020

using System;
public record MyRecord
{
    public string SomeMember { get; set; }
}

Not sure if it requires some complex rules or not.

https://sharplab.io/#v2:EYLgZgpghgLgrgJwgZwLRIMYHsEBNkA0uIA1AD4ACATAIwCwAUBQMwAEmOurAsgJ4BKEbHkYBvRq0msW0mgAZWAZSwBbCNwgrgEBK1GsA5hBgBuVsmNmAvoytA==

@joshgoebel
Copy link
Member

Yes, it's more like a class. See lines 148 or 159. We'd expect that MyRecord was highlighted as a title as well, which requires a custom rule.

init looks like more a normal boring keyword, at least from https://csharp.christiannagel.com/2020/04/21/c-9-positional-or-nominal-creation/ this.

@joshgoebel
Copy link
Member

So we'd need a new rule for record, plus a simple expects test to prove that the rule works as expected.

@Youssef1313
Copy link
Contributor Author

Youssef1313 commented Aug 19, 2020

I'm not familiar with making custom rules. :(
May I keep this PR for init only and open an issue to track adding record, or you'd like to close it all together and open an issue to track both keywords?

@joshgoebel
Copy link
Member

joshgoebel commented Aug 19, 2020

May I keep this PR for init only and open an issue to track adding record

This please. Thought you should consider giving it a try, it's not hard. I'm happy to help.

It'd look pretty much like (probably):

      {
        beginKeywords: 'record', end: /[{;=]/,
        illegal: /[^\s:]/,
        contains: [
          TITLE_MODE,
          // are generics allowed?
          hljs.C_LINE_COMMENT_MODE,
          hljs.C_BLOCK_COMMENT_MODE
        ]
      },

And then adding a test case to test/markup/csharp/. Let me know how I could encourage youto make a PR. :-)

@joshgoebel
Copy link
Member

Either way this would need a mention in CHANGES.md. :-)

@Youssef1313
Copy link
Contributor Author

That doesn't seem hard.

It looks like generics are allowed based on what I'm getting in sharplab.
I've updated csharp.js and will add the test and update CHANGES.md soon.

@joshgoebel Thanks for helping!

@joshgoebel joshgoebel changed the title Add C# 9.0 keywords (record + init) enh(csharp) add keywords record and init (C# 9.0) Aug 20, 2020
@joshgoebel
Copy link
Member

@Youssef1313 Thanks so much for your contribution! Wasn't so hard, was it?

@joshgoebel joshgoebel merged commit fb0b19c into highlightjs:master Aug 20, 2020
@Youssef1313 Youssef1313 deleted the patch-6 branch August 20, 2020 18:01
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.

None yet

2 participants