r.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. /**
  2. * R language patterns
  3. *
  4. * @author Simon Potter
  5. */
  6. Rainbow.extend('r', [
  7. /**
  8. * Note that a valid variable name is of the form:
  9. * [.a-zA-Z][0-9a-zA-Z._]*
  10. */
  11. {
  12. matches: {
  13. 1: {
  14. name: 'keyword.operator',
  15. pattern: /\=|<\-|&lt;-/g
  16. },
  17. 2: {
  18. name: 'string',
  19. matches: {
  20. name: 'constant.character.escape',
  21. pattern: /\\('|"){1}/g
  22. }
  23. }
  24. },
  25. pattern: /(\(|\s|\[|\=|:)(('|")([^\\\1]|\\.)*?(\3))/gm
  26. },
  27. /**
  28. * Most of these are known via the Language Reference.
  29. * The built-in constant symbols are known via ?Constants.
  30. */
  31. {
  32. matches: {
  33. 1: 'constant.language'
  34. },
  35. pattern: /\b(NULL|NA|TRUE|FALSE|T|F|NaN|Inf|NA_integer_|NA_real_|NA_complex_|NA_character_)\b/g
  36. },
  37. {
  38. matches: {
  39. 1: 'constant.symbol'
  40. },
  41. pattern: /[^0-9a-zA-Z\._](LETTERS|letters|month\.(abb|name)|pi)/g
  42. },
  43. /**
  44. * @todo: The list subsetting operator isn't quite working properly.
  45. * It includes the previous variable when it should only match [[
  46. */
  47. {
  48. name: 'keyword.operator',
  49. pattern: /&lt;-|<-|-|==|&lt;=|<=|&gt;>|>=|<|>|&amp;&amp;|&&|&amp;|&|!=|\|\|?|\*|\+|\^|\/|%%|%\/%|\=|%in%|%\*%|%o%|%x%|\$|:|~|\[{1,2}|\]{1,2}/g
  50. },
  51. {
  52. matches: {
  53. 1: 'storage',
  54. 3: 'entity.function'
  55. },
  56. pattern: /(\s|^)(.*)(?=\s?=\s?function\s\()/g
  57. },
  58. {
  59. matches: {
  60. 1: 'storage.function'
  61. },
  62. pattern: /[^a-zA-Z0-9._](function)(?=\s*\()/g
  63. },
  64. {
  65. matches: {
  66. 1: 'namespace',
  67. 2: 'keyword.operator',
  68. 3: 'function.call'
  69. },
  70. pattern: /([a-zA-Z][a-zA-Z0-9._]+)([:]{2,3})([.a-zA-Z][a-zA-Z0-9._]*(?=\s*\())\b/g
  71. },
  72. /*
  73. * Note that we would perhaps match more builtin functions and
  74. * variables, but there are so many that most are ommitted for now.
  75. * See ?builtins for more info.
  76. *
  77. * @todo: Fix the case where we have a function like tmp.logical().
  78. * This should just be a function call, at the moment it's
  79. * only partly a function all.
  80. */
  81. {
  82. name: 'support.function',
  83. pattern: /(^|[^0-9a-zA-Z\._])(array|character|complex|data\.frame|double|integer|list|logical|matrix|numeric|vector)(?=\s*\()/g
  84. }
  85. ], 'generic');