csharp_highlight_rules.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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", // character
  27. regex : /'(?:.|\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n]))'/
  28. }, {
  29. token : "string", start : '"', end : '"|$', next: [
  30. {token: "constant.language.escape", regex: /\\(:?u[\da-fA-F]+|x[\da-fA-F]+|[tbrf'"n])/},
  31. {token: "invalid", regex: /\\./}
  32. ]
  33. }, {
  34. token : "string", start : '@"', end : '"', next:[
  35. {token: "constant.language.escape", regex: '""'}
  36. ]
  37. }, {
  38. token : "constant.numeric", // hex
  39. regex : "0[xX][0-9a-fA-F]+\\b"
  40. }, {
  41. token : "constant.numeric", // float
  42. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  43. }, {
  44. token : "constant.language.boolean",
  45. regex : "(?:true|false)\\b"
  46. }, {
  47. token : keywordMapper,
  48. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  49. }, {
  50. token : "keyword.operator",
  51. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  52. }, {
  53. token : "keyword",
  54. regex : "^\\s*#(if|else|elif|endif|define|undef|warning|error|line|region|endregion|pragma)"
  55. }, {
  56. token : "punctuation.operator",
  57. regex : "\\?|\\:|\\,|\\;|\\."
  58. }, {
  59. token : "paren.lparen",
  60. regex : "[[({]"
  61. }, {
  62. token : "paren.rparen",
  63. regex : "[\\])}]"
  64. }, {
  65. token : "text",
  66. regex : "\\s+"
  67. }
  68. ],
  69. "comment" : [
  70. {
  71. token : "comment", // closing comment
  72. regex : ".*?\\*\\/",
  73. next : "start"
  74. }, {
  75. token : "comment", // comment spanning whole line
  76. regex : ".+"
  77. }
  78. ]
  79. };
  80. this.embedRules(DocCommentHighlightRules, "doc-",
  81. [ DocCommentHighlightRules.getEndRule("start") ]);
  82. this.normalizeRules();
  83. };
  84. oop.inherits(CSharpHighlightRules, TextHighlightRules);
  85. exports.CSharpHighlightRules = CSharpHighlightRules;
  86. });