mode-svg.js 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658
  1. ace.define("ace/mode/xml_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 XmlHighlightRules = function(normalize) {
  6. this.$rules = {
  7. start : [
  8. {token : "string.cdata.xml", regex : "<\\!\\[CDATA\\[", next : "cdata"},
  9. {
  10. token : ["punctuation.xml-decl.xml", "keyword.xml-decl.xml"],
  11. regex : "(<\\?)(xml)(?=[\\s])", next : "xml_decl", caseInsensitive: true
  12. },
  13. {
  14. token : ["punctuation.instruction.xml", "keyword.instruction.xml"],
  15. regex : "(<\\?)([-_a-zA-Z0-9]+)", next : "processing_instruction",
  16. },
  17. {token : "comment.xml", regex : "<\\!--", next : "comment"},
  18. {
  19. token : ["xml-pe.doctype.xml", "xml-pe.doctype.xml"],
  20. regex : "(<\\!)(DOCTYPE)(?=[\\s])", next : "doctype", caseInsensitive: true
  21. },
  22. {include : "tag"},
  23. {token : "text.end-tag-open.xml", regex: "</"},
  24. {token : "text.tag-open.xml", regex: "<"},
  25. {include : "reference"},
  26. {defaultToken : "text.xml"}
  27. ],
  28. xml_decl : [{
  29. token : "entity.other.attribute-name.decl-attribute-name.xml",
  30. regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
  31. }, {
  32. token : "keyword.operator.decl-attribute-equals.xml",
  33. regex : "="
  34. }, {
  35. include: "whitespace"
  36. }, {
  37. include: "string"
  38. }, {
  39. token : "punctuation.xml-decl.xml",
  40. regex : "\\?>",
  41. next : "start"
  42. }],
  43. processing_instruction : [
  44. {token : "punctuation.instruction.xml", regex : "\\?>", next : "start"},
  45. {defaultToken : "instruction.xml"}
  46. ],
  47. doctype : [
  48. {include : "whitespace"},
  49. {include : "string"},
  50. {token : "xml-pe.doctype.xml", regex : ">", next : "start"},
  51. {token : "xml-pe.xml", regex : "[-_a-zA-Z0-9:]+"},
  52. {token : "punctuation.int-subset", regex : "\\[", push : "int_subset"}
  53. ],
  54. int_subset : [{
  55. token : "text.xml",
  56. regex : "\\s+"
  57. }, {
  58. token: "punctuation.int-subset.xml",
  59. regex: "]",
  60. next: "pop"
  61. }, {
  62. token : ["punctuation.markup-decl.xml", "keyword.markup-decl.xml"],
  63. regex : "(<\\!)([-_a-zA-Z0-9]+)",
  64. push : [{
  65. token : "text",
  66. regex : "\\s+"
  67. },
  68. {
  69. token : "punctuation.markup-decl.xml",
  70. regex : ">",
  71. next : "pop"
  72. },
  73. {include : "string"}]
  74. }],
  75. cdata : [
  76. {token : "string.cdata.xml", regex : "\\]\\]>", next : "start"},
  77. {token : "text.xml", regex : "\\s+"},
  78. {token : "text.xml", regex : "(?:[^\\]]|\\](?!\\]>))+"}
  79. ],
  80. comment : [
  81. {token : "comment.xml", regex : "-->", next : "start"},
  82. {defaultToken : "comment.xml"}
  83. ],
  84. reference : [{
  85. token : "constant.language.escape.reference.xml",
  86. regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
  87. }],
  88. attr_reference : [{
  89. token : "constant.language.escape.reference.attribute-value.xml",
  90. regex : "(?:&#[0-9]+;)|(?:&#x[0-9a-fA-F]+;)|(?:&[a-zA-Z0-9_:\\.-]+;)"
  91. }],
  92. tag : [{
  93. token : ["meta.tag.punctuation.tag-open.xml", "meta.tag.punctuation.end-tag-open.xml", "meta.tag.tag-name.xml"],
  94. regex : "(?:(<)|(</))((?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+)",
  95. next: [
  96. {include : "attributes"},
  97. {token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : "start"}
  98. ]
  99. }],
  100. tag_whitespace : [
  101. {token : "text.tag-whitespace.xml", regex : "\\s+"}
  102. ],
  103. whitespace : [
  104. {token : "text.whitespace.xml", regex : "\\s+"}
  105. ],
  106. string: [{
  107. token : "string.xml",
  108. regex : "'",
  109. push : [
  110. {token : "string.xml", regex: "'", next: "pop"},
  111. {defaultToken : "string.xml"}
  112. ]
  113. }, {
  114. token : "string.xml",
  115. regex : '"',
  116. push : [
  117. {token : "string.xml", regex: '"', next: "pop"},
  118. {defaultToken : "string.xml"}
  119. ]
  120. }],
  121. attributes: [{
  122. token : "entity.other.attribute-name.xml",
  123. regex : "(?:[-_a-zA-Z0-9]+:)?[-_a-zA-Z0-9]+"
  124. }, {
  125. token : "keyword.operator.attribute-equals.xml",
  126. regex : "="
  127. }, {
  128. include: "tag_whitespace"
  129. }, {
  130. include: "attribute_value"
  131. }],
  132. attribute_value: [{
  133. token : "string.attribute-value.xml",
  134. regex : "'",
  135. push : [
  136. {token : "string.attribute-value.xml", regex: "'", next: "pop"},
  137. {include : "attr_reference"},
  138. {defaultToken : "string.attribute-value.xml"}
  139. ]
  140. }, {
  141. token : "string.attribute-value.xml",
  142. regex : '"',
  143. push : [
  144. {token : "string.attribute-value.xml", regex: '"', next: "pop"},
  145. {include : "attr_reference"},
  146. {defaultToken : "string.attribute-value.xml"}
  147. ]
  148. }]
  149. };
  150. if (this.constructor === XmlHighlightRules)
  151. this.normalizeRules();
  152. };
  153. (function() {
  154. this.embedTagRules = function(HighlightRules, prefix, tag){
  155. this.$rules.tag.unshift({
  156. token : ["meta.tag.punctuation.tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
  157. regex : "(<)(" + tag + "(?=\\s|>|$))",
  158. next: [
  159. {include : "attributes"},
  160. {token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next : prefix + "start"}
  161. ]
  162. });
  163. this.$rules[tag + "-end"] = [
  164. {include : "attributes"},
  165. {token : "meta.tag.punctuation.tag-close.xml", regex : "/?>", next: "start",
  166. onMatch : function(value, currentState, stack) {
  167. stack.splice(0);
  168. return this.token;
  169. }}
  170. ]
  171. this.embedRules(HighlightRules, prefix, [{
  172. token: ["meta.tag.punctuation.end-tag-open.xml", "meta.tag." + tag + ".tag-name.xml"],
  173. regex : "(</)(" + tag + "(?=\\s|>|$))",
  174. next: tag + "-end"
  175. }, {
  176. token: "string.cdata.xml",
  177. regex : "<\\!\\[CDATA\\["
  178. }, {
  179. token: "string.cdata.xml",
  180. regex : "\\]\\]>"
  181. }]);
  182. };
  183. }).call(TextHighlightRules.prototype);
  184. oop.inherits(XmlHighlightRules, TextHighlightRules);
  185. exports.XmlHighlightRules = XmlHighlightRules;
  186. });
  187. ace.define("ace/mode/behaviour/xml",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator"], function(require, exports, module) {
  188. "use strict";
  189. var oop = require("../../lib/oop");
  190. var Behaviour = require("../behaviour").Behaviour;
  191. var TokenIterator = require("../../token_iterator").TokenIterator;
  192. function is(token, type) {
  193. return token.type.lastIndexOf(type + ".xml") > -1;
  194. }
  195. var XmlBehaviour = function () {
  196. this.add("string_dquotes", "insertion", function (state, action, editor, session, text) {
  197. if (text == '"' || text == "'") {
  198. var quote = text;
  199. var selected = session.doc.getTextRange(editor.getSelectionRange());
  200. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  201. return {
  202. text: quote + selected + quote,
  203. selection: false
  204. };
  205. }
  206. var cursor = editor.getCursorPosition();
  207. var line = session.doc.getLine(cursor.row);
  208. var rightChar = line.substring(cursor.column, cursor.column + 1);
  209. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  210. var token = iterator.getCurrentToken();
  211. if (rightChar == quote && (is(token, "attribute-value") || is(token, "string"))) {
  212. return {
  213. text: "",
  214. selection: [1, 1]
  215. };
  216. }
  217. if (!token)
  218. token = iterator.stepBackward();
  219. if (!token)
  220. return;
  221. while (is(token, "tag-whitespace") || is(token, "whitespace")) {
  222. token = iterator.stepBackward();
  223. }
  224. var rightSpace = !rightChar || rightChar.match(/\s/);
  225. if (is(token, "attribute-equals") && (rightSpace || rightChar == '>') || (is(token, "decl-attribute-equals") && (rightSpace || rightChar == '?'))) {
  226. return {
  227. text: quote + quote,
  228. selection: [1, 1]
  229. };
  230. }
  231. }
  232. });
  233. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  234. var selected = session.doc.getTextRange(range);
  235. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  236. var line = session.doc.getLine(range.start.row);
  237. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  238. if (rightChar == selected) {
  239. range.end.column++;
  240. return range;
  241. }
  242. }
  243. });
  244. this.add("autoclosing", "insertion", function (state, action, editor, session, text) {
  245. if (text == '>') {
  246. var position = editor.getCursorPosition();
  247. var iterator = new TokenIterator(session, position.row, position.column);
  248. var token = iterator.getCurrentToken() || iterator.stepBackward();
  249. if (!token || !(is(token, "tag-name") || is(token, "tag-whitespace") || is(token, "attribute-name") || is(token, "attribute-equals") || is(token, "attribute-value")))
  250. return;
  251. if (is(token, "reference.attribute-value"))
  252. return;
  253. if (is(token, "attribute-value")) {
  254. var firstChar = token.value.charAt(0);
  255. if (firstChar == '"' || firstChar == "'") {
  256. var lastChar = token.value.charAt(token.value.length - 1);
  257. var tokenEnd = iterator.getCurrentTokenColumn() + token.value.length;
  258. if (tokenEnd > position.column || tokenEnd == position.column && firstChar != lastChar)
  259. return;
  260. }
  261. }
  262. while (!is(token, "tag-name")) {
  263. token = iterator.stepBackward();
  264. }
  265. var tokenRow = iterator.getCurrentTokenRow();
  266. var tokenColumn = iterator.getCurrentTokenColumn();
  267. if (is(iterator.stepBackward(), "end-tag-open"))
  268. return;
  269. var element = token.value;
  270. if (tokenRow == position.row)
  271. element = element.substring(0, position.column - tokenColumn);
  272. if (this.voidElements.hasOwnProperty(element.toLowerCase()))
  273. return;
  274. return {
  275. text: '>' + '</' + element + '>',
  276. selection: [1, 1]
  277. };
  278. }
  279. });
  280. this.add('autoindent', 'insertion', function (state, action, editor, session, text) {
  281. if (text == "\n") {
  282. var cursor = editor.getCursorPosition();
  283. var line = session.getLine(cursor.row);
  284. var rightChars = line.substring(cursor.column, cursor.column + 2);
  285. if (rightChars == '</') {
  286. var next_indent = this.$getIndent(line);
  287. var indent = next_indent + session.getTabString();
  288. return {
  289. text: '\n' + indent + '\n' + next_indent,
  290. selection: [1, indent.length, 1, indent.length]
  291. };
  292. }
  293. }
  294. });
  295. };
  296. oop.inherits(XmlBehaviour, Behaviour);
  297. exports.XmlBehaviour = XmlBehaviour;
  298. });
  299. ace.define("ace/mode/folding/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/range","ace/mode/folding/fold_mode","ace/token_iterator"], function(require, exports, module) {
  300. "use strict";
  301. var oop = require("../../lib/oop");
  302. var lang = require("../../lib/lang");
  303. var Range = require("../../range").Range;
  304. var BaseFoldMode = require("./fold_mode").FoldMode;
  305. var TokenIterator = require("../../token_iterator").TokenIterator;
  306. var FoldMode = exports.FoldMode = function(voidElements, optionalEndTags) {
  307. BaseFoldMode.call(this);
  308. this.voidElements = oop.mixin(voidElements || {}, optionalEndTags || {});
  309. };
  310. oop.inherits(FoldMode, BaseFoldMode);
  311. var Tag = function() {
  312. this.tagName = "";
  313. this.closing = false;
  314. this.selfClosing = false;
  315. this.start = {row: 0, column: 0};
  316. this.end = {row: 0, column: 0};
  317. };
  318. function is(token, type) {
  319. return token.type.lastIndexOf(type + ".xml") > -1;
  320. }
  321. (function() {
  322. this.getFoldWidget = function(session, foldStyle, row) {
  323. var tag = this._getFirstTagInLine(session, row);
  324. if (!tag)
  325. return "";
  326. if (tag.closing || (!tag.tagName && tag.selfClosing))
  327. return foldStyle == "markbeginend" ? "end" : "";
  328. if (!tag.tagName || tag.selfClosing || this.voidElements.hasOwnProperty(tag.tagName.toLowerCase()))
  329. return "";
  330. if (this._findEndTagInLine(session, row, tag.tagName, tag.end.column))
  331. return "";
  332. return "start";
  333. };
  334. this._getFirstTagInLine = function(session, row) {
  335. var tokens = session.getTokens(row);
  336. var tag = new Tag();
  337. for (var i = 0; i < tokens.length; i++) {
  338. var token = tokens[i];
  339. if (is(token, "tag-open")) {
  340. tag.end.column = tag.start.column + token.value.length;
  341. tag.closing = is(token, "end-tag-open");
  342. token = tokens[++i];
  343. if (!token)
  344. return null;
  345. tag.tagName = token.value;
  346. tag.end.column += token.value.length;
  347. for (i++; i < tokens.length; i++) {
  348. token = tokens[i];
  349. tag.end.column += token.value.length;
  350. if (is(token, "tag-close")) {
  351. tag.selfClosing = token.value == '/>';
  352. break;
  353. }
  354. }
  355. return tag;
  356. } else if (is(token, "tag-close")) {
  357. tag.selfClosing = token.value == '/>';
  358. return tag;
  359. }
  360. tag.start.column += token.value.length;
  361. }
  362. return null;
  363. };
  364. this._findEndTagInLine = function(session, row, tagName, startColumn) {
  365. var tokens = session.getTokens(row);
  366. var column = 0;
  367. for (var i = 0; i < tokens.length; i++) {
  368. var token = tokens[i];
  369. column += token.value.length;
  370. if (column < startColumn)
  371. continue;
  372. if (is(token, "end-tag-open")) {
  373. token = tokens[i + 1];
  374. if (token && token.value == tagName)
  375. return true;
  376. }
  377. }
  378. return false;
  379. };
  380. this._readTagForward = function(iterator) {
  381. var token = iterator.getCurrentToken();
  382. if (!token)
  383. return null;
  384. var tag = new Tag();
  385. do {
  386. if (is(token, "tag-open")) {
  387. tag.closing = is(token, "end-tag-open");
  388. tag.start.row = iterator.getCurrentTokenRow();
  389. tag.start.column = iterator.getCurrentTokenColumn();
  390. } else if (is(token, "tag-name")) {
  391. tag.tagName = token.value;
  392. } else if (is(token, "tag-close")) {
  393. tag.selfClosing = token.value == "/>";
  394. tag.end.row = iterator.getCurrentTokenRow();
  395. tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
  396. iterator.stepForward();
  397. return tag;
  398. }
  399. } while(token = iterator.stepForward());
  400. return null;
  401. };
  402. this._readTagBackward = function(iterator) {
  403. var token = iterator.getCurrentToken();
  404. if (!token)
  405. return null;
  406. var tag = new Tag();
  407. do {
  408. if (is(token, "tag-open")) {
  409. tag.closing = is(token, "end-tag-open");
  410. tag.start.row = iterator.getCurrentTokenRow();
  411. tag.start.column = iterator.getCurrentTokenColumn();
  412. iterator.stepBackward();
  413. return tag;
  414. } else if (is(token, "tag-name")) {
  415. tag.tagName = token.value;
  416. } else if (is(token, "tag-close")) {
  417. tag.selfClosing = token.value == "/>";
  418. tag.end.row = iterator.getCurrentTokenRow();
  419. tag.end.column = iterator.getCurrentTokenColumn() + token.value.length;
  420. }
  421. } while(token = iterator.stepBackward());
  422. return null;
  423. };
  424. this._pop = function(stack, tag) {
  425. while (stack.length) {
  426. var top = stack[stack.length-1];
  427. if (!tag || top.tagName == tag.tagName) {
  428. return stack.pop();
  429. }
  430. else if (this.voidElements.hasOwnProperty(tag.tagName)) {
  431. return;
  432. }
  433. else if (this.voidElements.hasOwnProperty(top.tagName)) {
  434. stack.pop();
  435. continue;
  436. } else {
  437. return null;
  438. }
  439. }
  440. };
  441. this.getFoldWidgetRange = function(session, foldStyle, row) {
  442. var firstTag = this._getFirstTagInLine(session, row);
  443. if (!firstTag)
  444. return null;
  445. var isBackward = firstTag.closing || firstTag.selfClosing;
  446. var stack = [];
  447. var tag;
  448. if (!isBackward) {
  449. var iterator = new TokenIterator(session, row, firstTag.start.column);
  450. var start = {
  451. row: row,
  452. column: firstTag.start.column + firstTag.tagName.length + 2
  453. };
  454. while (tag = this._readTagForward(iterator)) {
  455. if (tag.selfClosing) {
  456. if (!stack.length) {
  457. tag.start.column += tag.tagName.length + 2;
  458. tag.end.column -= 2;
  459. return Range.fromPoints(tag.start, tag.end);
  460. } else
  461. continue;
  462. }
  463. if (tag.closing) {
  464. this._pop(stack, tag);
  465. if (stack.length == 0)
  466. return Range.fromPoints(start, tag.start);
  467. }
  468. else {
  469. stack.push(tag);
  470. }
  471. }
  472. }
  473. else {
  474. var iterator = new TokenIterator(session, row, firstTag.end.column);
  475. var end = {
  476. row: row,
  477. column: firstTag.start.column
  478. };
  479. while (tag = this._readTagBackward(iterator)) {
  480. if (tag.selfClosing) {
  481. if (!stack.length) {
  482. tag.start.column += tag.tagName.length + 2;
  483. tag.end.column -= 2;
  484. return Range.fromPoints(tag.start, tag.end);
  485. } else
  486. continue;
  487. }
  488. if (!tag.closing) {
  489. this._pop(stack, tag);
  490. if (stack.length == 0) {
  491. tag.start.column += tag.tagName.length + 2;
  492. return Range.fromPoints(tag.start, end);
  493. }
  494. }
  495. else {
  496. stack.push(tag);
  497. }
  498. }
  499. }
  500. };
  501. }).call(FoldMode.prototype);
  502. });
  503. ace.define("ace/mode/xml",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text","ace/mode/xml_highlight_rules","ace/mode/behaviour/xml","ace/mode/folding/xml"], function(require, exports, module) {
  504. "use strict";
  505. var oop = require("../lib/oop");
  506. var lang = require("../lib/lang");
  507. var TextMode = require("./text").Mode;
  508. var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
  509. var XmlBehaviour = require("./behaviour/xml").XmlBehaviour;
  510. var XmlFoldMode = require("./folding/xml").FoldMode;
  511. var Mode = function() {
  512. this.HighlightRules = XmlHighlightRules;
  513. this.$behaviour = new XmlBehaviour();
  514. this.foldingRules = new XmlFoldMode();
  515. };
  516. oop.inherits(Mode, TextMode);
  517. (function() {
  518. this.voidElements = lang.arrayToMap([]);
  519. this.blockComment = {start: "<!--", end: "-->"};
  520. this.$id = "ace/mode/xml";
  521. }).call(Mode.prototype);
  522. exports.Mode = Mode;
  523. });
  524. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  525. "use strict";
  526. var oop = require("../lib/oop");
  527. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  528. var DocCommentHighlightRules = function() {
  529. this.$rules = {
  530. "start" : [ {
  531. token : "comment.doc.tag",
  532. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  533. }, {
  534. token : "comment.doc.tag",
  535. regex : "\\bTODO\\b"
  536. }, {
  537. defaultToken : "comment.doc"
  538. }]
  539. };
  540. };
  541. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  542. DocCommentHighlightRules.getStartRule = function(start) {
  543. return {
  544. token : "comment.doc", // doc comment
  545. regex : "\\/\\*(?=\\*)",
  546. next : start
  547. };
  548. };
  549. DocCommentHighlightRules.getEndRule = function (start) {
  550. return {
  551. token : "comment.doc", // closing comment
  552. regex : "\\*\\/",
  553. next : start
  554. };
  555. };
  556. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  557. });
  558. ace.define("ace/mode/javascript_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  559. "use strict";
  560. var oop = require("../lib/oop");
  561. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  562. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  563. var JavaScriptHighlightRules = function() {
  564. var keywordMapper = this.createKeywordMapper({
  565. "variable.language":
  566. "Array|Boolean|Date|Function|Iterator|Number|Object|RegExp|String|Proxy|" + // Constructors
  567. "Namespace|QName|XML|XMLList|" + // E4X
  568. "ArrayBuffer|Float32Array|Float64Array|Int16Array|Int32Array|Int8Array|" +
  569. "Uint16Array|Uint32Array|Uint8Array|Uint8ClampedArray|" +
  570. "Error|EvalError|InternalError|RangeError|ReferenceError|StopIteration|" + // Errors
  571. "SyntaxError|TypeError|URIError|" +
  572. "decodeURI|decodeURIComponent|encodeURI|encodeURIComponent|eval|isFinite|" + // Non-constructor functions
  573. "isNaN|parseFloat|parseInt|" +
  574. "JSON|Math|" + // Other
  575. "this|arguments|prototype|window|document" , // Pseudo
  576. "keyword":
  577. "const|yield|import|get|set|" +
  578. "break|case|catch|continue|default|delete|do|else|finally|for|function|" +
  579. "if|in|instanceof|new|return|switch|throw|try|typeof|let|var|while|with|debugger|" +
  580. "__parent__|__count__|escape|unescape|with|__proto__|" +
  581. "class|enum|extends|super|export|implements|private|public|interface|package|protected|static",
  582. "storage.type":
  583. "const|let|var|function",
  584. "constant.language":
  585. "null|Infinity|NaN|undefined",
  586. "support.function":
  587. "alert",
  588. "constant.language.boolean": "true|false"
  589. }, "identifier");
  590. var kwBeforeRe = "case|do|else|finally|in|instanceof|return|throw|try|typeof|yield|void";
  591. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  592. var escapedRe = "\\\\(?:x[0-9a-fA-F]{2}|" + // hex
  593. "u[0-9a-fA-F]{4}|" + // unicode
  594. "[0-2][0-7]{0,2}|" + // oct
  595. "3[0-6][0-7]?|" + // oct
  596. "37[0-7]?|" + // oct
  597. "[4-7][0-7]?|" + //oct
  598. ".)";
  599. this.$rules = {
  600. "no_regex" : [
  601. {
  602. token : "comment",
  603. regex : "\\/\\/",
  604. next : "line_comment"
  605. },
  606. DocCommentHighlightRules.getStartRule("doc-start"),
  607. {
  608. token : "comment", // multi line comment
  609. regex : /\/\*/,
  610. next : "comment"
  611. }, {
  612. token : "string",
  613. regex : "'(?=.)",
  614. next : "qstring"
  615. }, {
  616. token : "string",
  617. regex : '"(?=.)',
  618. next : "qqstring"
  619. }, {
  620. token : "constant.numeric", // hex
  621. regex : /0[xX][0-9a-fA-F]+\b/
  622. }, {
  623. token : "constant.numeric", // float
  624. regex : /[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  625. }, {
  626. token : [
  627. "storage.type", "punctuation.operator", "support.function",
  628. "punctuation.operator", "entity.name.function", "text","keyword.operator"
  629. ],
  630. regex : "(" + identifierRe + ")(\\.)(prototype)(\\.)(" + identifierRe +")(\\s*)(=)",
  631. next: "function_arguments"
  632. }, {
  633. token : [
  634. "storage.type", "punctuation.operator", "entity.name.function", "text",
  635. "keyword.operator", "text", "storage.type", "text", "paren.lparen"
  636. ],
  637. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  638. next: "function_arguments"
  639. }, {
  640. token : [
  641. "entity.name.function", "text", "keyword.operator", "text", "storage.type",
  642. "text", "paren.lparen"
  643. ],
  644. regex : "(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s*)(\\()",
  645. next: "function_arguments"
  646. }, {
  647. token : [
  648. "storage.type", "punctuation.operator", "entity.name.function", "text",
  649. "keyword.operator", "text",
  650. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  651. ],
  652. regex : "(" + identifierRe + ")(\\.)(" + identifierRe +")(\\s*)(=)(\\s*)(function)(\\s+)(\\w+)(\\s*)(\\()",
  653. next: "function_arguments"
  654. }, {
  655. token : [
  656. "storage.type", "text", "entity.name.function", "text", "paren.lparen"
  657. ],
  658. regex : "(function)(\\s+)(" + identifierRe + ")(\\s*)(\\()",
  659. next: "function_arguments"
  660. }, {
  661. token : [
  662. "entity.name.function", "text", "punctuation.operator",
  663. "text", "storage.type", "text", "paren.lparen"
  664. ],
  665. regex : "(" + identifierRe + ")(\\s*)(:)(\\s*)(function)(\\s*)(\\()",
  666. next: "function_arguments"
  667. }, {
  668. token : [
  669. "text", "text", "storage.type", "text", "paren.lparen"
  670. ],
  671. regex : "(:)(\\s*)(function)(\\s*)(\\()",
  672. next: "function_arguments"
  673. }, {
  674. token : "keyword",
  675. regex : "(?:" + kwBeforeRe + ")\\b",
  676. next : "start"
  677. }, {
  678. token : ["punctuation.operator", "support.function"],
  679. regex : /(\.)(s(?:h(?:ift|ow(?:Mod(?:elessDialog|alDialog)|Help))|croll(?:X|By(?:Pages|Lines)?|Y|To)?|t(?:op|rike)|i(?:n|zeToContent|debar|gnText)|ort|u(?:p|b(?:str(?:ing)?)?)|pli(?:ce|t)|e(?:nd|t(?:Re(?:sizable|questHeader)|M(?:i(?:nutes|lliseconds)|onth)|Seconds|Ho(?:tKeys|urs)|Year|Cursor|Time(?:out)?|Interval|ZOptions|Date|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Date|FullYear)|FullYear|Active)|arch)|qrt|lice|avePreferences|mall)|h(?:ome|andleEvent)|navigate|c(?:har(?:CodeAt|At)|o(?:s|n(?:cat|textual|firm)|mpile)|eil|lear(?:Timeout|Interval)?|a(?:ptureEvents|ll)|reate(?:StyleSheet|Popup|EventObject))|t(?:o(?:GMTString|S(?:tring|ource)|U(?:TCString|pperCase)|Lo(?:caleString|werCase))|est|a(?:n|int(?:Enabled)?))|i(?:s(?:NaN|Finite)|ndexOf|talics)|d(?:isableExternalCapture|ump|etachEvent)|u(?:n(?:shift|taint|escape|watch)|pdateCommands)|j(?:oin|avaEnabled)|p(?:o(?:p|w)|ush|lugins.refresh|a(?:ddings|rse(?:Int|Float)?)|r(?:int|ompt|eference))|e(?:scape|nableExternalCapture|val|lementFromPoint|x(?:p|ec(?:Script|Command)?))|valueOf|UTC|queryCommand(?:State|Indeterm|Enabled|Value)|f(?:i(?:nd|le(?:ModifiedDate|Size|CreatedDate|UpdatedDate)|xed)|o(?:nt(?:size|color)|rward)|loor|romCharCode)|watch|l(?:ink|o(?:ad|g)|astIndexOf)|a(?:sin|nchor|cos|t(?:tachEvent|ob|an(?:2)?)|pply|lert|b(?:s|ort))|r(?:ou(?:nd|teEvents)|e(?:size(?:By|To)|calc|turnValue|place|verse|l(?:oad|ease(?:Capture|Events)))|andom)|g(?:o|et(?:ResponseHeader|M(?:i(?:nutes|lliseconds)|onth)|Se(?:conds|lection)|Hours|Year|Time(?:zoneOffset)?|Da(?:y|te)|UTC(?:M(?:i(?:nutes|lliseconds)|onth)|Seconds|Hours|Da(?:y|te)|FullYear)|FullYear|A(?:ttention|llResponseHeaders)))|m(?:in|ove(?:B(?:y|elow)|To(?:Absolute)?|Above)|ergeAttributes|a(?:tch|rgins|x))|b(?:toa|ig|o(?:ld|rderWidths)|link|ack))\b(?=\()/
  680. }, {
  681. token : ["punctuation.operator", "support.function.dom"],
  682. regex : /(\.)(s(?:ub(?:stringData|mit)|plitText|e(?:t(?:NamedItem|Attribute(?:Node)?)|lect))|has(?:ChildNodes|Feature)|namedItem|c(?:l(?:ick|o(?:se|neNode))|reate(?:C(?:omment|DATASection|aption)|T(?:Head|extNode|Foot)|DocumentFragment|ProcessingInstruction|E(?:ntityReference|lement)|Attribute))|tabIndex|i(?:nsert(?:Row|Before|Cell|Data)|tem)|open|delete(?:Row|C(?:ell|aption)|T(?:Head|Foot)|Data)|focus|write(?:ln)?|a(?:dd|ppend(?:Child|Data))|re(?:set|place(?:Child|Data)|move(?:NamedItem|Child|Attribute(?:Node)?)?)|get(?:NamedItem|Element(?:sBy(?:Name|TagName)|ById)|Attribute(?:Node)?)|blur)\b(?=\()/
  683. }, {
  684. token : ["punctuation.operator", "support.constant"],
  685. regex : /(\.)(s(?:ystemLanguage|cr(?:ipts|ollbars|een(?:X|Y|Top|Left))|t(?:yle(?:Sheets)?|atus(?:Text|bar)?)|ibling(?:Below|Above)|ource|uffixes|e(?:curity(?:Policy)?|l(?:ection|f)))|h(?:istory|ost(?:name)?|as(?:h|Focus))|y|X(?:MLDocument|SLDocument)|n(?:ext|ame(?:space(?:s|URI)|Prop))|M(?:IN_VALUE|AX_VALUE)|c(?:haracterSet|o(?:n(?:structor|trollers)|okieEnabled|lorDepth|mp(?:onents|lete))|urrent|puClass|l(?:i(?:p(?:boardData)?|entInformation)|osed|asses)|alle(?:e|r)|rypto)|t(?:o(?:olbar|p)|ext(?:Transform|Indent|Decoration|Align)|ags)|SQRT(?:1_2|2)|i(?:n(?:ner(?:Height|Width)|put)|ds|gnoreCase)|zIndex|o(?:scpu|n(?:readystatechange|Line)|uter(?:Height|Width)|p(?:sProfile|ener)|ffscreenBuffering)|NEGATIVE_INFINITY|d(?:i(?:splay|alog(?:Height|Top|Width|Left|Arguments)|rectories)|e(?:scription|fault(?:Status|Ch(?:ecked|arset)|View)))|u(?:ser(?:Profile|Language|Agent)|n(?:iqueID|defined)|pdateInterval)|_content|p(?:ixelDepth|ort|ersonalbar|kcs11|l(?:ugins|atform)|a(?:thname|dding(?:Right|Bottom|Top|Left)|rent(?:Window|Layer)?|ge(?:X(?:Offset)?|Y(?:Offset)?))|r(?:o(?:to(?:col|type)|duct(?:Sub)?|mpter)|e(?:vious|fix)))|e(?:n(?:coding|abledPlugin)|x(?:ternal|pando)|mbeds)|v(?:isibility|endor(?:Sub)?|Linkcolor)|URLUnencoded|P(?:I|OSITIVE_INFINITY)|f(?:ilename|o(?:nt(?:Size|Family|Weight)|rmName)|rame(?:s|Element)|gColor)|E|whiteSpace|l(?:i(?:stStyleType|n(?:eHeight|kColor))|o(?:ca(?:tion(?:bar)?|lName)|wsrc)|e(?:ngth|ft(?:Context)?)|a(?:st(?:M(?:odified|atch)|Index|Paren)|yer(?:s|X)|nguage))|a(?:pp(?:MinorVersion|Name|Co(?:deName|re)|Version)|vail(?:Height|Top|Width|Left)|ll|r(?:ity|guments)|Linkcolor|bove)|r(?:ight(?:Context)?|e(?:sponse(?:XML|Text)|adyState))|global|x|m(?:imeTypes|ultiline|enubar|argin(?:Right|Bottom|Top|Left))|L(?:N(?:10|2)|OG(?:10E|2E))|b(?:o(?:ttom|rder(?:Width|RightWidth|BottomWidth|Style|Color|TopWidth|LeftWidth))|ufferDepth|elow|ackground(?:Color|Image)))\b/
  686. }, {
  687. token : ["support.constant"],
  688. regex : /that\b/
  689. }, {
  690. token : ["storage.type", "punctuation.operator", "support.function.firebug"],
  691. regex : /(console)(\.)(warn|info|log|error|time|trace|timeEnd|assert)\b/
  692. }, {
  693. token : keywordMapper,
  694. regex : identifierRe
  695. }, {
  696. token : "keyword.operator",
  697. regex : /--|\+\+|[!$%&*+\-~]|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\|\||\?\:|\*=|%=|\+=|\-=|&=|\^=/,
  698. next : "start"
  699. }, {
  700. token : "punctuation.operator",
  701. regex : /\?|\:|\,|\;|\./,
  702. next : "start"
  703. }, {
  704. token : "paren.lparen",
  705. regex : /[\[({]/,
  706. next : "start"
  707. }, {
  708. token : "paren.rparen",
  709. regex : /[\])}]/
  710. }, {
  711. token : "keyword.operator",
  712. regex : /\/=?/,
  713. next : "start"
  714. }, {
  715. token: "comment",
  716. regex: /^#!.*$/
  717. }
  718. ],
  719. "start": [
  720. DocCommentHighlightRules.getStartRule("doc-start"),
  721. {
  722. token : "comment", // multi line comment
  723. regex : "\\/\\*",
  724. next : "comment_regex_allowed"
  725. }, {
  726. token : "comment",
  727. regex : "\\/\\/",
  728. next : "line_comment_regex_allowed"
  729. }, {
  730. token: "string.regexp",
  731. regex: "\\/",
  732. next: "regex"
  733. }, {
  734. token : "text",
  735. regex : "\\s+|^$",
  736. next : "start"
  737. }, {
  738. token: "empty",
  739. regex: "",
  740. next: "no_regex"
  741. }
  742. ],
  743. "regex": [
  744. {
  745. token: "regexp.keyword.operator",
  746. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  747. }, {
  748. token: "string.regexp",
  749. regex: "/[sxngimy]*",
  750. next: "no_regex"
  751. }, {
  752. token : "invalid",
  753. regex: /\{\d+\b,?\d*\}[+*]|[+*$^?][+*]|[$^][?]|\?{3,}/
  754. }, {
  755. token : "constant.language.escape",
  756. regex: /\(\?[:=!]|\)|\{\d+\b,?\d*\}|[+*]\?|[()$^+*?.]/
  757. }, {
  758. token : "constant.language.delimiter",
  759. regex: /\|/
  760. }, {
  761. token: "constant.language.escape",
  762. regex: /\[\^?/,
  763. next: "regex_character_class"
  764. }, {
  765. token: "empty",
  766. regex: "$",
  767. next: "no_regex"
  768. }, {
  769. defaultToken: "string.regexp"
  770. }
  771. ],
  772. "regex_character_class": [
  773. {
  774. token: "regexp.keyword.operator",
  775. regex: "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)"
  776. }, {
  777. token: "constant.language.escape",
  778. regex: "]",
  779. next: "regex"
  780. }, {
  781. token: "constant.language.escape",
  782. regex: "-"
  783. }, {
  784. token: "empty",
  785. regex: "$",
  786. next: "no_regex"
  787. }, {
  788. defaultToken: "string.regexp.charachterclass"
  789. }
  790. ],
  791. "function_arguments": [
  792. {
  793. token: "variable.parameter",
  794. regex: identifierRe
  795. }, {
  796. token: "punctuation.operator",
  797. regex: "[, ]+"
  798. }, {
  799. token: "punctuation.operator",
  800. regex: "$"
  801. }, {
  802. token: "empty",
  803. regex: "",
  804. next: "no_regex"
  805. }
  806. ],
  807. "comment_regex_allowed" : [
  808. {token : "comment", regex : "\\*\\/", next : "start"},
  809. {defaultToken : "comment"}
  810. ],
  811. "comment" : [
  812. {token : "comment", regex : "\\*\\/", next : "no_regex"},
  813. {defaultToken : "comment"}
  814. ],
  815. "line_comment_regex_allowed" : [
  816. {token : "comment", regex : "$|^", next : "start"},
  817. {defaultToken : "comment"}
  818. ],
  819. "line_comment" : [
  820. {token : "comment", regex : "$|^", next : "no_regex"},
  821. {defaultToken : "comment"}
  822. ],
  823. "qqstring" : [
  824. {
  825. token : "constant.language.escape",
  826. regex : escapedRe
  827. }, {
  828. token : "string",
  829. regex : "\\\\$",
  830. next : "qqstring"
  831. }, {
  832. token : "string",
  833. regex : '"|$',
  834. next : "no_regex"
  835. }, {
  836. defaultToken: "string"
  837. }
  838. ],
  839. "qstring" : [
  840. {
  841. token : "constant.language.escape",
  842. regex : escapedRe
  843. }, {
  844. token : "string",
  845. regex : "\\\\$",
  846. next : "qstring"
  847. }, {
  848. token : "string",
  849. regex : "'|$",
  850. next : "no_regex"
  851. }, {
  852. defaultToken: "string"
  853. }
  854. ]
  855. };
  856. this.embedRules(DocCommentHighlightRules, "doc-",
  857. [ DocCommentHighlightRules.getEndRule("no_regex") ]);
  858. };
  859. oop.inherits(JavaScriptHighlightRules, TextHighlightRules);
  860. exports.JavaScriptHighlightRules = JavaScriptHighlightRules;
  861. });
  862. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  863. "use strict";
  864. var Range = require("../range").Range;
  865. var MatchingBraceOutdent = function() {};
  866. (function() {
  867. this.checkOutdent = function(line, input) {
  868. if (! /^\s+$/.test(line))
  869. return false;
  870. return /^\s*\}/.test(input);
  871. };
  872. this.autoOutdent = function(doc, row) {
  873. var line = doc.getLine(row);
  874. var match = line.match(/^(\s*\})/);
  875. if (!match) return 0;
  876. var column = match[1].length;
  877. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  878. if (!openBracePos || openBracePos.row == row) return 0;
  879. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  880. doc.replace(new Range(row, 0, row, column-1), indent);
  881. };
  882. this.$getIndent = function(line) {
  883. return line.match(/^\s*/)[0];
  884. };
  885. }).call(MatchingBraceOutdent.prototype);
  886. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  887. });
  888. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  889. "use strict";
  890. var oop = require("../../lib/oop");
  891. var Behaviour = require("../behaviour").Behaviour;
  892. var TokenIterator = require("../../token_iterator").TokenIterator;
  893. var lang = require("../../lib/lang");
  894. var SAFE_INSERT_IN_TOKENS =
  895. ["text", "paren.rparen", "punctuation.operator"];
  896. var SAFE_INSERT_BEFORE_TOKENS =
  897. ["text", "paren.rparen", "punctuation.operator", "comment"];
  898. var context;
  899. var contextCache = {}
  900. var initContext = function(editor) {
  901. var id = -1;
  902. if (editor.multiSelect) {
  903. id = editor.selection.id;
  904. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  905. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  906. }
  907. if (contextCache[id])
  908. return context = contextCache[id];
  909. context = contextCache[id] = {
  910. autoInsertedBrackets: 0,
  911. autoInsertedRow: -1,
  912. autoInsertedLineEnd: "",
  913. maybeInsertedBrackets: 0,
  914. maybeInsertedRow: -1,
  915. maybeInsertedLineStart: "",
  916. maybeInsertedLineEnd: ""
  917. };
  918. };
  919. var CstyleBehaviour = function() {
  920. this.add("braces", "insertion", function(state, action, editor, session, text) {
  921. var cursor = editor.getCursorPosition();
  922. var line = session.doc.getLine(cursor.row);
  923. if (text == '{') {
  924. initContext(editor);
  925. var selection = editor.getSelectionRange();
  926. var selected = session.doc.getTextRange(selection);
  927. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  928. return {
  929. text: '{' + selected + '}',
  930. selection: false
  931. };
  932. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  933. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  934. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  935. return {
  936. text: '{}',
  937. selection: [1, 1]
  938. };
  939. } else {
  940. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  941. return {
  942. text: '{',
  943. selection: [1, 1]
  944. };
  945. }
  946. }
  947. } else if (text == '}') {
  948. initContext(editor);
  949. var rightChar = line.substring(cursor.column, cursor.column + 1);
  950. if (rightChar == '}') {
  951. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  952. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  953. CstyleBehaviour.popAutoInsertedClosing();
  954. return {
  955. text: '',
  956. selection: [1, 1]
  957. };
  958. }
  959. }
  960. } else if (text == "\n" || text == "\r\n") {
  961. initContext(editor);
  962. var closing = "";
  963. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  964. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  965. CstyleBehaviour.clearMaybeInsertedClosing();
  966. }
  967. var rightChar = line.substring(cursor.column, cursor.column + 1);
  968. if (rightChar === '}') {
  969. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  970. if (!openBracePos)
  971. return null;
  972. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  973. } else if (closing) {
  974. var next_indent = this.$getIndent(line);
  975. } else {
  976. CstyleBehaviour.clearMaybeInsertedClosing();
  977. return;
  978. }
  979. var indent = next_indent + session.getTabString();
  980. return {
  981. text: '\n' + indent + '\n' + next_indent + closing,
  982. selection: [1, indent.length, 1, indent.length]
  983. };
  984. } else {
  985. CstyleBehaviour.clearMaybeInsertedClosing();
  986. }
  987. });
  988. this.add("braces", "deletion", function(state, action, editor, session, range) {
  989. var selected = session.doc.getTextRange(range);
  990. if (!range.isMultiLine() && selected == '{') {
  991. initContext(editor);
  992. var line = session.doc.getLine(range.start.row);
  993. var rightChar = line.substring(range.end.column, range.end.column + 1);
  994. if (rightChar == '}') {
  995. range.end.column++;
  996. return range;
  997. } else {
  998. context.maybeInsertedBrackets--;
  999. }
  1000. }
  1001. });
  1002. this.add("parens", "insertion", function(state, action, editor, session, text) {
  1003. if (text == '(') {
  1004. initContext(editor);
  1005. var selection = editor.getSelectionRange();
  1006. var selected = session.doc.getTextRange(selection);
  1007. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  1008. return {
  1009. text: '(' + selected + ')',
  1010. selection: false
  1011. };
  1012. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  1013. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  1014. return {
  1015. text: '()',
  1016. selection: [1, 1]
  1017. };
  1018. }
  1019. } else if (text == ')') {
  1020. initContext(editor);
  1021. var cursor = editor.getCursorPosition();
  1022. var line = session.doc.getLine(cursor.row);
  1023. var rightChar = line.substring(cursor.column, cursor.column + 1);
  1024. if (rightChar == ')') {
  1025. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  1026. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  1027. CstyleBehaviour.popAutoInsertedClosing();
  1028. return {
  1029. text: '',
  1030. selection: [1, 1]
  1031. };
  1032. }
  1033. }
  1034. }
  1035. });
  1036. this.add("parens", "deletion", function(state, action, editor, session, range) {
  1037. var selected = session.doc.getTextRange(range);
  1038. if (!range.isMultiLine() && selected == '(') {
  1039. initContext(editor);
  1040. var line = session.doc.getLine(range.start.row);
  1041. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  1042. if (rightChar == ')') {
  1043. range.end.column++;
  1044. return range;
  1045. }
  1046. }
  1047. });
  1048. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  1049. if (text == '[') {
  1050. initContext(editor);
  1051. var selection = editor.getSelectionRange();
  1052. var selected = session.doc.getTextRange(selection);
  1053. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  1054. return {
  1055. text: '[' + selected + ']',
  1056. selection: false
  1057. };
  1058. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  1059. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  1060. return {
  1061. text: '[]',
  1062. selection: [1, 1]
  1063. };
  1064. }
  1065. } else if (text == ']') {
  1066. initContext(editor);
  1067. var cursor = editor.getCursorPosition();
  1068. var line = session.doc.getLine(cursor.row);
  1069. var rightChar = line.substring(cursor.column, cursor.column + 1);
  1070. if (rightChar == ']') {
  1071. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  1072. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  1073. CstyleBehaviour.popAutoInsertedClosing();
  1074. return {
  1075. text: '',
  1076. selection: [1, 1]
  1077. };
  1078. }
  1079. }
  1080. }
  1081. });
  1082. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  1083. var selected = session.doc.getTextRange(range);
  1084. if (!range.isMultiLine() && selected == '[') {
  1085. initContext(editor);
  1086. var line = session.doc.getLine(range.start.row);
  1087. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  1088. if (rightChar == ']') {
  1089. range.end.column++;
  1090. return range;
  1091. }
  1092. }
  1093. });
  1094. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  1095. if (text == '"' || text == "'") {
  1096. initContext(editor);
  1097. var quote = text;
  1098. var selection = editor.getSelectionRange();
  1099. var selected = session.doc.getTextRange(selection);
  1100. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  1101. return {
  1102. text: quote + selected + quote,
  1103. selection: false
  1104. };
  1105. } else {
  1106. var cursor = editor.getCursorPosition();
  1107. var line = session.doc.getLine(cursor.row);
  1108. var leftChar = line.substring(cursor.column-1, cursor.column);
  1109. if (leftChar == '\\') {
  1110. return null;
  1111. }
  1112. var tokens = session.getTokens(selection.start.row);
  1113. var col = 0, token;
  1114. var quotepos = -1; // Track whether we're inside an open quote.
  1115. for (var x = 0; x < tokens.length; x++) {
  1116. token = tokens[x];
  1117. if (token.type == "string") {
  1118. quotepos = -1;
  1119. } else if (quotepos < 0) {
  1120. quotepos = token.value.indexOf(quote);
  1121. }
  1122. if ((token.value.length + col) > selection.start.column) {
  1123. break;
  1124. }
  1125. col += tokens[x].value.length;
  1126. }
  1127. if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
  1128. if (!CstyleBehaviour.isSaneInsertion(editor, session))
  1129. return;
  1130. return {
  1131. text: quote + quote,
  1132. selection: [1,1]
  1133. };
  1134. } else if (token && token.type === "string") {
  1135. var rightChar = line.substring(cursor.column, cursor.column + 1);
  1136. if (rightChar == quote) {
  1137. return {
  1138. text: '',
  1139. selection: [1, 1]
  1140. };
  1141. }
  1142. }
  1143. }
  1144. }
  1145. });
  1146. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  1147. var selected = session.doc.getTextRange(range);
  1148. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  1149. initContext(editor);
  1150. var line = session.doc.getLine(range.start.row);
  1151. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  1152. if (rightChar == selected) {
  1153. range.end.column++;
  1154. return range;
  1155. }
  1156. }
  1157. });
  1158. };
  1159. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  1160. var cursor = editor.getCursorPosition();
  1161. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  1162. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  1163. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  1164. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  1165. return false;
  1166. }
  1167. iterator.stepForward();
  1168. return iterator.getCurrentTokenRow() !== cursor.row ||
  1169. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  1170. };
  1171. CstyleBehaviour.$matchTokenType = function(token, types) {
  1172. return types.indexOf(token.type || token) > -1;
  1173. };
  1174. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  1175. var cursor = editor.getCursorPosition();
  1176. var line = session.doc.getLine(cursor.row);
  1177. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  1178. context.autoInsertedBrackets = 0;
  1179. context.autoInsertedRow = cursor.row;
  1180. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  1181. context.autoInsertedBrackets++;
  1182. };
  1183. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  1184. var cursor = editor.getCursorPosition();
  1185. var line = session.doc.getLine(cursor.row);
  1186. if (!this.isMaybeInsertedClosing(cursor, line))
  1187. context.maybeInsertedBrackets = 0;
  1188. context.maybeInsertedRow = cursor.row;
  1189. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  1190. context.maybeInsertedLineEnd = line.substr(cursor.column);
  1191. context.maybeInsertedBrackets++;
  1192. };
  1193. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  1194. return context.autoInsertedBrackets > 0 &&
  1195. cursor.row === context.autoInsertedRow &&
  1196. bracket === context.autoInsertedLineEnd[0] &&
  1197. line.substr(cursor.column) === context.autoInsertedLineEnd;
  1198. };
  1199. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  1200. return context.maybeInsertedBrackets > 0 &&
  1201. cursor.row === context.maybeInsertedRow &&
  1202. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  1203. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  1204. };
  1205. CstyleBehaviour.popAutoInsertedClosing = function() {
  1206. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  1207. context.autoInsertedBrackets--;
  1208. };
  1209. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  1210. if (context) {
  1211. context.maybeInsertedBrackets = 0;
  1212. context.maybeInsertedRow = -1;
  1213. }
  1214. };
  1215. oop.inherits(CstyleBehaviour, Behaviour);
  1216. exports.CstyleBehaviour = CstyleBehaviour;
  1217. });
  1218. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  1219. "use strict";
  1220. var oop = require("../../lib/oop");
  1221. var Range = require("../../range").Range;
  1222. var BaseFoldMode = require("./fold_mode").FoldMode;
  1223. var FoldMode = exports.FoldMode = function(commentRegex) {
  1224. if (commentRegex) {
  1225. this.foldingStartMarker = new RegExp(
  1226. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  1227. );
  1228. this.foldingStopMarker = new RegExp(
  1229. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  1230. );
  1231. }
  1232. };
  1233. oop.inherits(FoldMode, BaseFoldMode);
  1234. (function() {
  1235. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  1236. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  1237. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  1238. var line = session.getLine(row);
  1239. var match = line.match(this.foldingStartMarker);
  1240. if (match) {
  1241. var i = match.index;
  1242. if (match[1])
  1243. return this.openingBracketBlock(session, match[1], row, i);
  1244. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  1245. if (range && !range.isMultiLine()) {
  1246. if (forceMultiline) {
  1247. range = this.getSectionRange(session, row);
  1248. } else if (foldStyle != "all")
  1249. range = null;
  1250. }
  1251. return range;
  1252. }
  1253. if (foldStyle === "markbegin")
  1254. return;
  1255. var match = line.match(this.foldingStopMarker);
  1256. if (match) {
  1257. var i = match.index + match[0].length;
  1258. if (match[1])
  1259. return this.closingBracketBlock(session, match[1], row, i);
  1260. return session.getCommentFoldRange(row, i, -1);
  1261. }
  1262. };
  1263. this.getSectionRange = function(session, row) {
  1264. var line = session.getLine(row);
  1265. var startIndent = line.search(/\S/);
  1266. var startRow = row;
  1267. var startColumn = line.length;
  1268. row = row + 1;
  1269. var endRow = row;
  1270. var maxRow = session.getLength();
  1271. while (++row < maxRow) {
  1272. line = session.getLine(row);
  1273. var indent = line.search(/\S/);
  1274. if (indent === -1)
  1275. continue;
  1276. if (startIndent > indent)
  1277. break;
  1278. var subRange = this.getFoldWidgetRange(session, "all", row);
  1279. if (subRange) {
  1280. if (subRange.start.row <= startRow) {
  1281. break;
  1282. } else if (subRange.isMultiLine()) {
  1283. row = subRange.end.row;
  1284. } else if (startIndent == indent) {
  1285. break;
  1286. }
  1287. }
  1288. endRow = row;
  1289. }
  1290. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  1291. };
  1292. }).call(FoldMode.prototype);
  1293. });
  1294. ace.define("ace/mode/javascript",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/javascript_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/worker/worker_client","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  1295. "use strict";
  1296. var oop = require("../lib/oop");
  1297. var TextMode = require("./text").Mode;
  1298. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  1299. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  1300. var Range = require("../range").Range;
  1301. var WorkerClient = require("../worker/worker_client").WorkerClient;
  1302. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  1303. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  1304. var Mode = function() {
  1305. this.HighlightRules = JavaScriptHighlightRules;
  1306. this.$outdent = new MatchingBraceOutdent();
  1307. this.$behaviour = new CstyleBehaviour();
  1308. this.foldingRules = new CStyleFoldMode();
  1309. };
  1310. oop.inherits(Mode, TextMode);
  1311. (function() {
  1312. this.lineCommentStart = "//";
  1313. this.blockComment = {start: "/*", end: "*/"};
  1314. this.getNextLineIndent = function(state, line, tab) {
  1315. var indent = this.$getIndent(line);
  1316. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  1317. var tokens = tokenizedLine.tokens;
  1318. var endState = tokenizedLine.state;
  1319. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  1320. return indent;
  1321. }
  1322. if (state == "start" || state == "no_regex") {
  1323. var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
  1324. if (match) {
  1325. indent += tab;
  1326. }
  1327. } else if (state == "doc-start") {
  1328. if (endState == "start" || endState == "no_regex") {
  1329. return "";
  1330. }
  1331. var match = line.match(/^\s*(\/?)\*/);
  1332. if (match) {
  1333. if (match[1]) {
  1334. indent += " ";
  1335. }
  1336. indent += "* ";
  1337. }
  1338. }
  1339. return indent;
  1340. };
  1341. this.checkOutdent = function(state, line, input) {
  1342. return this.$outdent.checkOutdent(line, input);
  1343. };
  1344. this.autoOutdent = function(state, doc, row) {
  1345. this.$outdent.autoOutdent(doc, row);
  1346. };
  1347. this.createWorker = function(session) {
  1348. var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
  1349. worker.attachToDocument(session.getDocument());
  1350. worker.on("jslint", function(results) {
  1351. session.setAnnotations(results.data);
  1352. });
  1353. worker.on("terminate", function() {
  1354. session.clearAnnotations();
  1355. });
  1356. return worker;
  1357. };
  1358. this.$id = "ace/mode/javascript";
  1359. }).call(Mode.prototype);
  1360. exports.Mode = Mode;
  1361. });
  1362. ace.define("ace/mode/svg_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/javascript_highlight_rules","ace/mode/xml_highlight_rules"], function(require, exports, module) {
  1363. "use strict";
  1364. var oop = require("../lib/oop");
  1365. var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
  1366. var XmlHighlightRules = require("./xml_highlight_rules").XmlHighlightRules;
  1367. var SvgHighlightRules = function() {
  1368. XmlHighlightRules.call(this);
  1369. this.embedTagRules(JavaScriptHighlightRules, "js-", "script");
  1370. this.normalizeRules();
  1371. };
  1372. oop.inherits(SvgHighlightRules, XmlHighlightRules);
  1373. exports.SvgHighlightRules = SvgHighlightRules;
  1374. });
  1375. ace.define("ace/mode/folding/mixed",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode"], function(require, exports, module) {
  1376. "use strict";
  1377. var oop = require("../../lib/oop");
  1378. var BaseFoldMode = require("./fold_mode").FoldMode;
  1379. var FoldMode = exports.FoldMode = function(defaultMode, subModes) {
  1380. this.defaultMode = defaultMode;
  1381. this.subModes = subModes;
  1382. };
  1383. oop.inherits(FoldMode, BaseFoldMode);
  1384. (function() {
  1385. this.$getMode = function(state) {
  1386. if (typeof state != "string")
  1387. state = state[0];
  1388. for (var key in this.subModes) {
  1389. if (state.indexOf(key) === 0)
  1390. return this.subModes[key];
  1391. }
  1392. return null;
  1393. };
  1394. this.$tryMode = function(state, session, foldStyle, row) {
  1395. var mode = this.$getMode(state);
  1396. return (mode ? mode.getFoldWidget(session, foldStyle, row) : "");
  1397. };
  1398. this.getFoldWidget = function(session, foldStyle, row) {
  1399. return (
  1400. this.$tryMode(session.getState(row-1), session, foldStyle, row) ||
  1401. this.$tryMode(session.getState(row), session, foldStyle, row) ||
  1402. this.defaultMode.getFoldWidget(session, foldStyle, row)
  1403. );
  1404. };
  1405. this.getFoldWidgetRange = function(session, foldStyle, row) {
  1406. var mode = this.$getMode(session.getState(row-1));
  1407. if (!mode || !mode.getFoldWidget(session, foldStyle, row))
  1408. mode = this.$getMode(session.getState(row));
  1409. if (!mode || !mode.getFoldWidget(session, foldStyle, row))
  1410. mode = this.defaultMode;
  1411. return mode.getFoldWidgetRange(session, foldStyle, row);
  1412. };
  1413. }).call(FoldMode.prototype);
  1414. });
  1415. ace.define("ace/mode/svg",["require","exports","module","ace/lib/oop","ace/mode/xml","ace/mode/javascript","ace/mode/svg_highlight_rules","ace/mode/folding/mixed","ace/mode/folding/xml","ace/mode/folding/cstyle"], function(require, exports, module) {
  1416. "use strict";
  1417. var oop = require("../lib/oop");
  1418. var XmlMode = require("./xml").Mode;
  1419. var JavaScriptMode = require("./javascript").Mode;
  1420. var SvgHighlightRules = require("./svg_highlight_rules").SvgHighlightRules;
  1421. var MixedFoldMode = require("./folding/mixed").FoldMode;
  1422. var XmlFoldMode = require("./folding/xml").FoldMode;
  1423. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  1424. var Mode = function() {
  1425. XmlMode.call(this);
  1426. this.HighlightRules = SvgHighlightRules;
  1427. this.createModeDelegates({
  1428. "js-": JavaScriptMode
  1429. });
  1430. this.foldingRules = new MixedFoldMode(new XmlFoldMode(), {
  1431. "js-": new CStyleFoldMode()
  1432. });
  1433. };
  1434. oop.inherits(Mode, XmlMode);
  1435. (function() {
  1436. this.getNextLineIndent = function(state, line, tab) {
  1437. return this.$getIndent(line);
  1438. };
  1439. this.$id = "ace/mode/svg";
  1440. }).call(Mode.prototype);
  1441. exports.Mode = Mode;
  1442. });