mode-dart.js 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  1. define("ace/mode/doc_comment_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 DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. },
  11. DocCommentHighlightRules.getTagRule(),
  12. {
  13. defaultToken : "comment.doc",
  14. caseInsensitive: true
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getTagRule = function(start) {
  20. return {
  21. token : "comment.doc.tag.storage.type",
  22. regex : "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  23. };
  24. }
  25. DocCommentHighlightRules.getStartRule = function(start) {
  26. return {
  27. token : "comment.doc", // doc comment
  28. regex : "\\/\\*(?=\\*)",
  29. next : start
  30. };
  31. };
  32. DocCommentHighlightRules.getEndRule = function (start) {
  33. return {
  34. token : "comment.doc", // closing comment
  35. regex : "\\*\\/",
  36. next : start
  37. };
  38. };
  39. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  40. });
  41. define("ace/mode/c_cpp_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  42. "use strict";
  43. var oop = require("../lib/oop");
  44. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  45. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  46. var cFunctions = exports.cFunctions = "\\b(?:hypot(?:f|l)?|s(?:scanf|ystem|nprintf|ca(?:nf|lb(?:n(?:f|l)?|ln(?:f|l)?))|i(?:n(?:h(?:f|l)?|f|l)?|gn(?:al|bit))|tr(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?)|error|pbrk|ftime|len|rchr|xfrm)|printf|et(?:jmp|vbuf|locale|buf)|qrt(?:f|l)?|w(?:scanf|printf)|rand)|n(?:e(?:arbyint(?:f|l)?|xt(?:toward(?:f|l)?|after(?:f|l)?))|an(?:f|l)?)|c(?:s(?:in(?:h(?:f|l)?|f|l)?|qrt(?:f|l)?)|cos(?:h(?:f)?|f|l)?|imag(?:f|l)?|t(?:ime|an(?:h(?:f|l)?|f|l)?)|o(?:s(?:h(?:f|l)?|f|l)?|nj(?:f|l)?|pysign(?:f|l)?)|p(?:ow(?:f|l)?|roj(?:f|l)?)|e(?:il(?:f|l)?|xp(?:f|l)?)|l(?:o(?:ck|g(?:f|l)?)|earerr)|a(?:sin(?:h(?:f|l)?|f|l)?|cos(?:h(?:f|l)?|f|l)?|tan(?:h(?:f|l)?|f|l)?|lloc|rg(?:f|l)?|bs(?:f|l)?)|real(?:f|l)?|brt(?:f|l)?)|t(?:ime|o(?:upper|lower)|an(?:h(?:f|l)?|f|l)?|runc(?:f|l)?|gamma(?:f|l)?|mp(?:nam|file))|i(?:s(?:space|n(?:ormal|an)|cntrl|inf|digit|u(?:nordered|pper)|p(?:unct|rint)|finite|w(?:space|c(?:ntrl|type)|digit|upper|p(?:unct|rint)|lower|al(?:num|pha)|graph|xdigit|blank)|l(?:ower|ess(?:equal|greater)?)|al(?:num|pha)|gr(?:eater(?:equal)?|aph)|xdigit|blank)|logb(?:f|l)?|max(?:div|abs))|di(?:v|fftime)|_Exit|unget(?:c|wc)|p(?:ow(?:f|l)?|ut(?:s|c(?:har)?|wc(?:har)?)|error|rintf)|e(?:rf(?:c(?:f|l)?|f|l)?|x(?:it|p(?:2(?:f|l)?|f|l|m1(?:f|l)?)?))|v(?:s(?:scanf|nprintf|canf|printf|w(?:scanf|printf))|printf|f(?:scanf|printf|w(?:scanf|printf))|w(?:scanf|printf)|a_(?:start|copy|end|arg))|qsort|f(?:s(?:canf|e(?:tpos|ek))|close|tell|open|dim(?:f|l)?|p(?:classify|ut(?:s|c|w(?:s|c))|rintf)|e(?:holdexcept|set(?:e(?:nv|xceptflag)|round)|clearexcept|testexcept|of|updateenv|r(?:aiseexcept|ror)|get(?:e(?:nv|xceptflag)|round))|flush|w(?:scanf|ide|printf|rite)|loor(?:f|l)?|abs(?:f|l)?|get(?:s|c|pos|w(?:s|c))|re(?:open|e|ad|xp(?:f|l)?)|m(?:in(?:f|l)?|od(?:f|l)?|a(?:f|l|x(?:f|l)?)?))|l(?:d(?:iv|exp(?:f|l)?)|o(?:ngjmp|cal(?:time|econv)|g(?:1(?:p(?:f|l)?|0(?:f|l)?)|2(?:f|l)?|f|l|b(?:f|l)?)?)|abs|l(?:div|abs|r(?:int(?:f|l)?|ound(?:f|l)?))|r(?:int(?:f|l)?|ound(?:f|l)?)|gamma(?:f|l)?)|w(?:scanf|c(?:s(?:s(?:tr|pn)|nc(?:py|at|mp)|c(?:spn|hr|oll|py|at|mp)|to(?:imax|d|u(?:l(?:l)?|max)|k|f|l(?:d|l)?|mbs)|pbrk|ftime|len|r(?:chr|tombs)|xfrm)|to(?:b|mb)|rtomb)|printf|mem(?:set|c(?:hr|py|mp)|move))|a(?:s(?:sert|ctime|in(?:h(?:f|l)?|f|l)?)|cos(?:h(?:f|l)?|f|l)?|t(?:o(?:i|f|l(?:l)?)|exit|an(?:h(?:f|l)?|2(?:f|l)?|f|l)?)|b(?:s|ort))|g(?:et(?:s|c(?:har)?|env|wc(?:har)?)|mtime)|r(?:int(?:f|l)?|ound(?:f|l)?|e(?:name|alloc|wind|m(?:ove|quo(?:f|l)?|ainder(?:f|l)?))|a(?:nd|ise))|b(?:search|towc)|m(?:odf(?:f|l)?|em(?:set|c(?:hr|py|mp)|move)|ktime|alloc|b(?:s(?:init|towcs|rtowcs)|towc|len|r(?:towc|len))))\\b"
  47. var c_cppHighlightRules = function() {
  48. var keywordControls = (
  49. "break|case|continue|default|do|else|for|goto|if|_Pragma|" +
  50. "return|switch|while|catch|operator|try|throw|using"
  51. );
  52. var storageType = (
  53. "asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
  54. "_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
  55. "class|wchar_t|template|char16_t|char32_t"
  56. );
  57. var storageModifiers = (
  58. "const|extern|register|restrict|static|volatile|inline|private|" +
  59. "protected|public|friend|explicit|virtual|export|mutable|typename|" +
  60. "constexpr|new|delete|alignas|alignof|decltype|noexcept|thread_local"
  61. );
  62. var keywordOperators = (
  63. "and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq" +
  64. "const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace"
  65. );
  66. var builtinConstants = (
  67. "NULL|true|false|TRUE|FALSE|nullptr"
  68. );
  69. var keywordMapper = this.$keywords = this.createKeywordMapper({
  70. "keyword.control" : keywordControls,
  71. "storage.type" : storageType,
  72. "storage.modifier" : storageModifiers,
  73. "keyword.operator" : keywordOperators,
  74. "variable.language": "this",
  75. "constant.language": builtinConstants
  76. }, "identifier");
  77. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\d\\$_\u00a1-\uffff]*\\b";
  78. this.$rules = {
  79. "start" : [
  80. {
  81. token : "comment",
  82. regex : "//$",
  83. next : "start"
  84. }, {
  85. token : "comment",
  86. regex : "//",
  87. next : "singleLineComment"
  88. },
  89. DocCommentHighlightRules.getStartRule("doc-start"),
  90. {
  91. token : "comment", // multi line comment
  92. regex : "\\/\\*",
  93. next : "comment"
  94. }, {
  95. token : "string", // single line
  96. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  97. }, {
  98. token : "string", // multi line string start
  99. regex : '["].*\\\\$',
  100. next : "qqstring"
  101. }, {
  102. token : "string", // single line
  103. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  104. }, {
  105. token : "string", // multi line string start
  106. regex : "['].*\\\\$",
  107. next : "qstring"
  108. }, {
  109. token : "constant.numeric", // hex
  110. regex : "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  111. }, {
  112. token : "constant.numeric", // float
  113. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  114. }, {
  115. token : "keyword", // pre-compiler directives
  116. regex : "#\\s*(?:include|import|pragma|line|define|undef)\\b",
  117. next : "directive"
  118. }, {
  119. token : "keyword", // special case pre-compiler directive
  120. regex : "#\\s*(?:endif|if|ifdef|else|elif|ifndef)\\b"
  121. }, {
  122. token : "support.function.C99.c",
  123. regex : cFunctions
  124. }, {
  125. token : keywordMapper,
  126. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  127. }, {
  128. token : "keyword.operator",
  129. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
  130. }, {
  131. token : "punctuation.operator",
  132. regex : "\\?|\\:|\\,|\\;|\\."
  133. }, {
  134. token : "paren.lparen",
  135. regex : "[[({]"
  136. }, {
  137. token : "paren.rparen",
  138. regex : "[\\])}]"
  139. }, {
  140. token : "text",
  141. regex : "\\s+"
  142. }
  143. ],
  144. "comment" : [
  145. {
  146. token : "comment", // closing comment
  147. regex : ".*?\\*\\/",
  148. next : "start"
  149. }, {
  150. token : "comment", // comment spanning whole line
  151. regex : ".+"
  152. }
  153. ],
  154. "singleLineComment" : [
  155. {
  156. token : "comment",
  157. regex : /\\$/,
  158. next : "singleLineComment"
  159. }, {
  160. token : "comment",
  161. regex : /$/,
  162. next : "start"
  163. }, {
  164. defaultToken: "comment"
  165. }
  166. ],
  167. "qqstring" : [
  168. {
  169. token : "string",
  170. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  171. next : "start"
  172. }, {
  173. defaultToken : "string"
  174. }
  175. ],
  176. "qstring" : [
  177. {
  178. token : "string",
  179. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  180. next : "start"
  181. }, {
  182. defaultToken : "string"
  183. }
  184. ],
  185. "directive" : [
  186. {
  187. token : "constant.other.multiline",
  188. regex : /\\/
  189. },
  190. {
  191. token : "constant.other.multiline",
  192. regex : /.*\\/
  193. },
  194. {
  195. token : "constant.other",
  196. regex : "\\s*<.+?>",
  197. next : "start"
  198. },
  199. {
  200. token : "constant.other", // single line
  201. regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
  202. next : "start"
  203. },
  204. {
  205. token : "constant.other", // single line
  206. regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
  207. next : "start"
  208. },
  209. {
  210. token : "constant.other",
  211. regex : /[^\\\/]+/,
  212. next : "start"
  213. }
  214. ]
  215. };
  216. this.embedRules(DocCommentHighlightRules, "doc-",
  217. [ DocCommentHighlightRules.getEndRule("start") ]);
  218. };
  219. oop.inherits(c_cppHighlightRules, TextHighlightRules);
  220. exports.c_cppHighlightRules = c_cppHighlightRules;
  221. });
  222. define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  223. "use strict";
  224. var Range = require("../range").Range;
  225. var MatchingBraceOutdent = function() {};
  226. (function() {
  227. this.checkOutdent = function(line, input) {
  228. if (! /^\s+$/.test(line))
  229. return false;
  230. return /^\s*\}/.test(input);
  231. };
  232. this.autoOutdent = function(doc, row) {
  233. var line = doc.getLine(row);
  234. var match = line.match(/^(\s*\})/);
  235. if (!match) return 0;
  236. var column = match[1].length;
  237. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  238. if (!openBracePos || openBracePos.row == row) return 0;
  239. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  240. doc.replace(new Range(row, 0, row, column-1), indent);
  241. };
  242. this.$getIndent = function(line) {
  243. return line.match(/^\s*/)[0];
  244. };
  245. }).call(MatchingBraceOutdent.prototype);
  246. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  247. });
  248. define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  249. "use strict";
  250. var oop = require("../../lib/oop");
  251. var Behaviour = require("../behaviour").Behaviour;
  252. var TokenIterator = require("../../token_iterator").TokenIterator;
  253. var lang = require("../../lib/lang");
  254. var SAFE_INSERT_IN_TOKENS =
  255. ["text", "paren.rparen", "punctuation.operator"];
  256. var SAFE_INSERT_BEFORE_TOKENS =
  257. ["text", "paren.rparen", "punctuation.operator", "comment"];
  258. var context;
  259. var contextCache = {};
  260. var initContext = function(editor) {
  261. var id = -1;
  262. if (editor.multiSelect) {
  263. id = editor.selection.index;
  264. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  265. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  266. }
  267. if (contextCache[id])
  268. return context = contextCache[id];
  269. context = contextCache[id] = {
  270. autoInsertedBrackets: 0,
  271. autoInsertedRow: -1,
  272. autoInsertedLineEnd: "",
  273. maybeInsertedBrackets: 0,
  274. maybeInsertedRow: -1,
  275. maybeInsertedLineStart: "",
  276. maybeInsertedLineEnd: ""
  277. };
  278. };
  279. var getWrapped = function(selection, selected, opening, closing) {
  280. var rowDiff = selection.end.row - selection.start.row;
  281. return {
  282. text: opening + selected + closing,
  283. selection: [
  284. 0,
  285. selection.start.column + 1,
  286. rowDiff,
  287. selection.end.column + (rowDiff ? 0 : 1)
  288. ]
  289. };
  290. };
  291. var CstyleBehaviour = function() {
  292. this.add("braces", "insertion", function(state, action, editor, session, text) {
  293. var cursor = editor.getCursorPosition();
  294. var line = session.doc.getLine(cursor.row);
  295. if (text == '{') {
  296. initContext(editor);
  297. var selection = editor.getSelectionRange();
  298. var selected = session.doc.getTextRange(selection);
  299. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  300. return getWrapped(selection, selected, '{', '}');
  301. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  302. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  303. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  304. return {
  305. text: '{}',
  306. selection: [1, 1]
  307. };
  308. } else {
  309. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  310. return {
  311. text: '{',
  312. selection: [1, 1]
  313. };
  314. }
  315. }
  316. } else if (text == '}') {
  317. initContext(editor);
  318. var rightChar = line.substring(cursor.column, cursor.column + 1);
  319. if (rightChar == '}') {
  320. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  321. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  322. CstyleBehaviour.popAutoInsertedClosing();
  323. return {
  324. text: '',
  325. selection: [1, 1]
  326. };
  327. }
  328. }
  329. } else if (text == "\n" || text == "\r\n") {
  330. initContext(editor);
  331. var closing = "";
  332. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  333. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  334. CstyleBehaviour.clearMaybeInsertedClosing();
  335. }
  336. var rightChar = line.substring(cursor.column, cursor.column + 1);
  337. if (rightChar === '}') {
  338. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  339. if (!openBracePos)
  340. return null;
  341. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  342. } else if (closing) {
  343. var next_indent = this.$getIndent(line);
  344. } else {
  345. CstyleBehaviour.clearMaybeInsertedClosing();
  346. return;
  347. }
  348. var indent = next_indent + session.getTabString();
  349. return {
  350. text: '\n' + indent + '\n' + next_indent + closing,
  351. selection: [1, indent.length, 1, indent.length]
  352. };
  353. } else {
  354. CstyleBehaviour.clearMaybeInsertedClosing();
  355. }
  356. });
  357. this.add("braces", "deletion", function(state, action, editor, session, range) {
  358. var selected = session.doc.getTextRange(range);
  359. if (!range.isMultiLine() && selected == '{') {
  360. initContext(editor);
  361. var line = session.doc.getLine(range.start.row);
  362. var rightChar = line.substring(range.end.column, range.end.column + 1);
  363. if (rightChar == '}') {
  364. range.end.column++;
  365. return range;
  366. } else {
  367. context.maybeInsertedBrackets--;
  368. }
  369. }
  370. });
  371. this.add("parens", "insertion", function(state, action, editor, session, text) {
  372. if (text == '(') {
  373. initContext(editor);
  374. var selection = editor.getSelectionRange();
  375. var selected = session.doc.getTextRange(selection);
  376. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  377. return getWrapped(selection, selected, '(', ')');
  378. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  379. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  380. return {
  381. text: '()',
  382. selection: [1, 1]
  383. };
  384. }
  385. } else if (text == ')') {
  386. initContext(editor);
  387. var cursor = editor.getCursorPosition();
  388. var line = session.doc.getLine(cursor.row);
  389. var rightChar = line.substring(cursor.column, cursor.column + 1);
  390. if (rightChar == ')') {
  391. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  392. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  393. CstyleBehaviour.popAutoInsertedClosing();
  394. return {
  395. text: '',
  396. selection: [1, 1]
  397. };
  398. }
  399. }
  400. }
  401. });
  402. this.add("parens", "deletion", function(state, action, editor, session, range) {
  403. var selected = session.doc.getTextRange(range);
  404. if (!range.isMultiLine() && selected == '(') {
  405. initContext(editor);
  406. var line = session.doc.getLine(range.start.row);
  407. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  408. if (rightChar == ')') {
  409. range.end.column++;
  410. return range;
  411. }
  412. }
  413. });
  414. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  415. if (text == '[') {
  416. initContext(editor);
  417. var selection = editor.getSelectionRange();
  418. var selected = session.doc.getTextRange(selection);
  419. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  420. return getWrapped(selection, selected, '[', ']');
  421. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  422. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  423. return {
  424. text: '[]',
  425. selection: [1, 1]
  426. };
  427. }
  428. } else if (text == ']') {
  429. initContext(editor);
  430. var cursor = editor.getCursorPosition();
  431. var line = session.doc.getLine(cursor.row);
  432. var rightChar = line.substring(cursor.column, cursor.column + 1);
  433. if (rightChar == ']') {
  434. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  435. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  436. CstyleBehaviour.popAutoInsertedClosing();
  437. return {
  438. text: '',
  439. selection: [1, 1]
  440. };
  441. }
  442. }
  443. }
  444. });
  445. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  446. var selected = session.doc.getTextRange(range);
  447. if (!range.isMultiLine() && selected == '[') {
  448. initContext(editor);
  449. var line = session.doc.getLine(range.start.row);
  450. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  451. if (rightChar == ']') {
  452. range.end.column++;
  453. return range;
  454. }
  455. }
  456. });
  457. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  458. if (text == '"' || text == "'") {
  459. initContext(editor);
  460. var quote = text;
  461. var selection = editor.getSelectionRange();
  462. var selected = session.doc.getTextRange(selection);
  463. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  464. return getWrapped(selection, selected, quote, quote);
  465. } else if (!selected) {
  466. var cursor = editor.getCursorPosition();
  467. var line = session.doc.getLine(cursor.row);
  468. var leftChar = line.substring(cursor.column-1, cursor.column);
  469. var rightChar = line.substring(cursor.column, cursor.column + 1);
  470. var token = session.getTokenAt(cursor.row, cursor.column);
  471. var rightToken = session.getTokenAt(cursor.row, cursor.column + 1);
  472. if (leftChar == "\\" && token && /escape/.test(token.type))
  473. return null;
  474. var stringBefore = token && /string|escape/.test(token.type);
  475. var stringAfter = !rightToken || /string|escape/.test(rightToken.type);
  476. var pair;
  477. if (rightChar == quote) {
  478. pair = stringBefore !== stringAfter;
  479. } else {
  480. if (stringBefore && !stringAfter)
  481. return null; // wrap string with different quote
  482. if (stringBefore && stringAfter)
  483. return null; // do not pair quotes inside strings
  484. var wordRe = session.$mode.tokenRe;
  485. wordRe.lastIndex = 0;
  486. var isWordBefore = wordRe.test(leftChar);
  487. wordRe.lastIndex = 0;
  488. var isWordAfter = wordRe.test(leftChar);
  489. if (isWordBefore || isWordAfter)
  490. return null; // before or after alphanumeric
  491. if (rightChar && !/[\s;,.})\]\\]/.test(rightChar))
  492. return null; // there is rightChar and it isn't closing
  493. pair = true;
  494. }
  495. return {
  496. text: pair ? quote + quote : "",
  497. selection: [1,1]
  498. };
  499. }
  500. }
  501. });
  502. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  503. var selected = session.doc.getTextRange(range);
  504. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  505. initContext(editor);
  506. var line = session.doc.getLine(range.start.row);
  507. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  508. if (rightChar == selected) {
  509. range.end.column++;
  510. return range;
  511. }
  512. }
  513. });
  514. };
  515. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  516. var cursor = editor.getCursorPosition();
  517. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  518. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  519. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  520. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  521. return false;
  522. }
  523. iterator.stepForward();
  524. return iterator.getCurrentTokenRow() !== cursor.row ||
  525. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  526. };
  527. CstyleBehaviour.$matchTokenType = function(token, types) {
  528. return types.indexOf(token.type || token) > -1;
  529. };
  530. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  531. var cursor = editor.getCursorPosition();
  532. var line = session.doc.getLine(cursor.row);
  533. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  534. context.autoInsertedBrackets = 0;
  535. context.autoInsertedRow = cursor.row;
  536. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  537. context.autoInsertedBrackets++;
  538. };
  539. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  540. var cursor = editor.getCursorPosition();
  541. var line = session.doc.getLine(cursor.row);
  542. if (!this.isMaybeInsertedClosing(cursor, line))
  543. context.maybeInsertedBrackets = 0;
  544. context.maybeInsertedRow = cursor.row;
  545. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  546. context.maybeInsertedLineEnd = line.substr(cursor.column);
  547. context.maybeInsertedBrackets++;
  548. };
  549. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  550. return context.autoInsertedBrackets > 0 &&
  551. cursor.row === context.autoInsertedRow &&
  552. bracket === context.autoInsertedLineEnd[0] &&
  553. line.substr(cursor.column) === context.autoInsertedLineEnd;
  554. };
  555. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  556. return context.maybeInsertedBrackets > 0 &&
  557. cursor.row === context.maybeInsertedRow &&
  558. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  559. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  560. };
  561. CstyleBehaviour.popAutoInsertedClosing = function() {
  562. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  563. context.autoInsertedBrackets--;
  564. };
  565. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  566. if (context) {
  567. context.maybeInsertedBrackets = 0;
  568. context.maybeInsertedRow = -1;
  569. }
  570. };
  571. oop.inherits(CstyleBehaviour, Behaviour);
  572. exports.CstyleBehaviour = CstyleBehaviour;
  573. });
  574. define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  575. "use strict";
  576. var oop = require("../../lib/oop");
  577. var Range = require("../../range").Range;
  578. var BaseFoldMode = require("./fold_mode").FoldMode;
  579. var FoldMode = exports.FoldMode = function(commentRegex) {
  580. if (commentRegex) {
  581. this.foldingStartMarker = new RegExp(
  582. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  583. );
  584. this.foldingStopMarker = new RegExp(
  585. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  586. );
  587. }
  588. };
  589. oop.inherits(FoldMode, BaseFoldMode);
  590. (function() {
  591. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  592. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  593. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  594. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  595. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  596. this._getFoldWidgetBase = this.getFoldWidget;
  597. this.getFoldWidget = function(session, foldStyle, row) {
  598. var line = session.getLine(row);
  599. if (this.singleLineBlockCommentRe.test(line)) {
  600. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  601. return "";
  602. }
  603. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  604. if (!fw && this.startRegionRe.test(line))
  605. return "start"; // lineCommentRegionStart
  606. return fw;
  607. };
  608. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  609. var line = session.getLine(row);
  610. if (this.startRegionRe.test(line))
  611. return this.getCommentRegionBlock(session, line, row);
  612. var match = line.match(this.foldingStartMarker);
  613. if (match) {
  614. var i = match.index;
  615. if (match[1])
  616. return this.openingBracketBlock(session, match[1], row, i);
  617. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  618. if (range && !range.isMultiLine()) {
  619. if (forceMultiline) {
  620. range = this.getSectionRange(session, row);
  621. } else if (foldStyle != "all")
  622. range = null;
  623. }
  624. return range;
  625. }
  626. if (foldStyle === "markbegin")
  627. return;
  628. var match = line.match(this.foldingStopMarker);
  629. if (match) {
  630. var i = match.index + match[0].length;
  631. if (match[1])
  632. return this.closingBracketBlock(session, match[1], row, i);
  633. return session.getCommentFoldRange(row, i, -1);
  634. }
  635. };
  636. this.getSectionRange = function(session, row) {
  637. var line = session.getLine(row);
  638. var startIndent = line.search(/\S/);
  639. var startRow = row;
  640. var startColumn = line.length;
  641. row = row + 1;
  642. var endRow = row;
  643. var maxRow = session.getLength();
  644. while (++row < maxRow) {
  645. line = session.getLine(row);
  646. var indent = line.search(/\S/);
  647. if (indent === -1)
  648. continue;
  649. if (startIndent > indent)
  650. break;
  651. var subRange = this.getFoldWidgetRange(session, "all", row);
  652. if (subRange) {
  653. if (subRange.start.row <= startRow) {
  654. break;
  655. } else if (subRange.isMultiLine()) {
  656. row = subRange.end.row;
  657. } else if (startIndent == indent) {
  658. break;
  659. }
  660. }
  661. endRow = row;
  662. }
  663. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  664. };
  665. this.getCommentRegionBlock = function(session, line, row) {
  666. var startColumn = line.search(/\s*$/);
  667. var maxRow = session.getLength();
  668. var startRow = row;
  669. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  670. var depth = 1;
  671. while (++row < maxRow) {
  672. line = session.getLine(row);
  673. var m = re.exec(line);
  674. if (!m) continue;
  675. if (m[1]) depth--;
  676. else depth++;
  677. if (!depth) break;
  678. }
  679. var endRow = row;
  680. if (endRow > startRow) {
  681. return new Range(startRow, startColumn, endRow, line.length);
  682. }
  683. };
  684. }).call(FoldMode.prototype);
  685. });
  686. define("ace/mode/c_cpp",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/c_cpp_highlight_rules","ace/mode/matching_brace_outdent","ace/range","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  687. "use strict";
  688. var oop = require("../lib/oop");
  689. var TextMode = require("./text").Mode;
  690. var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
  691. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  692. var Range = require("../range").Range;
  693. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  694. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  695. var Mode = function() {
  696. this.HighlightRules = c_cppHighlightRules;
  697. this.$outdent = new MatchingBraceOutdent();
  698. this.$behaviour = new CstyleBehaviour();
  699. this.foldingRules = new CStyleFoldMode();
  700. };
  701. oop.inherits(Mode, TextMode);
  702. (function() {
  703. this.lineCommentStart = "//";
  704. this.blockComment = {start: "/*", end: "*/"};
  705. this.getNextLineIndent = function(state, line, tab) {
  706. var indent = this.$getIndent(line);
  707. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  708. var tokens = tokenizedLine.tokens;
  709. var endState = tokenizedLine.state;
  710. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  711. return indent;
  712. }
  713. if (state == "start") {
  714. var match = line.match(/^.*[\{\(\[]\s*$/);
  715. if (match) {
  716. indent += tab;
  717. }
  718. } else if (state == "doc-start") {
  719. if (endState == "start") {
  720. return "";
  721. }
  722. var match = line.match(/^\s*(\/?)\*/);
  723. if (match) {
  724. if (match[1]) {
  725. indent += " ";
  726. }
  727. indent += "* ";
  728. }
  729. }
  730. return indent;
  731. };
  732. this.checkOutdent = function(state, line, input) {
  733. return this.$outdent.checkOutdent(line, input);
  734. };
  735. this.autoOutdent = function(state, doc, row) {
  736. this.$outdent.autoOutdent(doc, row);
  737. };
  738. this.$id = "ace/mode/c_cpp";
  739. }).call(Mode.prototype);
  740. exports.Mode = Mode;
  741. });
  742. define("ace/mode/dart_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module) {
  743. "use strict";
  744. var oop = require("../lib/oop");
  745. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  746. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  747. var DartHighlightRules = function() {
  748. var constantLanguage = "true|false|null";
  749. var variableLanguage = "this|super";
  750. var keywordControl = "try|catch|finally|throw|rethrow|assert|break|case|continue|default|do|else|for|if|in|return|switch|while|new|deferred|async|await";
  751. var keywordDeclaration = "abstract|class|extends|external|factory|implements|get|native|operator|set|typedef|with|enum";
  752. var storageModifier = "static|final|const";
  753. var storageType = "void|bool|num|int|double|dynamic|var|String";
  754. var keywordMapper = this.createKeywordMapper({
  755. "constant.language.dart": constantLanguage,
  756. "variable.language.dart": variableLanguage,
  757. "keyword.control.dart": keywordControl,
  758. "keyword.declaration.dart": keywordDeclaration,
  759. "storage.modifier.dart": storageModifier,
  760. "storage.type.primitive.dart": storageType
  761. }, "identifier");
  762. var stringfill = {
  763. token : "string",
  764. regex : ".+"
  765. };
  766. this.$rules =
  767. {
  768. "start": [
  769. {
  770. token : "comment",
  771. regex : /\/\/.*$/
  772. },
  773. DocCommentHighlightRules.getStartRule("doc-start"),
  774. {
  775. token : "comment", // multi line comment
  776. regex : /\/\*/,
  777. next : "comment"
  778. },
  779. {
  780. token: ["meta.preprocessor.script.dart"],
  781. regex: "^(#!.*)$"
  782. },
  783. {
  784. token: "keyword.other.import.dart",
  785. regex: "(?:\\b)(?:library|import|export|part|of|show|hide)(?:\\b)"
  786. },
  787. {
  788. token : ["keyword.other.import.dart", "text"],
  789. regex : "(?:\\b)(prefix)(\\s*:)"
  790. },
  791. {
  792. regex: "\\bas\\b",
  793. token: "keyword.cast.dart"
  794. },
  795. {
  796. regex: "\\?|:",
  797. token: "keyword.control.ternary.dart"
  798. },
  799. {
  800. regex: "(?:\\b)(is\\!?)(?:\\b)",
  801. token: ["keyword.operator.dart"]
  802. },
  803. {
  804. regex: "(<<|>>>?|~|\\^|\\||&)",
  805. token: ["keyword.operator.bitwise.dart"]
  806. },
  807. {
  808. regex: "((?:&|\\^|\\||<<|>>>?)=)",
  809. token: ["keyword.operator.assignment.bitwise.dart"]
  810. },
  811. {
  812. regex: "(===?|!==?|<=?|>=?)",
  813. token: ["keyword.operator.comparison.dart"]
  814. },
  815. {
  816. regex: "((?:[+*/%-]|\\~)=)",
  817. token: ["keyword.operator.assignment.arithmetic.dart"]
  818. },
  819. {
  820. regex: "=",
  821. token: "keyword.operator.assignment.dart"
  822. },
  823. {
  824. token : "string",
  825. regex : "'''",
  826. next : "qdoc"
  827. },
  828. {
  829. token : "string",
  830. regex : '"""',
  831. next : "qqdoc"
  832. },
  833. {
  834. token : "string",
  835. regex : "'",
  836. next : "qstring"
  837. },
  838. {
  839. token : "string",
  840. regex : '"',
  841. next : "qqstring"
  842. },
  843. {
  844. regex: "(\\-\\-|\\+\\+)",
  845. token: ["keyword.operator.increment-decrement.dart"]
  846. },
  847. {
  848. regex: "(\\-|\\+|\\*|\\/|\\~\\/|%)",
  849. token: ["keyword.operator.arithmetic.dart"]
  850. },
  851. {
  852. regex: "(!|&&|\\|\\|)",
  853. token: ["keyword.operator.logical.dart"]
  854. },
  855. {
  856. token : "constant.numeric", // hex
  857. regex : "0[xX][0-9a-fA-F]+\\b"
  858. },
  859. {
  860. token : "constant.numeric", // float
  861. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  862. },
  863. {
  864. token : keywordMapper,
  865. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  866. }
  867. ],
  868. "comment" : [
  869. {
  870. token : "comment", // closing comment
  871. regex : ".*?\\*\\/",
  872. next : "start"
  873. }, {
  874. token : "comment", // comment spanning whole line
  875. regex : ".+"
  876. }
  877. ],
  878. "qdoc" : [
  879. {
  880. token : "string",
  881. regex : ".*?'''",
  882. next : "start"
  883. }, stringfill],
  884. "qqdoc" : [
  885. {
  886. token : "string",
  887. regex : '.*?"""',
  888. next : "start"
  889. }, stringfill],
  890. "qstring" : [
  891. {
  892. token : "string",
  893. regex : "[^\\\\']*(?:\\\\.[^\\\\']*)*'",
  894. next : "start"
  895. }, stringfill],
  896. "qqstring" : [
  897. {
  898. token : "string",
  899. regex : '[^\\\\"]*(?:\\\\.[^\\\\"]*)*"',
  900. next : "start"
  901. }, stringfill]
  902. }
  903. this.embedRules(DocCommentHighlightRules, "doc-",
  904. [ DocCommentHighlightRules.getEndRule("start") ]);
  905. };
  906. oop.inherits(DartHighlightRules, TextHighlightRules);
  907. exports.DartHighlightRules = DartHighlightRules;
  908. });
  909. define("ace/mode/dart",["require","exports","module","ace/lib/oop","ace/mode/c_cpp","ace/mode/dart_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  910. "use strict";
  911. var oop = require("../lib/oop");
  912. var CMode = require("./c_cpp").Mode;
  913. var DartHighlightRules = require("./dart_highlight_rules").DartHighlightRules;
  914. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  915. var Mode = function() {
  916. CMode.call(this);
  917. this.HighlightRules = DartHighlightRules;
  918. this.foldingRules = new CStyleFoldMode();
  919. };
  920. oop.inherits(Mode, CMode);
  921. (function() {
  922. this.lineCommentStart = "//";
  923. this.blockComment = {start: "/*", end: "*/"};
  924. this.$id = "ace/mode/dart";
  925. }).call(Mode.prototype);
  926. exports.Mode = Mode;
  927. });