mode-rdoc.js 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. ace.define("ace/mode/latex_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var LatexHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [{
  8. token : "keyword",
  9. regex : "\\\\(?:[^a-zA-Z]|[a-zA-Z]+)"
  10. }, {
  11. token : "lparen",
  12. regex : "[[({]"
  13. }, {
  14. token : "rparen",
  15. regex : "[\\])}]"
  16. }, {
  17. token : "string",
  18. regex : "\\$(?:(?:\\\\.)|(?:[^\\$\\\\]))*?\\$"
  19. }, {
  20. token : "comment",
  21. regex : "%.*$"
  22. }]
  23. };
  24. };
  25. oop.inherits(LatexHighlightRules, TextHighlightRules);
  26. exports.LatexHighlightRules = LatexHighlightRules;
  27. });
  28. ace.define("ace/mode/rdoc_highlight_rules",["require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules","ace/mode/latex_highlight_rules"], function(require, exports, module) {
  29. "use strict";
  30. var oop = require("../lib/oop");
  31. var lang = require("../lib/lang");
  32. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  33. var LaTeXHighlightRules = require("./latex_highlight_rules");
  34. var RDocHighlightRules = function() {
  35. this.$rules = {
  36. "start" : [
  37. {
  38. token : "comment",
  39. regex : "%.*$"
  40. }, {
  41. token : "text", // non-command
  42. regex : "\\\\[$&%#\\{\\}]"
  43. }, {
  44. token : "keyword", // command
  45. 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",
  46. next : "nospell"
  47. }, {
  48. token : "keyword", // command
  49. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
  50. }, {
  51. token : "paren.keyword.operator",
  52. regex : "[[({]"
  53. }, {
  54. token : "paren.keyword.operator",
  55. regex : "[\\])}]"
  56. }, {
  57. token : "text",
  58. regex : "\\s+"
  59. }
  60. ],
  61. "nospell" : [
  62. {
  63. token : "comment",
  64. regex : "%.*$",
  65. next : "start"
  66. }, {
  67. token : "nospell.text", // non-command
  68. regex : "\\\\[$&%#\\{\\}]"
  69. }, {
  70. token : "keyword", // command
  71. 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"
  72. }, {
  73. token : "keyword", // command
  74. regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
  75. next : "start"
  76. }, {
  77. token : "paren.keyword.operator",
  78. regex : "[[({]"
  79. }, {
  80. token : "paren.keyword.operator",
  81. regex : "[\\])]"
  82. }, {
  83. token : "paren.keyword.operator",
  84. regex : "}",
  85. next : "start"
  86. }, {
  87. token : "nospell.text",
  88. regex : "\\s+"
  89. }, {
  90. token : "nospell.text",
  91. regex : "\\w+"
  92. }
  93. ]
  94. };
  95. };
  96. oop.inherits(RDocHighlightRules, TextHighlightRules);
  97. exports.RDocHighlightRules = RDocHighlightRules;
  98. });
  99. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  100. "use strict";
  101. var Range = require("../range").Range;
  102. var MatchingBraceOutdent = function() {};
  103. (function() {
  104. this.checkOutdent = function(line, input) {
  105. if (! /^\s+$/.test(line))
  106. return false;
  107. return /^\s*\}/.test(input);
  108. };
  109. this.autoOutdent = function(doc, row) {
  110. var line = doc.getLine(row);
  111. var match = line.match(/^(\s*\})/);
  112. if (!match) return 0;
  113. var column = match[1].length;
  114. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  115. if (!openBracePos || openBracePos.row == row) return 0;
  116. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  117. doc.replace(new Range(row, 0, row, column-1), indent);
  118. };
  119. this.$getIndent = function(line) {
  120. return line.match(/^\s*/)[0];
  121. };
  122. }).call(MatchingBraceOutdent.prototype);
  123. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  124. });
  125. ace.define("ace/mode/rdoc",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/rdoc_highlight_rules","ace/mode/matching_brace_outdent"], function(require, exports, module) {
  126. "use strict";
  127. var oop = require("../lib/oop");
  128. var TextMode = require("./text").Mode;
  129. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  130. var RDocHighlightRules = require("./rdoc_highlight_rules").RDocHighlightRules;
  131. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  132. var Mode = function(suppressHighlighting) {
  133. this.HighlightRules = RDocHighlightRules;
  134. this.$outdent = new MatchingBraceOutdent();
  135. };
  136. oop.inherits(Mode, TextMode);
  137. (function() {
  138. this.getNextLineIndent = function(state, line, tab) {
  139. return this.$getIndent(line);
  140. };
  141. this.$id = "ace/mode/rdoc";
  142. }).call(Mode.prototype);
  143. exports.Mode = Mode;
  144. });