js_regex_highlight_rules.js 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 escape = "\\\\(?:u[\\da-fA-F]{4}|x[\\da-fA-F]{2}|.)";
  6. var quantifier = "({\\d+\\b,?\\d*}|[+*?])(\\??)";
  7. var JsRegexHighlightRules = function() {
  8. this.$rules = {
  9. "start": [{
  10. // operators
  11. token : "keyword",
  12. regex: "\\\\[bB]",
  13. next: "no_quantifier"
  14. }, {
  15. token: "regexp.keyword.operator",
  16. regex: escape
  17. }, {
  18. // flag
  19. token: "string.regexp",
  20. regex: "/\\w*",
  21. next: "start"
  22. }, {
  23. token : ["string", "string.regex"],
  24. regex: quantifier,
  25. next: "no_quantifier"
  26. }, {
  27. // operators
  28. token : "keyword",
  29. regex: "[$^]|\\\\[bB]",
  30. next: "no_quantifier"
  31. }, {
  32. // operators
  33. token : "constant.language.escape",
  34. regex: /\(\?[:=!]|\)|[()$^+*?]/,
  35. next: "no_quantifier"
  36. }, {
  37. token : "constant.language.delimiter",
  38. regex: /\|/,
  39. next: "no_quantifier"
  40. }, {
  41. token: "constant.language.escape",
  42. regex: /\[\^?/,
  43. next: "character_class"
  44. }, {
  45. token: "empty",
  46. regex: "$",
  47. next: "start"
  48. }
  49. ],
  50. "character_class": [{
  51. regex: /\\[dDwWsS]/
  52. },{
  53. token: "markup.list",
  54. regex: "(?:" + escape + "|.)-(?:[^\\]\\\\]|" + escape + ")"
  55. }, {
  56. token: "keyword",
  57. regex: escape
  58. }, {
  59. token: "constant.language.escape",
  60. regex: "]",
  61. next: "start"
  62. }, {
  63. token: "constant.language.escape",
  64. regex: "-"
  65. }, {
  66. token: "empty",
  67. regex: "$",
  68. next: "start"
  69. }, {
  70. defaultToken: "string.regexp.charachterclass"
  71. }
  72. ],
  73. "no_quantifier":[{
  74. token: "invalid",
  75. regex: quantifier
  76. }, {
  77. token: "invalid",
  78. regex: "",
  79. next: "start"
  80. }
  81. ]
  82. };
  83. };
  84. oop.inherits(JsRegexHighlightRules, TextHighlightRules);
  85. exports.JsRegexHighlightRules = JsRegexHighlightRules;
  86. });