]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/es/languages/crystal.js
1 /*! `crystal` grammar compiled for Highlight.js 11.11.1 */
2 var hljsGrammar
= (function () {
7 Author: TSUYUSATO Kitsune <make.just.on@gmail.com>
8 Website: https://crystal-lang.org
12 /** @type LanguageFn */
13 function crystal(hljs
) {
14 const INT_SUFFIX
= '(_?[ui](8|16|32|64|128))?';
15 const FLOAT_SUFFIX
= '(_?f(32|64))?';
16 const CRYSTAL_IDENT_RE
= '[a-zA-Z_]\\w*[!?=]?';
17 const CRYSTAL_METHOD_RE
= '[a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|[=!]~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~|]|//|//=|&[-+*]=?|&\\*\\*|\\[\\][=?]?';
18 const CRYSTAL_PATH_RE
= '[A-Za-z_]\\w*(::\\w+)*(\\?|!)?';
19 const CRYSTAL_KEYWORDS
= {
20 $pattern: CRYSTAL_IDENT_RE
,
22 'abstract alias annotation as as? asm begin break case class def do else elsif end ensure enum extend for fun if '
23 + 'include instance_sizeof is_a? lib macro module next nil? of out pointerof private protected rescue responds_to? '
24 + 'return require select self sizeof struct super then type typeof union uninitialized unless until verbatim when while with yield '
25 + '__DIR__ __END_LINE__ __FILE__ __LINE__',
26 literal: 'false nil true'
32 keywords: CRYSTAL_KEYWORDS
36 // negative-look forward attemps to prevent false matches like:
37 // @ident@ or $ident$ that might indicate this is not ruby at all
38 className: "variable",
39 begin: '(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])' + `(?![A-Za-z])(?![@$?'])`
42 className: 'template-variable',
53 keywords: CRYSTAL_KEYWORDS
56 function recursiveParen(begin
, end
) {
64 contains
[0].contains
= contains
;
70 hljs
.BACKSLASH_ESCAPE
,
89 contains: recursiveParen('\\(', '\\)')
94 contains: recursiveParen('\\[', '\\]')
99 contains: recursiveParen(/\{/, /\}/)
104 contains: recursiveParen('<', '>')
123 contains: recursiveParen('\\(', '\\)')
128 contains: recursiveParen('\\[', '\\]')
133 contains: recursiveParen(/\{/, /\}/)
138 contains: recursiveParen('<', '>')
152 begin: '(?!%\\})(' + hljs
.RE_STARTERS_RE
+ '|\\n|\\b(case|if|select|unless|until|when|while)\\b)\\s*',
153 keywords: 'case if select unless until when while',
158 hljs
.BACKSLASH_ESCAPE
,
178 hljs
.BACKSLASH_ESCAPE
,
185 contains: recursiveParen('\\(', '\\)')
190 contains: recursiveParen('\\[', '\\]')
195 contains: recursiveParen(/\{/, /\}/)
200 contains: recursiveParen('<', '>')
213 contains: [ hljs
.inherit(hljs
.QUOTE_STRING_MODE
, { className: 'string' }) ]
215 const CRYSTAL_DEFAULT_CONTAINS
= [
223 hljs
.HASH_COMMENT_MODE
,
226 beginKeywords: 'class module struct',
230 hljs
.HASH_COMMENT_MODE
,
231 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
}),
232 { // relevance booster for inheritance
238 beginKeywords: 'lib enum union',
242 hljs
.HASH_COMMENT_MODE
,
243 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
})
247 beginKeywords: 'annotation',
251 hljs
.HASH_COMMENT_MODE
,
252 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
})
257 className: 'function',
258 beginKeywords: 'def',
261 hljs
.inherit(hljs
.TITLE_MODE
, {
262 begin: CRYSTAL_METHOD_RE
,
268 className: 'function',
269 beginKeywords: 'fun macro',
272 hljs
.inherit(hljs
.TITLE_MODE
, {
273 begin: CRYSTAL_METHOD_RE
,
281 begin: hljs
.UNDERSCORE_IDENT_RE
+ '(!|\\?)?:',
289 { begin: CRYSTAL_METHOD_RE
}
296 { begin: '\\b0b([01_]+)' + INT_SUFFIX
},
297 { begin: '\\b0o([0-7_]+)' + INT_SUFFIX
},
298 { begin: '\\b0x([A-Fa-f0-9_]+)' + INT_SUFFIX
},
299 { begin: '\\b([1-9][0-9_]*[0-9]|[0-9])(\\.[0-9][0-9_]*)?([eE]_?[-+]?[0-9_]*)?' + FLOAT_SUFFIX
+ '(?!_)' },
300 { begin: '\\b([1-9][0-9_]*|0)' + INT_SUFFIX
}
305 SUBST
.contains
= CRYSTAL_DEFAULT_CONTAINS
;
306 EXPANSION
.contains
= CRYSTAL_DEFAULT_CONTAINS
.slice(1); // without EXPANSION
311 keywords: CRYSTAL_KEYWORDS
,
312 contains: CRYSTAL_DEFAULT_CONTAINS
320 export default hljsGrammar
;