643ef4de6914010141d57fcfbb21823f.js 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
  2. var oop = require("../lib/oop");
  3. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  4. var DocCommentHighlightRules = function () {
  5. this.$rules = {
  6. "start": [
  7. {
  8. token: "comment.doc.tag",
  9. regex: "@\\w+(?=\\s|$)"
  10. }, DocCommentHighlightRules.getTagRule(), {
  11. defaultToken: "comment.doc.body",
  12. caseInsensitive: true
  13. }
  14. ]
  15. };
  16. };
  17. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  18. DocCommentHighlightRules.getTagRule = function (start) {
  19. return {
  20. token: "comment.doc.tag.storage.type",
  21. regex: "\\b(?:TODO|FIXME|XXX|HACK)\\b"
  22. };
  23. };
  24. DocCommentHighlightRules.getStartRule = function (start) {
  25. return {
  26. token: "comment.doc", // doc comment
  27. regex: /\/\*\*(?!\/)/,
  28. next: start
  29. };
  30. };
  31. DocCommentHighlightRules.getEndRule = function (start) {
  32. return {
  33. token: "comment.doc", // closing comment
  34. regex: "\\*\\/",
  35. next: start
  36. };
  37. };
  38. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  39. });
  40. ace.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){"use strict";
  41. var oop = require("../lib/oop");
  42. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  43. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  44. var cFunctions = exports.cFunctions = "hypot|hypotf|hypotl|sscanf|system|snprintf|scanf|scalbn|scalbnf|scalbnl|scalbln|scalblnf|scalblnl|sin|sinh|sinhf|sinhl|sinf|sinl|signal|signbit|strstr|strspn|strncpy|strncat|strncmp|strcspn|strchr|strcoll|strcpy|strcat|strcmp|strtoimax|strtod|strtoul|strtoull|strtoumax|strtok|strtof|strtol|strtold|strtoll|strerror|strpbrk|strftime|strlen|strrchr|strxfrm|sprintf|setjmp|setvbuf|setlocale|setbuf|sqrt|sqrtf|sqrtl|swscanf|swprintf|srand|nearbyint|nearbyintf|nearbyintl|nexttoward|nexttowardf|nexttowardl|nextafter|nextafterf|nextafterl|nan|nanf|nanl|csin|csinh|csinhf|csinhl|csinf|csinl|csqrt|csqrtf|csqrtl|ccos|ccosh|ccoshf|ccosf|ccosl|cimag|cimagf|cimagl|ctime|ctan|ctanh|ctanhf|ctanhl|ctanf|ctanl|cos|cosh|coshf|coshl|cosf|cosl|conj|conjf|conjl|copysign|copysignf|copysignl|cpow|cpowf|cpowl|cproj|cprojf|cprojl|ceil|ceilf|ceill|cexp|cexpf|cexpl|clock|clog|clogf|clogl|clearerr|casin|casinh|casinhf|casinhl|casinf|casinl|cacos|cacosh|cacoshf|cacoshl|cacosf|cacosl|catan|catanh|catanhf|catanhl|catanf|catanl|calloc|carg|cargf|cargl|cabs|cabsf|cabsl|creal|crealf|creall|cbrt|cbrtf|cbrtl|time|toupper|tolower|tan|tanh|tanhf|tanhl|tanf|tanl|trunc|truncf|truncl|tgamma|tgammaf|tgammal|tmpnam|tmpfile|isspace|isnormal|isnan|iscntrl|isinf|isdigit|isunordered|isupper|ispunct|isprint|isfinite|iswspace|iswcntrl|iswctype|iswdigit|iswupper|iswpunct|iswprint|iswlower|iswalnum|iswalpha|iswgraph|iswxdigit|iswblank|islower|isless|islessequal|islessgreater|isalnum|isalpha|isgreater|isgreaterequal|isgraph|isxdigit|isblank|ilogb|ilogbf|ilogbl|imaxdiv|imaxabs|div|difftime|_Exit|ungetc|ungetwc|pow|powf|powl|puts|putc|putchar|putwc|putwchar|perror|printf|erf|erfc|erfcf|erfcl|erff|erfl|exit|exp|exp2|exp2f|exp2l|expf|expl|expm1|expm1f|expm1l|vsscanf|vsnprintf|vscanf|vsprintf|vswscanf|vswprintf|vprintf|vfscanf|vfprintf|vfwscanf|vfwprintf|vwscanf|vwprintf|va_start|va_copy|va_end|va_arg|qsort|fscanf|fsetpos|fseek|fclose|ftell|fopen|fdim|fdimf|fdiml|fpclassify|fputs|fputc|fputws|fputwc|fprintf|feholdexcept|fesetenv|fesetexceptflag|fesetround|feclearexcept|fetestexcept|feof|feupdateenv|feraiseexcept|ferror|fegetenv|fegetexceptflag|fegetround|fflush|fwscanf|fwide|fwprintf|fwrite|floor|floorf|floorl|fabs|fabsf|fabsl|fgets|fgetc|fgetpos|fgetws|fgetwc|freopen|free|fread|frexp|frexpf|frexpl|fmin|fminf|fminl|fmod|fmodf|fmodl|fma|fmaf|fmal|fmax|fmaxf|fmaxl|ldiv|ldexp|ldexpf|ldexpl|longjmp|localtime|localeconv|log|log1p|log1pf|log1pl|log10|log10f|log10l|log2|log2f|log2l|logf|logl|logb|logbf|logbl|labs|lldiv|llabs|llrint|llrintf|llrintl|llround|llroundf|llroundl|lrint|lrintf|lrintl|lround|lroundf|lroundl|lgamma|lgammaf|lgammal|wscanf|wcsstr|wcsspn|wcsncpy|wcsncat|wcsncmp|wcscspn|wcschr|wcscoll|wcscpy|wcscat|wcscmp|wcstoimax|wcstod|wcstoul|wcstoull|wcstoumax|wcstok|wcstof|wcstol|wcstold|wcstoll|wcstombs|wcspbrk|wcsftime|wcslen|wcsrchr|wcsrtombs|wcsxfrm|wctob|wctomb|wcrtomb|wprintf|wmemset|wmemchr|wmemcpy|wmemcmp|wmemmove|assert|asctime|asin|asinh|asinhf|asinhl|asinf|asinl|acos|acosh|acoshf|acoshl|acosf|acosl|atoi|atof|atol|atoll|atexit|atan|atanh|atanhf|atanhl|atan2|atan2f|atan2l|atanf|atanl|abs|abort|gets|getc|getchar|getenv|getwc|getwchar|gmtime|rint|rintf|rintl|round|roundf|roundl|rename|realloc|rewind|remove|remquo|remquof|remquol|remainder|remainderf|remainderl|rand|raise|bsearch|btowc|modf|modff|modfl|memset|memchr|memcpy|memcmp|memmove|mktime|malloc|mbsinit|mbstowcs|mbsrtowcs|mbtowc|mblen|mbrtowc|mbrlen";
  45. var c_cppHighlightRules = function (extraKeywords) {
  46. var keywordControls = ("break|case|continue|default|do|else|for|goto|if|_Pragma|" +
  47. "return|switch|while|catch|operator|try|throw|using");
  48. var storageType = ("asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
  49. "_Imaginary|int|int8_t|int16_t|int32_t|int64_t|long|short|signed|size_t|struct|typedef|uint8_t|uint16_t|uint32_t|uint64_t|union|unsigned|void|" +
  50. "class|wchar_t|template|char16_t|char32_t");
  51. var storageModifiers = ("const|extern|register|restrict|static|volatile|inline|private|" +
  52. "protected|public|friend|explicit|virtual|export|mutable|typename|" +
  53. "constexpr|new|delete|alignas|alignof|decltype|noexcept|thread_local");
  54. var keywordOperators = ("and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq|" +
  55. "const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace");
  56. var builtinConstants = ("NULL|true|false|TRUE|FALSE|nullptr");
  57. var keywordMapper = this.$keywords = this.createKeywordMapper(Object.assign({
  58. "keyword.control": keywordControls,
  59. "storage.type": storageType,
  60. "storage.modifier": storageModifiers,
  61. "keyword.operator": keywordOperators,
  62. "variable.language": "this",
  63. "constant.language": builtinConstants,
  64. "support.function.C99.c": cFunctions
  65. }, extraKeywords), "identifier");
  66. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\\d\\$_\u00a1-\uffff]*\\b";
  67. var escapeRe = /\\(?:['"?\\abfnrtv]|[0-7]{1,3}|x[a-fA-F\d]{2}|u[a-fA-F\d]{4}U[a-fA-F\d]{8}|.)/.source;
  68. var formatRe = "%"
  69. + /(\d+\$)?/.source // field (argument #)
  70. + /[#0\- +']*/.source // flags
  71. + /[,;:_]?/.source // separator character (AltiVec)
  72. + /((-?\d+)|\*(-?\d+\$)?)?/.source // minimum field width
  73. + /(\.((-?\d+)|\*(-?\d+\$)?)?)?/.source // precision
  74. + /(hh|h|ll|l|j|t|z|q|L|vh|vl|v|hv|hl)?/.source // length modifier
  75. + /(\[[^"\]]+\]|[diouxXDOUeEfFgGaACcSspn%])/.source; // conversion type
  76. this.$rules = {
  77. "start": [
  78. {
  79. token: "comment",
  80. regex: "//$",
  81. next: "start"
  82. }, {
  83. token: "comment",
  84. regex: "//",
  85. next: "singleLineComment"
  86. },
  87. DocCommentHighlightRules.getStartRule("doc-start"),
  88. {
  89. token: "comment", // multi line comment
  90. regex: "\\/\\*",
  91. next: "comment"
  92. }, {
  93. token: "string", // character
  94. regex: "'(?:" + escapeRe + "|.)?'"
  95. }, {
  96. token: "string.start",
  97. regex: '"',
  98. stateName: "qqstring",
  99. next: [
  100. { token: "string", regex: /\\\s*$/, next: "qqstring" },
  101. { token: "constant.language.escape", regex: escapeRe },
  102. { token: "constant.language.escape", regex: formatRe },
  103. { token: "string.end", regex: '"|$', next: "start" },
  104. { defaultToken: "string" }
  105. ]
  106. }, {
  107. token: "string.start",
  108. regex: 'R"\\(',
  109. stateName: "rawString",
  110. next: [
  111. { token: "string.end", regex: '\\)"', next: "start" },
  112. { defaultToken: "string" }
  113. ]
  114. }, {
  115. token: "constant.numeric", // hex
  116. regex: "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  117. }, {
  118. token: "constant.numeric", // float
  119. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  120. }, {
  121. token: "keyword", // pre-compiler directives
  122. regex: "#\\s*(?:include|import|pragma|line|define|undef)\\b",
  123. next: "directive"
  124. }, {
  125. token: "keyword", // special case pre-compiler directive
  126. regex: "#\\s*(?:endif|if|ifdef|else|elif|ifndef)\\b"
  127. }, {
  128. token: keywordMapper,
  129. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*"
  130. }, {
  131. token: "keyword.operator",
  132. regex: /--|\+\+|<<=|>>=|>>>=|<>|&&|\|\||\?:|[*%\/+\-&\^|~!<>=]=?/
  133. }, {
  134. token: "punctuation.operator",
  135. regex: "\\?|\\:|\\,|\\;|\\."
  136. }, {
  137. token: "paren.lparen",
  138. regex: "[[({]"
  139. }, {
  140. token: "paren.rparen",
  141. regex: "[\\])}]"
  142. }, {
  143. token: "text",
  144. regex: "\\s+"
  145. }
  146. ],
  147. "comment": [
  148. {
  149. token: "comment", // closing comment
  150. regex: "\\*\\/",
  151. next: "start"
  152. }, {
  153. defaultToken: "comment"
  154. }
  155. ],
  156. "singleLineComment": [
  157. {
  158. token: "comment",
  159. regex: /\\$/,
  160. next: "singleLineComment"
  161. }, {
  162. token: "comment",
  163. regex: /$/,
  164. next: "start"
  165. }, {
  166. defaultToken: "comment"
  167. }
  168. ],
  169. "directive": [
  170. {
  171. token: "constant.other.multiline",
  172. regex: /\\/
  173. },
  174. {
  175. token: "constant.other.multiline",
  176. regex: /.*\\/
  177. },
  178. {
  179. token: "constant.other",
  180. regex: "\\s*<.+?>",
  181. next: "start"
  182. },
  183. {
  184. token: "constant.other", // single line
  185. regex: '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
  186. next: "start"
  187. },
  188. {
  189. token: "constant.other", // single line
  190. regex: "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
  191. next: "start"
  192. },
  193. {
  194. token: "constant.other",
  195. regex: /[^\\\/]+/,
  196. next: "start"
  197. }
  198. ]
  199. };
  200. this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
  201. this.normalizeRules();
  202. };
  203. oop.inherits(c_cppHighlightRules, TextHighlightRules);
  204. exports.c_cppHighlightRules = c_cppHighlightRules;
  205. });
  206. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
  207. var Range = require("../range").Range;
  208. var MatchingBraceOutdent = function () { };
  209. (function () {
  210. this.checkOutdent = function (line, input) {
  211. if (!/^\s+$/.test(line))
  212. return false;
  213. return /^\s*\}/.test(input);
  214. };
  215. this.autoOutdent = function (doc, row) {
  216. var line = doc.getLine(row);
  217. var match = line.match(/^(\s*\})/);
  218. if (!match)
  219. return 0;
  220. var column = match[1].length;
  221. var openBracePos = doc.findMatchingBracket({ row: row, column: column });
  222. if (!openBracePos || openBracePos.row == row)
  223. return 0;
  224. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  225. doc.replace(new Range(row, 0, row, column - 1), indent);
  226. };
  227. this.$getIndent = function (line) {
  228. return line.match(/^\s*/)[0];
  229. };
  230. }).call(MatchingBraceOutdent.prototype);
  231. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  232. });
  233. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
  234. var oop = require("../../lib/oop");
  235. var Range = require("../../range").Range;
  236. var BaseFoldMode = require("./fold_mode").FoldMode;
  237. var FoldMode = exports.FoldMode = function (commentRegex) {
  238. if (commentRegex) {
  239. this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
  240. this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
  241. }
  242. };
  243. oop.inherits(FoldMode, BaseFoldMode);
  244. (function () {
  245. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  246. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  247. this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
  248. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  249. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  250. this._getFoldWidgetBase = this.getFoldWidget;
  251. this.getFoldWidget = function (session, foldStyle, row) {
  252. var line = session.getLine(row);
  253. if (this.singleLineBlockCommentRe.test(line)) {
  254. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  255. return "";
  256. }
  257. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  258. if (!fw && this.startRegionRe.test(line))
  259. return "start"; // lineCommentRegionStart
  260. return fw;
  261. };
  262. this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
  263. var line = session.getLine(row);
  264. if (this.startRegionRe.test(line))
  265. return this.getCommentRegionBlock(session, line, row);
  266. var match = line.match(this.foldingStartMarker);
  267. if (match) {
  268. var i = match.index;
  269. if (match[1])
  270. return this.openingBracketBlock(session, match[1], row, i);
  271. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  272. if (range && !range.isMultiLine()) {
  273. if (forceMultiline) {
  274. range = this.getSectionRange(session, row);
  275. }
  276. else if (foldStyle != "all")
  277. range = null;
  278. }
  279. return range;
  280. }
  281. if (foldStyle === "markbegin")
  282. return;
  283. var match = line.match(this.foldingStopMarker);
  284. if (match) {
  285. var i = match.index + match[0].length;
  286. if (match[1])
  287. return this.closingBracketBlock(session, match[1], row, i);
  288. return session.getCommentFoldRange(row, i, -1);
  289. }
  290. };
  291. this.getSectionRange = function (session, row) {
  292. var line = session.getLine(row);
  293. var startIndent = line.search(/\S/);
  294. var startRow = row;
  295. var startColumn = line.length;
  296. row = row + 1;
  297. var endRow = row;
  298. var maxRow = session.getLength();
  299. while (++row < maxRow) {
  300. line = session.getLine(row);
  301. var indent = line.search(/\S/);
  302. if (indent === -1)
  303. continue;
  304. if (startIndent > indent)
  305. break;
  306. var subRange = this.getFoldWidgetRange(session, "all", row);
  307. if (subRange) {
  308. if (subRange.start.row <= startRow) {
  309. break;
  310. }
  311. else if (subRange.isMultiLine()) {
  312. row = subRange.end.row;
  313. }
  314. else if (startIndent == indent) {
  315. break;
  316. }
  317. }
  318. endRow = row;
  319. }
  320. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  321. };
  322. this.getCommentRegionBlock = function (session, line, row) {
  323. var startColumn = line.search(/\s*$/);
  324. var maxRow = session.getLength();
  325. var startRow = row;
  326. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  327. var depth = 1;
  328. while (++row < maxRow) {
  329. line = session.getLine(row);
  330. var m = re.exec(line);
  331. if (!m)
  332. continue;
  333. if (m[1])
  334. depth--;
  335. else
  336. depth++;
  337. if (!depth)
  338. break;
  339. }
  340. var endRow = row;
  341. if (endRow > startRow) {
  342. return new Range(startRow, startColumn, endRow, line.length);
  343. }
  344. };
  345. }).call(FoldMode.prototype);
  346. });
  347. ace.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/mode/folding/cstyle"], function(require, exports, module){"use strict";
  348. var oop = require("../lib/oop");
  349. var TextMode = require("./text").Mode;
  350. var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
  351. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  352. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  353. var Mode = function () {
  354. this.HighlightRules = c_cppHighlightRules;
  355. this.$outdent = new MatchingBraceOutdent();
  356. this.$behaviour = this.$defaultBehaviour;
  357. this.foldingRules = new CStyleFoldMode();
  358. };
  359. oop.inherits(Mode, TextMode);
  360. (function () {
  361. this.lineCommentStart = "//";
  362. this.blockComment = { start: "/*", end: "*/" };
  363. this.getNextLineIndent = function (state, line, tab) {
  364. var indent = this.$getIndent(line);
  365. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  366. var tokens = tokenizedLine.tokens;
  367. var endState = tokenizedLine.state;
  368. if (tokens.length && tokens[tokens.length - 1].type == "comment") {
  369. return indent;
  370. }
  371. if (state == "start") {
  372. var match = line.match(/^.*[\{\(\[]\s*$/);
  373. if (match) {
  374. indent += tab;
  375. }
  376. }
  377. else if (state == "doc-start") {
  378. if (endState == "start") {
  379. return "";
  380. }
  381. var match = line.match(/^\s*(\/?)\*/);
  382. if (match) {
  383. if (match[1]) {
  384. indent += " ";
  385. }
  386. indent += "* ";
  387. }
  388. }
  389. return indent;
  390. };
  391. this.checkOutdent = function (state, line, input) {
  392. return this.$outdent.checkOutdent(line, input);
  393. };
  394. this.autoOutdent = function (state, doc, row) {
  395. this.$outdent.autoOutdent(doc, row);
  396. };
  397. this.$id = "ace/mode/c_cpp";
  398. this.snippetFileId = "ace/snippets/c_cpp";
  399. }).call(Mode.prototype);
  400. exports.Mode = Mode;
  401. }); (function() {
  402. ace.require(["ace/mode/c_cpp"], function(m) {
  403. if (typeof module == "object" && typeof exports == "object" && module) {
  404. module.exports = m;
  405. }
  406. });
  407. })();