UNPKG

4.37 kBJavaScriptView Raw
1(function (Prism) {
2 // https://agraef.github.io/pure-docs/pure.html#lexical-matters
3
4 Prism.languages.pure = {
5 'comment': [
6 {
7 pattern: /(^|[^\\])\/\*[\s\S]*?\*\//,
8 lookbehind: true
9 },
10 {
11 pattern: /(^|[^\\:])\/\/.*/,
12 lookbehind: true
13 },
14 /#!.+/
15 ],
16 'inline-lang': {
17 pattern: /%<[\s\S]+?%>/,
18 greedy: true,
19 inside: {
20 'lang': {
21 pattern: /(^%< *)-\*-.+?-\*-/,
22 lookbehind: true,
23 alias: 'comment'
24 },
25 'delimiter': {
26 pattern: /^%<.*|%>$/,
27 alias: 'punctuation'
28 }
29 }
30 },
31 'string': {
32 pattern: /"(?:\\.|[^"\\\r\n])*"/,
33 greedy: true
34 },
35 'number': {
36 // The look-behind prevents wrong highlighting of the .. operator
37 pattern: /((?:\.\.)?)(?:\b(?:inf|nan)\b|\b0x[\da-f]+|(?:\b(?:0b)?\d+(?:\.\d+)?|\B\.\d+)(?:e[+-]?\d+)?L?)/i,
38 lookbehind: true
39 },
40 'keyword': /\b(?:NULL|ans|break|bt|case|catch|cd|clear|const|def|del|dump|else|end|exit|extern|false|force|help|if|infix[lr]?|interface|let|ls|mem|namespace|nonfix|of|otherwise|outfix|override|postfix|prefix|private|public|pwd|quit|run|save|show|stats|then|throw|trace|true|type|underride|using|when|with)\b/,
41 'function': /\b(?:abs|add_(?:addr|constdef|(?:fundef|interface|macdef|typedef)(?:_at)?|vardef)|all|any|applp?|arity|bigintp?|blob(?:_crc|_size|p)?|boolp?|byte_c?string(?:_pointer)?|byte_(?:matrix|pointer)|calloc|cat|catmap|ceil|char[ps]?|check_ptrtag|chr|clear_sentry|clearsym|closurep?|cmatrixp?|cols?|colcat(?:map)?|colmap|colrev|colvector(?:p|seq)?|complex(?:_float_(?:matrix|pointer)|_matrix(?:_view)?|_pointer|p)?|conj|cookedp?|cst|cstring(?:_(?:dup|list|vector))?|curry3?|cyclen?|del_(?:constdef|fundef|interface|macdef|typedef|vardef)|delete|diag(?:mat)?|dim|dmatrixp?|do|double(?:_matrix(?:_view)?|_pointer|p)?|dowith3?|drop|dropwhile|eval(?:cmd)?|exactp|filter|fix|fixity|flip|float(?:_matrix|_pointer)|floor|fold[lr]1?|frac|free|funp?|functionp?|gcd|get(?:_(?:byte|constdef|double|float|fundef|int(?:64)?|interface(?:_typedef)?|long|macdef|pointer|ptrtag|sentry|short|string|typedef|vardef))?|globsym|hash|head|id|im|imatrixp?|index|inexactp|infp|init|insert|int(?:_matrix(?:_view)?|_pointer|p)?|int64_(?:matrix|pointer)|integerp?|iteraten?|iterwhile|join|keys?|lambdap?|last(?:err(?:pos)?)?|lcd|list[2p]?|listmap|make_ptrtag|malloc|map|matcat|matrixp?|max|member|min|nanp|nargs|nmatrixp?|null|numberp?|ord|pack(?:ed)?|pointer(?:_cast|_tag|_type|p)?|pow|pred|ptrtag|put(?:_(?:byte|double|float|int(?:64)?|long|pointer|short|string))?|rationalp?|re|realp?|realloc|recordp?|redim|reduce(?:_with)?|refp?|repeatn?|reverse|rlistp?|round|rows?|rowcat(?:map)?|rowmap|rowrev|rowvector(?:p|seq)?|same|scan[lr]1?|sentry|sgn|short_(?:matrix|pointer)|slice|smatrixp?|sort|split|str|strcat|stream|stride|string(?:_(?:dup|list|vector)|p)?|subdiag(?:mat)?|submat|subseq2?|substr|succ|supdiag(?:mat)?|symbolp?|tail|take|takewhile|thunkp?|transpose|trunc|tuplep?|typep|ubyte|uint(?:64)?|ulong|uncurry3?|unref|unzip3?|update|ushort|vals?|varp?|vector(?:p|seq)?|void|zip3?|zipwith3?)\b/,
42 'special': {
43 pattern: /\b__[a-z]+__\b/i,
44 alias: 'builtin'
45 },
46 // Any combination of operator chars can be an operator
47 // eslint-disable-next-line no-misleading-character-class
48 'operator': /(?:[!"#$%&'*+,\-.\/:<=>?@\\^`|~\u00a1-\u00bf\u00d7-\u00f7\u20d0-\u2bff]|\b_+\b)+|\b(?:and|div|mod|not|or)\b/,
49 // FIXME: How can we prevent | and , to be highlighted as operator when they are used alone?
50 'punctuation': /[(){}\[\];,|]/
51 };
52
53 var inlineLanguages = [
54 'c',
55 { lang: 'c++', alias: 'cpp' },
56 'fortran'
57 ];
58 var inlineLanguageRe = /%< *-\*- *<lang>\d* *-\*-[\s\S]+?%>/.source;
59
60 inlineLanguages.forEach(function (lang) {
61 var alias = lang;
62 if (typeof lang !== 'string') {
63 alias = lang.alias;
64 lang = lang.lang;
65 }
66 if (Prism.languages[alias]) {
67 var o = {};
68 o['inline-lang-' + alias] = {
69 pattern: RegExp(inlineLanguageRe.replace('<lang>', lang.replace(/([.+*?\/\\(){}\[\]])/g, '\\$1')), 'i'),
70 inside: Prism.util.clone(Prism.languages.pure['inline-lang'].inside)
71 };
72 o['inline-lang-' + alias].inside.rest = Prism.util.clone(Prism.languages[alias]);
73 Prism.languages.insertBefore('pure', 'inline-lang', o);
74 }
75 });
76
77 // C is the default inline language
78 if (Prism.languages.c) {
79 Prism.languages.pure['inline-lang'].inside.rest = Prism.util.clone(Prism.languages.c);
80 }
81
82}(Prism));