enh(scala) - add `using` directive support (#3810)

This commit is contained in:
Jamie Thompson 2023-07-08 01:02:09 +02:00 committed by GitHub
parent a3e401ec4e
commit e5e0220052
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 38 additions and 0 deletions

View File

@ -19,6 +19,7 @@ Core Grammars:
- enh(swift) support parameter pack keywords [Bradley Mackey][]
- enh(swift) regex literal support [Bradley Mackey][]
- enh(swift) `@unchecked` and `@Sendable` support [Bradley Mackey][]
- enh(scala) add using directives support `//> using foo bar` [Jamie Thompson][]
- enh(swift) ownership modifiers support [Bradley Mackey][]
- enh(nsis) Add `!assert` compiler flag [idleberg][]
- fix(haskell) do not treat double dashes inside infix operators as comments [Zlondrej][]

View File

@ -151,6 +151,34 @@ export default function(hljs) {
beginScope: { 2: "keyword", }
};
// glob all non-whitespace characters as a "string"
// sourced from https://github.com/scala/docs.scala-lang/pull/2845
const DIRECTIVE_VALUE = {
className: 'string',
begin: /\S+/,
}
// directives
// sourced from https://github.com/scala/docs.scala-lang/pull/2845
const USING_DIRECTIVE = {
begin: [
'//>',
/\s+/,
/using/,
/\s+/,
/\S+/
],
beginScope: {
1: "comment",
3: "keyword",
5: "type"
},
end: /$/,
contains: [
DIRECTIVE_VALUE,
]
}
return {
name: 'Scala',
keywords: {
@ -158,6 +186,7 @@ export default function(hljs) {
keyword: 'type yield lazy override def with val var sealed abstract private trait object if then forSome for while do throw finally protected extends import final return else break new catch super class case package default try this match continue throws implicit export enum given transparent'
},
contains: [
USING_DIRECTIVE,
hljs.C_LINE_COMMENT_MODE,
hljs.C_BLOCK_COMMENT_MODE,
STRING,

View File

@ -0,0 +1,4 @@
<span class="hljs-comment">//&gt;</span> <span class="hljs-keyword">using</span> <span class="hljs-type">scala</span> <span class="hljs-string">3.3.0</span>
<span class="hljs-comment">//&gt;</span> <span class="hljs-keyword">using</span> <span class="hljs-type">options</span> <span class="hljs-string">-source:future</span> <span class="hljs-string">-Xfatal-warnings</span>
<span class="hljs-comment">//&gt;</span> <span class="hljs-keyword">using</span> <span class="hljs-type">test.resourceDir</span> <span class="hljs-string">./resources</span>
<span class="hljs-comment">// using foo bar &lt;-- this should not be highlighted</span>

View File

@ -0,0 +1,4 @@
//> using scala 3.3.0
//> using options -source:future -Xfatal-warnings
//> using test.resourceDir ./resources
// using foo bar <-- this should not be highlighted