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 support for @identifier style identifiers #2414

Merged
merged 3 commits into from Feb 23, 2020
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -16,6 +16,7 @@ Core Changes:

Language Improvements:

- (csharp) add support for `@identifier` style identifiers (#2414) [Josh Goebel][]
- fix(elixir) Support function names with a slash (#2406) [Josh Goebel][]
- fix(javascript) comma is allowed in a "value container" (#2403) [Josh Goebel][]
- enh(apache) add `deny` and `allow` keywords [Josh Goebel][]
Expand Down
9 changes: 8 additions & 1 deletion src/languages/csharp.js
Expand Up @@ -93,6 +93,12 @@ export default function(hljs) {
keywords: "in out"
};
var TYPE_IDENT_RE = hljs.IDENT_RE + '(<' + hljs.IDENT_RE + '(\\s*,\\s*' + hljs.IDENT_RE + ')*>)?(\\[\\])?';
var AT_IDENTIFIER = {
// prevents expressions like `@class` from incorrect flagging
// `class` as a keyword
begin: "@" + hljs.IDENT_RE,
relevance: 0
};

return {
aliases: ['cs', 'c#'],
Expand Down Expand Up @@ -194,7 +200,8 @@ export default function(hljs) {
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE
]
}
},
AT_IDENTIFIER
]
};
}
3 changes: 3 additions & 0 deletions test/markup/csharp/identifiers.expect.txt
@@ -0,0 +1,3 @@
<span class="hljs-keyword">var</span> @class = <span class="hljs-keyword">new</span> MyClass();
doSomething(@var, @foo);
<span class="hljs-keyword">var</span> a;
4 changes: 4 additions & 0 deletions test/markup/csharp/identifiers.txt
@@ -0,0 +1,4 @@
var @class = new MyClass();
doSomething(@var, @foo);
var a;