haxe_highlight_rules.js 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 HaxeHighlightRules = function() {
  7. var keywords = (
  8. "break|case|cast|catch|class|continue|default|else|enum|extends|for|function|if|implements|import|in|inline|interface|new|override|package|private|public|return|static|super|switch|this|throw|trace|try|typedef|untyped|var|while|Array|Void|Bool|Int|UInt|Float|Dynamic|String|List|Hash|IntHash|Error|Unknown|Type|Std"
  9. );
  10. var buildinConstants = (
  11. "null|true|false"
  12. );
  13. var keywordMapper = this.createKeywordMapper({
  14. "variable.language": "this",
  15. "keyword": keywords,
  16. "constant.language": buildinConstants
  17. }, "identifier");
  18. // regexp must not have capturing parentheses. Use (?:) instead.
  19. // regexps are ordered -> the first match is used
  20. this.$rules = {
  21. "start" : [
  22. {
  23. token : "comment",
  24. regex : "\\/\\/.*$"
  25. },
  26. DocCommentHighlightRules.getStartRule("doc-start"),
  27. {
  28. token : "comment", // multi line comment
  29. regex : "\\/\\*",
  30. next : "comment"
  31. }, {
  32. token : "string.regexp",
  33. regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
  34. }, {
  35. token : "string", // single line
  36. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  37. }, {
  38. token : "string", // single line
  39. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  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. // TODO: Unicode escape sequences
  52. // TODO: Unicode identifiers
  53. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  54. }, {
  55. token : "keyword.operator",
  56. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|===|==|=|!=|!==|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^=|\\b(?:in|instanceof|new|delete|typeof|void)"
  57. }, {
  58. token : "punctuation.operator",
  59. regex : "\\?|\\:|\\,|\\;|\\."
  60. }, {
  61. token : "paren.lparen",
  62. regex : "[[({<]"
  63. }, {
  64. token : "paren.rparen",
  65. regex : "[\\])}>]"
  66. }, {
  67. token : "text",
  68. regex : "\\s+"
  69. }
  70. ],
  71. "comment" : [
  72. {
  73. token : "comment", // closing comment
  74. regex : ".*?\\*\\/",
  75. next : "start"
  76. }, {
  77. token : "comment", // comment spanning whole line
  78. regex : ".+"
  79. }
  80. ]
  81. };
  82. this.embedRules(DocCommentHighlightRules, "doc-",
  83. [ DocCommentHighlightRules.getEndRule("start") ]);
  84. };
  85. oop.inherits(HaxeHighlightRules, TextHighlightRules);
  86. exports.HaxeHighlightRules = HaxeHighlightRules;
  87. });