mode-r.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. define("ace/mode/tex_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules"], function(ace_require, exports, module) {
  2. "use strict";
  3. var oop = ace_require("../lib/oop");
  4. var lang = ace_require("../lib/lang");
  5. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  6. var TexHighlightRules = function(textClass) {
  7. if (!textClass)
  8. textClass = "text";
  9. this.$rules = {
  10. "start" : [
  11. {
  12. token : "comment",
  13. regex : "%.*$"
  14. }, {
  15. token : textClass, // non-command
  16. regex : "\\\\[$&%#\\{\\}]"
  17. }, {
  18. token : "keyword", // command
  19. 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",
  20. next : "nospell"
  21. }, {
  22. token : "keyword", // command
  23. regex : "\\\\(?:[a-zA-Z0-9]+|[^a-zA-Z0-9])"
  24. }, {
  25. token : "paren.keyword.operator",
  26. regex : "[[({]"
  27. }, {
  28. token : "paren.keyword.operator",
  29. regex : "[\\])}]"
  30. }, {
  31. token : textClass,
  32. regex : "\\s+"
  33. }
  34. ],
  35. "nospell" : [
  36. {
  37. token : "comment",
  38. regex : "%.*$",
  39. next : "start"
  40. }, {
  41. token : "nospell." + textClass, // non-command
  42. regex : "\\\\[$&%#\\{\\}]"
  43. }, {
  44. token : "keyword", // command
  45. 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"
  46. }, {
  47. token : "keyword", // command
  48. regex : "\\\\(?:[a-zA-Z0-9]+|[^a-zA-Z0-9])",
  49. next : "start"
  50. }, {
  51. token : "paren.keyword.operator",
  52. regex : "[[({]"
  53. }, {
  54. token : "paren.keyword.operator",
  55. regex : "[\\])]"
  56. }, {
  57. token : "paren.keyword.operator",
  58. regex : "}",
  59. next : "start"
  60. }, {
  61. token : "nospell." + textClass,
  62. regex : "\\s+"
  63. }, {
  64. token : "nospell." + textClass,
  65. regex : "\\w+"
  66. }
  67. ]
  68. };
  69. };
  70. oop.inherits(TexHighlightRules, TextHighlightRules);
  71. exports.TexHighlightRules = TexHighlightRules;
  72. });
  73. define("ace/mode/r_highlight_rules",["ace_require","exports","module","ace/lib/oop","ace/lib/lang","ace/mode/text_highlight_rules","ace/mode/tex_highlight_rules"], function(ace_require, exports, module)
  74. {
  75. var oop = ace_require("../lib/oop");
  76. var lang = ace_require("../lib/lang");
  77. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  78. var TexHighlightRules = ace_require("./tex_highlight_rules").TexHighlightRules;
  79. var RHighlightRules = function()
  80. {
  81. var keywords = lang.arrayToMap(
  82. ("function|if|in|break|next|repeat|else|for|return|switch|while|try|tryCatch|stop|warning|ace_require|library|attach|detach|source|setMethod|setGeneric|setGroupGeneric|setClass")
  83. .split("|")
  84. );
  85. var buildinConstants = lang.arrayToMap(
  86. ("NULL|NA|TRUE|FALSE|T|F|Inf|NaN|NA_integer_|NA_real_|NA_character_|" +
  87. "NA_complex_").split("|")
  88. );
  89. this.$rules = {
  90. "start" : [
  91. {
  92. token : "comment.sectionhead",
  93. regex : "#+(?!').*(?:----|====|####)\\s*$"
  94. },
  95. {
  96. token : "comment",
  97. regex : "#+'",
  98. next : "rd-start"
  99. },
  100. {
  101. token : "comment",
  102. regex : "#.*$"
  103. },
  104. {
  105. token : "string", // multi line string start
  106. regex : '["]',
  107. next : "qqstring"
  108. },
  109. {
  110. token : "string", // multi line string start
  111. regex : "[']",
  112. next : "qstring"
  113. },
  114. {
  115. token : "constant.numeric", // hex
  116. regex : "0[xX][0-9a-fA-F]+[Li]?\\b"
  117. },
  118. {
  119. token : "constant.numeric", // explicit integer
  120. regex : "\\d+L\\b"
  121. },
  122. {
  123. token : "constant.numeric", // number
  124. regex : "\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b"
  125. },
  126. {
  127. token : "constant.numeric", // number with leading decimal
  128. regex : "\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b"
  129. },
  130. {
  131. token : "constant.language.boolean",
  132. regex : "(?:TRUE|FALSE|T|F)\\b"
  133. },
  134. {
  135. token : "identifier",
  136. regex : "`.*?`"
  137. },
  138. {
  139. onMatch : function(value) {
  140. if (keywords[value])
  141. return "keyword";
  142. else if (buildinConstants[value])
  143. return "constant.language";
  144. else if (value == '...' || value.match(/^\.\.\d+$/))
  145. return "variable.language";
  146. else
  147. return "identifier";
  148. },
  149. regex : "[a-zA-Z.][a-zA-Z0-9._]*\\b"
  150. },
  151. {
  152. token : "keyword.operator",
  153. regex : "%%|>=|<=|==|!=|\\->|<\\-|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||~|\\$|:"
  154. },
  155. {
  156. token : "keyword.operator", // infix operators
  157. regex : "%.*?%"
  158. },
  159. {
  160. token : "paren.keyword.operator",
  161. regex : "[[({]"
  162. },
  163. {
  164. token : "paren.keyword.operator",
  165. regex : "[\\])}]"
  166. },
  167. {
  168. token : "text",
  169. regex : "\\s+"
  170. }
  171. ],
  172. "qqstring" : [
  173. {
  174. token : "string",
  175. regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
  176. next : "start"
  177. },
  178. {
  179. token : "string",
  180. regex : '.+'
  181. }
  182. ],
  183. "qstring" : [
  184. {
  185. token : "string",
  186. regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
  187. next : "start"
  188. },
  189. {
  190. token : "string",
  191. regex : '.+'
  192. }
  193. ]
  194. };
  195. var rdRules = new TexHighlightRules("comment").getRules();
  196. for (var i = 0; i < rdRules["start"].length; i++) {
  197. rdRules["start"][i].token += ".virtual-comment";
  198. }
  199. this.addRules(rdRules, "rd-");
  200. this.$rules["rd-start"].unshift({
  201. token: "text",
  202. regex: "^",
  203. next: "start"
  204. });
  205. this.$rules["rd-start"].unshift({
  206. token : "keyword",
  207. regex : "@(?!@)[^ ]*"
  208. });
  209. this.$rules["rd-start"].unshift({
  210. token : "comment",
  211. regex : "@@"
  212. });
  213. this.$rules["rd-start"].push({
  214. token : "comment",
  215. regex : "[^%\\\\[({\\])}]+"
  216. });
  217. };
  218. oop.inherits(RHighlightRules, TextHighlightRules);
  219. exports.RHighlightRules = RHighlightRules;
  220. });
  221. define("ace/mode/matching_brace_outdent",["ace_require","exports","module","ace/range"], function(ace_require, exports, module) {
  222. "use strict";
  223. var Range = ace_require("../range").Range;
  224. var MatchingBraceOutdent = function() {};
  225. (function() {
  226. this.checkOutdent = function(line, input) {
  227. if (! /^\s+$/.test(line))
  228. return false;
  229. return /^\s*\}/.test(input);
  230. };
  231. this.autoOutdent = function(doc, row) {
  232. var line = doc.getLine(row);
  233. var match = line.match(/^(\s*\})/);
  234. if (!match) return 0;
  235. var column = match[1].length;
  236. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  237. if (!openBracePos || openBracePos.row == row) return 0;
  238. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  239. doc.replace(new Range(row, 0, row, column-1), indent);
  240. };
  241. this.$getIndent = function(line) {
  242. return line.match(/^\s*/)[0];
  243. };
  244. }).call(MatchingBraceOutdent.prototype);
  245. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  246. });
  247. define("ace/mode/r",["ace_require","exports","module","ace/unicode","ace/range","ace/lib/oop","ace/mode/text","ace/mode/text_highlight_rules","ace/mode/r_highlight_rules","ace/mode/matching_brace_outdent"], function(ace_require, exports, module) {
  248. "use strict";
  249. var unicode = ace_require("../unicode");
  250. var Range = ace_require("../range").Range;
  251. var oop = ace_require("../lib/oop");
  252. var TextMode = ace_require("./text").Mode;
  253. var TextHighlightRules = ace_require("./text_highlight_rules").TextHighlightRules;
  254. var RHighlightRules = ace_require("./r_highlight_rules").RHighlightRules;
  255. var MatchingBraceOutdent = ace_require("./matching_brace_outdent").MatchingBraceOutdent;
  256. var Mode = function(){
  257. this.HighlightRules = RHighlightRules;
  258. this.$outdent = new MatchingBraceOutdent();
  259. this.$behaviour = this.$defaultBehaviour;
  260. };
  261. oop.inherits(Mode, TextMode);
  262. (function() {
  263. this.lineCommentStart = "#";
  264. this.tokenRe = new RegExp("^[" + unicode.wordChars + "._]+", "g");
  265. this.nonTokenRe = new RegExp("^(?:[^" + unicode.wordChars + "._]|\s])+", "g");
  266. this.$id = "ace/mode/r";
  267. this.snippetFileId = "ace/snippets/r";
  268. }).call(Mode.prototype);
  269. exports.Mode = Mode;
  270. }); (function() {
  271. window.ace_require(["ace/mode/r"], function(m) {
  272. if (typeof module == "object" && typeof exports == "object" && module) {
  273. module.exports = m;
  274. }
  275. });
  276. })();