UNPKG

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