4
* Copyright (C) 2009-11 by RStudio, Inc.
6
* The Initial Developer of the Original Code is
8
* Portions created by the Initial Developer are Copyright (C) 2010
9
* the Initial Developer. All Rights Reserved.
11
* This program is licensed to you under the terms of version 3 of the
12
* GNU Affero General Public License. This program is distributed WITHOUT
13
* ANY EXPRESS OR IMPLIED WARRANTY, INCLUDING THOSE OF NON-INFRINGEMENT,
14
* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Please refer to the
15
* AGPL (http://www.gnu.org/licenses/agpl-3.0.txt) for more details.
18
define('ace/mode/r', ['require', 'exports', 'module' , 'ace/range', 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/text_highlight_rules', 'ace/mode/r_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/unicode'], function(require, exports, module) {
21
var Range = require("../range").Range;
22
var oop = require("../lib/oop");
23
var TextMode = require("./text").Mode;
24
var Tokenizer = require("../tokenizer").Tokenizer;
25
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
26
var RHighlightRules = require("./r_highlight_rules").RHighlightRules;
27
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
28
var unicode = require("../unicode");
32
this.$tokenizer = new Tokenizer(new RHighlightRules().getRules());
33
this.$outdent = new MatchingBraceOutdent();
35
oop.inherits(Mode, TextMode);
39
this.tokenRe = new RegExp("^["
41
+ unicode.packages.Mn + unicode.packages.Mc
43
+ unicode.packages.Pc + "._]+", "g"
46
this.nonTokenRe = new RegExp("^(?:[^"
48
+ unicode.packages.Mn + unicode.packages.Mc
50
+ unicode.packages.Pc + "._]|\s])+", "g"
60
this.$reOpen = /^[(["'{]$/;
61
this.$reClose = /^[)\]"'}]$/;
63
this.getNextLineIndent = function(state, line, tab, tabSize, row)
65
return this.codeModel.getNextLineIndent(row, line, state, tab, tabSize);
68
this.allowAutoInsert = this.smartAllowAutoInsert;
70
this.checkOutdent = function(state, line, input) {
71
if (! /^\s+$/.test(line))
74
return /^\s*[\{\}\)]/.test(input);
77
this.getIndentForOpenBrace = function(openBracePos)
79
return this.codeModel.getIndentForOpenBrace(openBracePos);
82
this.autoOutdent = function(state, doc, row) {
86
var line = doc.getLine(row);
88
var match = line.match(/^(\s*[\}\)])/);
91
var column = match[1].length;
92
var openBracePos = doc.findMatchingBracket({row: row, column: column});
94
if (!openBracePos || openBracePos.row == row) return 0;
96
var indent = this.codeModel.getIndentForOpenBrace(openBracePos);
97
doc.replace(new Range(row, 0, row, column-1), indent);
100
match = line.match(/^(\s*\{)/);
103
var column = match[1].length;
104
var indent = this.codeModel.getBraceIndent(row-1);
105
doc.replace(new Range(row, 0, row, column-1), indent);
109
this.$getIndent = function(line) {
110
var match = line.match(/^(\s+)/);
118
this.transformAction = function(state, action, editor, session, text) {
119
if (action === 'insertion' && text === "\n") {
120
var pos = editor.getSelectionRange().start;
121
var match = /^((\s*#+')\s*)/.exec(session.doc.getLine(pos.row));
122
if (match && editor.getSelectionRange().start.column >= match[2].length) {
123
return {text: "\n" + match[1]};
128
}).call(Mode.prototype);
131
define('ace/mode/r_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules', 'ace/mode/tex_highlight_rules'], function(require, exports, module) {
133
var oop = require("../lib/oop");
134
var lang = require("../lib/lang");
135
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
136
var TexHighlightRules = require("./tex_highlight_rules").TexHighlightRules;
138
var RHighlightRules = function()
141
var keywords = lang.arrayToMap(
142
("function|if|in|break|next|repeat|else|for|return|switch|while|try|tryCatch|stop|warning|require|library|attach|detach|source|setMethod|setGeneric|setGroupGeneric|setClass")
146
var buildinConstants = lang.arrayToMap(
147
("NULL|NA|TRUE|FALSE|T|F|Inf|NaN|NA_integer_|NA_real_|NA_character_|" +
148
"NA_complex_").split("|")
154
token : "comment.sectionhead",
155
regex : "#+(?!').*(?:----|====|####)\\s*$"
167
token : "string", // multi line string start
172
token : "string", // multi line string start
177
token : "constant.numeric", // hex
178
regex : "0[xX][0-9a-fA-F]+[Li]?\\b"
181
token : "constant.numeric", // explicit integer
185
token : "constant.numeric", // number
186
regex : "\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b"
189
token : "constant.numeric", // number with leading decimal
190
regex : "\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b"
193
token : "constant.language.boolean",
194
regex : "(?:TRUE|FALSE|T|F)\\b"
197
token : "identifier",
201
onMatch : function(value) {
204
else if (buildinConstants[value])
205
return "constant.language";
206
else if (value == '...' || value.match(/^\.\.\d+$/))
207
return "variable.language";
211
regex : "[a-zA-Z.][a-zA-Z0-9._]*\\b"
214
token : "keyword.operator",
215
regex : "%%|>=|<=|==|!=|\\->|<\\-|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||~|\\$|:"
218
token : "keyword.operator", // infix operators
222
token : "paren.keyword.operator",
226
token : "paren.keyword.operator",
237
regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
248
regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
258
var rdRules = new TexHighlightRules("comment").getRules();
259
for (var i = 0; i < rdRules["start"].length; i++) {
260
rdRules["start"][i].token += ".virtual-comment";
263
this.addRules(rdRules, "rd-");
264
this.$rules["rd-start"].unshift({
269
this.$rules["rd-start"].unshift({
271
regex : "@(?!@)[^ ]*"
273
this.$rules["rd-start"].unshift({
277
this.$rules["rd-start"].push({
279
regex : "[^%\\\\[({\\])}]+"
283
oop.inherits(RHighlightRules, TextHighlightRules);
285
exports.RHighlightRules = RHighlightRules;
287
define('ace/mode/tex_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
290
var oop = require("../lib/oop");
291
var lang = require("../lib/lang");
292
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
294
var TexHighlightRules = function(textClass) {
305
token : textClass, // non-command
306
regex : "\\\\[$&%#\\{\\}]"
308
token : "keyword", // command
309
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",
312
token : "keyword", // command
313
regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
315
token : "paren.keyword.operator",
318
token : "paren.keyword.operator",
331
token : "nospell." + textClass, // non-command
332
regex : "\\\\[$&%#\\{\\}]"
334
token : "keyword", // command
335
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"
337
token : "keyword", // command
338
regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
341
token : "paren.keyword.operator",
344
token : "paren.keyword.operator",
347
token : "paren.keyword.operator",
351
token : "nospell." + textClass,
354
token : "nospell." + textClass,
361
oop.inherits(TexHighlightRules, TextHighlightRules);
363
exports.TexHighlightRules = TexHighlightRules;
366
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
369
var Range = require("../range").Range;
371
var MatchingBraceOutdent = function() {};
375
this.checkOutdent = function(line, input) {
376
if (! /^\s+$/.test(line))
379
return /^\s*\}/.test(input);
382
this.autoOutdent = function(doc, row) {
383
var line = doc.getLine(row);
384
var match = line.match(/^(\s*\})/);
386
if (!match) return 0;
388
var column = match[1].length;
389
var openBracePos = doc.findMatchingBracket({row: row, column: column});
391
if (!openBracePos || openBracePos.row == row) return 0;
393
var indent = this.$getIndent(doc.getLine(openBracePos.row));
394
doc.replace(new Range(row, 0, row, column-1), indent);
397
this.$getIndent = function(line) {
398
return line.match(/^\s*/)[0];
401
}).call(MatchingBraceOutdent.prototype);
403
exports.MatchingBraceOutdent = MatchingBraceOutdent;