prism-elixir.js 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. Prism.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. Prism.languages.elixir.string.forEach(function(o) {
  76. o.inside = {
  77. 'interpolation': {
  78. pattern: /#\{[^}]+\}/,
  79. inside: {
  80. 'delimiter': {
  81. pattern: /^#\{|\}$/,
  82. alias: 'punctuation'
  83. },
  84. rest: Prism.languages.elixir
  85. }
  86. }
  87. };
  88. });