haml_highlight_rules.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. define(function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var RubyExports = require("./ruby_highlight_rules");
  6. var RubyHighlightRules = RubyExports.RubyHighlightRules;
  7. var HamlHighlightRules = function() {
  8. // regexp must not have capturing parentheses. Use (?:) instead.
  9. // regexps are ordered -> the first match is used
  10. this.$rules =
  11. {
  12. "start": [
  13. {
  14. token : "punctuation.section.comment",
  15. regex : /^\s*\/.*/
  16. },
  17. {
  18. token : "punctuation.section.comment",
  19. regex : /^\s*#.*/
  20. },
  21. {
  22. token: "string.quoted.double",
  23. regex: "==.+?=="
  24. },
  25. {
  26. token: "keyword.other.doctype",
  27. regex: "^!!!\\s*(?:[a-zA-Z0-9-_]+)?"
  28. },
  29. RubyExports.qString,
  30. RubyExports.qqString,
  31. RubyExports.tString,
  32. {
  33. token: ["entity.name.tag.haml"],
  34. regex: /^\s*%[\w:]+/,
  35. next: "tag_single"
  36. },
  37. {
  38. token: [ "meta.escape.haml" ],
  39. regex: "^\\s*\\\\."
  40. },
  41. RubyExports.constantNumericHex,
  42. RubyExports.constantNumericFloat,
  43. RubyExports.constantOtherSymbol,
  44. {
  45. token: "text",
  46. regex: "=|-|~",
  47. next: "embedded_ruby"
  48. }
  49. ],
  50. "tag_single": [
  51. {
  52. token: "entity.other.attribute-name.class.haml",
  53. regex: "\\.[\\w-]+"
  54. },
  55. {
  56. token: "entity.other.attribute-name.id.haml",
  57. regex: "#[\\w-]+"
  58. },
  59. {
  60. token: "punctuation.section",
  61. regex: "\\{",
  62. next: "section"
  63. },
  64. RubyExports.constantOtherSymbol,
  65. {
  66. token: "text",
  67. regex: /\s/,
  68. next: "start"
  69. },
  70. {
  71. token: "empty",
  72. regex: "$|(?!\\.|#|\\{|\\[|=|-|~|\\/)",
  73. next: "start"
  74. }
  75. ],
  76. "section": [
  77. RubyExports.constantOtherSymbol,
  78. RubyExports.qString,
  79. RubyExports.qqString,
  80. RubyExports.tString,
  81. RubyExports.constantNumericHex,
  82. RubyExports.constantNumericFloat,
  83. {
  84. token: "punctuation.section",
  85. regex: "\\}",
  86. next: "start"
  87. }
  88. ],
  89. "embedded_ruby": [
  90. RubyExports.constantNumericHex,
  91. RubyExports.constantNumericFloat,
  92. {
  93. token : "support.class", // class name
  94. regex : "[A-Z][a-zA-Z_\\d]+"
  95. },
  96. {
  97. token : new RubyHighlightRules().getKeywords(),
  98. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  99. },
  100. {
  101. token : ["keyword", "text", "text"],
  102. regex : "(?:do|\\{)(?: \\|[^|]+\\|)?$",
  103. next : "start"
  104. },
  105. {
  106. token : ["text"],
  107. regex : "^$",
  108. next : "start"
  109. },
  110. {
  111. token : ["text"],
  112. regex : "^(?!.*\\|\\s*$)",
  113. next : "start"
  114. }
  115. ]
  116. }
  117. };
  118. oop.inherits(HamlHighlightRules, TextHighlightRules);
  119. exports.HamlHighlightRules = HamlHighlightRules;
  120. });