r.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. define(["require", "exports"], function (require, exports) {
  6. 'use strict';
  7. Object.defineProperty(exports, "__esModule", { value: true });
  8. exports.conf = {
  9. comments: {
  10. lineComment: '#'
  11. },
  12. brackets: [
  13. ['{', '}'],
  14. ['[', ']'],
  15. ['(', ')']
  16. ],
  17. autoClosingPairs: [
  18. { open: '{', close: '}' },
  19. { open: '[', close: ']' },
  20. { open: '(', close: ')' },
  21. { open: '"', close: '"' },
  22. ],
  23. surroundingPairs: [
  24. { open: '{', close: '}' },
  25. { open: '[', close: ']' },
  26. { open: '(', close: ')' },
  27. { open: '"', close: '"' },
  28. ]
  29. };
  30. exports.language = {
  31. defaultToken: '',
  32. tokenPostfix: '.r',
  33. roxygen: [
  34. '@param',
  35. '@return',
  36. '@name',
  37. '@rdname',
  38. '@examples',
  39. '@include',
  40. '@docType',
  41. '@S3method',
  42. '@TODO',
  43. '@aliases',
  44. '@alias',
  45. '@assignee',
  46. '@author',
  47. '@callGraphDepth',
  48. '@callGraph',
  49. '@callGraphPrimitives',
  50. '@concept',
  51. '@exportClass',
  52. '@exportMethod',
  53. '@exportPattern',
  54. '@export',
  55. '@formals',
  56. '@format',
  57. '@importClassesFrom',
  58. '@importFrom',
  59. '@importMethodsFrom',
  60. '@import',
  61. '@keywords',
  62. '@method',
  63. '@nord',
  64. '@note',
  65. '@references',
  66. '@seealso',
  67. '@setClass',
  68. '@slot',
  69. '@source',
  70. '@title',
  71. '@usage'
  72. ],
  73. constants: [
  74. 'NULL',
  75. 'FALSE',
  76. 'TRUE',
  77. 'NA',
  78. 'Inf',
  79. 'NaN ',
  80. 'NA_integer_',
  81. 'NA_real_',
  82. 'NA_complex_',
  83. 'NA_character_ ',
  84. 'T',
  85. 'F',
  86. 'LETTERS',
  87. 'letters',
  88. 'month.abb',
  89. 'month.name',
  90. 'pi',
  91. 'R.version.string'
  92. ],
  93. keywords: [
  94. 'break',
  95. 'next',
  96. 'return',
  97. 'if',
  98. 'else',
  99. 'for',
  100. 'in',
  101. 'repeat',
  102. 'while',
  103. 'array',
  104. 'category',
  105. 'character',
  106. 'complex',
  107. 'double',
  108. 'function',
  109. 'integer',
  110. 'list',
  111. 'logical',
  112. 'matrix',
  113. 'numeric',
  114. 'vector',
  115. 'data.frame',
  116. 'factor',
  117. 'library',
  118. 'require',
  119. 'attach',
  120. 'detach',
  121. 'source'
  122. ],
  123. special: [
  124. '\\n',
  125. '\\r',
  126. '\\t',
  127. '\\b',
  128. '\\a',
  129. '\\f',
  130. '\\v',
  131. '\\\'',
  132. '\\"',
  133. '\\\\'
  134. ],
  135. brackets: [
  136. { open: '{', close: '}', token: 'delimiter.curly' },
  137. { open: '[', close: ']', token: 'delimiter.bracket' },
  138. { open: '(', close: ')', token: 'delimiter.parenthesis' }
  139. ],
  140. tokenizer: {
  141. root: [
  142. { include: '@numbers' },
  143. { include: '@strings' },
  144. [/[{}\[\]()]/, '@brackets'],
  145. { include: '@operators' },
  146. [/#'/, 'comment.doc', '@roxygen'],
  147. [/(^#.*$)/, 'comment'],
  148. [/\s+/, 'white'],
  149. [/[,:;]/, 'delimiter'],
  150. [/@[a-zA-Z]\w*/, 'tag'],
  151. [/[a-zA-Z]\w*/, {
  152. cases: {
  153. '@keywords': 'keyword',
  154. '@constants': 'constant',
  155. '@default': 'identifier'
  156. }
  157. }]
  158. ],
  159. // Recognize Roxygen comments
  160. roxygen: [
  161. [/@\w+/, {
  162. cases: {
  163. '@roxygen': 'tag',
  164. '@eos': { token: 'comment.doc', next: '@pop' },
  165. '@default': 'comment.doc'
  166. }
  167. }],
  168. [/\s+/, {
  169. cases: {
  170. '@eos': { token: 'comment.doc', next: '@pop' },
  171. '@default': 'comment.doc'
  172. }
  173. }],
  174. [/.*/, { token: 'comment.doc', next: '@pop' }]
  175. ],
  176. // Recognize positives, negatives, decimals, imaginaries, and scientific notation
  177. numbers: [
  178. [/0[xX][0-9a-fA-F]+/, 'number.hex'],
  179. [/-?(\d*\.)?\d+([eE][+\-]?\d+)?/, 'number']
  180. ],
  181. // Recognize operators
  182. operators: [
  183. [/<{1,2}-/, 'operator'],
  184. [/->{1,2}/, 'operator'],
  185. [/%[^%\s]+%/, 'operator'],
  186. [/\*\*/, 'operator'],
  187. [/%%/, 'operator'],
  188. [/&&/, 'operator'],
  189. [/\|\|/, 'operator'],
  190. [/<</, 'operator'],
  191. [/>>/, 'operator'],
  192. [/[-+=&|!<>^~*/:$]/, 'operator']
  193. ],
  194. // Recognize strings, including those broken across lines
  195. strings: [
  196. [/'/, 'string.escape', '@stringBody'],
  197. [/"/, 'string.escape', '@dblStringBody']
  198. ],
  199. stringBody: [
  200. [/\\./, {
  201. cases: {
  202. '@special': 'string',
  203. '@default': 'error-token'
  204. }
  205. }],
  206. [/'/, 'string.escape', '@popall'],
  207. [/./, 'string'],
  208. ],
  209. dblStringBody: [
  210. [/\\./, {
  211. cases: {
  212. '@special': 'string',
  213. '@default': 'error-token'
  214. }
  215. }],
  216. [/"/, 'string.escape', '@popall'],
  217. [/./, 'string'],
  218. ]
  219. }
  220. };
  221. });