rdoc_highlight_rules.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * rdoc_highlight_rules.js
  3. *
  4. * Copyright (C) 2009-11 by RStudio, Inc.
  5. *
  6. * This program is licensed to you under the terms of version 3 of the
  7. * GNU Affero General Public License. This program is distributed WITHOUT
  8. * ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
  9. * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
  10. * AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
  11. *
  12. */
  13. define(function(require, exports, module) {
  14. "use strict";
  15. var oop = require("../lib/oop");
  16. var lang = require("../lib/lang");
  17. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  18. var LaTeXHighlightRules = require("./latex_highlight_rules");
  19. var RDocHighlightRules = function() {
  20. // regexp must not have capturing parentheses. Use (?:) instead.
  21. // regexps are ordered -> the first match is used
  22. this.$rules = {
  23. "start" : [
  24. {
  25. token : "comment",
  26. regex : "%.*$"
  27. }, {
  28. token : "text", // non-command
  29. regex : "\\\\[$&%#\\{\\}]"
  30. }, {
  31. token : "keyword", // command
  32. 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",
  33. next : "nospell"
  34. }, {
  35. token : "keyword", // command
  36. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
  37. }, {
  38. // Obviously these are neither keywords nor operators, but
  39. // labelling them as such was the easiest way to get them
  40. // to be colored distinctly from regular text
  41. token : "paren.keyword.operator",
  42. regex : "[[({]"
  43. }, {
  44. // Obviously these are neither keywords nor operators, but
  45. // labelling them as such was the easiest way to get them
  46. // to be colored distinctly from regular text
  47. token : "paren.keyword.operator",
  48. regex : "[\\])}]"
  49. }, {
  50. token : "text",
  51. regex : "\\s+"
  52. }
  53. ],
  54. // This mode is necessary to prevent spell checking, but to keep the
  55. // same syntax highlighting behavior.
  56. "nospell" : [
  57. {
  58. token : "comment",
  59. regex : "%.*$",
  60. next : "start"
  61. }, {
  62. token : "nospell.text", // non-command
  63. regex : "\\\\[$&%#\\{\\}]"
  64. }, {
  65. token : "keyword", // command
  66. 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"
  67. }, {
  68. token : "keyword", // command
  69. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
  70. next : "start"
  71. }, {
  72. token : "paren.keyword.operator",
  73. regex : "[[({]"
  74. }, {
  75. token : "paren.keyword.operator",
  76. regex : "[\\])]"
  77. }, {
  78. token : "paren.keyword.operator",
  79. regex : "}",
  80. next : "start"
  81. }, {
  82. token : "nospell.text",
  83. regex : "\\s+"
  84. }, {
  85. token : "nospell.text",
  86. regex : "\\w+"
  87. }
  88. ]
  89. };
  90. };
  91. oop.inherits(RDocHighlightRules, TextHighlightRules);
  92. exports.RDocHighlightRules = RDocHighlightRules;
  93. });