Projekt

Obecné

Profil

Stáhnout (11.1 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/rust_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
2
"use strict";
3

    
4
var oop = require("../lib/oop");
5
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
6

    
7
var stringEscape = /\\(?:[nrt0'"\\]|x[\da-fA-F]{2}|u\{[\da-fA-F]{6}\})/.source;
8
var RustHighlightRules = function() {
9

    
10
    this.$rules = { start:
11
       [ { token: 'variable.other.source.rust',
12
           regex: '\'[a-zA-Z_][a-zA-Z0-9_]*(?![\\\'])' },
13
         { token: 'string.quoted.single.source.rust',
14
           regex: "'(?:[^'\\\\]|" + stringEscape + ")'" },
15
         { token: 'identifier',
16
           regex:  /r#[a-zA-Z_][a-zA-Z0-9_]*\b/ },
17
         {
18
            stateName: "bracketedComment",
19
            onMatch : function(value, currentState, stack){
20
                stack.unshift(this.next, value.length - 1, currentState);
21
                return "string.quoted.raw.source.rust";
22
            },
23
            regex : /r#*"/,
24
            next  : [
25
                {
26
                    onMatch : function(value, currentState, stack) {
27
                        var token = "string.quoted.raw.source.rust";
28
                        if (value.length >= stack[1]) {
29
                            if (value.length > stack[1])
30
                                token = "invalid";
31
                            stack.shift();
32
                            stack.shift();
33
                            this.next = stack.shift();
34
                        } else {
35
                            this.next = "";
36
                        }
37
                        return token;
38
                    },
39
                    regex : /"#*/,
40
                    next  : "start"
41
                }, {
42
                    defaultToken : "string.quoted.raw.source.rust"
43
                }
44
            ]
45
         },
46
         { token: 'string.quoted.double.source.rust',
47
           regex: '"',
48
           push: 
49
            [ { token: 'string.quoted.double.source.rust',
50
                regex: '"',
51
                next: 'pop' },
52
              { token: 'constant.character.escape.source.rust',
53
                regex: stringEscape },
54
              { defaultToken: 'string.quoted.double.source.rust' } ] },
55
         { token: [ 'keyword.source.rust', 'text', 'entity.name.function.source.rust' ],
56
           regex: '\\b(fn)(\\s+)((?:r#)?[a-zA-Z_][a-zA-Z0-9_]*)' },
57
         { token: 'support.constant', regex: '\\b[a-zA-Z_][\\w\\d]*::' },
58
         { token: 'keyword.source.rust',
59
           regex: '\\b(?:abstract|alignof|as|async|await|become|box|break|catch|continue|const|crate|default|do|dyn|else|enum|extern|for|final|if|impl|in|let|loop|macro|match|mod|move|mut|offsetof|override|priv|proc|pub|pure|ref|return|self|sizeof|static|struct|super|trait|type|typeof|union|unsafe|unsized|use|virtual|where|while|yield)\\b' },
60
         { token: 'storage.type.source.rust',
61
           regex: '\\b(?:Self|isize|usize|char|bool|u8|u16|u32|u64|u128|f16|f32|f64|i8|i16|i32|i64|i128|str|option|either|c_float|c_double|c_void|FILE|fpos_t|DIR|dirent|c_char|c_schar|c_uchar|c_short|c_ushort|c_int|c_uint|c_long|c_ulong|size_t|ptrdiff_t|clock_t|time_t|c_longlong|c_ulonglong|intptr_t|uintptr_t|off_t|dev_t|ino_t|pid_t|mode_t|ssize_t)\\b' },
62
         { token: 'variable.language.source.rust', regex: '\\bself\\b' },
63
         
64
         { token: 'comment.line.doc.source.rust',
65
           regex: '//!.*$' },
66
         { token: 'comment.line.double-dash.source.rust',
67
           regex: '//.*$' },
68
         { token: 'comment.start.block.source.rust',
69
           regex: '/\\*',
70
           stateName: 'comment',
71
           push: 
72
            [ { token: 'comment.start.block.source.rust',
73
                regex: '/\\*',
74
                push: 'comment' },
75
              { token: 'comment.end.block.source.rust',
76
                regex: '\\*/',
77
                next: 'pop' },
78
              { defaultToken: 'comment.block.source.rust' } ] },
79
         
80
         { token: 'keyword.operator',
81
           regex: /\$|[-=]>|[-+%^=!&|<>]=?|[*/](?![*/])=?/ },
82
         { token : "punctuation.operator", regex : /[?:,;.]/ },
83
         { token : "paren.lparen", regex : /[\[({]/ },
84
         { token : "paren.rparen", regex : /[\])}]/ },
85
         { token: 'constant.language.source.rust',
86
           regex: '\\b(?:true|false|Some|None|Ok|Err)\\b' },
87
         { token: 'support.constant.source.rust',
88
           regex: '\\b(?:EXIT_FAILURE|EXIT_SUCCESS|RAND_MAX|EOF|SEEK_SET|SEEK_CUR|SEEK_END|_IOFBF|_IONBF|_IOLBF|BUFSIZ|FOPEN_MAX|FILENAME_MAX|L_tmpnam|TMP_MAX|O_RDONLY|O_WRONLY|O_RDWR|O_APPEND|O_CREAT|O_EXCL|O_TRUNC|S_IFIFO|S_IFCHR|S_IFBLK|S_IFDIR|S_IFREG|S_IFMT|S_IEXEC|S_IWRITE|S_IREAD|S_IRWXU|S_IXUSR|S_IWUSR|S_IRUSR|F_OK|R_OK|W_OK|X_OK|STDIN_FILENO|STDOUT_FILENO|STDERR_FILENO)\\b' },
89
         { token: 'meta.preprocessor.source.rust',
90
           regex: '\\b\\w\\(\\w\\)*!|#\\[[\\w=\\(\\)_]+\\]\\b' },
91
         { token: 'constant.numeric.source.rust',
92
           regex: /\b(?:0x[a-fA-F0-9_]+|0o[0-7_]+|0b[01_]+|[0-9][0-9_]*(?!\.))(?:[iu](?:size|8|16|32|64|128))?\b/ },
93
         { token: 'constant.numeric.source.rust',
94
           regex: /\b(?:[0-9][0-9_]*)(?:\.[0-9][0-9_]*)?(?:[Ee][+-][0-9][0-9_]*)?(?:f32|f64)?\b/ } ] };
95
    
96
    this.normalizeRules();
97
};
98

    
99
RustHighlightRules.metaData = { fileTypes: [ 'rs', 'rc' ],
100
      foldingStartMarker: '^.*\\bfn\\s*(\\w+\\s*)?\\([^\\)]*\\)(\\s*\\{[^\\}]*)?\\s*$',
101
      foldingStopMarker: '^\\s*\\}',
102
      name: 'Rust',
103
      scopeName: 'source.rust' };
104

    
105

    
106
oop.inherits(RustHighlightRules, TextHighlightRules);
107

    
108
exports.RustHighlightRules = RustHighlightRules;
109
});
110

    
111
ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
112
"use strict";
113

    
114
var oop = require("../../lib/oop");
115
var Range = require("../../range").Range;
116
var BaseFoldMode = require("./fold_mode").FoldMode;
117

    
118
var FoldMode = exports.FoldMode = function(commentRegex) {
119
    if (commentRegex) {
120
        this.foldingStartMarker = new RegExp(
121
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
122
        );
123
        this.foldingStopMarker = new RegExp(
124
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
125
        );
126
    }
127
};
128
oop.inherits(FoldMode, BaseFoldMode);
129

    
130
(function() {
131
    
132
    this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
133
    this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
134
    this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
135
    this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
136
    this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
137
    this._getFoldWidgetBase = this.getFoldWidget;
138
    this.getFoldWidget = function(session, foldStyle, row) {
139
        var line = session.getLine(row);
140
    
141
        if (this.singleLineBlockCommentRe.test(line)) {
142
            if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
143
                return "";
144
        }
145
    
146
        var fw = this._getFoldWidgetBase(session, foldStyle, row);
147
    
148
        if (!fw && this.startRegionRe.test(line))
149
            return "start"; // lineCommentRegionStart
150
    
151
        return fw;
152
    };
153

    
154
    this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
155
        var line = session.getLine(row);
156
        
157
        if (this.startRegionRe.test(line))
158
            return this.getCommentRegionBlock(session, line, row);
159
        
160
        var match = line.match(this.foldingStartMarker);
161
        if (match) {
162
            var i = match.index;
163

    
164
            if (match[1])
165
                return this.openingBracketBlock(session, match[1], row, i);
166
                
167
            var range = session.getCommentFoldRange(row, i + match[0].length, 1);
168
            
169
            if (range && !range.isMultiLine()) {
170
                if (forceMultiline) {
171
                    range = this.getSectionRange(session, row);
172
                } else if (foldStyle != "all")
173
                    range = null;
174
            }
175
            
176
            return range;
177
        }
178

    
179
        if (foldStyle === "markbegin")
180
            return;
181

    
182
        var match = line.match(this.foldingStopMarker);
183
        if (match) {
184
            var i = match.index + match[0].length;
185

    
186
            if (match[1])
187
                return this.closingBracketBlock(session, match[1], row, i);
188

    
189
            return session.getCommentFoldRange(row, i, -1);
190
        }
191
    };
192
    
193
    this.getSectionRange = function(session, row) {
194
        var line = session.getLine(row);
195
        var startIndent = line.search(/\S/);
196
        var startRow = row;
197
        var startColumn = line.length;
198
        row = row + 1;
199
        var endRow = row;
200
        var maxRow = session.getLength();
201
        while (++row < maxRow) {
202
            line = session.getLine(row);
203
            var indent = line.search(/\S/);
204
            if (indent === -1)
205
                continue;
206
            if  (startIndent > indent)
207
                break;
208
            var subRange = this.getFoldWidgetRange(session, "all", row);
209
            
210
            if (subRange) {
211
                if (subRange.start.row <= startRow) {
212
                    break;
213
                } else if (subRange.isMultiLine()) {
214
                    row = subRange.end.row;
215
                } else if (startIndent == indent) {
216
                    break;
217
                }
218
            }
219
            endRow = row;
220
        }
221
        
222
        return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
223
    };
224
    this.getCommentRegionBlock = function(session, line, row) {
225
        var startColumn = line.search(/\s*$/);
226
        var maxRow = session.getLength();
227
        var startRow = row;
228
        
229
        var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
230
        var depth = 1;
231
        while (++row < maxRow) {
232
            line = session.getLine(row);
233
            var m = re.exec(line);
234
            if (!m) continue;
235
            if (m[1]) depth--;
236
            else depth++;
237

    
238
            if (!depth) break;
239
        }
240

    
241
        var endRow = row;
242
        if (endRow > startRow) {
243
            return new Range(startRow, startColumn, endRow, line.length);
244
        }
245
    };
246

    
247
}).call(FoldMode.prototype);
248

    
249
});
250

    
251
ace.define("ace/mode/rust",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/rust_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
252
"use strict";
253

    
254
var oop = require("../lib/oop");
255
var TextMode = require("./text").Mode;
256
var RustHighlightRules = require("./rust_highlight_rules").RustHighlightRules;
257
var FoldMode = require("./folding/cstyle").FoldMode;
258

    
259
var Mode = function() {
260
    this.HighlightRules = RustHighlightRules;
261
    this.foldingRules = new FoldMode();
262
    this.$behaviour = this.$defaultBehaviour;
263
};
264
oop.inherits(Mode, TextMode);
265

    
266
(function() {
267
    this.lineCommentStart = "//";
268
    this.blockComment = {start: "/*", end: "*/", nestable: true};
269
    this.$quotes = { '"': '"' };
270
    this.$id = "ace/mode/rust";
271
}).call(Mode.prototype);
272

    
273
exports.Mode = Mode;
274
});                (function() {
275
                    ace.require(["ace/mode/rust"], function(m) {
276
                        if (typeof module == "object" && typeof exports == "object" && module) {
277
                            module.exports = m;
278
                        }
279
                    });
280
                })();
281
            
(158-158/244)