Skip to content

Commit 1bf73b0

Browse files
saplfGolmote
authored andcommitted
Add keywords of Kotlin and modify it's number pattern. (#1389)
* Add keywords & modify number pattern. - Missing keywords by the creator: vararg dynamic infix operator; - New keywords by Kotlin 1.1&1.2: suspend typealias external expect actual; - Remove keyword 'to' as it just a common function name; - Add seperator '_' for the number iteral; - Prefix of hexadecimal and binary can also be capital. * Fix the wrong format of test file.
1 parent f6e81cb commit 1bf73b0

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

components/prism-kotlin.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
Prism.languages.kotlin = Prism.languages.extend('clike', {
33
'keyword': {
44
// The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
5-
pattern: /(^|[^.])\b(?:abstract|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|else|enum|final|finally|for|fun|get|if|import|in|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|out|override|package|private|protected|public|reified|return|sealed|set|super|tailrec|this|throw|to|try|val|var|when|where|while)\b/,
5+
pattern: /(^|[^.])\b(?:abstract|actual|annotation|as|break|by|catch|class|companion|const|constructor|continue|crossinline|data|do|dynamic|else|enum|expect|external|final|finally|for|fun|get|if|import|in|infix|init|inline|inner|interface|internal|is|lateinit|noinline|null|object|open|operator|out|override|package|private|protected|public|reified|return|sealed|set|super|suspend|tailrec|this|throw|try|typealias|val|var|vararg|when|where|while)\b/,
66
lookbehind: true
77
},
88
'function': [
@@ -12,7 +12,7 @@
1212
lookbehind: true
1313
}
1414
],
15-
'number': /\b(?:0[bx][\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?[fFL]?)\b/,
15+
'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
1616
'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
1717
});
1818

components/prism-kotlin.min.js

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/languages/kotlin/keyword_feature.test

+18-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
abstract
2+
actual
23
annotation
34
as
45
break
@@ -12,8 +13,11 @@ continue
1213
crossinline
1314
data
1415
do
16+
dynamic
1517
else
1618
enum
19+
expect
20+
external
1721
final
1822
finally
1923
for
@@ -22,6 +26,7 @@ get
2226
if
2327
import
2428
in
29+
infix
2530
init
2631
inline
2732
inner
@@ -33,6 +38,7 @@ noinline
3338
null
3439
object
3540
open
41+
operator
3642
out
3743
override
3844
package
@@ -44,13 +50,15 @@ return
4450
sealed
4551
set
4652
super
53+
suspend
4754
tailrec
4855
this
4956
throw
50-
to
5157
try
58+
typealias
5259
val
5360
var
61+
vararg
5462
when
5563
where
5664
while
@@ -59,6 +67,7 @@ while
5967

6068
[
6169
["keyword", "abstract"],
70+
["keyword", "actual"],
6271
["keyword", "annotation"],
6372
["keyword", "as"],
6473
["keyword", "break"],
@@ -72,8 +81,11 @@ while
7281
["keyword", "crossinline"],
7382
["keyword", "data"],
7483
["keyword", "do"],
84+
["keyword", "dynamic"],
7585
["keyword", "else"],
7686
["keyword", "enum"],
87+
["keyword", "expect"],
88+
["keyword", "external"],
7789
["keyword", "final"],
7890
["keyword", "finally"],
7991
["keyword", "for"],
@@ -82,6 +94,7 @@ while
8294
["keyword", "if"],
8395
["keyword", "import"],
8496
["keyword", "in"],
97+
["keyword", "infix"],
8598
["keyword", "init"],
8699
["keyword", "inline"],
87100
["keyword", "inner"],
@@ -93,6 +106,7 @@ while
93106
["keyword", "null"],
94107
["keyword", "object"],
95108
["keyword", "open"],
109+
["keyword", "operator"],
96110
["keyword", "out"],
97111
["keyword", "override"],
98112
["keyword", "package"],
@@ -104,13 +118,15 @@ while
104118
["keyword", "sealed"],
105119
["keyword", "set"],
106120
["keyword", "super"],
121+
["keyword", "suspend"],
107122
["keyword", "tailrec"],
108123
["keyword", "this"],
109124
["keyword", "throw"],
110-
["keyword", "to"],
111125
["keyword", "try"],
126+
["keyword", "typealias"],
112127
["keyword", "val"],
113128
["keyword", "var"],
129+
["keyword", "vararg"],
114130
["keyword", "when"],
115131
["keyword", "where"],
116132
["keyword", "while"]

tests/languages/kotlin/number_feature.test

+11-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@
88
123.5e+10
99
123.5f
1010
123.5F
11+
123_456
12+
123_456L
13+
0X01AB_23CD
14+
0B1001_1101
15+
12E34_56
1116

1217
----------------------------------------------------
1318

@@ -21,7 +26,12 @@
2126
["number", "123.5e-10"],
2227
["number", "123.5e+10"],
2328
["number", "123.5f"],
24-
["number", "123.5F"]
29+
["number", "123.5F"],
30+
["number", "123_456"],
31+
["number", "123_456L"],
32+
["number", "0X01AB_23CD"],
33+
["number", "0B1001_1101"],
34+
["number", "12E34_56"]
2535
]
2636

2737
----------------------------------------------------

0 commit comments

Comments
 (0)