prism-crystal.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. (function (Prism) {
  2. Prism.languages.crystal = Prism.languages.extend('ruby', {
  3. 'keyword': [
  4. /\b(?:__DIR__|__END_LINE__|__FILE__|__LINE__|abstract|alias|annotation|as|asm|begin|break|case|class|def|do|else|elsif|end|ensure|enum|extend|for|fun|if|ifdef|include|instance_sizeof|lib|macro|module|next|of|out|pointerof|private|protected|ptr|require|rescue|return|select|self|sizeof|struct|super|then|type|typeof|undef|uninitialized|union|unless|until|when|while|with|yield)\b/,
  5. {
  6. pattern: /(\.\s*)(?:is_a|responds_to)\?/,
  7. lookbehind: true
  8. }
  9. ],
  10. 'number': /\b(?:0b[01_]*[01]|0o[0-7_]*[0-7]|0x[\da-fA-F_]*[\da-fA-F]|(?:\d(?:[\d_]*\d)?)(?:\.[\d_]*\d)?(?:[eE][+-]?[\d_]*\d)?)(?:_(?:[uif](?:8|16|32|64))?)?\b/,
  11. 'operator': [
  12. /->/,
  13. Prism.languages.ruby.operator,
  14. ],
  15. 'punctuation': /[(){}[\].,;\\]/,
  16. });
  17. Prism.languages.insertBefore('crystal', 'string-literal', {
  18. 'attribute': {
  19. pattern: /@\[.*?\]/,
  20. inside: {
  21. 'delimiter': {
  22. pattern: /^@\[|\]$/,
  23. alias: 'punctuation'
  24. },
  25. 'attribute': {
  26. pattern: /^(\s*)\w+/,
  27. lookbehind: true,
  28. alias: 'class-name'
  29. },
  30. 'args': {
  31. pattern: /\S(?:[\s\S]*\S)?/,
  32. inside: Prism.languages.crystal
  33. },
  34. }
  35. },
  36. 'expansion': {
  37. pattern: /\{(?:\{.*?\}|%.*?%)\}/,
  38. inside: {
  39. 'content': {
  40. pattern: /^(\{.)[\s\S]+(?=.\}$)/,
  41. lookbehind: true,
  42. inside: Prism.languages.crystal
  43. },
  44. 'delimiter': {
  45. pattern: /^\{[\{%]|[\}%]\}$/,
  46. alias: 'operator'
  47. }
  48. }
  49. },
  50. 'char': {
  51. pattern: /'(?:[^\\\r\n]{1,2}|\\(?:.|u(?:[A-Fa-f0-9]{1,4}|\{[A-Fa-f0-9]{1,6}\})))'/,
  52. greedy: true
  53. }
  54. });
  55. }(Prism));