vala_highlight_rules.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from https://raw.githubusercontent.com/technosophos/Vala-TMBundle/master/Syntaxes/Vala.tmLanguage (uuid: ) */
  31. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var ValaHighlightRules = function() {
  40. // regexp must not have capturing parentheses. Use (?:) instead.
  41. // regexps are ordered -> the first match is used
  42. this.$rules = { start:
  43. [ { token:
  44. [ 'meta.using.vala',
  45. 'keyword.other.using.vala',
  46. 'meta.using.vala',
  47. 'storage.modifier.using.vala',
  48. 'meta.using.vala',
  49. 'punctuation.terminator.vala' ],
  50. regex: '^(\\s*)(using)\\b(?:(\\s*)([^ ;$]+)(\\s*)((?:;)?))?' },
  51. { include: '#code' } ],
  52. '#all-types':
  53. [ { include: '#primitive-arrays' },
  54. { include: '#primitive-types' },
  55. { include: '#object-types' } ],
  56. '#annotations':
  57. [ { token:
  58. [ 'storage.type.annotation.vala',
  59. 'punctuation.definition.annotation-arguments.begin.vala' ],
  60. regex: '(@[^ (]+)(\\()',
  61. push:
  62. [ { token: 'punctuation.definition.annotation-arguments.end.vala',
  63. regex: '\\)',
  64. next: 'pop' },
  65. { token:
  66. [ 'constant.other.key.vala',
  67. 'text',
  68. 'keyword.operator.assignment.vala' ],
  69. regex: '(\\w*)(\\s*)(=)' },
  70. { include: '#code' },
  71. { token: 'punctuation.seperator.property.vala', regex: ',' },
  72. { defaultToken: 'meta.declaration.annotation.vala' } ] },
  73. { token: 'storage.type.annotation.vala', regex: '@\\w*' } ],
  74. '#anonymous-classes-and-new':
  75. [ { token: 'keyword.control.new.vala',
  76. regex: '\\bnew\\b',
  77. push_disabled:
  78. [ { token: 'text',
  79. regex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
  80. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  81. originalRegex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
  82. next: 'pop' },
  83. { token: [ 'storage.type.vala', 'text' ],
  84. regex: '(\\w+)(\\s*)(?=\\[)',
  85. push:
  86. [ { token: 'text', regex: '}|(?=;|\\))', next: 'pop' },
  87. { token: 'text',
  88. regex: '\\[',
  89. push:
  90. [ { token: 'text', regex: '\\]', next: 'pop' },
  91. { include: '#code' } ] },
  92. { token: 'text',
  93. regex: '{',
  94. push:
  95. [ { token: 'text', regex: '(?=})', next: 'pop' },
  96. { include: '#code' } ] } ] },
  97. { token: 'text',
  98. regex: '(?=\\w.*\\()',
  99. push:
  100. [ { token: 'text',
  101. regex: '(?<=\\))',
  102. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  103. originalRegex: '(?<=\\))',
  104. next: 'pop' },
  105. { include: '#object-types' },
  106. { token: 'text',
  107. regex: '\\(',
  108. push:
  109. [ { token: 'text', regex: '\\)', next: 'pop' },
  110. { include: '#code' } ] } ] },
  111. { token: 'meta.inner-class.vala',
  112. regex: '{',
  113. push:
  114. [ { token: 'meta.inner-class.vala', regex: '}', next: 'pop' },
  115. { include: '#class-body' },
  116. { defaultToken: 'meta.inner-class.vala' } ] } ] } ],
  117. '#assertions':
  118. [ { token:
  119. [ 'keyword.control.assert.vala',
  120. 'meta.declaration.assertion.vala' ],
  121. regex: '\\b(assert|requires|ensures)(\\s)',
  122. push:
  123. [ { token: 'meta.declaration.assertion.vala',
  124. regex: '$',
  125. next: 'pop' },
  126. { token: 'keyword.operator.assert.expression-seperator.vala',
  127. regex: ':' },
  128. { include: '#code' },
  129. { defaultToken: 'meta.declaration.assertion.vala' } ] } ],
  130. '#class':
  131. [ { token: 'meta.class.vala',
  132. regex: '(?=\\w?[\\w\\s]*(?:class|(?:@)?interface|enum|struct|namespace)\\s+\\w+)',
  133. push:
  134. [ { token: 'paren.vala',
  135. regex: '}',
  136. next: 'pop' },
  137. { include: '#storage-modifiers' },
  138. { include: '#comments' },
  139. { token:
  140. [ 'storage.modifier.vala',
  141. 'meta.class.identifier.vala',
  142. 'entity.name.type.class.vala' ],
  143. regex: '(class|(?:@)?interface|enum|struct|namespace)(\\s+)([\\w\\.]+)' },
  144. { token: 'storage.modifier.extends.vala',
  145. regex: ':',
  146. push:
  147. [ { token: 'meta.definition.class.inherited.classes.vala',
  148. regex: '(?={|,)',
  149. next: 'pop' },
  150. { include: '#object-types-inherited' },
  151. { include: '#comments' },
  152. { defaultToken: 'meta.definition.class.inherited.classes.vala' } ] },
  153. { token:
  154. [ 'storage.modifier.implements.vala',
  155. 'meta.definition.class.implemented.interfaces.vala' ],
  156. regex: '(,)(\\s)',
  157. push:
  158. [ { token: 'meta.definition.class.implemented.interfaces.vala',
  159. regex: '(?=\\{)',
  160. next: 'pop' },
  161. { include: '#object-types-inherited' },
  162. { include: '#comments' },
  163. { defaultToken: 'meta.definition.class.implemented.interfaces.vala' } ] },
  164. { token: 'paren.vala',
  165. regex: '{',
  166. push:
  167. [ { token: 'paren.vala', regex: '(?=})', next: 'pop' },
  168. { include: '#class-body' },
  169. { defaultToken: 'meta.class.body.vala' } ] },
  170. { defaultToken: 'meta.class.vala' } ],
  171. comment: 'attempting to put namespace in here.' } ],
  172. '#class-body':
  173. [ { include: '#comments' },
  174. { include: '#class' },
  175. { include: '#enums' },
  176. { include: '#methods' },
  177. { include: '#annotations' },
  178. { include: '#storage-modifiers' },
  179. { include: '#code' } ],
  180. '#code':
  181. [ { include: '#comments' },
  182. { include: '#class' },
  183. { token: 'text',
  184. regex: '{',
  185. push:
  186. [ { token: 'text', regex: '}', next: 'pop' },
  187. { include: '#code' } ] },
  188. { include: '#assertions' },
  189. { include: '#parens' },
  190. { include: '#constants-and-special-vars' },
  191. { include: '#anonymous-classes-and-new' },
  192. { include: '#keywords' },
  193. { include: '#storage-modifiers' },
  194. { include: '#strings' },
  195. { include: '#all-types' } ],
  196. '#comments':
  197. [ { token: 'punctuation.definition.comment.vala',
  198. regex: '/\\*\\*/' },
  199. { include: 'text.html.javadoc' },
  200. { include: '#comments-inline' } ],
  201. '#comments-inline':
  202. [ { token: 'punctuation.definition.comment.vala',
  203. regex: '/\\*',
  204. push:
  205. [ { token: 'punctuation.definition.comment.vala',
  206. regex: '\\*/',
  207. next: 'pop' },
  208. { defaultToken: 'comment.block.vala' } ] },
  209. { token:
  210. [ 'text',
  211. 'punctuation.definition.comment.vala',
  212. 'comment.line.double-slash.vala' ],
  213. regex: '(\\s*)(//)(.*$)' } ],
  214. '#constants-and-special-vars':
  215. [ { token: 'constant.language.vala',
  216. regex: '\\b(?:true|false|null)\\b' },
  217. { token: 'variable.language.vala',
  218. regex: '\\b(?:this|base)\\b' },
  219. { token: 'constant.numeric.vala',
  220. regex: '\\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:(?:e|E)(?:\\+|-)?[0-9]+)?)(?:[LlFfUuDd]|UL|ul)?\\b' },
  221. { token: [ 'keyword.operator.dereference.vala', 'constant.other.vala' ],
  222. regex: '((?:\\.)?)\\b([A-Z][A-Z0-9_]+)(?!<|\\.class|\\s*\\w+\\s*=)\\b' } ],
  223. '#enums':
  224. [ { token: 'text',
  225. regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
  226. push:
  227. [ { token: 'text', regex: '(?=;|})', next: 'pop' },
  228. { token: 'constant.other.enum.vala',
  229. regex: '\\w+',
  230. push:
  231. [ { token: 'meta.enum.vala', regex: '(?=,|;|})', next: 'pop' },
  232. { include: '#parens' },
  233. { token: 'text',
  234. regex: '{',
  235. push:
  236. [ { token: 'text', regex: '}', next: 'pop' },
  237. { include: '#class-body' } ] },
  238. { defaultToken: 'meta.enum.vala' } ] } ] } ],
  239. '#keywords':
  240. [ { token: 'keyword.control.catch-exception.vala',
  241. regex: '\\b(?:try|catch|finally|throw)\\b' },
  242. { token: 'keyword.control.vala', regex: '\\?|:|\\?\\?' },
  243. { token: 'keyword.control.vala',
  244. regex: '\\b(?:return|break|case|continue|default|do|while|for|foreach|switch|if|else|in|yield|get|set|value)\\b' },
  245. { token: 'keyword.operator.vala',
  246. regex: '\\b(?:typeof|is|as)\\b' },
  247. { token: 'keyword.operator.comparison.vala',
  248. regex: '==|!=|<=|>=|<>|<|>' },
  249. { token: 'keyword.operator.assignment.vala', regex: '=' },
  250. { token: 'keyword.operator.increment-decrement.vala',
  251. regex: '\\-\\-|\\+\\+' },
  252. { token: 'keyword.operator.arithmetic.vala',
  253. regex: '\\-|\\+|\\*|\\/|%' },
  254. { token: 'keyword.operator.logical.vala', regex: '!|&&|\\|\\|' },
  255. { token: 'keyword.operator.dereference.vala',
  256. regex: '\\.(?=\\S)',
  257. originalRegex: '(?<=\\S)\\.(?=\\S)' },
  258. { token: 'punctuation.terminator.vala', regex: ';' },
  259. { token: 'keyword.operator.ownership', regex: 'owned|unowned' } ],
  260. '#methods':
  261. [ { token: 'meta.method.vala',
  262. regex: '(?!new)(?=\\w.*\\s+)(?=[^=]+\\()',
  263. push:
  264. [ { token: 'paren.vala', regex: '}|(?=;)', next: 'pop' },
  265. { include: '#storage-modifiers' },
  266. { token: [ 'entity.name.function.vala', 'meta.method.identifier.vala' ],
  267. regex: '([\\~\\w\\.]+)(\\s*\\()',
  268. push:
  269. [ { token: 'meta.method.identifier.vala',
  270. regex: '\\)',
  271. next: 'pop' },
  272. { include: '#parameters' },
  273. { defaultToken: 'meta.method.identifier.vala' } ] },
  274. { token: 'meta.method.return-type.vala',
  275. regex: '(?=\\w.*\\s+\\w+\\s*\\()',
  276. push:
  277. [ { token: 'meta.method.return-type.vala',
  278. regex: '(?=\\w+\\s*\\()',
  279. next: 'pop' },
  280. { include: '#all-types' },
  281. { defaultToken: 'meta.method.return-type.vala' } ] },
  282. { include: '#throws' },
  283. { token: 'paren.vala',
  284. regex: '{',
  285. push:
  286. [ { token: 'paren.vala', regex: '(?=})', next: 'pop' },
  287. { include: '#code' },
  288. { defaultToken: 'meta.method.body.vala' } ] },
  289. { defaultToken: 'meta.method.vala' } ] } ],
  290. '#namespace':
  291. [ { token: 'text',
  292. regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
  293. push:
  294. [ { token: 'text', regex: '(?=;|})', next: 'pop' },
  295. { token: 'constant.other.namespace.vala',
  296. regex: '\\w+',
  297. push:
  298. [ { token: 'meta.namespace.vala', regex: '(?=,|;|})', next: 'pop' },
  299. { include: '#parens' },
  300. { token: 'text',
  301. regex: '{',
  302. push:
  303. [ { token: 'text', regex: '}', next: 'pop' },
  304. { include: '#code' } ] },
  305. { defaultToken: 'meta.namespace.vala' } ] } ],
  306. comment: 'This is not quite right. See the class grammar right now' } ],
  307. '#object-types':
  308. [ { token: 'storage.type.generic.vala',
  309. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
  310. push:
  311. [ { token: 'storage.type.generic.vala',
  312. regex: '>|[^\\w\\s,\\?<\\[()\\]]',
  313. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  314. originalRegex: '>|[^\\w\\s,\\?<\\[(?:[,]+)\\]]',
  315. next: 'pop' },
  316. { include: '#object-types' },
  317. { token: 'storage.type.generic.vala',
  318. regex: '<',
  319. push:
  320. [ { token: 'storage.type.generic.vala',
  321. regex: '>|[^\\w\\s,\\[\\]<]',
  322. next: 'pop' },
  323. { defaultToken: 'storage.type.generic.vala' } ],
  324. comment: 'This is just to support <>\'s with no actual type prefix' },
  325. { defaultToken: 'storage.type.generic.vala' } ] },
  326. { token: 'storage.type.object.array.vala',
  327. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*(?=\\[)',
  328. push:
  329. [ { token: 'storage.type.object.array.vala',
  330. regex: '(?=[^\\]\\s])',
  331. next: 'pop' },
  332. { token: 'text',
  333. regex: '\\[',
  334. push:
  335. [ { token: 'text', regex: '\\]', next: 'pop' },
  336. { include: '#code' } ] },
  337. { defaultToken: 'storage.type.object.array.vala' } ] },
  338. { token:
  339. [ 'storage.type.vala',
  340. 'keyword.operator.dereference.vala',
  341. 'storage.type.vala' ],
  342. regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*\\b)' } ],
  343. '#object-types-inherited':
  344. [ { token: 'entity.other.inherited-class.vala',
  345. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
  346. push:
  347. [ { token: 'entity.other.inherited-class.vala',
  348. regex: '>|[^\\w\\s,<]',
  349. next: 'pop' },
  350. { include: '#object-types' },
  351. { token: 'storage.type.generic.vala',
  352. regex: '<',
  353. push:
  354. [ { token: 'storage.type.generic.vala',
  355. regex: '>|[^\\w\\s,<]',
  356. next: 'pop' },
  357. { defaultToken: 'storage.type.generic.vala' } ],
  358. comment: 'This is just to support <>\'s with no actual type prefix' },
  359. { defaultToken: 'entity.other.inherited-class.vala' } ] },
  360. { token:
  361. [ 'entity.other.inherited-class.vala',
  362. 'keyword.operator.dereference.vala',
  363. 'entity.other.inherited-class.vala' ],
  364. regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*)' } ],
  365. '#parameters':
  366. [ { token: 'storage.modifier.vala', regex: 'final' },
  367. { include: '#primitive-arrays' },
  368. { include: '#primitive-types' },
  369. { include: '#object-types' },
  370. { token: 'variable.parameter.vala', regex: '\\w+' } ],
  371. '#parens':
  372. [ { token: 'text',
  373. regex: '\\(',
  374. push:
  375. [ { token: 'text', regex: '\\)', next: 'pop' },
  376. { include: '#code' } ] } ],
  377. '#primitive-arrays':
  378. [ { token: 'storage.type.primitive.array.vala',
  379. regex: '\\b(?:bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|int8|int16|int32|int64|uint8|uint16|uint32|uint64)(?:\\[\\])*\\b' } ],
  380. '#primitive-types':
  381. [ { token: 'storage.type.primitive.vala',
  382. regex: '\\b(?:var|bool|byte|sbyte|char|decimal|double|float|int|uint|long|ulong|object|short|ushort|string|void|signal|int8|int16|int32|int64|uint8|uint16|uint32|uint64)\\b',
  383. comment: 'var is not really a primitive, but acts like one in most cases' } ],
  384. '#storage-modifiers':
  385. [ { token: 'storage.modifier.vala',
  386. regex: '\\b(?:public|private|protected|internal|static|final|sealed|virtual|override|abstract|readonly|volatile|dynamic|async|unsafe|out|ref|weak|owned|unowned|const)\\b',
  387. comment: 'Not sure about unsafe and readonly' } ],
  388. '#strings':
  389. [ { token: 'punctuation.definition.string.begin.vala',
  390. regex: '@"',
  391. push:
  392. [ { token: 'punctuation.definition.string.end.vala',
  393. regex: '"',
  394. next: 'pop' },
  395. { token: 'constant.character.escape.vala',
  396. regex: '\\\\.|%[\\w\\.\\-]+|\\$(?:\\w+|\\([\\w\\s\\+\\-\\*\\/]+\\))' },
  397. { defaultToken: 'string.quoted.interpolated.vala' } ] },
  398. { token: 'punctuation.definition.string.begin.vala',
  399. regex: '"',
  400. push:
  401. [ { token: 'punctuation.definition.string.end.vala',
  402. regex: '"',
  403. next: 'pop' },
  404. { token: 'constant.character.escape.vala', regex: '\\\\.' },
  405. { token: 'constant.character.escape.vala',
  406. regex: '%[\\w\\.\\-]+' },
  407. { defaultToken: 'string.quoted.double.vala' } ] },
  408. { token: 'punctuation.definition.string.begin.vala',
  409. regex: '\'',
  410. push:
  411. [ { token: 'punctuation.definition.string.end.vala',
  412. regex: '\'',
  413. next: 'pop' },
  414. { token: 'constant.character.escape.vala', regex: '\\\\.' },
  415. { defaultToken: 'string.quoted.single.vala' } ] },
  416. { token: 'punctuation.definition.string.begin.vala',
  417. regex: '"""',
  418. push:
  419. [ { token: 'punctuation.definition.string.end.vala',
  420. regex: '"""',
  421. next: 'pop' },
  422. { token: 'constant.character.escape.vala',
  423. regex: '%[\\w\\.\\-]+' },
  424. { defaultToken: 'string.quoted.triple.vala' } ] } ],
  425. '#throws':
  426. [ { token: 'storage.modifier.vala',
  427. regex: 'throws',
  428. push:
  429. [ { token: 'meta.throwables.vala', regex: '(?={|;)', next: 'pop' },
  430. { include: '#object-types' },
  431. { defaultToken: 'meta.throwables.vala' } ] } ],
  432. '#values':
  433. [ { include: '#strings' },
  434. { include: '#object-types' },
  435. { include: '#constants-and-special-vars' } ] }
  436. this.normalizeRules();
  437. };
  438. ValaHighlightRules.metaData = {
  439. comment: 'Based heavily on the Java bundle\'s language syntax. TODO:\n* Closures\n* Delegates\n* Properties: Better support for properties.\n* Annotations\n* Error domains\n* Named arguments\n* Array slicing, negative indexes, multidimensional\n* construct blocks\n* lock blocks?\n* regex literals\n* DocBlock syntax highlighting. (Currently importing javadoc)\n* Folding rule for comments.\n',
  440. fileTypes: [ 'vala' ],
  441. foldingStartMarker: '(\\{\\s*(//.*)?$|^\\s*// \\{\\{\\{)',
  442. foldingStopMarker: '^\\s*(\\}|// \\}\\}\\}$)',
  443. name: 'Vala',
  444. scopeName: 'source.vala' }
  445. oop.inherits(ValaHighlightRules, TextHighlightRules);
  446. exports.ValaHighlightRules = ValaHighlightRules;
  447. });