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(scala) add inline soft keyword #3329

Merged
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
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -18,6 +18,7 @@ Grammars:
- enh(scala) add missing `do` and `then` keyword (#3323) [Nicolas Stucki][]
- enh(scala) add missing `enum`, `export` and `given` keywords (#3328) [Nicolas Stucki][]
- enh(scala) remove symbol syntax and fix quoted code syntax (#3324) [Nicolas Stucki][]
- enh(scala) add `inline` soft keyword (#3329) [Nicolas Stucki][]

[Austin Schick]: https://github.com/austin-schick
[Josh Goebel]: https://github.com/joshgoebel
Expand Down
11 changes: 11 additions & 0 deletions src/languages/scala.js
Expand Up @@ -112,6 +112,16 @@ export default function(hljs) {
contains: [ NAME ]
};

// TODO: use negative look-behind in future
// /(?<!\.)\binline(?=\s)/
const INLINE_MODES = [{
match: /\.inline\b/
},
{
begin: /\binline(?=\s)/,
keywords: 'inline'
}];

return {
name: 'Scala',
keywords: {
Expand All @@ -126,6 +136,7 @@ export default function(hljs) {
METHOD,
CLASS,
hljs.C_NUMBER_MODE,
...INLINE_MODES,
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> <span class="hljs-keyword">given</span> <span class="hljs-type">Int</span> = <span class="hljs-number">9</span>

notinline <span class="hljs-keyword">given</span> <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