]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/kotlin.js
1 /*! `kotlin` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
5 // https://docs.oracle.com/javase/specs/jls/se15/html/jls-3.html#jls-3.10
6 var decimalDigits
= '[0-9](_*[0-9])*';
7 var frac
= `\\.(${decimalDigits})`;
8 var hexDigits
= '[0-9a-fA-F](_*[0-9a-fA-F])*';
12 // DecimalFloatingPointLiteral
13 // including ExponentPart
14 { begin: `(\\b(${decimalDigits})((${frac})|\\.)?|(${frac}))` +
15 `[eE][+-]?(${decimalDigits})[fFdD]?\\b` },
16 // excluding ExponentPart
17 { begin: `\\b(${decimalDigits})((${frac})[fFdD]?\\b|\\.([fFdD]\\b)?)` },
18 { begin: `(${frac})[fFdD]?\\b` },
19 { begin: `\\b(${decimalDigits})[fFdD]\\b` },
21 // HexadecimalFloatingPointLiteral
22 { begin: `\\b0[xX]((${hexDigits})\\.?|(${hexDigits})?\\.(${hexDigits}))` +
23 `[pP][+-]?(${decimalDigits})[fFdD]?\\b` },
25 // DecimalIntegerLiteral
26 { begin: '\\b(0|[1-9](_*[0-9])*)[lL]?\\b' },
29 { begin: `\\b0[xX](${hexDigits})[lL]?\\b` },
31 // OctalIntegerLiteral
32 { begin: '\\b0(_*[0-7])*[lL]?\\b' },
34 // BinaryIntegerLiteral
35 { begin: '\\b0[bB][01](_*[01])*[lL]?\\b' },
42 Description: Kotlin is an OSS statically typed programming language that targets the JVM, Android, JavaScript and Native.
43 Author: Sergey Mashkov <cy6erGn0m@gmail.com>
44 Website: https://kotlinlang.org
49 function kotlin(hljs
) {
52 'abstract as val var vararg get set class object open private protected public noinline '
53 + 'crossinline dynamic final enum if else do while for when throw try catch finally '
54 + 'import package is in fun override companion reified inline lateinit init '
55 + 'interface annotation data sealed internal infix operator out by constructor super '
56 + 'tailrec where const inner suspend typealias external expect actual',
58 'Byte Short Char Int Long Boolean Float Double Void Unit Nothing',
62 const KEYWORDS_WITH_LABEL
= {
64 begin: /\b(break|continue|return|this)\b/,
74 begin: hljs
.UNDERSCORE_IDENT_RE
+ '@'
77 // for string templates
82 contains: [ hljs
.C_NUMBER_MODE
]
85 className: 'variable',
86 begin: '\\$' + hljs
.UNDERSCORE_IDENT_RE
99 // Can't use built-in modes easily, as we want to use STRING in the meta
100 // context as 'meta-string' and there's no syntax to remove explicitly set
101 // classNames in built-in modes.
106 contains: [ hljs
.BACKSLASH_ESCAPE
]
113 hljs
.BACKSLASH_ESCAPE
,
120 SUBST
.contains
.push(STRING
);
122 const ANNOTATION_USE_SITE
= {
124 begin: '@(?:file|property|field|get|set|receiver|param|setparam|delegate)\\s*:(?:\\s*' + hljs
.UNDERSCORE_IDENT_RE
+ ')?'
128 begin: '@' + hljs
.UNDERSCORE_IDENT_RE
,
134 hljs
.inherit(STRING
, { className: 'string' }),
141 // https://kotlinlang.org/docs/reference/whatsnew11.html#underscores-in-numeric-literals
142 // According to the doc above, the number mode of kotlin is the same as java 8,
143 // so the code below is copied from java.js
144 const KOTLIN_NUMBER_MODE
= NUMERIC
;
145 const KOTLIN_NESTED_COMMENT
= hljs
.COMMENT(
147 { contains: [ hljs
.C_BLOCK_COMMENT_MODE
] }
149 const KOTLIN_PAREN_TYPE
= { variants: [
152 begin: hljs
.UNDERSCORE_IDENT_RE
157 contains: [] // defined later
160 const KOTLIN_PAREN_TYPE2
= KOTLIN_PAREN_TYPE
;
161 KOTLIN_PAREN_TYPE2
.variants
[1].contains
= [ KOTLIN_PAREN_TYPE
];
162 KOTLIN_PAREN_TYPE
.variants
[1].contains
= [ KOTLIN_PAREN_TYPE2
];
185 hljs
.C_LINE_COMMENT_MODE
,
186 KOTLIN_NESTED_COMMENT
,
192 className: 'function',
193 beginKeywords: 'fun',
201 begin: hljs
.UNDERSCORE_IDENT_RE
+ '\\s*\\(',
204 contains: [ hljs
.UNDERSCORE_TITLE_MODE
]
224 endsWithParent: true,
227 hljs
.C_LINE_COMMENT_MODE
,
228 KOTLIN_NESTED_COMMENT
232 hljs
.C_LINE_COMMENT_MODE
,
233 KOTLIN_NESTED_COMMENT
,
240 KOTLIN_NESTED_COMMENT
245 /class|interface|trait/,
247 hljs
.UNDERSCORE_IDENT_RE
252 keywords: 'class interface trait',
255 illegal: 'extends implements',
257 { beginKeywords: 'public protected internal private constructor' },
258 hljs
.UNDERSCORE_TITLE_MODE
,
281 begin: "^#!/usr/bin/env",
294 export default hljsGrammar
;