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 all 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
3 changes: 3 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) enh(fortran) support intrinsic data types (#2379) [Josh Goebel][]
- enh(java) annotations can include numbers (#2377) [Josh Goebel][]
- enh(java) annotations can take params (#2377) [Josh Goebel][]
Expand Down
12 changes: 10 additions & 2 deletions src/languages/csharp.js
Expand Up @@ -22,6 +22,7 @@ function(hljs) {
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 +87,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 +137,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 +148,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
{}
}