/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to codeigniter/js/ace/mode-perl.js

  • Committer: Erik Wikström
  • Date: 2013-03-28 07:43:18 UTC
  • mto: This revision was merged to the branch mainline in revision 7.
  • Revision ID: wikxen@gmail.com-20130328074318-9v6krijkyap59nct
Removed trunk folder and moved its contents to the root

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* ***** BEGIN LICENSE BLOCK *****
2
 
 * Distributed under the BSD license:
3
 
 *
4
 
 * Copyright (c) 2010, Ajax.org B.V.
5
 
 * All rights reserved.
6
 
 * 
7
 
 * Redistribution and use in source and binary forms, with or without
8
 
 * modification, are permitted provided that the following conditions are met:
9
 
 *     * Redistributions of source code must retain the above copyright
10
 
 *       notice, this list of conditions and the following disclaimer.
11
 
 *     * Redistributions in binary form must reproduce the above copyright
12
 
 *       notice, this list of conditions and the following disclaimer in the
13
 
 *       documentation and/or other materials provided with the distribution.
14
 
 *     * Neither the name of Ajax.org B.V. nor the
15
 
 *       names of its contributors may be used to endorse or promote products
16
 
 *       derived from this software without specific prior written permission.
17
 
 * 
18
 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
 
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
 
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
 
 * DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
 
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
 
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
 
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
 
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
 
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
 
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
 
 *
29
 
 * ***** END LICENSE BLOCK ***** */
30
 
 
31
 
define('ace/mode/perl', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/perl_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/range', 'ace/mode/folding/cstyle'], function(require, exports, module) {
32
 
 
33
 
 
34
 
var oop = require("../lib/oop");
35
 
var TextMode = require("./text").Mode;
36
 
var Tokenizer = require("../tokenizer").Tokenizer;
37
 
var PerlHighlightRules = require("./perl_highlight_rules").PerlHighlightRules;
38
 
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
 
var Range = require("../range").Range;
40
 
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
41
 
 
42
 
var Mode = function() {
43
 
    this.$tokenizer = new Tokenizer(new PerlHighlightRules().getRules());
44
 
    this.$outdent = new MatchingBraceOutdent();
45
 
    this.foldingRules = new CStyleFoldMode({start: "^=(begin|item)\\b", end: "^=(cut)\\b"});
46
 
};
47
 
oop.inherits(Mode, TextMode);
48
 
 
49
 
(function() {
50
 
 
51
 
    this.lineCommentStart = "#";
52
 
    this.blockComment = [
53
 
        {start: "=begin", end: "=cut"},
54
 
        {start: "=item", end: "=cut"}
55
 
    ];
56
 
 
57
 
 
58
 
    this.getNextLineIndent = function(state, line, tab) {
59
 
        var indent = this.$getIndent(line);
60
 
 
61
 
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
62
 
        var tokens = tokenizedLine.tokens;
63
 
 
64
 
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
65
 
            return indent;
66
 
        }
67
 
 
68
 
        if (state == "start") {
69
 
            var match = line.match(/^.*[\{\(\[\:]\s*$/);
70
 
            if (match) {
71
 
                indent += tab;
72
 
            }
73
 
        }
74
 
 
75
 
        return indent;
76
 
    };
77
 
 
78
 
    this.checkOutdent = function(state, line, input) {
79
 
        return this.$outdent.checkOutdent(line, input);
80
 
    };
81
 
 
82
 
    this.autoOutdent = function(state, doc, row) {
83
 
        this.$outdent.autoOutdent(doc, row);
84
 
    };
85
 
 
86
 
}).call(Mode.prototype);
87
 
 
88
 
exports.Mode = Mode;
89
 
});
90
 
 
91
 
define('ace/mode/perl_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
92
 
 
93
 
 
94
 
var oop = require("../lib/oop");
95
 
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
96
 
 
97
 
var PerlHighlightRules = function() {
98
 
 
99
 
    var keywords = (
100
 
        "base|constant|continue|else|elsif|for|foreach|format|goto|if|last|local|my|next|" +
101
 
         "no|package|parent|redo|require|scalar|sub|unless|until|while|use|vars"
102
 
    );
103
 
 
104
 
    var buildinConstants = ("ARGV|ENV|INC|SIG");
105
 
 
106
 
    var builtinFunctions = (
107
 
        "getprotobynumber|getprotobyname|getservbyname|gethostbyaddr|" +
108
 
         "gethostbyname|getservbyport|getnetbyaddr|getnetbyname|getsockname|" +
109
 
         "getpeername|setpriority|getprotoent|setprotoent|getpriority|" +
110
 
         "endprotoent|getservent|setservent|endservent|sethostent|socketpair|" +
111
 
         "getsockopt|gethostent|endhostent|setsockopt|setnetent|quotemeta|" +
112
 
         "localtime|prototype|getnetent|endnetent|rewinddir|wantarray|getpwuid|" +
113
 
         "closedir|getlogin|readlink|endgrent|getgrgid|getgrnam|shmwrite|" +
114
 
         "shutdown|readline|endpwent|setgrent|readpipe|formline|truncate|" +
115
 
         "dbmclose|syswrite|setpwent|getpwnam|getgrent|getpwent|ucfirst|sysread|" +
116
 
         "setpgrp|shmread|sysseek|sysopen|telldir|defined|opendir|connect|" +
117
 
         "lcfirst|getppid|binmode|syscall|sprintf|getpgrp|readdir|seekdir|" +
118
 
         "waitpid|reverse|unshift|symlink|dbmopen|semget|msgrcv|rename|listen|" +
119
 
         "chroot|msgsnd|shmctl|accept|unpack|exists|fileno|shmget|system|" +
120
 
         "unlink|printf|gmtime|msgctl|semctl|values|rindex|substr|splice|" +
121
 
         "length|msgget|select|socket|return|caller|delete|alarm|ioctl|index|" +
122
 
         "undef|lstat|times|srand|chown|fcntl|close|write|umask|rmdir|study|" +
123
 
         "sleep|chomp|untie|print|utime|mkdir|atan2|split|crypt|flock|chmod|" +
124
 
         "BEGIN|bless|chdir|semop|shift|reset|link|stat|chop|grep|fork|dump|" +
125
 
         "join|open|tell|pipe|exit|glob|warn|each|bind|sort|pack|eval|push|" +
126
 
         "keys|getc|kill|seek|sqrt|send|wait|rand|tied|read|time|exec|recv|" +
127
 
         "eof|chr|int|ord|exp|pos|pop|sin|log|abs|oct|hex|tie|cos|vec|END|ref|" +
128
 
         "map|die|uc|lc|do"
129
 
    );
130
 
 
131
 
    var keywordMapper = this.createKeywordMapper({
132
 
        "keyword": keywords,
133
 
        "constant.language": buildinConstants,
134
 
        "support.function": builtinFunctions
135
 
    }, "identifier");
136
 
 
137
 
    this.$rules = {
138
 
        "start" : [
139
 
            {
140
 
                token : "comment",
141
 
                regex : "#.*$"
142
 
            }, {
143
 
                token : "comment.doc",
144
 
                regex : "^=(?:begin|item)\\b",
145
 
                next : "block_comment"
146
 
            }, {
147
 
                token : "string.regexp",
148
 
                regex : "[/](?:(?:\\[(?:\\\\]|[^\\]])+\\])|(?:\\\\/|[^\\]/]))*[/]\\w*\\s*(?=[).,;]|$)"
149
 
            }, {
150
 
                token : "string", // single line
151
 
                regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
152
 
            }, {
153
 
                token : "string", // multi line string start
154
 
                regex : '["].*\\\\$',
155
 
                next : "qqstring"
156
 
            }, {
157
 
                token : "string", // single line
158
 
                regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
159
 
            }, {
160
 
                token : "string", // multi line string start
161
 
                regex : "['].*\\\\$",
162
 
                next : "qstring"
163
 
            }, {
164
 
                token : "constant.numeric", // hex
165
 
                regex : "0x[0-9a-fA-F]+\\b"
166
 
            }, {
167
 
                token : "constant.numeric", // float
168
 
                regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
169
 
            }, {
170
 
                token : keywordMapper,
171
 
                regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
172
 
            }, {
173
 
                token : "keyword.operator",
174
 
                regex : "\\.\\.\\.|\\|\\|=|>>=|<<=|<=>|&&=|=>|!~|\\^=|&=|\\|=|\\.=|x=|%=|\\/=|\\*=|\\-=|\\+=|=~|\\*\\*|\\-\\-|\\.\\.|\\|\\||&&|\\+\\+|\\->|!=|==|>=|<=|>>|<<|,|=|\\?\\:|\\^|\\||x|%|\\/|\\*|<|&|\\\\|~|!|>|\\.|\\-|\\+|\\-C|\\-b|\\-S|\\-u|\\-t|\\-p|\\-l|\\-d|\\-f|\\-g|\\-s|\\-z|\\-k|\\-e|\\-O|\\-T|\\-B|\\-M|\\-A|\\-X|\\-W|\\-c|\\-R|\\-o|\\-x|\\-w|\\-r|\\b(?:and|cmp|eq|ge|gt|le|lt|ne|not|or|xor)"
175
 
            }, {
176
 
                token : "lparen",
177
 
                regex : "[[({]"
178
 
            }, {
179
 
                token : "rparen",
180
 
                regex : "[\\])}]"
181
 
            }, {
182
 
                token : "text",
183
 
                regex : "\\s+"
184
 
            }
185
 
        ],
186
 
        "qqstring" : [
187
 
            {
188
 
                token : "string",
189
 
                regex : '(?:(?:\\\\.)|(?:[^"\\\\]))*?"',
190
 
                next : "start"
191
 
            }, {
192
 
                token : "string",
193
 
                regex : '.+'
194
 
            }
195
 
        ],
196
 
        "qstring" : [
197
 
            {
198
 
                token : "string",
199
 
                regex : "(?:(?:\\\\.)|(?:[^'\\\\]))*?'",
200
 
                next : "start"
201
 
            }, {
202
 
                token : "string",
203
 
                regex : '.+'
204
 
            }
205
 
        ],
206
 
        "block_comment": [
207
 
            {
208
 
                token: "comment.doc", 
209
 
                regex: "^=cut\\b",
210
 
                next: "start"
211
 
            },
212
 
            {
213
 
                defaultToken: "comment.doc"
214
 
            }
215
 
        ]
216
 
    };
217
 
};
218
 
 
219
 
oop.inherits(PerlHighlightRules, TextHighlightRules);
220
 
 
221
 
exports.PerlHighlightRules = PerlHighlightRules;
222
 
});
223
 
 
224
 
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
225
 
 
226
 
 
227
 
var Range = require("../range").Range;
228
 
 
229
 
var MatchingBraceOutdent = function() {};
230
 
 
231
 
(function() {
232
 
 
233
 
    this.checkOutdent = function(line, input) {
234
 
        if (! /^\s+$/.test(line))
235
 
            return false;
236
 
 
237
 
        return /^\s*\}/.test(input);
238
 
    };
239
 
 
240
 
    this.autoOutdent = function(doc, row) {
241
 
        var line = doc.getLine(row);
242
 
        var match = line.match(/^(\s*\})/);
243
 
 
244
 
        if (!match) return 0;
245
 
 
246
 
        var column = match[1].length;
247
 
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
248
 
 
249
 
        if (!openBracePos || openBracePos.row == row) return 0;
250
 
 
251
 
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
252
 
        doc.replace(new Range(row, 0, row, column-1), indent);
253
 
    };
254
 
 
255
 
    this.$getIndent = function(line) {
256
 
        return line.match(/^\s*/)[0];
257
 
    };
258
 
 
259
 
}).call(MatchingBraceOutdent.prototype);
260
 
 
261
 
exports.MatchingBraceOutdent = MatchingBraceOutdent;
262
 
});
263
 
 
264
 
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
265
 
 
266
 
 
267
 
var oop = require("../../lib/oop");
268
 
var Range = require("../../range").Range;
269
 
var BaseFoldMode = require("./fold_mode").FoldMode;
270
 
 
271
 
var FoldMode = exports.FoldMode = function(commentRegex) {
272
 
    if (commentRegex) {
273
 
        this.foldingStartMarker = new RegExp(
274
 
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
275
 
        );
276
 
        this.foldingStopMarker = new RegExp(
277
 
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
278
 
        );
279
 
    }
280
 
};
281
 
oop.inherits(FoldMode, BaseFoldMode);
282
 
 
283
 
(function() {
284
 
 
285
 
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
286
 
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
287
 
 
288
 
    this.getFoldWidgetRange = function(session, foldStyle, row) {
289
 
        var line = session.getLine(row);
290
 
        var match = line.match(this.foldingStartMarker);
291
 
        if (match) {
292
 
            var i = match.index;
293
 
 
294
 
            if (match[1])
295
 
                return this.openingBracketBlock(session, match[1], row, i);
296
 
 
297
 
            return session.getCommentFoldRange(row, i + match[0].length, 1);
298
 
        }
299
 
 
300
 
        if (foldStyle !== "markbeginend")
301
 
            return;
302
 
 
303
 
        var match = line.match(this.foldingStopMarker);
304
 
        if (match) {
305
 
            var i = match.index + match[0].length;
306
 
 
307
 
            if (match[1])
308
 
                return this.closingBracketBlock(session, match[1], row, i);
309
 
 
310
 
            return session.getCommentFoldRange(row, i, -1);
311
 
        }
312
 
    };
313
 
 
314
 
}).call(FoldMode.prototype);
315
 
 
316
 
});