UNPKG

2.65 kBJavaScriptView Raw
1Prism.languages.elixir = {
2 'comment': /#.*/m,
3 // ~r"""foo""" (multi-line), ~r'''foo''' (multi-line), ~r/foo/, ~r|foo|, ~r"foo", ~r'foo', ~r(foo), ~r[foo], ~r{foo}, ~r<foo>
4 'regex': {
5 pattern: /~[rR](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[uismxfr]*/,
6 greedy: true
7 },
8 'string': [
9 {
10 // ~s"""foo""" (multi-line), ~s'''foo''' (multi-line), ~s/foo/, ~s|foo|, ~s"foo", ~s'foo', ~s(foo), ~s[foo], ~s{foo} (with interpolation care), ~s<foo>
11 pattern: /~[cCsSwW](?:("""|''')(?:\\[\s\S]|(?!\1)[^\\])+\1|([\/|"'])(?:\\.|(?!\2)[^\\\r\n])+\2|\((?:\\.|[^\\)\r\n])+\)|\[(?:\\.|[^\\\]\r\n])+\]|\{(?:\\.|#\{[^}]+\}|[^\\}\r\n])+\}|<(?:\\.|[^\\>\r\n])+>)[csa]?/,
12 greedy: true,
13 inside: {
14 // See interpolation below
15 }
16 },
17 {
18 pattern: /("""|''')[\s\S]*?\1/,
19 greedy: true,
20 inside: {
21 // See interpolation below
22 }
23 },
24 {
25 // Multi-line strings are allowed
26 pattern: /("|')(?:\\(?:\r\n|[\s\S])|(?!\1)[^\\\r\n])*\1/,
27 greedy: true,
28 inside: {
29 // See interpolation below
30 }
31 }
32 ],
33 'atom': {
34 // Look-behind prevents bad highlighting of the :: operator
35 pattern: /(^|[^:]):\w+/,
36 lookbehind: true,
37 alias: 'symbol'
38 },
39 // Look-ahead prevents bad highlighting of the :: operator
40 'attr-name': /\w+\??:(?!:)/,
41 'capture': {
42 // Look-behind prevents bad highlighting of the && operator
43 pattern: /(^|[^&])&(?:[^&\s\d()][^\s()]*|(?=\())/,
44 lookbehind: true,
45 alias: 'function'
46 },
47 'argument': {
48 // Look-behind prevents bad highlighting of the && operator
49 pattern: /(^|[^&])&\d+/,
50 lookbehind: true,
51 alias: 'variable'
52 },
53 'attribute': {
54 pattern: /@\w+/,
55 alias: 'variable'
56 },
57 'number': /\b(?:0[box][a-f\d_]+|\d[\d_]*)(?:\.[\d_]+)?(?:e[+-]?[\d_]+)?\b/i,
58 'keyword': /\b(?:after|alias|and|case|catch|cond|def(?:callback|exception|impl|module|p|protocol|struct)?|do|else|end|fn|for|if|import|not|or|require|rescue|try|unless|use|when)\b/,
59 'boolean': /\b(?:true|false|nil)\b/,
60 'operator': [
61 /\bin\b|&&?|\|[|>]?|\\\\|::|\.\.\.?|\+\+?|-[->]?|<[-=>]|>=|!==?|\B!|=(?:==?|[>~])?|[*\/^]/,
62 {
63 // We don't want to match <<
64 pattern: /([^<])<(?!<)/,
65 lookbehind: true
66 },
67 {
68 // We don't want to match >>
69 pattern: /([^>])>(?!>)/,
70 lookbehind: true
71 }
72 ],
73 'punctuation': /<<|>>|[.,%\[\]{}()]/
74};
75
76Prism.languages.elixir.string.forEach(function(o) {
77 o.inside = {
78 'interpolation': {
79 pattern: /#\{[^}]+\}/,
80 inside: {
81 'delimiter': {
82 pattern: /^#\{|\}$/,
83 alias: 'punctuation'
84 },
85 rest: Prism.languages.elixir
86 }
87 }
88 };
89});
90
\No newline at end of file