mode-rust.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281
  1. define("ace/mode/rust_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  5. var stringEscape = /\\(?:[nrt0'"\\]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\})/.source;
  6. var RustHighlightRules = function() {
  7. this.$rules = { start:
  8. [ { token: 'variable.other.source.rust',
  9. regex: '\'[a-zA-Z_][a-zA-Z0-9_]*(?![\\\'])' },
  10. { token: 'string.quoted.single.source.rust',
  11. regex: "'(?:[^'\\\\]|" + stringEscape + ")'" },
  12. { token: 'identifier',
  13. regex: /r#[a-zA-Z_][a-zA-Z0-9_]*\b/ },
  14. {
  15. stateName: "bracketedComment",
  16. onMatch : function(value, currentState, stack){
  17. stack.unshift(this.next, value.length - 1, currentState);
  18. return "string.quoted.raw.source.rust";
  19. },
  20. regex : /r#*"/,
  21. next : [
  22. {
  23. onMatch : function(value, currentState, stack) {
  24. var token = "string.quoted.raw.source.rust";
  25. if (value.length >= stack[1]) {
  26. if (value.length > stack[1])
  27. token = "invalid";
  28. stack.shift();
  29. stack.shift();
  30. this.next = stack.shift();
  31. } else {
  32. this.next = "";
  33. }
  34. return token;
  35. },
  36. regex : /"#*/,
  37. next : "start"
  38. }, {
  39. defaultToken : "string.quoted.raw.source.rust"
  40. }
  41. ]
  42. },
  43. { token: 'string.quoted.double.source.rust',
  44. regex: '"',
  45. push:
  46. [ { token: 'string.quoted.double.source.rust',
  47. regex: '"',
  48. next: 'pop' },
  49. { token: 'constant.character.escape.source.rust',
  50. regex: stringEscape },
  51. { defaultToken: 'string.quoted.double.source.rust' } ] },
  52. { token: [ 'keyword.source.rust', 'text', 'entity.name.function.source.rust' ],
  53. regex: '\\b(fn)(\\s+)((?:r#)?[a-zA-Z_][a-zA-Z0-9_]*)' },
  54. { token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
  55. { token: 'keyword.source.rust',
  56. regex: '\\b(?:abstract|alignof|as|async|await|become|box|break|catch|continue|const|crate|default|do|dyn|else|enum|extern|for|final|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|proc|pub|pure|ref|return|self|sizeof|static|struct|super|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\\b' },
  57. { token: 'storage.type.source.rust',
  58. regex: '\\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|u128|f16|f32|f64|i8|i16|i32|i64|i128|str|option|either|c_float|c_double|c_void|FILE|fpos_t|DIR|dirent|c_char|c_schar|c_uchar|c_short|c_ushort|c_int|c_uint|c_long|c_ulong|size_t|ptrdiff_t|clock_t|time_t|c_longlong|c_ulonglong|intptr_t|uintptr_t|off_t|dev_t|ino_t|pid_t|mode_t|ssize_t)\\b' },
  59. { token: 'variable.language.source.rust', regex: '\\bself\\b' },
  60. { token: 'comment.line.doc.source.rust',
  61. regex: '//!.*$' },
  62. { token: 'comment.line.double-dash.source.rust',
  63. regex: '//.*$' },
  64. { token: 'comment.start.block.source.rust',
  65. regex: '/\\*',
  66. stateName: 'comment',
  67. push:
  68. [ { token: 'comment.start.block.source.rust',
  69. regex: '/\\*',
  70. push: 'comment' },
  71. { token: 'comment.end.block.source.rust',
  72. regex: '\\*/',
  73. next: 'pop' },
  74. { defaultToken: 'comment.block.source.rust' } ] },
  75. { token: 'keyword.operator',
  76. regex: /\$|[-=]>|[-+%^=!&|<>]=?|[*/](?![*/])=?/ },
  77. { token : "punctuation.operator", regex : /[?:,;.]/ },
  78. { token : "paren.lparen", regex : /[\[({]/ },
  79. { token : "paren.rparen", regex : /[\])}]/ },
  80. { token: 'constant.language.source.rust',
  81. regex: '\\b(?:true|false|Some|None|Ok|Err)\\b' },
  82. { token: 'support.constant.source.rust',
  83. regex: '\\b(?:EXIT_FAILURE|EXIT_SUCCESS|RAND_MAX|EOF|SEEK_SET|SEEK_CUR|SEEK_END|_IOFBF|_IONBF|_IOLBF|BUFSIZ|FOPEN_MAX|FILENAME_MAX|L_tmpnam|TMP_MAX|O_RDONLY|O_WRONLY|O_RDWR|O_APPEND|O_CREAT|O_EXCL|O_TRUNC|S_IFIFO|S_IFCHR|S_IFBLK|S_IFDIR|S_IFREG|S_IFMT|S_IEXEC|S_IWRITE|S_IREAD|S_IRWXU|S_IXUSR|S_IWUSR|S_IRUSR|F_OK|R_OK|W_OK|X_OK|STDIN_FILENO|STDOUT_FILENO|STDERR_FILENO)\\b' },
  84. { token: 'meta.preprocessor.source.rust',
  85. regex: '\\b\\w\\(\\w\\)*!|#\\[[\\w=\\(\\)_]+\\]\\b' },
  86. { token: 'constant.numeric.source.rust',
  87. regex: /\b(?:0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*(?!\.))(?:[iu](?:size|8|16|32|64|128))?\b/ },
  88. { token: 'constant.numeric.source.rust',
  89. regex: /\b(?:[0-9][0-9_]*)(?:\.[0-9][0-9_]*)?(?:[Ee][+-][0-9][0-9_]*)?(?:f32|f64)?\b/ } ] };
  90. this.normalizeRules();
  91. };
  92. RustHighlightRules.metaData = { fileTypes: [ 'rs', 'rc' ],
  93. foldingStartMarker: '^.*\\bfn\\s*(\\w+\\s*)?\\([^\\)]*\\)(\\s*\\{[^\\}]*)?\\s*$',
  94. foldingStopMarker: '^\\s*\\}',
  95. name: 'Rust',
  96. scopeName: 'source.rust' };
  97. oop.inherits(RustHighlightRules, TextHighlightRules);
  98. exports.RustHighlightRules = RustHighlightRules;
  99. });
  100. define("ace/mode/folding/cstyle",["ace_require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(ace_require, exports, module) {
  101. "use strict";
  102. var oop = ace_require("../../lib/oop");
  103. var Range = ace_require("../../range").Range;
  104. var BaseFoldMode = ace_require("./fold_mode").FoldMode;
  105. var FoldMode = exports.FoldMode = function(commentRegex) {
  106. if (commentRegex) {
  107. this.foldingStartMarker = new RegExp(
  108. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  109. );
  110. this.foldingStopMarker = new RegExp(
  111. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  112. );
  113. }
  114. };
  115. oop.inherits(FoldMode, BaseFoldMode);
  116. (function() {
  117. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  118. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  119. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  120. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  121. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  122. this._getFoldWidgetBase = this.getFoldWidget;
  123. this.getFoldWidget = function(session, foldStyle, row) {
  124. var line = session.getLine(row);
  125. if (this.singleLineBlockCommentRe.test(line)) {
  126. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  127. return "";
  128. }
  129. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  130. if (!fw && this.startRegionRe.test(line))
  131. return "start"; // lineCommentRegionStart
  132. return fw;
  133. };
  134. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  135. var line = session.getLine(row);
  136. if (this.startRegionRe.test(line))
  137. return this.getCommentRegionBlock(session, line, row);
  138. var match = line.match(this.foldingStartMarker);
  139. if (match) {
  140. var i = match.index;
  141. if (match[1])
  142. return this.openingBracketBlock(session, match[1], row, i);
  143. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  144. if (range && !range.isMultiLine()) {
  145. if (forceMultiline) {
  146. range = this.getSectionRange(session, row);
  147. } else if (foldStyle != "all")
  148. range = null;
  149. }
  150. return range;
  151. }
  152. if (foldStyle === "markbegin")
  153. return;
  154. var match = line.match(this.foldingStopMarker);
  155. if (match) {
  156. var i = match.index + match[0].length;
  157. if (match[1])
  158. return this.closingBracketBlock(session, match[1], row, i);
  159. return session.getCommentFoldRange(row, i, -1);
  160. }
  161. };
  162. this.getSectionRange = function(session, row) {
  163. var line = session.getLine(row);
  164. var startIndent = line.search(/\S/);
  165. var startRow = row;
  166. var startColumn = line.length;
  167. row = row + 1;
  168. var endRow = row;
  169. var maxRow = session.getLength();
  170. while (++row < maxRow) {
  171. line = session.getLine(row);
  172. var indent = line.search(/\S/);
  173. if (indent === -1)
  174. continue;
  175. if (startIndent > indent)
  176. break;
  177. var subRange = this.getFoldWidgetRange(session, "all", row);
  178. if (subRange) {
  179. if (subRange.start.row <= startRow) {
  180. break;
  181. } else if (subRange.isMultiLine()) {
  182. row = subRange.end.row;
  183. } else if (startIndent == indent) {
  184. break;
  185. }
  186. }
  187. endRow = row;
  188. }
  189. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  190. };
  191. this.getCommentRegionBlock = function(session, line, row) {
  192. var startColumn = line.search(/\s*$/);
  193. var maxRow = session.getLength();
  194. var startRow = row;
  195. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  196. var depth = 1;
  197. while (++row < maxRow) {
  198. line = session.getLine(row);
  199. var m = re.exec(line);
  200. if (!m) continue;
  201. if (m[1]) depth--;
  202. else depth++;
  203. if (!depth) break;
  204. }
  205. var endRow = row;
  206. if (endRow > startRow) {
  207. return new Range(startRow, startColumn, endRow, line.length);
  208. }
  209. };
  210. }).call(FoldMode.prototype);
  211. });
  212. define("ace/mode/rust",["ace_require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/rust_highlight_rules","ace/mode/folding/cstyle"], function(ace_require, exports, module) {
  213. "use strict";
  214. var oop = ace_require("../lib/oop");
  215. var TextMode = ace_require("./text").Mode;
  216. var RustHighlightRules = ace_require("./rust_highlight_rules").RustHighlightRules;
  217. var FoldMode = ace_require("./folding/cstyle").FoldMode;
  218. var Mode = function() {
  219. this.HighlightRules = RustHighlightRules;
  220. this.foldingRules = new FoldMode();
  221. this.$behaviour = this.$defaultBehaviour;
  222. };
  223. oop.inherits(Mode, TextMode);
  224. (function() {
  225. this.lineCommentStart = "//";
  226. this.blockComment = {start: "/*", end: "*/", nestable: true};
  227. this.$quotes = { '"': '"' };
  228. this.$id = "ace/mode/rust";
  229. }).call(Mode.prototype);
  230. exports.Mode = Mode;
  231. }); (function() {
  232. window.ace_require(["ace/mode/rust"], function(m) {
  233. if (typeof module == "object" && typeof exports == "object" && module) {
  234. module.exports = m;
  235. }
  236. });
  237. })();