Skip to content

Commit

Permalink
enh(scala) add inline soft keyword
Browse files Browse the repository at this point in the history
Make `inline` a keyword when it is not part of a member selection of application.

Basic idea form https://github.com/scala/vscode-scala-syntax/blob/main/src/typescript/Scala.tmLanguage.ts#L665, but without the need to distinguish the two kinds of keyword.
Also see https://docs.scala-lang.org/scala3/reference/soft-modifier.html
  • Loading branch information
nicolasstucki committed Sep 6, 2021
1 parent 3cc0800 commit d183241
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/languages/scala.js
Expand Up @@ -117,6 +117,11 @@ export default function(hljs) {
contains: [ NAME ]
};

const INLINE = {
className: 'keyword',
begin: /(?<!\.)\binline(?=\s)/
};

return {
name: 'Scala',
keywords: {
Expand All @@ -132,6 +137,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
INLINE,
ANNOTATION
]
};
Expand Down
15 changes: 15 additions & 0 deletions test/markup/scala/inline.expect.txt
@@ -0,0 +1,15 @@
<span class="hljs-keyword">inline</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">pow</span></span>(<span class="hljs-keyword">inline</span> x: <span class="hljs-type">Int</span>, <span class="hljs-keyword">inline</span> n: <span class="hljs-type">Int</span>) = ???
transparent <span class="hljs-keyword">inline</span> <span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">f</span></span>: <span class="hljs-type">Int</span> = ???
<span class="hljs-keyword">inline</span> <span class="hljs-keyword">val</span> a: <span class="hljs-type">Int</span> = <span class="hljs-number">9</span>
<span class="hljs-keyword">inline</span> given <span class="hljs-type">Int</span> = <span class="hljs-number">9</span>

notinline given <span class="hljs-type">Int</span> = <span class="hljs-number">9</span>

<span class="hljs-function"><span class="hljs-keyword">def</span> <span class="hljs-title">expressions</span> </span>=
<span class="hljs-keyword">inline</span> <span class="hljs-keyword">if</span> <span class="hljs-literal">true</span> <span class="hljs-keyword">then</span> () <span class="hljs-keyword">else</span> ()
<span class="hljs-keyword">inline</span> x <span class="hljs-keyword">match</span> ...

x.inline
x.inline(y)
x.inline[<span class="hljs-type">T</span>]
`inline` + <span class="hljs-number">1</span>
15 changes: 15 additions & 0 deletions test/markup/scala/inline.txt
@@ -0,0 +1,15 @@
inline def pow(inline x: Int, inline n: Int) = ???
transparent inline def f: Int = ???
inline val a: Int = 9
inline given Int = 9

notinline given Int = 9

def expressions =
inline if true then () else ()
inline x match ...

x.inline
x.inline(y)
x.inline[T]
`inline` + 1

0 comments on commit d183241

Please sign in to comment.