]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/kotlin.js
1 /*! `kotlin` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
6 // https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
7 var decimalDigits
= '[0-9](_*[0-9])*';
8 var frac
= `\\.(${decimalDigits})`;
9 var hexDigits
= '[0-9a-fA-F](_*[0-9a-fA-F])*';
13 // DecimalFloatingPointLiteral
14 // including ExponentPart
15 { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
16 `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
17 // excluding ExponentPart
18 { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
19 { begin: `(${frac})[fFdD]?\\b` },
20 { begin: `\\b(${decimalDigits})[fFdD]\\b` },
22 // HexadecimalFloatingPointLiteral
23 { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
24 `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
26 // DecimalIntegerLiteral
27 { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
30 { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
32 // OctalIntegerLiteral
33 { begin: '\\b0(_*[0-7])*[lL]?\\b' },
35 // BinaryIntegerLiteral
36 { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
43 Description: Kotlin is an OSS statically typed programming language that targets the JVM, Android, JavaScript and Native.
44 Author: Sergey Mashkov <cy6erGn0m@gmail.com>
45 Website: https://kotlinlang.org
50 function kotlin(hljs
) {
53 'abstract as val var vararg get set class object open private protected public noinline '
54 + 'crossinline dynamic final enum if else do while for when throw try catch finally '
55 + 'import package is in fun override companion reified inline lateinit init '
56 + 'interface annotation data sealed internal infix operator out by constructor super '
57 + 'tailrec where const inner suspend typealias external expect actual',
59 'Byte Short Char Int Long Boolean Float Double Void Unit Nothing',
63 const KEYWORDS_WITH_LABEL
= {
65 begin: /\b(break|continue|return|this)\b/,
75 begin: hljs
.UNDERSCORE_IDENT_RE
+ '@'
78 // for string templates
83 contains: [ hljs
.C_NUMBER_MODE
]
86 className: 'variable',
87 begin: '\\$' + hljs
.UNDERSCORE_IDENT_RE
100 // Can't use built-in modes easily, as we want to use STRING in the meta
101 // context as 'meta-string' and there's no syntax to remove explicitly set
102 // classNames in built-in modes.
107 contains: [ hljs
.BACKSLASH_ESCAPE
]
114 hljs
.BACKSLASH_ESCAPE
,
121 SUBST
.contains
.push(STRING
);
123 const ANNOTATION_USE_SITE
= {
125 begin: '@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*' + hljs
.UNDERSCORE_IDENT_RE
+ ')?'
129 begin: '@' + hljs
.UNDERSCORE_IDENT_RE
,
135 hljs
.inherit(STRING
, { className: 'string' }),
142 // https://kotlinlang.org/docs/reference/whatsnew11.html#underscores-in-numeric-literals
143 // According to the doc above, the number mode of kotlin is the same as java 8,
144 // so the code below is copied from java.js
145 const KOTLIN_NUMBER_MODE
= NUMERIC
;
146 const KOTLIN_NESTED_COMMENT
= hljs
.COMMENT(
148 { contains: [ hljs
.C_BLOCK_COMMENT_MODE
] }
150 const KOTLIN_PAREN_TYPE
= { variants: [
153 begin: hljs
.UNDERSCORE_IDENT_RE
158 contains: [] // defined later
161 const KOTLIN_PAREN_TYPE2
= KOTLIN_PAREN_TYPE
;
162 KOTLIN_PAREN_TYPE2
.variants
[1].contains
= [ KOTLIN_PAREN_TYPE
];
163 KOTLIN_PAREN_TYPE
.variants
[1].contains
= [ KOTLIN_PAREN_TYPE2
];
186 hljs
.C_LINE_COMMENT_MODE
,
187 KOTLIN_NESTED_COMMENT
,
193 className: 'function',
194 beginKeywords: 'fun',
202 begin: hljs
.UNDERSCORE_IDENT_RE
+ '\\s*\\(',
205 contains: [ hljs
.UNDERSCORE_TITLE_MODE
]
225 endsWithParent: true,
228 hljs
.C_LINE_COMMENT_MODE
,
229 KOTLIN_NESTED_COMMENT
233 hljs
.C_LINE_COMMENT_MODE
,
234 KOTLIN_NESTED_COMMENT
,
241 KOTLIN_NESTED_COMMENT
246 /class|interface|trait/,
248 hljs
.UNDERSCORE_IDENT_RE
253 keywords: 'class interface trait',
256 illegal: 'extends implements',
258 { beginKeywords: 'public protected internal private constructor' },
259 hljs
.UNDERSCORE_TITLE_MODE
,
282 begin: "^#!/usr/bin/env",
295 hljs
.registerLanguage('kotlin', hljsGrammar
);