apex.js 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  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. // the default separators except `@$`
  7. wordPattern: /(-?\d*\.\d\w*)|([^\`\~\!\#\%\^\&\*\(\)\-\=\+\[\{\]\}\\\|\;\:\'\"\,\.\<\>\/\?\s]+)/g,
  8. comments: {
  9. lineComment: '//',
  10. blockComment: ['/*', '*/']
  11. },
  12. brackets: [
  13. ['{', '}'],
  14. ['[', ']'],
  15. ['(', ')']
  16. ],
  17. autoClosingPairs: [
  18. { open: '{', close: '}' },
  19. { open: '[', close: ']' },
  20. { open: '(', close: ')' },
  21. { open: '"', close: '"' },
  22. { open: "'", close: "'" }
  23. ],
  24. surroundingPairs: [
  25. { open: '{', close: '}' },
  26. { open: '[', close: ']' },
  27. { open: '(', close: ')' },
  28. { open: '"', close: '"' },
  29. { open: "'", close: "'" },
  30. { open: '<', close: '>' }
  31. ],
  32. folding: {
  33. markers: {
  34. start: new RegExp('^\\s*//\\s*(?:(?:#?region\\b)|(?:<editor-fold\\b))'),
  35. end: new RegExp('^\\s*//\\s*(?:(?:#?endregion\\b)|(?:</editor-fold>))')
  36. }
  37. }
  38. };
  39. var keywords = [
  40. 'abstract',
  41. 'activate',
  42. 'and',
  43. 'any',
  44. 'array',
  45. 'as',
  46. 'asc',
  47. 'assert',
  48. 'autonomous',
  49. 'begin',
  50. 'bigdecimal',
  51. 'blob',
  52. 'boolean',
  53. 'break',
  54. 'bulk',
  55. 'by',
  56. 'case',
  57. 'cast',
  58. 'catch',
  59. 'char',
  60. 'class',
  61. 'collect',
  62. 'commit',
  63. 'const',
  64. 'continue',
  65. 'convertcurrency',
  66. 'decimal',
  67. 'default',
  68. 'delete',
  69. 'desc',
  70. 'do',
  71. 'double',
  72. 'else',
  73. 'end',
  74. 'enum',
  75. 'exception',
  76. 'exit',
  77. 'export',
  78. 'extends',
  79. 'false',
  80. 'final',
  81. 'finally',
  82. 'float',
  83. 'for',
  84. 'from',
  85. 'future',
  86. 'get',
  87. 'global',
  88. 'goto',
  89. 'group',
  90. 'having',
  91. 'hint',
  92. 'if',
  93. 'implements',
  94. 'import',
  95. 'in',
  96. 'inner',
  97. 'insert',
  98. 'instanceof',
  99. 'int',
  100. 'interface',
  101. 'into',
  102. 'join',
  103. 'last_90_days',
  104. 'last_month',
  105. 'last_n_days',
  106. 'last_week',
  107. 'like',
  108. 'limit',
  109. 'list',
  110. 'long',
  111. 'loop',
  112. 'map',
  113. 'merge',
  114. 'native',
  115. 'new',
  116. 'next_90_days',
  117. 'next_month',
  118. 'next_n_days',
  119. 'next_week',
  120. 'not',
  121. 'null',
  122. 'nulls',
  123. 'number',
  124. 'object',
  125. 'of',
  126. 'on',
  127. 'or',
  128. 'outer',
  129. 'override',
  130. 'package',
  131. 'parallel',
  132. 'pragma',
  133. 'private',
  134. 'protected',
  135. 'public',
  136. 'retrieve',
  137. 'return',
  138. 'returning',
  139. 'rollback',
  140. 'savepoint',
  141. 'search',
  142. 'select',
  143. 'set',
  144. 'short',
  145. 'sort',
  146. 'stat',
  147. 'static',
  148. 'strictfp',
  149. 'super',
  150. 'switch',
  151. 'synchronized',
  152. 'system',
  153. 'testmethod',
  154. 'then',
  155. 'this',
  156. 'this_month',
  157. 'this_week',
  158. 'throw',
  159. 'throws',
  160. 'today',
  161. 'tolabel',
  162. 'tomorrow',
  163. 'transaction',
  164. 'transient',
  165. 'trigger',
  166. 'true',
  167. 'try',
  168. 'type',
  169. 'undelete',
  170. 'update',
  171. 'upsert',
  172. 'using',
  173. 'virtual',
  174. 'void',
  175. 'volatile',
  176. 'webservice',
  177. 'when',
  178. 'where',
  179. 'while',
  180. 'yesterday'
  181. ];
  182. // create case variations of the keywords - apex is case insensitive, but we can't make the highlighter case insensitive
  183. // because we use a heuristic to assume that identifiers starting with an upper case letter are types.
  184. var uppercaseFirstLetter = function (lowercase) {
  185. return lowercase.charAt(0).toUpperCase() + lowercase.substr(1);
  186. };
  187. var keywordsWithCaseVariations = [];
  188. keywords.forEach(function (lowercase) {
  189. keywordsWithCaseVariations.push(lowercase);
  190. keywordsWithCaseVariations.push(lowercase.toUpperCase());
  191. keywordsWithCaseVariations.push(uppercaseFirstLetter(lowercase));
  192. });
  193. export var language = {
  194. defaultToken: '',
  195. tokenPostfix: '.apex',
  196. keywords: keywordsWithCaseVariations,
  197. operators: [
  198. '=',
  199. '>',
  200. '<',
  201. '!',
  202. '~',
  203. '?',
  204. ':',
  205. '==',
  206. '<=',
  207. '>=',
  208. '!=',
  209. '&&',
  210. '||',
  211. '++',
  212. '--',
  213. '+',
  214. '-',
  215. '*',
  216. '/',
  217. '&',
  218. '|',
  219. '^',
  220. '%',
  221. '<<',
  222. '>>',
  223. '>>>',
  224. '+=',
  225. '-=',
  226. '*=',
  227. '/=',
  228. '&=',
  229. '|=',
  230. '^=',
  231. '%=',
  232. '<<=',
  233. '>>=',
  234. '>>>='
  235. ],
  236. // we include these common regular expressions
  237. symbols: /[=><!~?:&|+\-*\/\^%]+/,
  238. escapes: /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
  239. digits: /\d+(_+\d+)*/,
  240. octaldigits: /[0-7]+(_+[0-7]+)*/,
  241. binarydigits: /[0-1]+(_+[0-1]+)*/,
  242. hexdigits: /[[0-9a-fA-F]+(_+[0-9a-fA-F]+)*/,
  243. // The main tokenizer for our languages
  244. tokenizer: {
  245. root: [
  246. // identifiers and keywords
  247. [
  248. /[a-z_$][\w$]*/,
  249. {
  250. cases: {
  251. '@keywords': { token: 'keyword.$0' },
  252. '@default': 'identifier'
  253. }
  254. }
  255. ],
  256. // assume that identifiers starting with an uppercase letter are types
  257. [
  258. /[A-Z][\w\$]*/,
  259. {
  260. cases: {
  261. '@keywords': { token: 'keyword.$0' },
  262. '@default': 'type.identifier'
  263. }
  264. }
  265. ],
  266. // whitespace
  267. { include: '@whitespace' },
  268. // delimiters and operators
  269. [/[{}()\[\]]/, '@brackets'],
  270. [/[<>](?!@symbols)/, '@brackets'],
  271. [
  272. /@symbols/,
  273. {
  274. cases: {
  275. '@operators': 'delimiter',
  276. '@default': ''
  277. }
  278. }
  279. ],
  280. // @ annotations.
  281. [/@\s*[a-zA-Z_\$][\w\$]*/, 'annotation'],
  282. // numbers
  283. [/(@digits)[eE]([\-+]?(@digits))?[fFdD]?/, 'number.float'],
  284. [/(@digits)\.(@digits)([eE][\-+]?(@digits))?[fFdD]?/, 'number.float'],
  285. [/(@digits)[fFdD]/, 'number.float'],
  286. [/(@digits)[lL]?/, 'number'],
  287. // delimiter: after number because of .\d floats
  288. [/[;,.]/, 'delimiter'],
  289. // strings
  290. [/"([^"\\]|\\.)*$/, 'string.invalid'],
  291. [/'([^'\\]|\\.)*$/, 'string.invalid'],
  292. [/"/, 'string', '@string."'],
  293. [/'/, 'string', "@string.'"],
  294. // characters
  295. [/'[^\\']'/, 'string'],
  296. [/(')(@escapes)(')/, ['string', 'string.escape', 'string']],
  297. [/'/, 'string.invalid']
  298. ],
  299. whitespace: [
  300. [/[ \t\r\n]+/, ''],
  301. [/\/\*\*(?!\/)/, 'comment.doc', '@apexdoc'],
  302. [/\/\*/, 'comment', '@comment'],
  303. [/\/\/.*$/, 'comment']
  304. ],
  305. comment: [
  306. [/[^\/*]+/, 'comment'],
  307. // [/\/\*/, 'comment', '@push' ], // nested comment not allowed :-(
  308. // [/\/\*/, 'comment.invalid' ], // this breaks block comments in the shape of /* //*/
  309. [/\*\//, 'comment', '@pop'],
  310. [/[\/*]/, 'comment']
  311. ],
  312. //Identical copy of comment above, except for the addition of .doc
  313. apexdoc: [
  314. [/[^\/*]+/, 'comment.doc'],
  315. [/\*\//, 'comment.doc', '@pop'],
  316. [/[\/*]/, 'comment.doc']
  317. ],
  318. string: [
  319. [/[^\\"']+/, 'string'],
  320. [/@escapes/, 'string.escape'],
  321. [/\\./, 'string.escape.invalid'],
  322. [
  323. /["']/,
  324. {
  325. cases: {
  326. '$#==$S2': { token: 'string', next: '@pop' },
  327. '@default': 'string'
  328. }
  329. }
  330. ]
  331. ]
  332. }
  333. };