mode-rdoc.js 6.6 KB

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