apex.js 9.4 KB

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