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) generic modifiers, reference paths, where keyword #2378

Merged
merged 5 commits into from Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGES.md
Expand Up @@ -14,6 +14,9 @@ Core Changes:

Language Improvements:

- enh(csharp) Support `where` keyword as class constraint (#2378) [Josh Goebel][]
- enh(csharp) Allow reference path in class inheritance lists (#2378) [Josh Goebel][]
- enh(csharp) Add generic modifiers (in, out) (#2378) [Josh Goebel][]
- (fortran) Add Fortran 2018 keywords and coarray intrinsics (#2361) [Sam Miller][]
- (delphi) highlight hexadecimal, octal, and binary numbers (#2370) [Robert Riebisch]()
- enh(plaintext) added `text` and `txt` as alias (#2360) [Taufik Nurrohman][]
Expand All @@ -22,6 +25,7 @@ Developer Tools:

- none.

[Josh Goebel]: https://github.com/yyyc514
[Sam Miller]: https://github.com/smillerc
[Robert Riebisch]: https://github.com/bttrx
[Taufik Nurrohman]: https://github.com/taufik-nurrohman
Expand Down
16 changes: 13 additions & 3 deletions src/languages/csharp.js
Expand Up @@ -18,10 +18,13 @@ function(hljs) {
'uint ulong unchecked unsafe ushort using virtual void volatile while ' +
// Contextual keywords.
'add alias ascending async await by descending dynamic equals from get global group into join ' +
'let nameof on orderby partial remove select set value var when where yield',
'let nameof on orderby partial remove select set value var when where yield ' +
// generic modifiers
'in out',
joshgoebel marked this conversation as resolved.
Show resolved Hide resolved
literal:
'null false true'
};
var TITLE_MODE = hljs.inherit(hljs.TITLE_MODE, {begin: '[a-zA-Z](\\.?\\w)*'});
var NUMBERS = {
className: 'number',
variants: [
Expand Down Expand Up @@ -86,6 +89,11 @@ function(hljs) {
]
};

var GENERIC_MODIFIER = {
begin: "<",
end: ">",
keywords: "in out"
};
var TYPE_IDENT_RE = hljs.IDENT_RE + '(<' + hljs.IDENT_RE + '(\\s*,\\s*' + hljs.IDENT_RE + ')*>)?(\\[\\])?';

return {
Expand Down Expand Up @@ -131,7 +139,9 @@ function(hljs) {
beginKeywords: 'class interface', end: /[{;=]/,
illegal: /[^\s:,]/,
contains: [
hljs.TITLE_MODE,
{ beginKeywords: "where class" },
TITLE_MODE,
GENERIC_MODIFIER,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
Expand All @@ -140,7 +150,7 @@ function(hljs) {
beginKeywords: 'namespace', end: /[{;=]/,
illegal: /[^\s:]/,
contains: [
hljs.inherit(hljs.TITLE_MODE, {begin: '[a-zA-Z](\\.?\\w)*'}),
TITLE_MODE,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
Expand Down
7 changes: 7 additions & 0 deletions test/markup/csharp/generic_modifiers.expect.txt
@@ -0,0 +1,7 @@
<span class="hljs-keyword">interface</span> <span class="hljs-title">IObserver</span>&lt;<span class="hljs-keyword">in</span> T&gt;;
{}

<span class="hljs-keyword">interface</span> <span class="hljs-title">IObservable</span>&lt;<span class="hljs-keyword">out</span> T&gt;;
{}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">delegate</span> <span class="hljs-keyword">void</span> DContravariant&lt;<span class="hljs-keyword">in</span> A&gt;(A argument);
7 changes: 7 additions & 0 deletions test/markup/csharp/generic_modifiers.txt
@@ -0,0 +1,7 @@
interface IObserver<in T>;
{}

interface IObservable<out T>;
{}

public delegate void DContravariant<in A>(A argument);
4 changes: 3 additions & 1 deletion test/markup/csharp/titles.expect.txt
@@ -1,6 +1,6 @@
<span class="hljs-keyword">namespace</span> <span class="hljs-title">Foo</span> <span class="hljs-comment">// namespace</span>
{
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Greet</span> : <span class="hljs-title">Base</span>, <span class="hljs-title">Other</span> <span class="hljs-comment">// class</span>
<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">Greet</span> : <span class="hljs-title">Base</span>, <span class="hljs-title">Other</span>, <span class="hljs-title">IInterface.test.path</span> <span class="hljs-comment">// class</span>
{
<span class="hljs-function"><span class="hljs-keyword">public</span> <span class="hljs-title">Greet</span>(<span class="hljs-params"><span class="hljs-keyword">string</span> who</span>) <span class="hljs-comment">// function</span></span>
{
Expand All @@ -16,4 +16,6 @@
}
}

<span class="hljs-keyword">public</span> <span class="hljs-keyword">class</span> <span class="hljs-title">TesterA</span>&lt;R, S&gt; <span class="hljs-keyword">where</span> <span class="hljs-title">R</span> : <span class="hljs-keyword">class</span> <span class="hljs-keyword">where</span> <span class="hljs-title">S</span> : <span class="hljs-title">IComparable</span>
{}
}
4 changes: 3 additions & 1 deletion test/markup/csharp/titles.txt
@@ -1,6 +1,6 @@
namespace Foo // namespace
{
public class Greet : Base, Other // class
public class Greet : Base, Other, IInterface.test.path // class
{
public Greet(string who) // function
{
Expand All @@ -16,4 +16,6 @@ namespace Foo // namespace
}
}

public class TesterA<R, S> where R : class where S : IComparable
{}
}