Skip to content

Commit

Permalink
Add keywords of Kotlin and modify it's number pattern. (#1389)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
saplf authored and Golmote committed Apr 13, 2018
1 parent f6e81cb commit 1bf73b0
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions components/prism-kotlin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
Prism.languages.kotlin = Prism.languages.extend('clike', {
'keyword': {
// The lookbehind prevents wrong highlighting of e.g. kotlin.properties.get
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/,
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/,
lookbehind: true
},
'function': [
Expand All @@ -12,7 +12,7 @@
lookbehind: true
}
],
'number': /\b(?:0[bx][\da-fA-F]+|\d+(?:\.\d+)?(?:e[+-]?\d+)?[fFL]?)\b/,
'number': /\b(?:0[xX][\da-fA-F]+(?:_[\da-fA-F]+)*|0[bB][01]+(?:_[01]+)*|\d+(?:_\d+)*(?:\.\d+(?:_\d+)*)?(?:[eE][+-]?\d+(?:_\d+)*)?[fFL]?)\b/,
'operator': /\+[+=]?|-[-=>]?|==?=?|!(?:!|==?)?|[\/*%<>]=?|[?:]:?|\.\.|&&|\|\||\b(?:and|inv|or|shl|shr|ushr|xor)\b/
});

Expand Down
2 changes: 1 addition & 1 deletion components/prism-kotlin.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 18 additions & 2 deletions tests/languages/kotlin/keyword_feature.test
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
abstract
actual
annotation
as
break
Expand All @@ -12,8 +13,11 @@ continue
crossinline
data
do
dynamic
else
enum
expect
external
final
finally
for
Expand All @@ -22,6 +26,7 @@ get
if
import
in
infix
init
inline
inner
Expand All @@ -33,6 +38,7 @@ noinline
null
object
open
operator
out
override
package
Expand All @@ -44,13 +50,15 @@ return
sealed
set
super
suspend
tailrec
this
throw
to
try
typealias
val
var
vararg
when
where
while
Expand All @@ -59,6 +67,7 @@ while

[
["keyword", "abstract"],
["keyword", "actual"],
["keyword", "annotation"],
["keyword", "as"],
["keyword", "break"],
Expand All @@ -72,8 +81,11 @@ while
["keyword", "crossinline"],
["keyword", "data"],
["keyword", "do"],
["keyword", "dynamic"],
["keyword", "else"],
["keyword", "enum"],
["keyword", "expect"],
["keyword", "external"],
["keyword", "final"],
["keyword", "finally"],
["keyword", "for"],
Expand All @@ -82,6 +94,7 @@ while
["keyword", "if"],
["keyword", "import"],
["keyword", "in"],
["keyword", "infix"],
["keyword", "init"],
["keyword", "inline"],
["keyword", "inner"],
Expand All @@ -93,6 +106,7 @@ while
["keyword", "null"],
["keyword", "object"],
["keyword", "open"],
["keyword", "operator"],
["keyword", "out"],
["keyword", "override"],
["keyword", "package"],
Expand All @@ -104,13 +118,15 @@ while
["keyword", "sealed"],
["keyword", "set"],
["keyword", "super"],
["keyword", "suspend"],
["keyword", "tailrec"],
["keyword", "this"],
["keyword", "throw"],
["keyword", "to"],
["keyword", "try"],
["keyword", "typealias"],
["keyword", "val"],
["keyword", "var"],
["keyword", "vararg"],
["keyword", "when"],
["keyword", "where"],
["keyword", "while"]
Expand Down
12 changes: 11 additions & 1 deletion tests/languages/kotlin/number_feature.test
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
123.5e+10
123.5f
123.5F
123_456
123_456L
0X01AB_23CD
0B1001_1101
12E34_56

----------------------------------------------------

Expand All @@ -21,7 +26,12 @@
["number", "123.5e-10"],
["number", "123.5e+10"],
["number", "123.5f"],
["number", "123.5F"]
["number", "123.5F"],
["number", "123_456"],
["number", "123_456L"],
["number", "0X01AB_23CD"],
["number", "0B1001_1101"],
["number", "12E34_56"]
]

----------------------------------------------------
Expand Down

0 comments on commit 1bf73b0

Please sign in to comment.