rust_highlight_rules.js 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* ***** BEGIN LICENSE BLOCK *****
  2. * Distributed under the BSD license:
  3. *
  4. * Copyright (c) 2012, Ajax.org B.V.
  5. * All rights reserved.
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions are met:
  9. * * Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * * Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * * Neither the name of Ajax.org B.V. nor the
  15. * names of its contributors may be used to endorse or promote products
  16. * derived from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  19. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  20. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  21. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  22. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  23. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  24. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  25. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
  27. * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. *
  29. * ***** END LICENSE BLOCK ***** */
  30. /* This file was autogenerated from https://raw.github.com/dbp/sublime-rust/master/Rust.tmLanguage (uuid: ) */
  31. define(function(require, exports, module) {
  32. "use strict";
  33. var oop = require("../lib/oop");
  34. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  35. var stringEscape = /\\(?:[nrt0'"]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\})/.source;
  36. var RustHighlightRules = function() {
  37. // regexp must not have capturing parentheses. Use (?:) instead.
  38. // regexps are ordered -> the first match is used
  39. this.$rules = { start:
  40. [ { token: 'variable.other.source.rust',
  41. // `(?![\\\'])` to keep a lifetime name highlighting from continuing one character
  42. // past the name. The end `\'` will block this from matching for a character like
  43. // `'a'` (it should have character highlighting, not variable highlighting).
  44. regex: '\'[a-zA-Z_][a-zA-Z0-9_]*(?![\\\'])' },
  45. { token: 'string.quoted.single.source.rust',
  46. regex: "'(?:[^'\\\\]|" + stringEscape + ")'" },
  47. {
  48. stateName: "bracketedComment",
  49. onMatch : function(value, currentState, stack){
  50. stack.unshift(this.next, value.length - 1, currentState);
  51. return "string.quoted.raw.source.rust";
  52. },
  53. regex : /r#*"/,
  54. next : [
  55. {
  56. onMatch : function(value, currentState, stack) {
  57. var token = "string.quoted.raw.source.rust";
  58. if (value.length >= stack[1]) {
  59. if (value.length > stack[1])
  60. token = "invalid";
  61. stack.shift();
  62. stack.shift();
  63. this.next = stack.shift();
  64. } else {
  65. this.next = "";
  66. }
  67. return token;
  68. },
  69. regex : /"#*/,
  70. next : "start"
  71. }, {
  72. defaultToken : "string.quoted.raw.source.rust"
  73. }
  74. ]
  75. },
  76. { token: 'string.quoted.double.source.rust',
  77. regex: '"',
  78. push:
  79. [ { token: 'string.quoted.double.source.rust',
  80. regex: '"',
  81. next: 'pop' },
  82. { token: 'constant.character.escape.source.rust',
  83. regex: stringEscape },
  84. { defaultToken: 'string.quoted.double.source.rust' } ] },
  85. { token: [ 'keyword.source.rust', 'text', 'entity.name.function.source.rust' ],
  86. regex: '\\b(fn)(\\s+)([a-zA-Z_][a-zA-Z0-9_]*)' },
  87. { token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
  88. { token: 'keyword.source.rust',
  89. regex: '\\b(?:abstract|alignof|as|box|break|continue|const|crate|do|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|unsafe|unsized|use|virtual|where|while|yield)\\b' },
  90. { token: 'storage.type.source.rust',
  91. regex: '\\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|f16|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' },
  92. { token: 'variable.language.source.rust', regex: '\\bself\\b' },
  93. { token: 'comment.line.doc.source.rust',
  94. regex: '//!.*$' },
  95. { token: 'comment.line.double-dash.source.rust',
  96. regex: '//.*$' },
  97. { token: 'comment.start.block.source.rust',
  98. regex: '/\\*',
  99. stateName: 'comment',
  100. push:
  101. [ { token: 'comment.start.block.source.rust',
  102. regex: '/\\*',
  103. push: 'comment' },
  104. { token: 'comment.end.block.source.rust',
  105. regex: '\\*/',
  106. next: 'pop' },
  107. { defaultToken: 'comment.block.source.rust' } ] },
  108. { token: 'keyword.operator',
  109. // `[*/](?![*/])=?` is separated because `//` and `/* */` become comments and must be
  110. // guarded against. This states either `*` or `/` may be matched as long as the match
  111. // it isn't followed by either of the two. An `=` may be on the end.
  112. regex: /\$|[-=]>|[-+%^=!&|<>]=?|[*/](?![*/])=?/ },
  113. { token : "punctuation.operator", regex : /[?:,;.]/ },
  114. { token : "paren.lparen", regex : /[\[({]/ },
  115. { token : "paren.rparen", regex : /[\])}]/ },
  116. { token: 'constant.language.source.rust',
  117. regex: '\\b(?:true|false|Some|None|Ok|Err)\\b' },
  118. { token: 'support.constant.source.rust',
  119. 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' },
  120. { token: 'meta.preprocessor.source.rust',
  121. regex: '\\b\\w\\(\\w\\)*!|#\\[[\\w=\\(\\)_]+\\]\\b' },
  122. { token: 'constant.numeric.source.rust',
  123. regex: /(?:0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*(?!\.))(?:[iu](?:size|8|16|32|64))?\b/ },
  124. { token: 'constant.numeric.source.rust',
  125. regex: /(?:[0-9][0-9_]*)(?:\.[0-9][0-9_]*)?(?:[Ee][+-][0-9][0-9_]*)?(?:f32|f64)?\b/ } ] }
  126. this.normalizeRules();
  127. };
  128. RustHighlightRules.metaData = { fileTypes: [ 'rs', 'rc' ],
  129. foldingStartMarker: '^.*\\bfn\\s*(\\w+\\s*)?\\([^\\)]*\\)(\\s*\\{[^\\}]*)?\\s*$',
  130. foldingStopMarker: '^\\s*\\}',
  131. name: 'Rust',
  132. scopeName: 'source.rust' }
  133. oop.inherits(RustHighlightRules, TextHighlightRules);
  134. exports.RustHighlightRules = RustHighlightRules;
  135. });