rust_highlight_rules.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  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. /****************************************************************************************
  32. * IT MIGHT NOT BE PERFECT ...But it's a good start from an existing *.tmlanguage file. *
  33. * fileTypes *
  34. ****************************************************************************************/
  35. define(function(require, exports, module) {
  36. "use strict";
  37. var oop = require("../lib/oop");
  38. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var RustHighlightRules = function() {
  40. // regexp must not have capturing parentheses. Use (?:) instead.
  41. // regexps are ordered -> the first match is used
  42. this.$rules = { start:
  43. [ { token: 'variable.other.source.rust',
  44. regex: '\'[a-zA-Z_][a-zA-Z0-9_]*[^\\\']' },
  45. { token: 'string.quoted.single.source.rust',
  46. regex: '\'',
  47. push:
  48. [ { token: 'string.quoted.single.source.rust',
  49. regex: '\'',
  50. next: 'pop' },
  51. { include: '#rust_escaped_character' },
  52. { defaultToken: 'string.quoted.single.source.rust' } ] },
  53. { token: 'string.quoted.double.source.rust',
  54. regex: '"',
  55. push:
  56. [ { token: 'string.quoted.double.source.rust',
  57. regex: '"',
  58. next: 'pop' },
  59. { include: '#rust_escaped_character' },
  60. { defaultToken: 'string.quoted.double.source.rust' } ] },
  61. { token: [ 'keyword.source.rust', 'meta.function.source.rust',
  62. 'entity.name.function.source.rust', 'meta.function.source.rust' ],
  63. regex: '\\b(fn)(\\s+)([a-zA-Z_][a-zA-Z0-9_][\\w\\:,+ \\\'<>]*)(\\s*\\()' },
  64. { token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
  65. { token: 'keyword.source.rust',
  66. 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' },
  67. { token: 'storage.type.source.rust',
  68. 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' },
  69. { token: 'variable.language.source.rust', regex: '\\bself\\b' },
  70. { token: 'keyword.operator',
  71. regex: '!|\\$|\\*|\\-\\-|\\-|\\+\\+|\\+|-->|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|/=|%=|\\+=|\\-=|&=|\\^=|,|;' },
  72. { token: 'constant.language.source.rust',
  73. regex: '\\b(?:true|false|Some|None|Left|Right|Ok|Err)\\b' },
  74. { token: 'support.constant.source.rust',
  75. 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' },
  76. { token: 'meta.preprocessor.source.rust',
  77. regex: '\\b\\w\\(\\w\\)*!|#\\[[\\w=\\(\\)_]+\\]\\b' },
  78. { token: 'constant.numeric.integer.source.rust',
  79. 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' },
  80. { token: 'constant.numeric.hex.source.rust',
  81. 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' },
  82. { token: 'constant.numeric.binary.source.rust',
  83. regex: '\\b(?:0b[01_]+|0b[01_]+(?:u|u8|u16|u32|u64)|0b[01_]+(?:i|i8|i16|i32|i64))\\b' },
  84. { token: 'constant.numeric.float.source.rust',
  85. 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)' },
  86. { token: 'comment.line.documentation.source.rust',
  87. regex: '//!.*$',
  88. push_:
  89. [ { token: 'comment.line.documentation.source.rust',
  90. regex: '$',
  91. next: 'pop' },
  92. { defaultToken: 'comment.line.documentation.source.rust' } ] },
  93. { token: 'comment.line.double-dash.source.rust',
  94. regex: '//.*$',
  95. push_:
  96. [ { token: 'comment.line.double-dash.source.rust',
  97. regex: '$',
  98. next: 'pop' },
  99. { defaultToken: 'comment.line.double-dash.source.rust' } ] },
  100. { token: 'comment.block.source.rust',
  101. regex: '/\\*',
  102. push:
  103. [ { token: 'comment.block.source.rust',
  104. regex: '\\*/',
  105. next: 'pop' },
  106. { defaultToken: 'comment.block.source.rust' } ] } ],
  107. '#rust_escaped_character':
  108. [ { token: 'constant.character.escape.source.rust',
  109. regex: '\\\\(?:x[\\da-fA-F]{2}|[0-2][0-7]{,2}|3[0-6][0-7]?|37[0-7]?|[4-7][0-7]?|.)' } ] }
  110. this.normalizeRules();
  111. };
  112. RustHighlightRules.metaData = { fileTypes: [ 'rs', 'rc' ],
  113. foldingStartMarker: '^.*\\bfn\\s*(\\w+\\s*)?\\([^\\)]*\\)(\\s*\\{[^\\}]*)?\\s*$',
  114. foldingStopMarker: '^\\s*\\}',
  115. name: 'Rust',
  116. scopeName: 'source.rust' }
  117. oop.inherits(RustHighlightRules, TextHighlightRules);
  118. exports.RustHighlightRules = RustHighlightRules;
  119. });