r.js 6.2 KB

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