apex.js 8.6 KB

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