/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk
20.1.1 by galaxyAbstractor
* Added an simple admin panel to the codeviewer-cmssy stuff
1
/*
2
 * r.js
3
 *
4
 * Copyright (C) 2009-11 by RStudio, Inc.
5
 *
6
 * The Initial Developer of the Original Code is
7
 * Ajax.org B.V.
8
 * Portions created by the Initial Developer are Copyright (C) 2010
9
 * the Initial Developer. All Rights Reserved.
10
 *
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.
16
 *
17
 */
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) {
19
   
20
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");
29
30
   var Mode = function()
31
   {
32
      this.$tokenizer = new Tokenizer(new RHighlightRules().getRules());
33
      this.$outdent = new MatchingBraceOutdent();
34
   };
35
   oop.inherits(Mode, TextMode);
36
37
   (function()
38
   {
39
      this.tokenRe = new RegExp("^["
40
          + unicode.packages.L
41
          + unicode.packages.Mn + unicode.packages.Mc
42
          + unicode.packages.Nd
43
          + unicode.packages.Pc + "._]+", "g"
44
      );
45
46
      this.nonTokenRe = new RegExp("^(?:[^"
47
          + unicode.packages.L
48
          + unicode.packages.Mn + unicode.packages.Mc
49
          + unicode.packages.Nd
50
          + unicode.packages.Pc + "._]|\s])+", "g"
51
      );
52
53
      this.$complements = {
54
               "(": ")",
55
               "[": "]",
56
               '"': '"',
57
               "'": "'",
58
               "{": "}"
59
            };
60
      this.$reOpen = /^[(["'{]$/;
61
      this.$reClose = /^[)\]"'}]$/;
62
63
      this.getNextLineIndent = function(state, line, tab, tabSize, row)
64
      {
65
         return this.codeModel.getNextLineIndent(row, line, state, tab, tabSize);
66
      };
67
68
      this.allowAutoInsert = this.smartAllowAutoInsert;
69
70
      this.checkOutdent = function(state, line, input) {
71
         if (! /^\s+$/.test(line))
72
            return false;
73
74
         return /^\s*[\{\}\)]/.test(input);
75
      };
76
77
      this.getIndentForOpenBrace = function(openBracePos)
78
      {
79
         return this.codeModel.getIndentForOpenBrace(openBracePos);
80
      };
81
82
      this.autoOutdent = function(state, doc, row) {
83
         if (row == 0)
84
            return 0;
85
86
         var line = doc.getLine(row);
87
88
         var match = line.match(/^(\s*[\}\)])/);
89
         if (match)
90
         {
91
            var column = match[1].length;
92
            var openBracePos = doc.findMatchingBracket({row: row, column: column});
93
94
            if (!openBracePos || openBracePos.row == row) return 0;
95
96
            var indent = this.codeModel.getIndentForOpenBrace(openBracePos);
97
            doc.replace(new Range(row, 0, row, column-1), indent);
98
         }
99
100
         match = line.match(/^(\s*\{)/);
101
         if (match)
102
         {
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);
106
         }
107
      };
108
109
      this.$getIndent = function(line) {
110
         var match = line.match(/^(\s+)/);
111
         if (match) {
112
            return match[1];
113
         }
114
115
         return "";
116
      };
117
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]};
124
            }
125
         }
126
         return false;
127
      };
128
   }).call(Mode.prototype);
129
   exports.Mode = Mode;
130
});
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) {
132
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;
137
138
   var RHighlightRules = function()
139
   {
140
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")
143
                  .split("|")
144
            );
145
146
      var buildinConstants = lang.arrayToMap(
147
            ("NULL|NA|TRUE|FALSE|T|F|Inf|NaN|NA_integer_|NA_real_|NA_character_|" +
148
             "NA_complex_").split("|")
149
            );
150
151
      this.$rules = {
152
         "start" : [
153
            {
154
               token : "comment.sectionhead",
155
               regex : "#+(?!').*(?:----|====|####)\\s*$"
156
            },
157
            {
158
               token : "comment",
159
               regex : "#+'",
160
               next : "rd-start"
161
            },
162
            {
163
               token : "comment",
164
               regex : "#.*$"
165
            },
166
            {
167
               token : "string", // multi line string start
168
               regex : '["]',
169
               next : "qqstring"
170
            },
171
            {
172
               token : "string", // multi line string start
173
               regex : "[']",
174
               next : "qstring"
175
            },
176
            {
177
               token : "constant.numeric", // hex
178
               regex : "0[xX][0-9a-fA-F]+[Li]?\\b"
179
            },
180
            {
181
               token : "constant.numeric", // explicit integer
182
               regex : "\\d+L\\b"
183
            },
184
            {
185
               token : "constant.numeric", // number
186
               regex : "\\d+(?:\\.\\d*)?(?:[eE][+\\-]?\\d*)?i?\\b"
187
            },
188
            {
189
               token : "constant.numeric", // number with leading decimal
190
               regex : "\\.\\d+(?:[eE][+\\-]?\\d*)?i?\\b"
191
            },
192
            {
193
               token : "constant.language.boolean",
194
               regex : "(?:TRUE|FALSE|T|F)\\b"
195
            },
196
            {
197
               token : "identifier",
198
               regex : "`.*?`"
199
            },
200
            {
201
               onMatch : function(value) {
202
                  if (keywords[value])
203
                     return "keyword";
204
                  else if (buildinConstants[value])
205
                     return "constant.language";
206
                  else if (value == '...' || value.match(/^\.\.\d+$/))
207
                     return "variable.language";
208
                  else
209
                     return "identifier";
210
               },
211
               regex : "[a-zA-Z.][a-zA-Z0-9._]*\\b"
212
            },
213
            {
214
               token : "keyword.operator",
215
               regex : "%%|>=|<=|==|!=|\\->|<\\-|\\|\\||&&|=|\\+|\\-|\\*|/|\\^|>|<|!|&|\\||~|\\$|:"
216
            },
217
            {
218
               token : "keyword.operator", // infix operators
219
               regex : "%.*?%"
220
            },
221
            {
222
               token : "paren.keyword.operator",
223
               regex : "[[({]"
224
            },
225
            {
226
               token : "paren.keyword.operator",
227
               regex : "[\\])}]"
228
            },
229
            {
230
               token : "text",
231
               regex : "\\s+"
232
            }
233
         ],
234
         "qqstring" : [
235
            {
236
               token : "string",
237
               regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
238
               next : "start"
239
            },
240
            {
241
               token : "string",
242
               regex : '.+'
243
            }
244
         ],
245
         "qstring" : [
246
            {
247
               token : "string",
248
               regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
249
               next : "start"
250
            },
251
            {
252
               token : "string",
253
               regex : '.+'
254
            }
255
         ]
256
      };
257
258
      var rdRules = new TexHighlightRules("comment").getRules();
259
      for (var i = 0; i < rdRules["start"].length; i++) {
260
         rdRules["start"][i].token += ".virtual-comment";
261
      }
262
263
      this.addRules(rdRules, "rd-");
264
      this.$rules["rd-start"].unshift({
265
          token: "text",
266
          regex: "^",
267
          next: "start"
268
      });
269
      this.$rules["rd-start"].unshift({
270
         token : "keyword",
271
         regex : "@(?!@)[^ ]*"
272
      });
273
      this.$rules["rd-start"].unshift({
274
         token : "comment",
275
         regex : "@@"
276
      });
277
      this.$rules["rd-start"].push({
278
         token : "comment",
279
         regex : "[^%\\\\[({\\])}]+"
280
      });
281
   };
282
283
   oop.inherits(RHighlightRules, TextHighlightRules);
284
285
   exports.RHighlightRules = RHighlightRules;
286
});
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) {
288
289
290
var oop = require("../lib/oop");
291
var lang = require("../lib/lang");
292
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
293
294
var TexHighlightRules = function(textClass) {
295
296
    if (!textClass)
297
        textClass = "text";
298
299
    this.$rules = {
300
        "start" : [
301
	        {
302
	            token : "comment",
303
	            regex : "%.*$"
304
	        }, {
305
	            token : textClass, // non-command
306
	            regex : "\\\\[$&%#\\{\\}]"
307
	        }, {
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",
310
               next : "nospell"
311
	        }, {
312
	            token : "keyword", // command
313
	            regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])"
314
	        }, {
315
               token : "paren.keyword.operator",
316
	            regex : "[[({]"
317
	        }, {
318
               token : "paren.keyword.operator",
319
	            regex : "[\\])}]"
320
	        }, {
321
	            token : textClass,
322
	            regex : "\\s+"
323
	        }
324
        ],
325
        "nospell" : [
326
           {
327
               token : "comment",
328
               regex : "%.*$",
329
               next : "start"
330
           }, {
331
               token : "nospell." + textClass, // non-command
332
               regex : "\\\\[$&%#\\{\\}]"
333
           }, {
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"
336
           }, {
337
               token : "keyword", // command
338
               regex : "\\\\(?:[a-zA-z0-9]+|[^a-zA-z0-9])",
339
               next : "start"
340
           }, {
341
               token : "paren.keyword.operator",
342
               regex : "[[({]"
343
           }, {
344
               token : "paren.keyword.operator",
345
               regex : "[\\])]"
346
           }, {
347
               token : "paren.keyword.operator",
348
               regex : "}",
349
               next : "start"
350
           }, {
351
               token : "nospell." + textClass,
352
               regex : "\\s+"
353
           }, {
354
               token : "nospell." + textClass,
355
               regex : "\\w+"
356
           }
357
        ]
358
    };
359
};
360
361
oop.inherits(TexHighlightRules, TextHighlightRules);
362
363
exports.TexHighlightRules = TexHighlightRules;
364
});
365
366
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
367
368
369
var Range = require("../range").Range;
370
371
var MatchingBraceOutdent = function() {};
372
373
(function() {
374
375
    this.checkOutdent = function(line, input) {
376
        if (! /^\s+$/.test(line))
377
            return false;
378
379
        return /^\s*\}/.test(input);
380
    };
381
382
    this.autoOutdent = function(doc, row) {
383
        var line = doc.getLine(row);
384
        var match = line.match(/^(\s*\})/);
385
386
        if (!match) return 0;
387
388
        var column = match[1].length;
389
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
390
391
        if (!openBracePos || openBracePos.row == row) return 0;
392
393
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
394
        doc.replace(new Range(row, 0, row, column-1), indent);
395
    };
396
397
    this.$getIndent = function(line) {
398
        return line.match(/^\s*/)[0];
399
    };
400
401
}).call(MatchingBraceOutdent.prototype);
402
403
exports.MatchingBraceOutdent = MatchingBraceOutdent;
404
});