coffeescript.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  1. /**
  2. * Coffeescript patterns
  3. *
  4. * @author Craig Campbell
  5. */
  6. Rainbow.extend('coffeescript', [
  7. {
  8. name: 'comment.block',
  9. pattern: /(\#{3})[\s\S]*\1/gm
  10. },
  11. {
  12. name: 'string.block',
  13. pattern: /('{3}|"{3})[\s\S]*\1/gm
  14. },
  15. /**
  16. * multiline regex with comments
  17. */
  18. {
  19. name: 'string.regex',
  20. matches: {
  21. 2: {
  22. name: 'comment',
  23. pattern: /\#(.*?)(?=\n)/g
  24. }
  25. },
  26. pattern: /(\/{3})([\s\S]*)\1/gm
  27. },
  28. {
  29. matches: {
  30. 1: 'keyword'
  31. },
  32. pattern: /\b(in|when|is|isnt|of|not|unless|until|super)(?=\b)/gi
  33. },
  34. {
  35. name: 'keyword.operator',
  36. pattern: /\?/g
  37. },
  38. {
  39. name: 'constant.language',
  40. pattern: /\b(undefined|yes|on|no|off)\b/g
  41. },
  42. {
  43. name: 'keyword.variable.coffee',
  44. pattern: /@(\w+)/gi
  45. },
  46. /**
  47. * reset global keywards from generic
  48. */
  49. {
  50. name: 'reset',
  51. pattern: /object|class|print/gi
  52. },
  53. /**
  54. * named function
  55. */
  56. {
  57. 'matches' : {
  58. 1: 'entity.name.function',
  59. 2: 'keyword.operator',
  60. 3: {
  61. name: 'function.argument.coffee',
  62. pattern: /([\@\w]+)/g
  63. },
  64. 4: 'keyword.function'
  65. },
  66. pattern: /(\w+)\s{0,}(=|:)\s{0,}\((.*?)((-|=)>)/gi
  67. },
  68. /**
  69. * anonymous function
  70. */
  71. {
  72. matches: {
  73. 1: {
  74. name: 'function.argument.coffee',
  75. pattern: /([\@\w]+)/g
  76. },
  77. 2: 'keyword.function'
  78. },
  79. pattern: /\s\((.*?)\)\s{0,}((-|=)>)/gi
  80. },
  81. /**
  82. * direct function no arguments
  83. */
  84. {
  85. 'matches' : {
  86. 1: 'entity.name.function',
  87. 2: 'keyword.operator',
  88. 3: 'keyword.function'
  89. },
  90. pattern: /(\w+)\s{0,}(=|:)\s{0,}((-|=)>)/gi
  91. },
  92. /**
  93. * class definitions
  94. */
  95. {
  96. matches: {
  97. 1: 'storage.class',
  98. 2: 'entity.name.class',
  99. 3: 'storage.modifier.extends',
  100. 4: 'entity.other.inherited-class'
  101. },
  102. pattern: /\b(class)\s(\w+)(\sextends\s)?([\w\\]*)?\b/g
  103. },
  104. /**
  105. * object instantiation
  106. */
  107. {
  108. matches: {
  109. 1: 'keyword.new',
  110. 2: {
  111. name: 'support.class',
  112. pattern: /\w+/g
  113. }
  114. },
  115. pattern: /\b(new)\s(.*?)(?=\s)/g
  116. }
  117. ], 'generic');
  118. Rainbow.addAlias('coffee', 'coffeescript');