rdoc_highlight_rules.js 4.8 KB

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