prism-ruby.js 1.0 KB

123456789101112131415161718192021
  1. /**
  2. * Original by Samuel Flores
  3. *
  4. * Adds the following new token classes:
  5. * constant, builtin, variable, symbol, regex
  6. */
  7. Prism.languages.ruby = Prism.languages.extend('clike', {
  8. 'comment': /#[^\r\n]*(\r?\n|$)/,
  9. 'keyword': /\b(alias|and|BEGIN|begin|break|case|class|def|define_method|defined|do|each|else|elsif|END|end|ensure|false|for|if|in|module|new|next|nil|not|or|raise|redo|require|rescue|retry|return|self|super|then|throw|true|undef|unless|until|when|while|yield)\b/,
  10. 'builtin': /\b(Array|Bignum|Binding|Class|Continuation|Dir|Exception|FalseClass|File|Stat|File|Fixnum|Fload|Hash|Integer|IO|MatchData|Method|Module|NilClass|Numeric|Object|Proc|Range|Regexp|String|Struct|TMS|Symbol|ThreadGroup|Thread|Time|TrueClass)\b/,
  11. 'constant': /\b[A-Z][a-zA-Z_0-9]*[?!]?\b/
  12. });
  13. Prism.languages.insertBefore('ruby', 'keyword', {
  14. 'regex': {
  15. pattern: /(^|[^/])\/(?!\/)(\[.+?]|\\.|[^/\r\n])+\/[gim]{0,3}(?=\s*($|[\r\n,.;})]))/,
  16. lookbehind: true
  17. },
  18. 'variable': /[@$]+\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/,
  19. 'symbol': /:\b[a-zA-Z_][a-zA-Z_0-9]*[?!]?\b/
  20. });