vb.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373
  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. blockComment: ['/*', '*/']
  9. },
  10. brackets: [
  11. ['{', '}'],
  12. ['[', ']'],
  13. ['(', ')'],
  14. ['<', '>'],
  15. ['addhandler', 'end addhandler'],
  16. ['class', 'end class'],
  17. ['enum', 'end enum'],
  18. ['event', 'end event'],
  19. ['function', 'end function'],
  20. ['get', 'end get'],
  21. ['if', 'end if'],
  22. ['interface', 'end interface'],
  23. ['module', 'end module'],
  24. ['namespace', 'end namespace'],
  25. ['operator', 'end operator'],
  26. ['property', 'end property'],
  27. ['raiseevent', 'end raiseevent'],
  28. ['removehandler', 'end removehandler'],
  29. ['select', 'end select'],
  30. ['set', 'end set'],
  31. ['structure', 'end structure'],
  32. ['sub', 'end sub'],
  33. ['synclock', 'end synclock'],
  34. ['try', 'end try'],
  35. ['while', 'end while'],
  36. ['with', 'end with'],
  37. ['using', 'end using'],
  38. ['do', 'loop'],
  39. ['for', 'next']
  40. ],
  41. autoClosingPairs: [
  42. { open: '{', close: '}', notIn: ['string', 'comment'] },
  43. { open: '[', close: ']', notIn: ['string', 'comment'] },
  44. { open: '(', close: ')', notIn: ['string', 'comment'] },
  45. { open: '"', close: '"', notIn: ['string', 'comment'] },
  46. { open: '<', close: '>', notIn: ['string', 'comment'] }
  47. ],
  48. folding: {
  49. markers: {
  50. start: new RegExp('^\\s*#Region\\b'),
  51. end: new RegExp('^\\s*#End Region\\b')
  52. }
  53. }
  54. };
  55. export var language = {
  56. defaultToken: '',
  57. tokenPostfix: '.vb',
  58. ignoreCase: true,
  59. brackets: [
  60. { token: 'delimiter.bracket', open: '{', close: '}' },
  61. { token: 'delimiter.array', open: '[', close: ']' },
  62. { token: 'delimiter.parenthesis', open: '(', close: ')' },
  63. { token: 'delimiter.angle', open: '<', close: '>' },
  64. // Special bracket statement pairs
  65. // according to https://msdn.microsoft.com/en-us/library/tsw2a11z.aspx
  66. {
  67. token: 'keyword.tag-addhandler',
  68. open: 'addhandler',
  69. close: 'end addhandler'
  70. },
  71. { token: 'keyword.tag-class', open: 'class', close: 'end class' },
  72. { token: 'keyword.tag-enum', open: 'enum', close: 'end enum' },
  73. { token: 'keyword.tag-event', open: 'event', close: 'end event' },
  74. {
  75. token: 'keyword.tag-function',
  76. open: 'function',
  77. close: 'end function'
  78. },
  79. { token: 'keyword.tag-get', open: 'get', close: 'end get' },
  80. { token: 'keyword.tag-if', open: 'if', close: 'end if' },
  81. {
  82. token: 'keyword.tag-interface',
  83. open: 'interface',
  84. close: 'end interface'
  85. },
  86. { token: 'keyword.tag-module', open: 'module', close: 'end module' },
  87. {
  88. token: 'keyword.tag-namespace',
  89. open: 'namespace',
  90. close: 'end namespace'
  91. },
  92. {
  93. token: 'keyword.tag-operator',
  94. open: 'operator',
  95. close: 'end operator'
  96. },
  97. {
  98. token: 'keyword.tag-property',
  99. open: 'property',
  100. close: 'end property'
  101. },
  102. {
  103. token: 'keyword.tag-raiseevent',
  104. open: 'raiseevent',
  105. close: 'end raiseevent'
  106. },
  107. {
  108. token: 'keyword.tag-removehandler',
  109. open: 'removehandler',
  110. close: 'end removehandler'
  111. },
  112. { token: 'keyword.tag-select', open: 'select', close: 'end select' },
  113. { token: 'keyword.tag-set', open: 'set', close: 'end set' },
  114. {
  115. token: 'keyword.tag-structure',
  116. open: 'structure',
  117. close: 'end structure'
  118. },
  119. { token: 'keyword.tag-sub', open: 'sub', close: 'end sub' },
  120. {
  121. token: 'keyword.tag-synclock',
  122. open: 'synclock',
  123. close: 'end synclock'
  124. },
  125. { token: 'keyword.tag-try', open: 'try', close: 'end try' },
  126. { token: 'keyword.tag-while', open: 'while', close: 'end while' },
  127. { token: 'keyword.tag-with', open: 'with', close: 'end with' },
  128. // Other pairs
  129. { token: 'keyword.tag-using', open: 'using', close: 'end using' },
  130. { token: 'keyword.tag-do', open: 'do', close: 'loop' },
  131. { token: 'keyword.tag-for', open: 'for', close: 'next' }
  132. ],
  133. keywords: [
  134. 'AddHandler',
  135. 'AddressOf',
  136. 'Alias',
  137. 'And',
  138. 'AndAlso',
  139. 'As',
  140. 'Async',
  141. 'Boolean',
  142. 'ByRef',
  143. 'Byte',
  144. 'ByVal',
  145. 'Call',
  146. 'Case',
  147. 'Catch',
  148. 'CBool',
  149. 'CByte',
  150. 'CChar',
  151. 'CDate',
  152. 'CDbl',
  153. 'CDec',
  154. 'Char',
  155. 'CInt',
  156. 'Class',
  157. 'CLng',
  158. 'CObj',
  159. 'Const',
  160. 'Continue',
  161. 'CSByte',
  162. 'CShort',
  163. 'CSng',
  164. 'CStr',
  165. 'CType',
  166. 'CUInt',
  167. 'CULng',
  168. 'CUShort',
  169. 'Date',
  170. 'Decimal',
  171. 'Declare',
  172. 'Default',
  173. 'Delegate',
  174. 'Dim',
  175. 'DirectCast',
  176. 'Do',
  177. 'Double',
  178. 'Each',
  179. 'Else',
  180. 'ElseIf',
  181. 'End',
  182. 'EndIf',
  183. 'Enum',
  184. 'Erase',
  185. 'Error',
  186. 'Event',
  187. 'Exit',
  188. 'False',
  189. 'Finally',
  190. 'For',
  191. 'Friend',
  192. 'Function',
  193. 'Get',
  194. 'GetType',
  195. 'GetXMLNamespace',
  196. 'Global',
  197. 'GoSub',
  198. 'GoTo',
  199. 'Handles',
  200. 'If',
  201. 'Implements',
  202. 'Imports',
  203. 'In',
  204. 'Inherits',
  205. 'Integer',
  206. 'Interface',
  207. 'Is',
  208. 'IsNot',
  209. 'Let',
  210. 'Lib',
  211. 'Like',
  212. 'Long',
  213. 'Loop',
  214. 'Me',
  215. 'Mod',
  216. 'Module',
  217. 'MustInherit',
  218. 'MustOverride',
  219. 'MyBase',
  220. 'MyClass',
  221. 'NameOf',
  222. 'Namespace',
  223. 'Narrowing',
  224. 'New',
  225. 'Next',
  226. 'Not',
  227. 'Nothing',
  228. 'NotInheritable',
  229. 'NotOverridable',
  230. 'Object',
  231. 'Of',
  232. 'On',
  233. 'Operator',
  234. 'Option',
  235. 'Optional',
  236. 'Or',
  237. 'OrElse',
  238. 'Out',
  239. 'Overloads',
  240. 'Overridable',
  241. 'Overrides',
  242. 'ParamArray',
  243. 'Partial',
  244. 'Private',
  245. 'Property',
  246. 'Protected',
  247. 'Public',
  248. 'RaiseEvent',
  249. 'ReadOnly',
  250. 'ReDim',
  251. 'RemoveHandler',
  252. 'Resume',
  253. 'Return',
  254. 'SByte',
  255. 'Select',
  256. 'Set',
  257. 'Shadows',
  258. 'Shared',
  259. 'Short',
  260. 'Single',
  261. 'Static',
  262. 'Step',
  263. 'Stop',
  264. 'String',
  265. 'Structure',
  266. 'Sub',
  267. 'SyncLock',
  268. 'Then',
  269. 'Throw',
  270. 'To',
  271. 'True',
  272. 'Try',
  273. 'TryCast',
  274. 'TypeOf',
  275. 'UInteger',
  276. 'ULong',
  277. 'UShort',
  278. 'Using',
  279. 'Variant',
  280. 'Wend',
  281. 'When',
  282. 'While',
  283. 'Widening',
  284. 'With',
  285. 'WithEvents',
  286. 'WriteOnly',
  287. 'Xor'
  288. ],
  289. tagwords: [
  290. 'If',
  291. 'Sub',
  292. 'Select',
  293. 'Try',
  294. 'Class',
  295. 'Enum',
  296. 'Function',
  297. 'Get',
  298. 'Interface',
  299. 'Module',
  300. 'Namespace',
  301. 'Operator',
  302. 'Set',
  303. 'Structure',
  304. 'Using',
  305. 'While',
  306. 'With',
  307. 'Do',
  308. 'Loop',
  309. 'For',
  310. 'Next',
  311. 'Property',
  312. 'Continue',
  313. 'AddHandler',
  314. 'RemoveHandler',
  315. 'Event',
  316. 'RaiseEvent',
  317. 'SyncLock'
  318. ],
  319. // we include these common regular expressions
  320. symbols: /[=><!~?;\.,:&|+\-*\/\^%]+/,
  321. integersuffix: /U?[DI%L&S@]?/,
  322. floatsuffix: /[R#F!]?/,
  323. // The main tokenizer for our languages
  324. tokenizer: {
  325. root: [
  326. // whitespace
  327. { include: '@whitespace' },
  328. // special ending tag-words
  329. [/next(?!\w)/, { token: 'keyword.tag-for' }],
  330. [/loop(?!\w)/, { token: 'keyword.tag-do' }],
  331. // usual ending tags
  332. [
  333. /end\s+(?!for|do)(addhandler|class|enum|event|function|get|if|interface|module|namespace|operator|property|raiseevent|removehandler|select|set|structure|sub|synclock|try|while|with|using)/,
  334. { token: 'keyword.tag-$1' }
  335. ],
  336. // identifiers, tagwords, and keywords
  337. [
  338. /[a-zA-Z_]\w*/,
  339. {
  340. cases: {
  341. '@tagwords': { token: 'keyword.tag-$0' },
  342. '@keywords': { token: 'keyword.$0' },
  343. '@default': 'identifier'
  344. }
  345. }
  346. ],
  347. // Preprocessor directive
  348. [/^\s*#\w+/, 'keyword'],
  349. // numbers
  350. [/\d*\d+e([\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  351. [/\d*\.\d+(e[\-+]?\d+)?(@floatsuffix)/, 'number.float'],
  352. [/&H[0-9a-f]+(@integersuffix)/, 'number.hex'],
  353. [/&0[0-7]+(@integersuffix)/, 'number.octal'],
  354. [/\d+(@integersuffix)/, 'number'],
  355. // date literal
  356. [/#.*#/, 'number'],
  357. // delimiters and operators
  358. [/[{}()\[\]]/, '@brackets'],
  359. [/@symbols/, 'delimiter'],
  360. // strings
  361. [/["\u201c\u201d]/, { token: 'string.quote', next: '@string' }]
  362. ],
  363. whitespace: [
  364. [/[ \t\r\n]+/, ''],
  365. [/(\'|REM(?!\w)).*$/, 'comment']
  366. ],
  367. string: [
  368. [/[^"\u201c\u201d]+/, 'string'],
  369. [/["\u201c\u201d]{2}/, 'string.escape'],
  370. [/["\u201c\u201d]C?/, { token: 'string.quote', next: '@pop' }]
  371. ]
  372. }
  373. };