tex_highlight_rules.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * tex_highlight_rules.js
  3. *
  4. * Copyright (C) 2009-11 by RStudio, Inc.
  5. *
  6. * The Initial Developer of the Original Code is
  7. * Ajax.org B.V.
  8. * Portions created by the Initial Developer are Copyright (C) 2010
  9. * the Initial Developer. All Rights Reserved.
  10. *
  11. * Distributed under the BSD license:
  12. *
  13. * Copyright (c) 2010, Ajax.org B.V.
  14. * All rights reserved.
  15. *
  16. * Redistribution and use in source and binary forms, with or without
  17. * modification, are permitted provided that the following conditions are met:
  18. * * Redistributions of source code must retain the above copyright
  19. * notice, this list of conditions and the following disclaimer.
  20. * * Redistributions in binary form must reproduce the above copyright
  21. * notice, this list of conditions and the following disclaimer in the
  22. * documentation and/or other materials provided with the distribution.
  23. * * Neither the name of Ajax.org B.V. nor the
  24. * names of its contributors may be used to endorse or promote products
  25. * derived from this software without specific prior written permission.
  26. *
  27. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
  28. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
  29. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  30. * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
  31. * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
  32. * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  33. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  34. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  35. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  36. *
  37. */
  38. define(function(require, exports, module) {
  39. "use strict";
  40. var oop = require("../lib/oop");
  41. var lang = require("../lib/lang");
  42. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  43. var TexHighlightRules = function(textClass) {
  44. if (!textClass)
  45. textClass = "text";
  46. // regexp must not have capturing parentheses. Use (?:) instead.
  47. // regexps are ordered -> the first match is used
  48. this.$rules = {
  49. "start" : [
  50. {
  51. token : "comment",
  52. regex : "%.*$"
  53. }, {
  54. token : textClass, // non-command
  55. regex : "\\\\[$&%#\\{\\}]"
  56. }, {
  57. token : "keyword", // command
  58. regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b",
  59. next : "nospell"
  60. }, {
  61. token : "keyword", // command
  62. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
  63. }, {
  64. // Obviously these are neither keywords nor operators, but
  65. // labelling them as such was the easiest way to get them
  66. // to be colored distinctly from regular text
  67. token : "paren.keyword.operator",
  68. regex : "[[({]"
  69. }, {
  70. // Obviously these are neither keywords nor operators, but
  71. // labelling them as such was the easiest way to get them
  72. // to be colored distinctly from regular text
  73. token : "paren.keyword.operator",
  74. regex : "[\\])}]"
  75. }, {
  76. token : textClass,
  77. regex : "\\s+"
  78. }
  79. ],
  80. // This mode is necessary to prevent spell checking, but to keep the
  81. // same syntax highlighting behavior. The list of commands comes from
  82. // Texlipse.
  83. "nospell" : [
  84. {
  85. token : "comment",
  86. regex : "%.*$",
  87. next : "start"
  88. }, {
  89. token : "nospell." + textClass, // non-command
  90. regex : "\\\\[$&%#\\{\\}]"
  91. }, {
  92. token : "keyword", // command
  93. regex : "\\\\(?:documentclass|usepackage|newcounter|setcounter|addtocounter|value|arabic|stepcounter|newenvironment|renewenvironment|ref|vref|eqref|pageref|label|cite[a-zA-Z]*|tag|begin|end|bibitem)\\b"
  94. }, {
  95. token : "keyword", // command
  96. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
  97. next : "start"
  98. }, {
  99. token : "paren.keyword.operator",
  100. regex : "[[({]"
  101. }, {
  102. token : "paren.keyword.operator",
  103. regex : "[\\])]"
  104. }, {
  105. token : "paren.keyword.operator",
  106. regex : "}",
  107. next : "start"
  108. }, {
  109. token : "nospell." + textClass,
  110. regex : "\\s+"
  111. }, {
  112. token : "nospell." + textClass,
  113. regex : "\\w+"
  114. }
  115. ]
  116. };
  117. };
  118. oop.inherits(TexHighlightRules, TextHighlightRules);
  119. exports.TexHighlightRules = TexHighlightRules;
  120. });