csharp_highlight_rules.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  5. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  6. var CSharpHighlightRules = function() {
  7. var keywordMapper = this.createKeywordMapper({
  8. "variable.language": "this",
  9. "keyword": "abstract|event|new|struct|as|explicit|null|switch|base|extern|object|this|bool|false|operator|throw|break|finally|out|true|byte|fixed|override|try|case|float|params|typeof|catch|for|private|uint|char|foreach|protected|ulong|checked|goto|public|unchecked|class|if|readonly|unsafe|const|implicit|ref|ushort|continue|in|return|using|decimal|int|sbyte|virtual|default|interface|sealed|volatile|delegate|internal|short|void|do|is|sizeof|while|double|lock|stackalloc|else|long|static|enum|namespace|string|var|dynamic",
  10. "constant.language": "null|true|false"
  11. }, "identifier");
  12. // regexp must not have capturing parentheses. Use (?:) instead.
  13. // regexps are ordered -> the first match is used
  14. this.$rules = {
  15. "start" : [
  16. {
  17. token : "comment",
  18. regex : "\\/\\/.*$"
  19. },
  20. DocCommentHighlightRules.getStartRule("doc-start"),
  21. {
  22. token : "comment", // multi line comment
  23. regex : "\\/\\*",
  24. next : "comment"
  25. }, {
  26. token : "string.regexp",
  27. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  28. }, {
  29. token : "string", // character
  30. regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
  31. }, {
  32. token : "string", start : '"', end : '"|$', next: [
  33. {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/},
  34. {token: "invalid", regex: /\\./}
  35. ]
  36. }, {
  37. token : "string", start : '@"', end : '"', next:[
  38. {token: "constant.language.escape", regex: '""'}
  39. ]
  40. }, {
  41. token : "constant.numeric", // hex
  42. regex : "0[xX][0-9a-fA-F]+\\b"
  43. }, {
  44. token : "constant.numeric", // float
  45. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  46. }, {
  47. token : "constant.language.boolean",
  48. regex : "(?:true|false)\\b"
  49. }, {
  50. token : keywordMapper,
  51. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  52. }, {
  53. token : "keyword.operator",
  54. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  55. }, {
  56. token : "keyword",
  57. regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)"
  58. }, {
  59. token : "punctuation.operator",
  60. regex : "\\?|\\:|\\,|\\;|\\."
  61. }, {
  62. token : "paren.lparen",
  63. regex : "[[({]"
  64. }, {
  65. token : "paren.rparen",
  66. regex : "[\\])}]"
  67. }, {
  68. token : "text",
  69. regex : "\\s+"
  70. }
  71. ],
  72. "comment" : [
  73. {
  74. token : "comment", // closing comment
  75. regex : ".*?\\*\\/",
  76. next : "start"
  77. }, {
  78. token : "comment", // comment spanning whole line
  79. regex : ".+"
  80. }
  81. ]
  82. };
  83. this.embedRules(DocCommentHighlightRules, "doc-",
  84. [ DocCommentHighlightRules.getEndRule("start") ]);
  85. this.normalizeRules();
  86. };
  87. oop.inherits(CSharpHighlightRules, TextHighlightRules);
  88. exports.CSharpHighlightRules = CSharpHighlightRules;
  89. });