Skip to content

Commit

Permalink
enh(csharp) add generic modifiers
Browse files Browse the repository at this point in the history
  • Loading branch information
joshgoebel committed Jan 31, 2020
1 parent 86e5b1b commit bc30724
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGES.md
Expand Up @@ -14,6 +14,7 @@ Core Changes:

Language Improvements:

- 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 +23,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
10 changes: 9 additions & 1 deletion src/languages/csharp.js
Expand Up @@ -18,7 +18,9 @@ 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',
literal:
'null false true'
};
Expand Down Expand Up @@ -86,6 +88,11 @@ function(hljs) {
]
};

GENERIC_var 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,6 +138,7 @@ function(hljs) {
beginKeywords: 'class interface', end: /[{;=]/,
illegal: /[^\s:,]/,
contains: [
GENERIC_MODIFIER,
hljs.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);

0 comments on commit bc30724

Please sign in to comment.