Нема описа
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288
  1. ace.define("ace/mode/rust_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 RustHighlightRules = function() {
  6. this.$rules = { start:
  7. [ { token: 'variable.other.source.rust',
  8. regex: '\'[a-zA-Z_][a-zA-Z0-9_]*[^\\\']' },
  9. { token: 'string.quoted.single.source.rust',
  10. regex: '\'',
  11. push:
  12. [ { token: 'string.quoted.single.source.rust',
  13. regex: '\'',
  14. next: 'pop' },
  15. { include: '#rust_escaped_character' },
  16. { defaultToken: 'string.quoted.single.source.rust' } ] },
  17. {
  18. stateName: "bracketedComment",
  19. onMatch : function(value, currentState, stack){
  20. stack.unshift(this.next, value.length - 1, currentState);
  21. return "string.quoted.raw.source.rust";
  22. },
  23. regex : /r#*"/,
  24. next : [
  25. {
  26. onMatch : function(value, currentState, stack) {
  27. var token = "string.quoted.raw.source.rust";
  28. if (value.length >= stack[1]) {
  29. if (value.length > stack[1])
  30. token = "invalid";
  31. stack.shift();
  32. stack.shift();
  33. this.next = stack.shift();
  34. } else {
  35. this.next = "";
  36. }
  37. return token;
  38. },
  39. regex : /"#*/,
  40. next : "start"
  41. }, {
  42. defaultToken : "string.quoted.raw.source.rust"
  43. }
  44. ]
  45. },
  46. { token: 'string.quoted.double.source.rust',
  47. regex: '"',
  48. push:
  49. [ { token: 'string.quoted.double.source.rust',
  50. regex: '"',
  51. next: 'pop' },
  52. { include: '#rust_escaped_character' },
  53. { defaultToken: 'string.quoted.double.source.rust' } ] },
  54. { token: [ 'keyword.source.rust', 'meta.function.source.rust',
  55. 'entity.name.function.source.rust', 'meta.function.source.rust' ],
  56. regex: '\\b(fn)(\\s+)([a-zA-Z_][a-zA-Z0-9_][\\w\\:,+ \\\'<>]*)(\\s*\\()' },
  57. { token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
  58. { token: 'keyword.source.rust',
  59. regex: '\\b(?:as|assert|break|claim|const|copy|Copy|do|drop|else|extern|fail|for|if|impl|in|let|log|loop|match|mod|module|move|mut|Owned|priv|pub|pure|ref|return|unchecked|unsafe|use|while|mod|Send|static|trait|class|struct|enum|type)\\b' },
  60. { token: 'storage.type.source.rust',
  61. regex: '\\b(?:Self|m32|m64|m128|f80|f16|f128|int|uint|float|char|bool|u8|u16|u32|u64|f32|f64|i8|i16|i32|i64|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' },
  62. { token: 'variable.language.source.rust', regex: '\\bself\\b' },
  63. { token: 'keyword.operator',
  64. regex: '!|\\$|\\*|\\-\\-|\\-|\\+\\+|\\+|-->|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|/=|%=|\\+=|\\-=|&=|\\^=|,|;' },
  65. { token: 'constant.language.source.rust',
  66. regex: '\\b(?:true|false|Some|None|Left|Right|Ok|Err)\\b' },
  67. { token: 'support.constant.source.rust',
  68. 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' },
  69. { token: 'meta.preprocessor.source.rust',
  70. regex: '\\b\\w\\(\\w\\)*!|#\\[[\\w=\\(\\)_]+\\]\\b' },
  71. { token: 'constant.numeric.integer.source.rust',
  72. regex: '\\b(?:[0-9][0-9_]*|[0-9][0-9_]*(?:u|u8|u16|u32|u64)|[0-9][0-9_]*(?:i|i8|i16|i32|i64))\\b' },
  73. { token: 'constant.numeric.hex.source.rust',
  74. regex: '\\b(?:0x[a-fA-F0-9_]+|0x[a-fA-F0-9_]+(?:u|u8|u16|u32|u64)|0x[a-fA-F0-9_]+(?:i|i8|i16|i32|i64))\\b' },
  75. { token: 'constant.numeric.binary.source.rust',
  76. regex: '\\b(?:0b[01_]+|0b[01_]+(?:u|u8|u16|u32|u64)|0b[01_]+(?:i|i8|i16|i32|i64))\\b' },
  77. { token: 'constant.numeric.float.source.rust',
  78. regex: '[0-9][0-9_]*(?:f32|f64|f)|[0-9][0-9_]*[eE][+-]=[0-9_]+|[0-9][0-9_]*[eE][+-]=[0-9_]+(?:f32|f64|f)|[0-9][0-9_]*\\.[0-9_]+|[0-9][0-9_]*\\.[0-9_]+(?:f32|f64|f)|[0-9][0-9_]*\\.[0-9_]+%[eE][+-]=[0-9_]+|[0-9][0-9_]*\\.[0-9_]+%[eE][+-]=[0-9_]+(?:f32|f64|f)' },
  79. { token: 'comment.line.documentation.source.rust',
  80. regex: '//!.*$',
  81. push_:
  82. [ { token: 'comment.line.documentation.source.rust',
  83. regex: '$',
  84. next: 'pop' },
  85. { defaultToken: 'comment.line.documentation.source.rust' } ] },
  86. { token: 'comment.line.double-dash.source.rust',
  87. regex: '//.*$',
  88. push_:
  89. [ { token: 'comment.line.double-dash.source.rust',
  90. regex: '$',
  91. next: 'pop' },
  92. { defaultToken: 'comment.line.double-dash.source.rust' } ] },
  93. { token: 'comment.start.block.source.rust',
  94. regex: '/\\*',
  95. stateName: 'comment',
  96. push:
  97. [ { token: 'comment.start.block.source.rust',
  98. regex: '/\\*',
  99. push: 'comment' },
  100. { token: 'comment.end.block.source.rust',
  101. regex: '\\*/',
  102. next: 'pop' },
  103. { defaultToken: 'comment.block.source.rust' } ] } ],
  104. '#rust_escaped_character':
  105. [ { token: 'constant.character.escape.source.rust',
  106. regex: '\\\\(?:x[\\da-fA-F]{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)' } ] }
  107. this.normalizeRules();
  108. };
  109. RustHighlightRules.metaData = { fileTypes: [ 'rs', 'rc' ],
  110. foldingStartMarker: '^.*\\bfn\\s*(\\w+\\s*)?\\([^\\)]*\\)(\\s*\\{[^\\}]*)?\\s*$',
  111. foldingStopMarker: '^\\s*\\}',
  112. name: 'Rust',
  113. scopeName: 'source.rust' }
  114. oop.inherits(RustHighlightRules, TextHighlightRules);
  115. exports.RustHighlightRules = RustHighlightRules;
  116. });
  117. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  118. "use strict";
  119. var oop = require("../../lib/oop");
  120. var Range = require("../../range").Range;
  121. var BaseFoldMode = require("./fold_mode").FoldMode;
  122. var FoldMode = exports.FoldMode = function(commentRegex) {
  123. if (commentRegex) {
  124. this.foldingStartMarker = new RegExp(
  125. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  126. );
  127. this.foldingStopMarker = new RegExp(
  128. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  129. );
  130. }
  131. };
  132. oop.inherits(FoldMode, BaseFoldMode);
  133. (function() {
  134. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  135. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  136. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  137. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  138. this.startRegionRe = /^\s*(\/\*|\/\/)#region\b/;
  139. this._getFoldWidgetBase = this.getFoldWidget;
  140. this.getFoldWidget = function(session, foldStyle, row) {
  141. var line = session.getLine(row);
  142. if (this.singleLineBlockCommentRe.test(line)) {
  143. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  144. return "";
  145. }
  146. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  147. if (!fw && this.startRegionRe.test(line))
  148. return "start"; // lineCommentRegionStart
  149. return fw;
  150. };
  151. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  152. var line = session.getLine(row);
  153. if (this.startRegionRe.test(line))
  154. return this.getCommentRegionBlock(session, line, row);
  155. var match = line.match(this.foldingStartMarker);
  156. if (match) {
  157. var i = match.index;
  158. if (match[1])
  159. return this.openingBracketBlock(session, match[1], row, i);
  160. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  161. if (range && !range.isMultiLine()) {
  162. if (forceMultiline) {
  163. range = this.getSectionRange(session, row);
  164. } else if (foldStyle != "all")
  165. range = null;
  166. }
  167. return range;
  168. }
  169. if (foldStyle === "markbegin")
  170. return;
  171. var match = line.match(this.foldingStopMarker);
  172. if (match) {
  173. var i = match.index + match[0].length;
  174. if (match[1])
  175. return this.closingBracketBlock(session, match[1], row, i);
  176. return session.getCommentFoldRange(row, i, -1);
  177. }
  178. };
  179. this.getSectionRange = function(session, row) {
  180. var line = session.getLine(row);
  181. var startIndent = line.search(/\S/);
  182. var startRow = row;
  183. var startColumn = line.length;
  184. row = row + 1;
  185. var endRow = row;
  186. var maxRow = session.getLength();
  187. while (++row < maxRow) {
  188. line = session.getLine(row);
  189. var indent = line.search(/\S/);
  190. if (indent === -1)
  191. continue;
  192. if (startIndent > indent)
  193. break;
  194. var subRange = this.getFoldWidgetRange(session, "all", row);
  195. if (subRange) {
  196. if (subRange.start.row <= startRow) {
  197. break;
  198. } else if (subRange.isMultiLine()) {
  199. row = subRange.end.row;
  200. } else if (startIndent == indent) {
  201. break;
  202. }
  203. }
  204. endRow = row;
  205. }
  206. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  207. };
  208. this.getCommentRegionBlock = function(session, line, row) {
  209. var startColumn = line.search(/\s*$/);
  210. var maxRow = session.getLength();
  211. var startRow = row;
  212. var re = /^\s*(?:\/\*|\/\/)#(end)?region\b/;
  213. var depth = 1;
  214. while (++row < maxRow) {
  215. line = session.getLine(row);
  216. var m = re.exec(line);
  217. if (!m) continue;
  218. if (m[1]) depth--;
  219. else depth++;
  220. if (!depth) break;
  221. }
  222. var endRow = row;
  223. if (endRow > startRow) {
  224. return new Range(startRow, startColumn, endRow, line.length);
  225. }
  226. };
  227. }).call(FoldMode.prototype);
  228. });
  229. ace.define("ace/mode/rust",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/rust_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  230. "use strict";
  231. var oop = require("../lib/oop");
  232. var TextMode = require("./text").Mode;
  233. var RustHighlightRules = require("./rust_highlight_rules").RustHighlightRules;
  234. var FoldMode = require("./folding/cstyle").FoldMode;
  235. var Mode = function() {
  236. this.HighlightRules = RustHighlightRules;
  237. this.foldingRules = new FoldMode();
  238. };
  239. oop.inherits(Mode, TextMode);
  240. (function() {
  241. this.lineCommentStart = "//";
  242. this.blockComment = {start: "/*", end: "*/"};
  243. this.$id = "ace/mode/rust";
  244. }).call(Mode.prototype);
  245. exports.Mode = Mode;
  246. });