rainbow-javascript.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /**
  2. * Javascript patterns
  3. *
  4. * @author Craig Campbell
  5. * @version 1.0.7
  6. */
  7. Rainbow.extend('javascript', [
  8. /**
  9. * matches $. or $(
  10. */
  11. {
  12. 'name': 'selector',
  13. 'pattern': /(\s|^)\$(?=\.|\()/g
  14. },
  15. {
  16. 'name': 'support',
  17. 'pattern': /\b(window|document)\b/g
  18. },
  19. {
  20. 'matches': {
  21. 1: 'support.property'
  22. },
  23. 'pattern': /\.(length|node(Name|Value))\b/g
  24. },
  25. {
  26. 'matches': {
  27. 1: 'support.function'
  28. },
  29. 'pattern': /(setTimeout|setInterval)(?=\()/g
  30. },
  31. {
  32. 'matches': {
  33. 1: 'support.method'
  34. },
  35. 'pattern': /\.(getAttribute|push|getElementById|getElementsByClassName|log|setTimeout|setInterval)(?=\()/g
  36. },
  37. {
  38. 'matches': {
  39. 1: 'support.tag.script',
  40. 2: [
  41. {
  42. 'name': 'string',
  43. 'pattern': /('|")(.*?)(\1)/g
  44. },
  45. {
  46. 'name': 'entity.tag.script',
  47. 'pattern': /(\w+)/g
  48. }
  49. ],
  50. 3: 'support.tag.script'
  51. },
  52. 'pattern': /(<\/?)(script.*?)(>)/g
  53. },
  54. /**
  55. * matches any escaped characters inside of a js regex pattern
  56. *
  57. * @see https://github.com/ccampbell/rainbow/issues/22
  58. *
  59. * this was causing single line comments to fail so it now makes sure
  60. * the opening / is not directly followed by a *
  61. *
  62. * @todo check that there is valid regex in match group 1
  63. */
  64. {
  65. 'name': 'string.regexp',
  66. 'matches': {
  67. 1: 'string.regexp.open',
  68. 2: {
  69. 'name': 'constant.regexp.escape',
  70. 'pattern': /\\(.){1}/g
  71. },
  72. 3: 'string.regexp.cclose',
  73. 4: 'string.regexp.modifier'
  74. },
  75. 'pattern': /(\/)(?!\*)(.+)(\/)([igm]{0,3})/g
  76. },
  77. /**
  78. * matches runtime function declarations
  79. */
  80. {
  81. 'matches': {
  82. 1: 'storage',
  83. 3: 'entity.function'
  84. },
  85. 'pattern': /(var)?(\s|^)(.*)(?=\s?=\s?function\()/g
  86. },
  87. /**
  88. * matches constructor call
  89. */
  90. {
  91. 'matches': {
  92. 1: 'keyword',
  93. 2: 'entity.function'
  94. },
  95. 'pattern': /(new)\s+(.*)(?=\()/g
  96. },
  97. /**
  98. * matches any function call in the style functionName: function()
  99. */
  100. {
  101. 'name': 'entity.function',
  102. 'pattern': /(\w+)(?=:\s{0,}function)/g
  103. }
  104. ]);