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