]>
luflow.net public git repositories - flow-web.git/blob - static/highlight/languages/crystal.js
1 /*! `crystal` grammar compiled for Highlight.js 11.11.1 */
3 var hljsGrammar
= (function () {
8 Author: TSUYUSATO Kitsune <make.just.on@gmail.com>
9 Website: https://crystal-lang.org
13 /** @type LanguageFn */
14 function crystal(hljs
) {
15 const INT_SUFFIX
= '(_?[ui](8|16|32|64|128))?';
16 const FLOAT_SUFFIX
= '(_?f(32|64))?';
17 const CRYSTAL_IDENT_RE
= '[a-zA-Z_]\\w*[!?=]?';
18 const CRYSTAL_METHOD_RE
= '[a-zA-Z_]\\w*[!?=]?|[-+~]@|<<|>>|[=!]~|===?|<=>|[<>]=?|\\*\\*|[-/+%^&*~|]|//|//=|&[-+*]=?|&\\*\\*|\\[\\][=?]?';
19 const CRYSTAL_PATH_RE
= '[A-Za-z_]\\w*(::\\w+)*(\\?|!)?';
20 const CRYSTAL_KEYWORDS
= {
21 $pattern: CRYSTAL_IDENT_RE
,
23 'abstract alias annotation as as? asm begin break case class def do else elsif end ensure enum extend for fun if '
24 + 'include instance_sizeof is_a? lib macro module next nil? of out pointerof private protected rescue responds_to? '
25 + 'return require select self sizeof struct super then type typeof union uninitialized unless until verbatim when while with yield '
26 + '__DIR__ __END_LINE__ __FILE__ __LINE__',
27 literal: 'false nil true'
33 keywords: CRYSTAL_KEYWORDS
37 // negative-look forward attemps to prevent false matches like:
38 // @ident@ or $ident$ that might indicate this is not ruby at all
39 className: "variable",
40 begin: '(\\$\\W)|((\\$|@@?)(\\w+))(?=[^@$?])' + `(?![A-Za-z])(?![@$?'])`
43 className: 'template-variable',
54 keywords: CRYSTAL_KEYWORDS
57 function recursiveParen(begin
, end
) {
65 contains
[0].contains
= contains
;
71 hljs
.BACKSLASH_ESCAPE
,
90 contains: recursiveParen('\\(', '\\)')
95 contains: recursiveParen('\\[', '\\]')
100 contains: recursiveParen(/\{/, /\}/)
105 contains: recursiveParen('<', '>')
124 contains: recursiveParen('\\(', '\\)')
129 contains: recursiveParen('\\[', '\\]')
134 contains: recursiveParen(/\{/, /\}/)
139 contains: recursiveParen('<', '>')
153 begin: '(?!%\\})(' + hljs
.RE_STARTERS_RE
+ '|\\n|\\b(case|if|select|unless|until|when|while)\\b)\\s*',
154 keywords: 'case if select unless until when while',
159 hljs
.BACKSLASH_ESCAPE
,
179 hljs
.BACKSLASH_ESCAPE
,
186 contains: recursiveParen('\\(', '\\)')
191 contains: recursiveParen('\\[', '\\]')
196 contains: recursiveParen(/\{/, /\}/)
201 contains: recursiveParen('<', '>')
214 contains: [ hljs
.inherit(hljs
.QUOTE_STRING_MODE
, { className: 'string' }) ]
216 const CRYSTAL_DEFAULT_CONTAINS
= [
224 hljs
.HASH_COMMENT_MODE
,
227 beginKeywords: 'class module struct',
231 hljs
.HASH_COMMENT_MODE
,
232 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
}),
233 { // relevance booster for inheritance
239 beginKeywords: 'lib enum union',
243 hljs
.HASH_COMMENT_MODE
,
244 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
})
248 beginKeywords: 'annotation',
252 hljs
.HASH_COMMENT_MODE
,
253 hljs
.inherit(hljs
.TITLE_MODE
, { begin: CRYSTAL_PATH_RE
})
258 className: 'function',
259 beginKeywords: 'def',
262 hljs
.inherit(hljs
.TITLE_MODE
, {
263 begin: CRYSTAL_METHOD_RE
,
269 className: 'function',
270 beginKeywords: 'fun macro',
273 hljs
.inherit(hljs
.TITLE_MODE
, {
274 begin: CRYSTAL_METHOD_RE
,
282 begin: hljs
.UNDERSCORE_IDENT_RE
+ '(!|\\?)?:',
290 { begin: CRYSTAL_METHOD_RE
}
297 { begin: '\\b0b([01_]+)' + INT_SUFFIX
},
298 { begin: '\\b0o([0-7_]+)' + INT_SUFFIX
},
299 { begin: '\\b0x([A-Fa-f0-9_]+)' + INT_SUFFIX
},
300 { begin: '\\b([1-9][0-9_]*[0-9]|[0-9])(\\.[0-9][0-9_]*)?([eE]_?[-+]?[0-9_]*)?' + FLOAT_SUFFIX
+ '(?!_)' },
301 { begin: '\\b([1-9][0-9_]*|0)' + INT_SUFFIX
}
306 SUBST
.contains
= CRYSTAL_DEFAULT_CONTAINS
;
307 EXPANSION
.contains
= CRYSTAL_DEFAULT_CONTAINS
.slice(1); // without EXPANSION
312 keywords: CRYSTAL_KEYWORDS
,
313 contains: CRYSTAL_DEFAULT_CONTAINS
321 hljs
.registerLanguage('crystal', hljsGrammar
);