prismjs_components_prism-ruby.js 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. // node_modules/prismjs/components/prism-ruby.js
  2. (function(Prism2) {
  3. Prism2.languages.ruby = Prism2.languages.extend("clike", {
  4. "comment": {
  5. pattern: /#.*|^=begin\s[\s\S]*?^=end/m,
  6. greedy: true
  7. },
  8. "class-name": {
  9. pattern: /(\b(?:class|module)\s+|\bcatch\s+\()[\w.\\]+|\b[A-Z_]\w*(?=\s*\.\s*new\b)/,
  10. lookbehind: true,
  11. inside: {
  12. "punctuation": /[.\\]/
  13. }
  14. },
  15. "keyword": /\b(?:BEGIN|END|alias|and|begin|break|case|class|def|define_method|defined|do|each|else|elsif|end|ensure|extend|for|if|in|include|module|new|next|nil|not|or|prepend|private|protected|public|raise|redo|require|rescue|retry|return|self|super|then|throw|undef|unless|until|when|while|yield)\b/,
  16. "operator": /\.{2,3}|&\.|===|<?=>|[!=]?~|(?:&&|\|\||<<|>>|\*\*|[+\-*/%<>!^&|=])=?|[?:]/,
  17. "punctuation": /[(){}[\].,;]/
  18. });
  19. Prism2.languages.insertBefore("ruby", "operator", {
  20. "double-colon": {
  21. pattern: /::/,
  22. alias: "punctuation"
  23. }
  24. });
  25. var interpolation = {
  26. pattern: /((?:^|[^\\])(?:\\{2})*)#\{(?:[^{}]|\{[^{}]*\})*\}/,
  27. lookbehind: true,
  28. inside: {
  29. "content": {
  30. pattern: /^(#\{)[\s\S]+(?=\}$)/,
  31. lookbehind: true,
  32. inside: Prism2.languages.ruby
  33. },
  34. "delimiter": {
  35. pattern: /^#\{|\}$/,
  36. alias: "punctuation"
  37. }
  38. }
  39. };
  40. delete Prism2.languages.ruby.function;
  41. var percentExpression = "(?:" + [
  42. /([^a-zA-Z0-9\s{(\[<=])(?:(?!\1)[^\\]|\\[\s\S])*\1/.source,
  43. /\((?:[^()\\]|\\[\s\S]|\((?:[^()\\]|\\[\s\S])*\))*\)/.source,
  44. /\{(?:[^{}\\]|\\[\s\S]|\{(?:[^{}\\]|\\[\s\S])*\})*\}/.source,
  45. /\[(?:[^\[\]\\]|\\[\s\S]|\[(?:[^\[\]\\]|\\[\s\S])*\])*\]/.source,
  46. /<(?:[^<>\\]|\\[\s\S]|<(?:[^<>\\]|\\[\s\S])*>)*>/.source
  47. ].join("|") + ")";
  48. var symbolName = /(?:"(?:\\.|[^"\\\r\n])*"|(?:\b[a-zA-Z_]\w*|[^\s\0-\x7F]+)[?!]?|\$.)/.source;
  49. Prism2.languages.insertBefore("ruby", "keyword", {
  50. "regex-literal": [
  51. {
  52. pattern: RegExp(/%r/.source + percentExpression + /[egimnosux]{0,6}/.source),
  53. greedy: true,
  54. inside: {
  55. "interpolation": interpolation,
  56. "regex": /[\s\S]+/
  57. }
  58. },
  59. {
  60. pattern: /(^|[^/])\/(?!\/)(?:\[[^\r\n\]]+\]|\\.|[^[/\\\r\n])+\/[egimnosux]{0,6}(?=\s*(?:$|[\r\n,.;})#]))/,
  61. lookbehind: true,
  62. greedy: true,
  63. inside: {
  64. "interpolation": interpolation,
  65. "regex": /[\s\S]+/
  66. }
  67. }
  68. ],
  69. "variable": /[@$]+[a-zA-Z_]\w*(?:[?!]|\b)/,
  70. "symbol": [
  71. {
  72. pattern: RegExp(/(^|[^:]):/.source + symbolName),
  73. lookbehind: true,
  74. greedy: true
  75. },
  76. {
  77. pattern: RegExp(/([\r\n{(,][ \t]*)/.source + symbolName + /(?=:(?!:))/.source),
  78. lookbehind: true,
  79. greedy: true
  80. }
  81. ],
  82. "method-definition": {
  83. pattern: /(\bdef\s+)\w+(?:\s*\.\s*\w+)?/,
  84. lookbehind: true,
  85. inside: {
  86. "function": /\b\w+$/,
  87. "keyword": /^self\b/,
  88. "class-name": /^\w+/,
  89. "punctuation": /\./
  90. }
  91. }
  92. });
  93. Prism2.languages.insertBefore("ruby", "string", {
  94. "string-literal": [
  95. {
  96. pattern: RegExp(/%[qQiIwWs]?/.source + percentExpression),
  97. greedy: true,
  98. inside: {
  99. "interpolation": interpolation,
  100. "string": /[\s\S]+/
  101. }
  102. },
  103. {
  104. pattern: /("|')(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|(?!\1)[^\\#\r\n])*\1/,
  105. greedy: true,
  106. inside: {
  107. "interpolation": interpolation,
  108. "string": /[\s\S]+/
  109. }
  110. },
  111. {
  112. pattern: /<<[-~]?([a-z_]\w*)[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  113. alias: "heredoc-string",
  114. greedy: true,
  115. inside: {
  116. "delimiter": {
  117. pattern: /^<<[-~]?[a-z_]\w*|\b[a-z_]\w*$/i,
  118. inside: {
  119. "symbol": /\b\w+/,
  120. "punctuation": /^<<[-~]?/
  121. }
  122. },
  123. "interpolation": interpolation,
  124. "string": /[\s\S]+/
  125. }
  126. },
  127. {
  128. pattern: /<<[-~]?'([a-z_]\w*)'[\r\n](?:.*[\r\n])*?[\t ]*\1/i,
  129. alias: "heredoc-string",
  130. greedy: true,
  131. inside: {
  132. "delimiter": {
  133. pattern: /^<<[-~]?'[a-z_]\w*'|\b[a-z_]\w*$/i,
  134. inside: {
  135. "symbol": /\b\w+/,
  136. "punctuation": /^<<[-~]?'|'$/
  137. }
  138. },
  139. "string": /[\s\S]+/
  140. }
  141. }
  142. ],
  143. "command-literal": [
  144. {
  145. pattern: RegExp(/%x/.source + percentExpression),
  146. greedy: true,
  147. inside: {
  148. "interpolation": interpolation,
  149. "command": {
  150. pattern: /[\s\S]+/,
  151. alias: "string"
  152. }
  153. }
  154. },
  155. {
  156. pattern: /`(?:#\{[^}]+\}|#(?!\{)|\\(?:\r\n|[\s\S])|[^\\`#\r\n])*`/,
  157. greedy: true,
  158. inside: {
  159. "interpolation": interpolation,
  160. "command": {
  161. pattern: /[\s\S]+/,
  162. alias: "string"
  163. }
  164. }
  165. }
  166. ]
  167. });
  168. delete Prism2.languages.ruby.string;
  169. Prism2.languages.insertBefore("ruby", "number", {
  170. "builtin": /\b(?:Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Fixnum|Float|Hash|IO|Integer|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|Stat|String|Struct|Symbol|TMS|Thread|ThreadGroup|Time|TrueClass)\b/,
  171. "constant": /\b[A-Z][A-Z0-9_]*(?:[?!]|\b)/
  172. });
  173. Prism2.languages.rb = Prism2.languages.ruby;
  174. })(Prism);
  175. //# sourceMappingURL=prismjs_components_prism-ruby.js.map