mode-vala.js 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669
  1. ace.define("ace/mode/vala_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var ValaHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token:
  8. [ 'meta.using.vala',
  9. 'keyword.other.using.vala',
  10. 'meta.using.vala',
  11. 'storage.modifier.using.vala',
  12. 'meta.using.vala',
  13. 'punctuation.terminator.vala' ],
  14. regex: '^(\\s*)(using)\\b(?:(\\s*)([^ ;$]+)(\\s*)((?:;)?))?' },
  15. { include: '#code' } ],
  16. '#all-types':
  17. [ { include: '#primitive-arrays' },
  18. { include: '#primitive-types' },
  19. { include: '#object-types' } ],
  20. '#annotations':
  21. [ { token:
  22. [ 'storage.type.annotation.vala',
  23. 'punctuation.definition.annotation-arguments.begin.vala' ],
  24. regex: '(@[^ (]+)(\\()',
  25. push:
  26. [ { token: 'punctuation.definition.annotation-arguments.end.vala',
  27. regex: '\\)',
  28. next: 'pop' },
  29. { token:
  30. [ 'constant.other.key.vala',
  31. 'text',
  32. 'keyword.operator.assignment.vala' ],
  33. regex: '(\\w*)(\\s*)(=)' },
  34. { include: '#code' },
  35. { token: 'punctuation.seperator.property.vala', regex: ',' },
  36. { defaultToken: 'meta.declaration.annotation.vala' } ] },
  37. { token: 'storage.type.annotation.vala', regex: '@\\w*' } ],
  38. '#anonymous-classes-and-new':
  39. [ { token: 'keyword.control.new.vala',
  40. regex: '\\bnew\\b',
  41. push_disabled:
  42. [ { token: 'text',
  43. regex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
  44. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  45. originalRegex: '(?<=\\)|\\])(?!\\s*{)|(?<=})|(?=;)',
  46. next: 'pop' },
  47. { token: [ 'storage.type.vala', 'text' ],
  48. regex: '(\\w+)(\\s*)(?=\\[)',
  49. push:
  50. [ { token: 'text', regex: '}|(?=;|\\))', next: 'pop' },
  51. { token: 'text',
  52. regex: '\\[',
  53. push:
  54. [ { token: 'text', regex: '\\]', next: 'pop' },
  55. { include: '#code' } ] },
  56. { token: 'text',
  57. regex: '{',
  58. push:
  59. [ { token: 'text', regex: '(?=})', next: 'pop' },
  60. { include: '#code' } ] } ] },
  61. { token: 'text',
  62. regex: '(?=\\w.*\\()',
  63. push:
  64. [ { token: 'text',
  65. regex: '(?<=\\))',
  66. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  67. originalRegex: '(?<=\\))',
  68. next: 'pop' },
  69. { include: '#object-types' },
  70. { token: 'text',
  71. regex: '\\(',
  72. push:
  73. [ { token: 'text', regex: '\\)', next: 'pop' },
  74. { include: '#code' } ] } ] },
  75. { token: 'meta.inner-class.vala',
  76. regex: '{',
  77. push:
  78. [ { token: 'meta.inner-class.vala', regex: '}', next: 'pop' },
  79. { include: '#class-body' },
  80. { defaultToken: 'meta.inner-class.vala' } ] } ] } ],
  81. '#assertions':
  82. [ { token:
  83. [ 'keyword.control.assert.vala',
  84. 'meta.declaration.assertion.vala' ],
  85. regex: '\\b(assert|requires|ensures)(\\s)',
  86. push:
  87. [ { token: 'meta.declaration.assertion.vala',
  88. regex: '$',
  89. next: 'pop' },
  90. { token: 'keyword.operator.assert.expression-seperator.vala',
  91. regex: ':' },
  92. { include: '#code' },
  93. { defaultToken: 'meta.declaration.assertion.vala' } ] } ],
  94. '#class':
  95. [ { token: 'meta.class.vala',
  96. regex: '(?=\\w?[\\w\\s]*(?:class|(?:@)?interface|enum|struct|namespace)\\s+\\w+)',
  97. push:
  98. [ { token: 'paren.vala',
  99. regex: '}',
  100. next: 'pop' },
  101. { include: '#storage-modifiers' },
  102. { include: '#comments' },
  103. { token:
  104. [ 'storage.modifier.vala',
  105. 'meta.class.identifier.vala',
  106. 'entity.name.type.class.vala' ],
  107. regex: '(class|(?:@)?interface|enum|struct|namespace)(\\s+)([\\w\\.]+)' },
  108. { token: 'storage.modifier.extends.vala',
  109. regex: ':',
  110. push:
  111. [ { token: 'meta.definition.class.inherited.classes.vala',
  112. regex: '(?={|,)',
  113. next: 'pop' },
  114. { include: '#object-types-inherited' },
  115. { include: '#comments' },
  116. { defaultToken: 'meta.definition.class.inherited.classes.vala' } ] },
  117. { token:
  118. [ 'storage.modifier.implements.vala',
  119. 'meta.definition.class.implemented.interfaces.vala' ],
  120. regex: '(,)(\\s)',
  121. push:
  122. [ { token: 'meta.definition.class.implemented.interfaces.vala',
  123. regex: '(?=\\{)',
  124. next: 'pop' },
  125. { include: '#object-types-inherited' },
  126. { include: '#comments' },
  127. { defaultToken: 'meta.definition.class.implemented.interfaces.vala' } ] },
  128. { token: 'paren.vala',
  129. regex: '{',
  130. push:
  131. [ { token: 'paren.vala', regex: '(?=})', next: 'pop' },
  132. { include: '#class-body' },
  133. { defaultToken: 'meta.class.body.vala' } ] },
  134. { defaultToken: 'meta.class.vala' } ],
  135. comment: 'attempting to put namespace in here.' } ],
  136. '#class-body':
  137. [ { include: '#comments' },
  138. { include: '#class' },
  139. { include: '#enums' },
  140. { include: '#methods' },
  141. { include: '#annotations' },
  142. { include: '#storage-modifiers' },
  143. { include: '#code' } ],
  144. '#code':
  145. [ { include: '#comments' },
  146. { include: '#class' },
  147. { token: 'text',
  148. regex: '{',
  149. push:
  150. [ { token: 'text', regex: '}', next: 'pop' },
  151. { include: '#code' } ] },
  152. { include: '#assertions' },
  153. { include: '#parens' },
  154. { include: '#constants-and-special-vars' },
  155. { include: '#anonymous-classes-and-new' },
  156. { include: '#keywords' },
  157. { include: '#storage-modifiers' },
  158. { include: '#strings' },
  159. { include: '#all-types' } ],
  160. '#comments':
  161. [ { token: 'punctuation.definition.comment.vala',
  162. regex: '/\\*\\*/' },
  163. { include: 'text.html.javadoc' },
  164. { include: '#comments-inline' } ],
  165. '#comments-inline':
  166. [ { token: 'punctuation.definition.comment.vala',
  167. regex: '/\\*',
  168. push:
  169. [ { token: 'punctuation.definition.comment.vala',
  170. regex: '\\*/',
  171. next: 'pop' },
  172. { defaultToken: 'comment.block.vala' } ] },
  173. { token:
  174. [ 'text',
  175. 'punctuation.definition.comment.vala',
  176. 'comment.line.double-slash.vala' ],
  177. regex: '(\\s*)(//)(.*$)' } ],
  178. '#constants-and-special-vars':
  179. [ { token: 'constant.language.vala',
  180. regex: '\\b(?:true|false|null)\\b' },
  181. { token: 'variable.language.vala',
  182. regex: '\\b(?:this|base)\\b' },
  183. { token: 'constant.numeric.vala',
  184. regex: '\\b(?:0(?:x|X)[0-9a-fA-F]*|(?:[0-9]+\\.?[0-9]*|\\.[0-9]+)(?:(?:e|E)(?:\\+|-)?[0-9]+)?)(?:[LlFfUuDd]|UL|ul)?\\b' },
  185. { token: [ 'keyword.operator.dereference.vala', 'constant.other.vala' ],
  186. regex: '((?:\\.)?)\\b([A-Z][A-Z0-9_]+)(?!<|\\.class|\\s*\\w+\\s*=)\\b' } ],
  187. '#enums':
  188. [ { token: 'text',
  189. regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
  190. push:
  191. [ { token: 'text', regex: '(?=;|})', next: 'pop' },
  192. { token: 'constant.other.enum.vala',
  193. regex: '\\w+',
  194. push:
  195. [ { token: 'meta.enum.vala', regex: '(?=,|;|})', next: 'pop' },
  196. { include: '#parens' },
  197. { token: 'text',
  198. regex: '{',
  199. push:
  200. [ { token: 'text', regex: '}', next: 'pop' },
  201. { include: '#class-body' } ] },
  202. { defaultToken: 'meta.enum.vala' } ] } ] } ],
  203. '#keywords':
  204. [ { token: 'keyword.control.catch-exception.vala',
  205. regex: '\\b(?:try|catch|finally|throw)\\b' },
  206. { token: 'keyword.control.vala', regex: '\\?|:|\\?\\?' },
  207. { token: 'keyword.control.vala',
  208. regex: '\\b(?:return|break|case|continue|default|do|while|for|foreach|switch|if|else|in|yield|get|set|value)\\b' },
  209. { token: 'keyword.operator.vala',
  210. regex: '\\b(?:typeof|is|as)\\b' },
  211. { token: 'keyword.operator.comparison.vala',
  212. regex: '==|!=|<=|>=|<>|<|>' },
  213. { token: 'keyword.operator.assignment.vala', regex: '=' },
  214. { token: 'keyword.operator.increment-decrement.vala',
  215. regex: '\\-\\-|\\+\\+' },
  216. { token: 'keyword.operator.arithmetic.vala',
  217. regex: '\\-|\\+|\\*|\\/|%' },
  218. { token: 'keyword.operator.logical.vala', regex: '!|&&|\\|\\|' },
  219. { token: 'keyword.operator.dereference.vala',
  220. regex: '\\.(?=\\S)',
  221. originalRegex: '(?<=\\S)\\.(?=\\S)' },
  222. { token: 'punctuation.terminator.vala', regex: ';' },
  223. { token: 'keyword.operator.ownership', regex: 'owned|unowned' } ],
  224. '#methods':
  225. [ { token: 'meta.method.vala',
  226. regex: '(?!new)(?=\\w.*\\s+)(?=[^=]+\\()',
  227. push:
  228. [ { token: 'paren.vala', regex: '}|(?=;)', next: 'pop' },
  229. { include: '#storage-modifiers' },
  230. { token: [ 'entity.name.function.vala', 'meta.method.identifier.vala' ],
  231. regex: '([\\~\\w\\.]+)(\\s*\\()',
  232. push:
  233. [ { token: 'meta.method.identifier.vala',
  234. regex: '\\)',
  235. next: 'pop' },
  236. { include: '#parameters' },
  237. { defaultToken: 'meta.method.identifier.vala' } ] },
  238. { token: 'meta.method.return-type.vala',
  239. regex: '(?=\\w.*\\s+\\w+\\s*\\()',
  240. push:
  241. [ { token: 'meta.method.return-type.vala',
  242. regex: '(?=\\w+\\s*\\()',
  243. next: 'pop' },
  244. { include: '#all-types' },
  245. { defaultToken: 'meta.method.return-type.vala' } ] },
  246. { include: '#throws' },
  247. { token: 'paren.vala',
  248. regex: '{',
  249. push:
  250. [ { token: 'paren.vala', regex: '(?=})', next: 'pop' },
  251. { include: '#code' },
  252. { defaultToken: 'meta.method.body.vala' } ] },
  253. { defaultToken: 'meta.method.vala' } ] } ],
  254. '#namespace':
  255. [ { token: 'text',
  256. regex: '^(?=\\s*[A-Z0-9_]+\\s*(?:{|\\(|,))',
  257. push:
  258. [ { token: 'text', regex: '(?=;|})', next: 'pop' },
  259. { token: 'constant.other.namespace.vala',
  260. regex: '\\w+',
  261. push:
  262. [ { token: 'meta.namespace.vala', regex: '(?=,|;|})', next: 'pop' },
  263. { include: '#parens' },
  264. { token: 'text',
  265. regex: '{',
  266. push:
  267. [ { token: 'text', regex: '}', next: 'pop' },
  268. { include: '#code' } ] },
  269. { defaultToken: 'meta.namespace.vala' } ] } ],
  270. comment: 'This is not quite right. See the class grammar right now' } ],
  271. '#object-types':
  272. [ { token: 'storage.type.generic.vala',
  273. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
  274. push:
  275. [ { token: 'storage.type.generic.vala',
  276. regex: '>|[^\\w\\s,\\?<\\[()\\]]',
  277. TODO: 'FIXME: regexp doesn\'t have js equivalent',
  278. originalRegex: '>|[^\\w\\s,\\?<\\[(?:[,]+)\\]]',
  279. next: 'pop' },
  280. { include: '#object-types' },
  281. { token: 'storage.type.generic.vala',
  282. regex: '<',
  283. push:
  284. [ { token: 'storage.type.generic.vala',
  285. regex: '>|[^\\w\\s,\\[\\]<]',
  286. next: 'pop' },
  287. { defaultToken: 'storage.type.generic.vala' } ],
  288. comment: 'This is just to support <>\'s with no actual type prefix' },
  289. { defaultToken: 'storage.type.generic.vala' } ] },
  290. { token: 'storage.type.object.array.vala',
  291. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*(?=\\[)',
  292. push:
  293. [ { token: 'storage.type.object.array.vala',
  294. regex: '(?=[^\\]\\s])',
  295. next: 'pop' },
  296. { token: 'text',
  297. regex: '\\[',
  298. push:
  299. [ { token: 'text', regex: '\\]', next: 'pop' },
  300. { include: '#code' } ] },
  301. { defaultToken: 'storage.type.object.array.vala' } ] },
  302. { token:
  303. [ 'storage.type.vala',
  304. 'keyword.operator.dereference.vala',
  305. 'storage.type.vala' ],
  306. regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*\\b)' } ],
  307. '#object-types-inherited':
  308. [ { token: 'entity.other.inherited-class.vala',
  309. regex: '\\b(?:[a-z]\\w*\\.)*[A-Z]+\\w*<',
  310. push:
  311. [ { token: 'entity.other.inherited-class.vala',
  312. regex: '>|[^\\w\\s,<]',
  313. next: 'pop' },
  314. { include: '#object-types' },
  315. { token: 'storage.type.generic.vala',
  316. regex: '<',
  317. push:
  318. [ { token: 'storage.type.generic.vala',
  319. regex: '>|[^\\w\\s,<]',
  320. next: 'pop' },
  321. { defaultToken: 'storage.type.generic.vala' } ],
  322. comment: 'This is just to support <>\'s with no actual type prefix' },
  323. { defaultToken: 'entity.other.inherited-class.vala' } ] },
  324. { token:
  325. [ 'entity.other.inherited-class.vala',
  326. 'keyword.operator.dereference.vala',
  327. 'entity.other.inherited-class.vala' ],
  328. regex: '\\b(?:([a-z]\\w*)(\\.))*([A-Z]+\\w*)' } ],
  329. '#parameters':
  330. [ { token: 'storage.modifier.vala', regex: 'final' },
  331. { include: '#primitive-arrays' },
  332. { include: '#primitive-types' },
  333. { include: '#object-types' },
  334. { token: 'variable.parameter.vala', regex: '\\w+' } ],
  335. '#parens':
  336. [ { token: 'text',
  337. regex: '\\(',
  338. push:
  339. [ { token: 'text', regex: '\\)', next: 'pop' },
  340. { include: '#code' } ] } ],
  341. '#primitive-arrays':
  342. [ { token: 'storage.type.primitive.array.vala',
  343. 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' } ],
  344. '#primitive-types':
  345. [ { token: 'storage.type.primitive.vala',
  346. 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',
  347. comment: 'var is not really a primitive, but acts like one in most cases' } ],
  348. '#storage-modifiers':
  349. [ { token: 'storage.modifier.vala',
  350. regex: '\\b(?:public|private|protected|internal|static|final|sealed|virtual|override|abstract|readonly|volatile|dynamic|async|unsafe|out|ref|weak|owned|unowned|const)\\b',
  351. comment: 'Not sure about unsafe and readonly' } ],
  352. '#strings':
  353. [ { token: 'punctuation.definition.string.begin.vala',
  354. regex: '@"',
  355. push:
  356. [ { token: 'punctuation.definition.string.end.vala',
  357. regex: '"',
  358. next: 'pop' },
  359. { token: 'constant.character.escape.vala',
  360. regex: '\\\\.|%[\\w\\.\\-]+|\\$(?:\\w+|\\([\\w\\s\\+\\-\\*\\/]+\\))' },
  361. { defaultToken: 'string.quoted.interpolated.vala' } ] },
  362. { token: 'punctuation.definition.string.begin.vala',
  363. regex: '"',
  364. push:
  365. [ { token: 'punctuation.definition.string.end.vala',
  366. regex: '"',
  367. next: 'pop' },
  368. { token: 'constant.character.escape.vala', regex: '\\\\.' },
  369. { token: 'constant.character.escape.vala',
  370. regex: '%[\\w\\.\\-]+' },
  371. { defaultToken: 'string.quoted.double.vala' } ] },
  372. { token: 'punctuation.definition.string.begin.vala',
  373. regex: '\'',
  374. push:
  375. [ { token: 'punctuation.definition.string.end.vala',
  376. regex: '\'',
  377. next: 'pop' },
  378. { token: 'constant.character.escape.vala', regex: '\\\\.' },
  379. { defaultToken: 'string.quoted.single.vala' } ] },
  380. { token: 'punctuation.definition.string.begin.vala',
  381. regex: '"""',
  382. push:
  383. [ { token: 'punctuation.definition.string.end.vala',
  384. regex: '"""',
  385. next: 'pop' },
  386. { token: 'constant.character.escape.vala',
  387. regex: '%[\\w\\.\\-]+' },
  388. { defaultToken: 'string.quoted.triple.vala' } ] } ],
  389. '#throws':
  390. [ { token: 'storage.modifier.vala',
  391. regex: 'throws',
  392. push:
  393. [ { token: 'meta.throwables.vala', regex: '(?={|;)', next: 'pop' },
  394. { include: '#object-types' },
  395. { defaultToken: 'meta.throwables.vala' } ] } ],
  396. '#values':
  397. [ { include: '#strings' },
  398. { include: '#object-types' },
  399. { include: '#constants-and-special-vars' } ] }
  400. this.normalizeRules();
  401. };
  402. ValaHighlightRules.metaData = {
  403. 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',
  404. fileTypes: [ 'vala' ],
  405. foldingStartMarker: '(\\{\\s*(//.*)?$|^\\s*// \\{\\{\\{)',
  406. foldingStopMarker: '^\\s*(\\}|// \\}\\}\\}$)',
  407. name: 'Vala',
  408. scopeName: 'source.vala' }
  409. oop.inherits(ValaHighlightRules, TextHighlightRules);
  410. exports.ValaHighlightRules = ValaHighlightRules;
  411. });
  412. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  413. "use strict";
  414. var oop = require("../../lib/oop");
  415. var Range = require("../../range").Range;
  416. var BaseFoldMode = require("./fold_mode").FoldMode;
  417. var FoldMode = exports.FoldMode = function(commentRegex) {
  418. if (commentRegex) {
  419. this.foldingStartMarker = new RegExp(
  420. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  421. );
  422. this.foldingStopMarker = new RegExp(
  423. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  424. );
  425. }
  426. };
  427. oop.inherits(FoldMode, BaseFoldMode);
  428. (function() {
  429. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  430. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  431. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  432. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  433. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  434. this._getFoldWidgetBase = this.getFoldWidget;
  435. this.getFoldWidget = function(session, foldStyle, row) {
  436. var line = session.getLine(row);
  437. if (this.singleLineBlockCommentRe.test(line)) {
  438. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  439. return "";
  440. }
  441. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  442. if (!fw && this.startRegionRe.test(line))
  443. return "start"; // lineCommentRegionStart
  444. return fw;
  445. };
  446. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  447. var line = session.getLine(row);
  448. if (this.startRegionRe.test(line))
  449. return this.getCommentRegionBlock(session, line, row);
  450. var match = line.match(this.foldingStartMarker);
  451. if (match) {
  452. var i = match.index;
  453. if (match[1])
  454. return this.openingBracketBlock(session, match[1], row, i);
  455. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  456. if (range && !range.isMultiLine()) {
  457. if (forceMultiline) {
  458. range = this.getSectionRange(session, row);
  459. } else if (foldStyle != "all")
  460. range = null;
  461. }
  462. return range;
  463. }
  464. if (foldStyle === "markbegin")
  465. return;
  466. var match = line.match(this.foldingStopMarker);
  467. if (match) {
  468. var i = match.index + match[0].length;
  469. if (match[1])
  470. return this.closingBracketBlock(session, match[1], row, i);
  471. return session.getCommentFoldRange(row, i, -1);
  472. }
  473. };
  474. this.getSectionRange = function(session, row) {
  475. var line = session.getLine(row);
  476. var startIndent = line.search(/\S/);
  477. var startRow = row;
  478. var startColumn = line.length;
  479. row = row + 1;
  480. var endRow = row;
  481. var maxRow = session.getLength();
  482. while (++row < maxRow) {
  483. line = session.getLine(row);
  484. var indent = line.search(/\S/);
  485. if (indent === -1)
  486. continue;
  487. if (startIndent > indent)
  488. break;
  489. var subRange = this.getFoldWidgetRange(session, "all", row);
  490. if (subRange) {
  491. if (subRange.start.row <= startRow) {
  492. break;
  493. } else if (subRange.isMultiLine()) {
  494. row = subRange.end.row;
  495. } else if (startIndent == indent) {
  496. break;
  497. }
  498. }
  499. endRow = row;
  500. }
  501. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  502. };
  503. this.getCommentRegionBlock = function(session, line, row) {
  504. var startColumn = line.search(/\s*$/);
  505. var maxRow = session.getLength();
  506. var startRow = row;
  507. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  508. var depth = 1;
  509. while (++row < maxRow) {
  510. line = session.getLine(row);
  511. var m = re.exec(line);
  512. if (!m) continue;
  513. if (m[1]) depth--;
  514. else depth++;
  515. if (!depth) break;
  516. }
  517. var endRow = row;
  518. if (endRow > startRow) {
  519. return new Range(startRow, startColumn, endRow, line.length);
  520. }
  521. };
  522. }).call(FoldMode.prototype);
  523. });
  524. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  525. "use strict";
  526. var Range = require("../range").Range;
  527. var MatchingBraceOutdent = function() {};
  528. (function() {
  529. this.checkOutdent = function(line, input) {
  530. if (! /^\s+$/.test(line))
  531. return false;
  532. return /^\s*\}/.test(input);
  533. };
  534. this.autoOutdent = function(doc, row) {
  535. var line = doc.getLine(row);
  536. var match = line.match(/^(\s*\})/);
  537. if (!match) return 0;
  538. var column = match[1].length;
  539. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  540. if (!openBracePos || openBracePos.row == row) return 0;
  541. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  542. doc.replace(new Range(row, 0, row, column-1), indent);
  543. };
  544. this.$getIndent = function(line) {
  545. return line.match(/^\s*/)[0];
  546. };
  547. }).call(MatchingBraceOutdent.prototype);
  548. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  549. });
  550. ace.define("ace/mode/vala",["require","exports","module","ace/lib/oop","ace/mode/text","ace/tokenizer","ace/mode/vala_highlight_rules","ace/mode/folding/cstyle","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/mode/matching_brace_outdent"], function(require, exports, module) {
  551. "use strict";
  552. var oop = require("../lib/oop");
  553. var TextMode = require("./text").Mode;
  554. var Tokenizer = require("../tokenizer").Tokenizer;
  555. var ValaHighlightRules = require("./vala_highlight_rules").ValaHighlightRules;
  556. var FoldMode = require("./folding/cstyle").FoldMode;
  557. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  558. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  559. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  560. var Mode = function() {
  561. this.HighlightRules = ValaHighlightRules;
  562. this.$outdent = new MatchingBraceOutdent();
  563. this.$behaviour = new CstyleBehaviour();
  564. this.foldingRules = new CStyleFoldMode();
  565. };
  566. oop.inherits(Mode, TextMode);
  567. (function() {
  568. this.lineCommentStart = "//";
  569. this.blockComment = {start: "/*", end: "*/"};
  570. this.getNextLineIndent = function(state, line, tab) {
  571. var indent = this.$getIndent(line);
  572. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  573. var tokens = tokenizedLine.tokens;
  574. var endState = tokenizedLine.state;
  575. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  576. return indent;
  577. }
  578. if (state == "start" || state == "no_regex") {
  579. var match = line.match(/^.*(?:\bcase\b.*:|[\{\(\[])\s*$/);
  580. if (match) {
  581. indent += tab;
  582. }
  583. } else if (state == "doc-start") {
  584. if (endState == "start" || endState == "no_regex") {
  585. return "";
  586. }
  587. var match = line.match(/^\s*(\/?)\*/);
  588. if (match) {
  589. if (match[1]) {
  590. indent += " ";
  591. }
  592. indent += "* ";
  593. }
  594. }
  595. return indent;
  596. };
  597. this.checkOutdent = function(state, line, input) {
  598. return this.$outdent.checkOutdent(line, input);
  599. };
  600. this.autoOutdent = function(state, doc, row) {
  601. this.$outdent.autoOutdent(doc, row);
  602. };
  603. this.$id = "ace/mode/vala"
  604. }).call(Mode.prototype);
  605. exports.Mode = Mode;
  606. });