From 98b9cec1845ecf2e8d7d770557f472638d282a13 Mon Sep 17 00:00:00 2001 From: Josh Goebel Date: Thu, 6 Feb 2020 16:36:15 -0500 Subject: [PATCH] enh(csharp) generic modifiers, reference paths, `where` keyword (#2378) * enh(csharp) add generic modifiers * enh(csharp) Allow reference path in class inheritance lists. Closes #1947. * enh(csharp) Support `where` keyword as class constraint --- CHANGES.md | 3 +++ src/languages/csharp.js | 12 ++++++++++-- test/markup/csharp/generic_modifiers.expect.txt | 7 +++++++ test/markup/csharp/generic_modifiers.txt | 7 +++++++ test/markup/csharp/titles.expect.txt | 4 +++- test/markup/csharp/titles.txt | 4 +++- 6 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 test/markup/csharp/generic_modifiers.expect.txt create mode 100644 test/markup/csharp/generic_modifiers.txt diff --git a/CHANGES.md b/CHANGES.md index 0491d5be76..c12ea5f3ed 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -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][] diff --git a/src/languages/csharp.js b/src/languages/csharp.js index 5891bfa670..9952fd22a1 100644 --- a/src/languages/csharp.js +++ b/src/languages/csharp.js @@ -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: [ @@ -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 { @@ -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 ] @@ -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 ] diff --git a/test/markup/csharp/generic_modifiers.expect.txt b/test/markup/csharp/generic_modifiers.expect.txt new file mode 100644 index 0000000000..bf6d8c3fba --- /dev/null +++ b/test/markup/csharp/generic_modifiers.expect.txt @@ -0,0 +1,7 @@ +interface IObserver<in T>; +{} + +interface IObservable<out T>; +{} + +public delegate void DContravariant<in A>(A argument); diff --git a/test/markup/csharp/generic_modifiers.txt b/test/markup/csharp/generic_modifiers.txt new file mode 100644 index 0000000000..0af70e5c53 --- /dev/null +++ b/test/markup/csharp/generic_modifiers.txt @@ -0,0 +1,7 @@ +interface IObserver; +{} + +interface IObservable; +{} + +public delegate void DContravariant(A argument); diff --git a/test/markup/csharp/titles.expect.txt b/test/markup/csharp/titles.expect.txt index 185cb34c2e..be471a6db1 100644 --- a/test/markup/csharp/titles.expect.txt +++ b/test/markup/csharp/titles.expect.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 { @@ -16,4 +16,6 @@ } } + public class TesterA<R, S> where R : class where S : IComparable + {} } diff --git a/test/markup/csharp/titles.txt b/test/markup/csharp/titles.txt index ee1d81547a..802e305e55 100644 --- a/test/markup/csharp/titles.txt +++ b/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 { @@ -16,4 +16,6 @@ namespace Foo // namespace } } + public class TesterA where R : class where S : IComparable + {} }