PageRenderTime 61ms CodeModel.GetById 22ms RepoModel.GetById 1ms app.codeStats 0ms

/files/ace/1.1.5/noconflict/mode-protobuf.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 877 lines | 801 code | 76 blank | 0 comment | 55 complexity | 96df5edb783a65cc304053e8393fcb1e MD5 | raw file
  1. ace.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. token : "comment.doc.tag",
  12. regex : "\\bTODO\\b"
  13. }, {
  14. defaultToken : "comment.doc"
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getStartRule = function(start) {
  20. return {
  21. token : "comment.doc", // doc comment
  22. regex : "\\/\\*(?=\\*)",
  23. next : start
  24. };
  25. };
  26. DocCommentHighlightRules.getEndRule = function (start) {
  27. return {
  28. token : "comment.doc", // closing comment
  29. regex : "\\*\\/",
  30. next : start
  31. };
  32. };
  33. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  34. });
  35. 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) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  39. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  40. 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"
  41. var c_cppHighlightRules = function() {
  42. var keywordControls = (
  43. "break|case|continue|default|do|else|for|goto|if|_Pragma|" +
  44. "return|switch|while|catch|operator|try|throw|using"
  45. );
  46. var storageType = (
  47. "asm|__asm__|auto|bool|_Bool|char|_Complex|double|enum|float|" +
  48. "_Imaginary|int|long|short|signed|struct|typedef|union|unsigned|void|" +
  49. "class|wchar_t|template"
  50. );
  51. var storageModifiers = (
  52. "const|extern|register|restrict|static|volatile|inline|private:|" +
  53. "protected:|public:|friend|explicit|virtual|export|mutable|typename"
  54. );
  55. var keywordOperators = (
  56. "and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|typeid|xor|xor_eq" +
  57. "const_cast|dynamic_cast|reinterpret_cast|static_cast|sizeof|namespace"
  58. );
  59. var builtinConstants = (
  60. "NULL|true|false|TRUE|FALSE"
  61. );
  62. var keywordMapper = this.$keywords = this.createKeywordMapper({
  63. "keyword.control" : keywordControls,
  64. "storage.type" : storageType,
  65. "storage.modifier" : storageModifiers,
  66. "keyword.operator" : keywordOperators,
  67. "variable.language": "this",
  68. "constant.language": builtinConstants
  69. }, "identifier");
  70. var identifierRe = "[a-zA-Z\\$_\u00a1-\uffff][a-zA-Z\d\\$_\u00a1-\uffff]*\\b";
  71. this.$rules = {
  72. "start" : [
  73. {
  74. token : "comment",
  75. regex : "\\/\\/.*$"
  76. },
  77. DocCommentHighlightRules.getStartRule("doc-start"),
  78. {
  79. token : "comment", // multi line comment
  80. regex : "\\/\\*",
  81. next : "comment"
  82. }, {
  83. token : "string", // single line
  84. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  85. }, {
  86. token : "string", // multi line string start
  87. regex : '["].*\\\\$',
  88. next : "qqstring"
  89. }, {
  90. token : "string", // single line
  91. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  92. }, {
  93. token : "string", // multi line string start
  94. regex : "['].*\\\\$",
  95. next : "qstring"
  96. }, {
  97. token : "constant.numeric", // hex
  98. regex : "0[xX][0-9a-fA-F]+(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  99. }, {
  100. token : "constant.numeric", // float
  101. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?(L|l|UL|ul|u|U|F|f|ll|LL|ull|ULL)?\\b"
  102. }, {
  103. token : "keyword", // pre-compiler directives
  104. regex : "#\\s*(?:include|import|pragma|line|define|undef|if|ifdef|else|elif|ifndef)\\b",
  105. next : "directive"
  106. }, {
  107. token : "keyword", // special case pre-compiler directive
  108. regex : "(?:#\\s*endif)\\b"
  109. }, {
  110. token : "support.function.C99.c",
  111. regex : cFunctions
  112. }, {
  113. token : keywordMapper,
  114. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  115. }, {
  116. token : "keyword.operator",
  117. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|new|delete|typeof|void)"
  118. }, {
  119. token : "punctuation.operator",
  120. regex : "\\?|\\:|\\,|\\;|\\."
  121. }, {
  122. token : "paren.lparen",
  123. regex : "[[({]"
  124. }, {
  125. token : "paren.rparen",
  126. regex : "[\\])}]"
  127. }, {
  128. token : "text",
  129. regex : "\\s+"
  130. }
  131. ],
  132. "comment" : [
  133. {
  134. token : "comment", // closing comment
  135. regex : ".*?\\*\\/",
  136. next : "start"
  137. }, {
  138. token : "comment", // comment spanning whole line
  139. regex : ".+"
  140. }
  141. ],
  142. "qqstring" : [
  143. {
  144. token : "string",
  145. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  146. next : "start"
  147. }, {
  148. token : "string",
  149. regex : '.+'
  150. }
  151. ],
  152. "qstring" : [
  153. {
  154. token : "string",
  155. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  156. next : "start"
  157. }, {
  158. token : "string",
  159. regex : '.+'
  160. }
  161. ],
  162. "directive" : [
  163. {
  164. token : "constant.other.multiline",
  165. regex : /\\/
  166. },
  167. {
  168. token : "constant.other.multiline",
  169. regex : /.*\\/
  170. },
  171. {
  172. token : "constant.other",
  173. regex : "\\s*<.+?>",
  174. next : "start"
  175. },
  176. {
  177. token : "constant.other", // single line
  178. regex : '\\s*["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]',
  179. next : "start"
  180. },
  181. {
  182. token : "constant.other", // single line
  183. regex : "\\s*['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']",
  184. next : "start"
  185. },
  186. {
  187. token : "constant.other",
  188. regex : /[^\\\/]+/,
  189. next : "start"
  190. }
  191. ]
  192. };
  193. this.embedRules(DocCommentHighlightRules, "doc-",
  194. [ DocCommentHighlightRules.getEndRule("start") ]);
  195. };
  196. oop.inherits(c_cppHighlightRules, TextHighlightRules);
  197. exports.c_cppHighlightRules = c_cppHighlightRules;
  198. });
  199. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  200. "use strict";
  201. var Range = require("../range").Range;
  202. var MatchingBraceOutdent = function() {};
  203. (function() {
  204. this.checkOutdent = function(line, input) {
  205. if (! /^\s+$/.test(line))
  206. return false;
  207. return /^\s*\}/.test(input);
  208. };
  209. this.autoOutdent = function(doc, row) {
  210. var line = doc.getLine(row);
  211. var match = line.match(/^(\s*\})/);
  212. if (!match) return 0;
  213. var column = match[1].length;
  214. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  215. if (!openBracePos || openBracePos.row == row) return 0;
  216. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  217. doc.replace(new Range(row, 0, row, column-1), indent);
  218. };
  219. this.$getIndent = function(line) {
  220. return line.match(/^\s*/)[0];
  221. };
  222. }).call(MatchingBraceOutdent.prototype);
  223. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  224. });
  225. 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) {
  226. "use strict";
  227. var oop = require("../../lib/oop");
  228. var Behaviour = require("../behaviour").Behaviour;
  229. var TokenIterator = require("../../token_iterator").TokenIterator;
  230. var lang = require("../../lib/lang");
  231. var SAFE_INSERT_IN_TOKENS =
  232. ["text", "paren.rparen", "punctuation.operator"];
  233. var SAFE_INSERT_BEFORE_TOKENS =
  234. ["text", "paren.rparen", "punctuation.operator", "comment"];
  235. var context;
  236. var contextCache = {}
  237. var initContext = function(editor) {
  238. var id = -1;
  239. if (editor.multiSelect) {
  240. id = editor.selection.id;
  241. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  242. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  243. }
  244. if (contextCache[id])
  245. return context = contextCache[id];
  246. context = contextCache[id] = {
  247. autoInsertedBrackets: 0,
  248. autoInsertedRow: -1,
  249. autoInsertedLineEnd: "",
  250. maybeInsertedBrackets: 0,
  251. maybeInsertedRow: -1,
  252. maybeInsertedLineStart: "",
  253. maybeInsertedLineEnd: ""
  254. };
  255. };
  256. var CstyleBehaviour = function() {
  257. this.add("braces", "insertion", function(state, action, editor, session, text) {
  258. var cursor = editor.getCursorPosition();
  259. var line = session.doc.getLine(cursor.row);
  260. if (text == '{') {
  261. initContext(editor);
  262. var selection = editor.getSelectionRange();
  263. var selected = session.doc.getTextRange(selection);
  264. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  265. return {
  266. text: '{' + selected + '}',
  267. selection: false
  268. };
  269. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  270. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  271. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  272. return {
  273. text: '{}',
  274. selection: [1, 1]
  275. };
  276. } else {
  277. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  278. return {
  279. text: '{',
  280. selection: [1, 1]
  281. };
  282. }
  283. }
  284. } else if (text == '}') {
  285. initContext(editor);
  286. var rightChar = line.substring(cursor.column, cursor.column + 1);
  287. if (rightChar == '}') {
  288. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  289. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  290. CstyleBehaviour.popAutoInsertedClosing();
  291. return {
  292. text: '',
  293. selection: [1, 1]
  294. };
  295. }
  296. }
  297. } else if (text == "\n" || text == "\r\n") {
  298. initContext(editor);
  299. var closing = "";
  300. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  301. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  302. CstyleBehaviour.clearMaybeInsertedClosing();
  303. }
  304. var rightChar = line.substring(cursor.column, cursor.column + 1);
  305. if (rightChar === '}') {
  306. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  307. if (!openBracePos)
  308. return null;
  309. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  310. } else if (closing) {
  311. var next_indent = this.$getIndent(line);
  312. } else {
  313. CstyleBehaviour.clearMaybeInsertedClosing();
  314. return;
  315. }
  316. var indent = next_indent + session.getTabString();
  317. return {
  318. text: '\n' + indent + '\n' + next_indent + closing,
  319. selection: [1, indent.length, 1, indent.length]
  320. };
  321. } else {
  322. CstyleBehaviour.clearMaybeInsertedClosing();
  323. }
  324. });
  325. this.add("braces", "deletion", function(state, action, editor, session, range) {
  326. var selected = session.doc.getTextRange(range);
  327. if (!range.isMultiLine() && selected == '{') {
  328. initContext(editor);
  329. var line = session.doc.getLine(range.start.row);
  330. var rightChar = line.substring(range.end.column, range.end.column + 1);
  331. if (rightChar == '}') {
  332. range.end.column++;
  333. return range;
  334. } else {
  335. context.maybeInsertedBrackets--;
  336. }
  337. }
  338. });
  339. this.add("parens", "insertion", function(state, action, editor, session, text) {
  340. if (text == '(') {
  341. initContext(editor);
  342. var selection = editor.getSelectionRange();
  343. var selected = session.doc.getTextRange(selection);
  344. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  345. return {
  346. text: '(' + selected + ')',
  347. selection: false
  348. };
  349. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  350. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  351. return {
  352. text: '()',
  353. selection: [1, 1]
  354. };
  355. }
  356. } else if (text == ')') {
  357. initContext(editor);
  358. var cursor = editor.getCursorPosition();
  359. var line = session.doc.getLine(cursor.row);
  360. var rightChar = line.substring(cursor.column, cursor.column + 1);
  361. if (rightChar == ')') {
  362. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  363. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  364. CstyleBehaviour.popAutoInsertedClosing();
  365. return {
  366. text: '',
  367. selection: [1, 1]
  368. };
  369. }
  370. }
  371. }
  372. });
  373. this.add("parens", "deletion", function(state, action, editor, session, range) {
  374. var selected = session.doc.getTextRange(range);
  375. if (!range.isMultiLine() && selected == '(') {
  376. initContext(editor);
  377. var line = session.doc.getLine(range.start.row);
  378. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  379. if (rightChar == ')') {
  380. range.end.column++;
  381. return range;
  382. }
  383. }
  384. });
  385. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  386. if (text == '[') {
  387. initContext(editor);
  388. var selection = editor.getSelectionRange();
  389. var selected = session.doc.getTextRange(selection);
  390. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  391. return {
  392. text: '[' + selected + ']',
  393. selection: false
  394. };
  395. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  396. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  397. return {
  398. text: '[]',
  399. selection: [1, 1]
  400. };
  401. }
  402. } else if (text == ']') {
  403. initContext(editor);
  404. var cursor = editor.getCursorPosition();
  405. var line = session.doc.getLine(cursor.row);
  406. var rightChar = line.substring(cursor.column, cursor.column + 1);
  407. if (rightChar == ']') {
  408. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  409. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  410. CstyleBehaviour.popAutoInsertedClosing();
  411. return {
  412. text: '',
  413. selection: [1, 1]
  414. };
  415. }
  416. }
  417. }
  418. });
  419. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  420. var selected = session.doc.getTextRange(range);
  421. if (!range.isMultiLine() && selected == '[') {
  422. initContext(editor);
  423. var line = session.doc.getLine(range.start.row);
  424. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  425. if (rightChar == ']') {
  426. range.end.column++;
  427. return range;
  428. }
  429. }
  430. });
  431. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  432. if (text == '"' || text == "'") {
  433. initContext(editor);
  434. var quote = text;
  435. var selection = editor.getSelectionRange();
  436. var selected = session.doc.getTextRange(selection);
  437. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  438. return {
  439. text: quote + selected + quote,
  440. selection: false
  441. };
  442. } else {
  443. var cursor = editor.getCursorPosition();
  444. var line = session.doc.getLine(cursor.row);
  445. var leftChar = line.substring(cursor.column-1, cursor.column);
  446. if (leftChar == '\\') {
  447. return null;
  448. }
  449. var tokens = session.getTokens(selection.start.row);
  450. var col = 0, token;
  451. var quotepos = -1; // Track whether we're inside an open quote.
  452. for (var x = 0; x < tokens.length; x++) {
  453. token = tokens[x];
  454. if (token.type == "string") {
  455. quotepos = -1;
  456. } else if (quotepos < 0) {
  457. quotepos = token.value.indexOf(quote);
  458. }
  459. if ((token.value.length + col) > selection.start.column) {
  460. break;
  461. }
  462. col += tokens[x].value.length;
  463. }
  464. 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)))) {
  465. if (!CstyleBehaviour.isSaneInsertion(editor, session))
  466. return;
  467. return {
  468. text: quote + quote,
  469. selection: [1,1]
  470. };
  471. } else if (token && token.type === "string") {
  472. var rightChar = line.substring(cursor.column, cursor.column + 1);
  473. if (rightChar == quote) {
  474. return {
  475. text: '',
  476. selection: [1, 1]
  477. };
  478. }
  479. }
  480. }
  481. }
  482. });
  483. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  484. var selected = session.doc.getTextRange(range);
  485. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  486. initContext(editor);
  487. var line = session.doc.getLine(range.start.row);
  488. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  489. if (rightChar == selected) {
  490. range.end.column++;
  491. return range;
  492. }
  493. }
  494. });
  495. };
  496. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  497. var cursor = editor.getCursorPosition();
  498. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  499. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  500. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  501. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  502. return false;
  503. }
  504. iterator.stepForward();
  505. return iterator.getCurrentTokenRow() !== cursor.row ||
  506. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  507. };
  508. CstyleBehaviour.$matchTokenType = function(token, types) {
  509. return types.indexOf(token.type || token) > -1;
  510. };
  511. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  512. var cursor = editor.getCursorPosition();
  513. var line = session.doc.getLine(cursor.row);
  514. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  515. context.autoInsertedBrackets = 0;
  516. context.autoInsertedRow = cursor.row;
  517. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  518. context.autoInsertedBrackets++;
  519. };
  520. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  521. var cursor = editor.getCursorPosition();
  522. var line = session.doc.getLine(cursor.row);
  523. if (!this.isMaybeInsertedClosing(cursor, line))
  524. context.maybeInsertedBrackets = 0;
  525. context.maybeInsertedRow = cursor.row;
  526. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  527. context.maybeInsertedLineEnd = line.substr(cursor.column);
  528. context.maybeInsertedBrackets++;
  529. };
  530. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  531. return context.autoInsertedBrackets > 0 &&
  532. cursor.row === context.autoInsertedRow &&
  533. bracket === context.autoInsertedLineEnd[0] &&
  534. line.substr(cursor.column) === context.autoInsertedLineEnd;
  535. };
  536. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  537. return context.maybeInsertedBrackets > 0 &&
  538. cursor.row === context.maybeInsertedRow &&
  539. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  540. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  541. };
  542. CstyleBehaviour.popAutoInsertedClosing = function() {
  543. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  544. context.autoInsertedBrackets--;
  545. };
  546. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  547. if (context) {
  548. context.maybeInsertedBrackets = 0;
  549. context.maybeInsertedRow = -1;
  550. }
  551. };
  552. oop.inherits(CstyleBehaviour, Behaviour);
  553. exports.CstyleBehaviour = CstyleBehaviour;
  554. });
  555. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  556. "use strict";
  557. var oop = require("../../lib/oop");
  558. var Range = require("../../range").Range;
  559. var BaseFoldMode = require("./fold_mode").FoldMode;
  560. var FoldMode = exports.FoldMode = function(commentRegex) {
  561. if (commentRegex) {
  562. this.foldingStartMarker = new RegExp(
  563. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  564. );
  565. this.foldingStopMarker = new RegExp(
  566. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  567. );
  568. }
  569. };
  570. oop.inherits(FoldMode, BaseFoldMode);
  571. (function() {
  572. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  573. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  574. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  575. var line = session.getLine(row);
  576. var match = line.match(this.foldingStartMarker);
  577. if (match) {
  578. var i = match.index;
  579. if (match[1])
  580. return this.openingBracketBlock(session, match[1], row, i);
  581. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  582. if (range && !range.isMultiLine()) {
  583. if (forceMultiline) {
  584. range = this.getSectionRange(session, row);
  585. } else if (foldStyle != "all")
  586. range = null;
  587. }
  588. return range;
  589. }
  590. if (foldStyle === "markbegin")
  591. return;
  592. var match = line.match(this.foldingStopMarker);
  593. if (match) {
  594. var i = match.index + match[0].length;
  595. if (match[1])
  596. return this.closingBracketBlock(session, match[1], row, i);
  597. return session.getCommentFoldRange(row, i, -1);
  598. }
  599. };
  600. this.getSectionRange = function(session, row) {
  601. var line = session.getLine(row);
  602. var startIndent = line.search(/\S/);
  603. var startRow = row;
  604. var startColumn = line.length;
  605. row = row + 1;
  606. var endRow = row;
  607. var maxRow = session.getLength();
  608. while (++row < maxRow) {
  609. line = session.getLine(row);
  610. var indent = line.search(/\S/);
  611. if (indent === -1)
  612. continue;
  613. if (startIndent > indent)
  614. break;
  615. var subRange = this.getFoldWidgetRange(session, "all", row);
  616. if (subRange) {
  617. if (subRange.start.row <= startRow) {
  618. break;
  619. } else if (subRange.isMultiLine()) {
  620. row = subRange.end.row;
  621. } else if (startIndent == indent) {
  622. break;
  623. }
  624. }
  625. endRow = row;
  626. }
  627. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  628. };
  629. }).call(FoldMode.prototype);
  630. });
  631. 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/range","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  632. "use strict";
  633. var oop = require("../lib/oop");
  634. var TextMode = require("./text").Mode;
  635. var c_cppHighlightRules = require("./c_cpp_highlight_rules").c_cppHighlightRules;
  636. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  637. var Range = require("../range").Range;
  638. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  639. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  640. var Mode = function() {
  641. this.HighlightRules = c_cppHighlightRules;
  642. this.$outdent = new MatchingBraceOutdent();
  643. this.$behaviour = new CstyleBehaviour();
  644. this.foldingRules = new CStyleFoldMode();
  645. };
  646. oop.inherits(Mode, TextMode);
  647. (function() {
  648. this.lineCommentStart = "//";
  649. this.blockComment = {start: "/*", end: "*/"};
  650. this.getNextLineIndent = function(state, line, tab) {
  651. var indent = this.$getIndent(line);
  652. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  653. var tokens = tokenizedLine.tokens;
  654. var endState = tokenizedLine.state;
  655. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  656. return indent;
  657. }
  658. if (state == "start") {
  659. var match = line.match(/^.*[\{\(\[]\s*$/);
  660. if (match) {
  661. indent += tab;
  662. }
  663. } else if (state == "doc-start") {
  664. if (endState == "start") {
  665. return "";
  666. }
  667. var match = line.match(/^\s*(\/?)\*/);
  668. if (match) {
  669. if (match[1]) {
  670. indent += " ";
  671. }
  672. indent += "* ";
  673. }
  674. }
  675. return indent;
  676. };
  677. this.checkOutdent = function(state, line, input) {
  678. return this.$outdent.checkOutdent(line, input);
  679. };
  680. this.autoOutdent = function(state, doc, row) {
  681. this.$outdent.autoOutdent(doc, row);
  682. };
  683. this.$id = "ace/mode/c_cpp";
  684. }).call(Mode.prototype);
  685. exports.Mode = Mode;
  686. });
  687. ace.define("ace/mode/protobuf_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  688. "use strict";
  689. var oop = require("../lib/oop");
  690. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  691. var ProtobufHighlightRules = function() {
  692. var builtinTypes = "double|float|int32|int64|uint32|uint64|sint32|" +
  693. "sint64|fixed32|fixed64|sfixed32|sfixed64|bool|" +
  694. "string|bytes";
  695. var keywordDeclaration = "message|required|optional|repeated|package|" +
  696. "import|option|enum";
  697. var keywordMapper = this.createKeywordMapper({
  698. "keyword.declaration.protobuf": keywordDeclaration,
  699. "support.type": builtinTypes
  700. }, "identifier");
  701. this.$rules = {
  702. "start": [{
  703. token: "comment",
  704. regex: /\/\/.*$/
  705. }, {
  706. token: "comment",
  707. regex: /\/\*/,
  708. next: "comment"
  709. }, {
  710. token: "constant",
  711. regex: "<[^>]+>"
  712. }, {
  713. regex: "=",
  714. token: "keyword.operator.assignment.protobuf"
  715. }, {
  716. token : "string", // single line
  717. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  718. }, {
  719. token : "string", // single line
  720. regex : '[\'](?:(?:\\\\.)|(?:[^\'\\\\]))*?[\']'
  721. }, {
  722. token: "constant.numeric", // hex
  723. regex: "0[xX][0-9a-fA-F]+\\b"
  724. }, {
  725. token: "constant.numeric", // float
  726. regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  727. }, {
  728. token: keywordMapper,
  729. regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  730. }],
  731. "comment": [{
  732. token: "comment", // closing comment
  733. regex: ".*?\\*\\/",
  734. next: "start"
  735. }, {
  736. token: "comment", // comment spanning whole line
  737. regex: ".+"
  738. }]
  739. };
  740. this.normalizeRules();
  741. };
  742. oop.inherits(ProtobufHighlightRules, TextHighlightRules);
  743. exports.ProtobufHighlightRules = ProtobufHighlightRules;
  744. });
  745. ace.define("ace/mode/protobuf",["require","exports","module","ace/lib/oop","ace/mode/c_cpp","ace/mode/protobuf_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  746. "use strict";
  747. var oop = require("../lib/oop");
  748. var CMode = require("./c_cpp").Mode;
  749. var ProtobufHighlightRules = require("./protobuf_highlight_rules").ProtobufHighlightRules;
  750. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  751. var Mode = function() {
  752. CMode.call(this);
  753. this.foldingRules = new CStyleFoldMode();
  754. this.HighlightRules = ProtobufHighlightRules;
  755. };
  756. oop.inherits(Mode, CMode);
  757. (function() {
  758. this.lineCommentStart = "//";
  759. this.blockComment = {start: "/*", end: "*/"};
  760. this.$id = "ace/mode/protobuf";
  761. }).call(Mode.prototype);
  762. exports.Mode = Mode;
  763. });