Projekt

Obecné

Profil

Stáhnout (12.9 KB) Statistiky
| Větev: | Tag: | Revize:
1
ace.define("ace/mode/terraform_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
var TerraformHighlightRules = function () {
7

    
8

    
9
    this.$rules = {
10
        "start": [
11
            {
12
                token: ['storage.function.terraform'],
13
                regex: '\\b(output|resource|data|variable|module|export)\\b'
14
            },
15
            {
16
                token: "variable.terraform",
17
                regex: "\\$\\s",
18
                push: [
19
                    {
20
                        token: "keyword.terraform",
21
                        regex: "(-var-file|-var)"
22
                    },
23
                    {
24
                        token: "variable.terraform",
25
                        regex: "\\n|$",
26
                        next: "pop"
27
                    },
28

    
29
                    {include: "strings"},
30
                    {include: "variables"},
31
                    {include: "operators"},
32

    
33
                    {defaultToken: "text"}
34
                ]
35
            },
36
            {
37
                token: "language.support.class",
38
                regex: "\\b(timeouts|provider|connection|provisioner|lifecycleprovider|atlas)\\b"
39
            },
40

    
41
            {
42
                token: "singleline.comment.terraform",
43
                regex: '#(.)*$'
44
            },
45
            {
46
                token: "multiline.comment.begin.terraform",
47
                regex: '^\\s*\\/\\*',
48
                push: "blockComment"
49
            },
50
            {
51
                token: "storage.function.terraform",
52
                regex: "^\\s*(locals|terraform)\\s*{"
53
            },
54
            {
55
                token: "paren.lparen",
56
                regex: "[[({]"
57
            },
58

    
59
            {
60
                token: "paren.rparen",
61
                regex: "[\\])}]"
62
            },
63
            {include: "constants"},
64
            {include: "strings"},
65
            {include: "operators"},
66
            {include: "variables"}
67
        ],
68
        blockComment: [{
69
            regex: "^\\s*\\/\\*",
70
            token: "multiline.comment.begin.terraform",
71
            push: "blockComment"
72
        }, {
73
            regex: "\\*\\/\\s*$",
74
            token: "multiline.comment.end.terraform",
75
            next: "pop"
76
        }, {
77
            defaultToken: "comment"
78
        }],
79
        "constants": [
80
            {
81
                token: "constant.language.terraform",
82
                regex: "\\b(true|false|yes|no|on|off|EOF)\\b"
83
            },
84
            {
85
                token: "constant.numeric.terraform",
86
                regex: "(\\b([0-9]+)([kKmMgG]b?)?\\b)|(\\b(0x[0-9A-Fa-f]+)([kKmMgG]b?)?\\b)"
87
            }
88
        ],
89
        "variables": [
90
            {
91
                token: ["variable.assignment.terraform", "keyword.operator"],
92
                regex: "\\b([a-zA-Z_]+)(\\s*=)"
93
            }
94
        ],
95
        "interpolated_variables": [
96
            {
97
                token: "variable.terraform",
98
                regex: "\\b(var|self|count|path|local)\\b(?:\\.*[a-zA-Z_-]*)?"
99
            }
100
        ],
101
        "strings": [
102
            {
103
                token: "punctuation.quote.terraform",
104
                regex: "'",
105
                push:
106
                    [{
107
                        token: 'punctuation.quote.terraform',
108
                        regex: "'",
109
                        next: 'pop'
110
                    },
111
                        {include: "escaped_chars"},
112
                        {defaultToken: 'string'}]
113
            },
114
            {
115
                token: "punctuation.quote.terraform",
116
                regex: '"',
117
                push:
118
                    [{
119
                        token: 'punctuation.quote.terraform',
120
                        regex: '"',
121
                        next: 'pop'
122
                    },
123
                        {include: "interpolation"},
124
                        {include: "escaped_chars"},
125
                        {defaultToken: 'string'}]
126
            }
127
        ],
128
        "escaped_chars": [
129
            {
130
                token: "constant.escaped_char.terraform",
131
                regex: "\\\\."
132
            }
133
        ],
134
        "operators": [
135
            {
136
                token: "keyword.operator",
137
                regex: "\\?|:|==|!=|>|<|>=|<=|&&|\\|\\\||!|%|&|\\*|\\+|\\-|/|="
138
            }
139
        ],
140
        "interpolation": [
141
            {// TODO: double $
142
                token: "punctuation.interpolated.begin.terraform",
143
                regex: "\\$?\\$\\{",
144
                push: [{
145
                    token: "punctuation.interpolated.end.terraform",
146
                    regex: "\\}",
147
                    next: "pop"
148
                },
149
                    {include: "interpolated_variables"},
150
                    {include: "operators"},
151
                    {include: "constants"},
152
                    {include: "strings"},
153
                    {include: "functions"},
154
                    {include: "parenthesis"},
155
                    {defaultToken: "punctuation"}
156
                ]
157
            }
158
        ],
159
        "functions": [
160
            {
161
                token: "keyword.function.terraform",
162
                regex: "\\b(abs|basename|base64decode|base64encode|base64gzip|base64sha256|base64sha512|bcrypt|ceil|chomp|chunklist|cidrhost|cidrnetmask|cidrsubnet|coalesce|coalescelist|compact|concat|contains|dirname|distinct|element|file|floor|flatten|format|formatlist|indent|index|join|jsonencode|keys|length|list|log|lookup|lower|map|matchkeys|max|merge|min|md5|pathexpand|pow|replace|rsadecrypt|sha1|sha256|sha512|signum|slice|sort|split|substr|timestamp|timeadd|title|transpose|trimspace|upper|urlencode|uuid|values|zipmap)\\b"
163
            }
164
        ],
165
        "parenthesis": [
166
            {
167
                token: "paren.lparen",
168
                regex: "\\["
169
            },
170
            {
171
                token: "paren.rparen",
172
                regex: "\\]"
173
            }
174
        ]
175
    };
176
    this.normalizeRules();
177
};
178

    
179
oop.inherits(TerraformHighlightRules, TextHighlightRules);
180

    
181
exports.TerraformHighlightRules = TerraformHighlightRules;
182
});
183

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

    
187
var oop = require("../../lib/oop");
188
var Range = require("../../range").Range;
189
var BaseFoldMode = require("./fold_mode").FoldMode;
190

    
191
var FoldMode = exports.FoldMode = function(commentRegex) {
192
    if (commentRegex) {
193
        this.foldingStartMarker = new RegExp(
194
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
195
        );
196
        this.foldingStopMarker = new RegExp(
197
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
198
        );
199
    }
200
};
201
oop.inherits(FoldMode, BaseFoldMode);
202

    
203
(function() {
204
    
205
    this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
206
    this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
207
    this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
208
    this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
209
    this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
210
    this._getFoldWidgetBase = this.getFoldWidget;
211
    this.getFoldWidget = function(session, foldStyle, row) {
212
        var line = session.getLine(row);
213
    
214
        if (this.singleLineBlockCommentRe.test(line)) {
215
            if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
216
                return "";
217
        }
218
    
219
        var fw = this._getFoldWidgetBase(session, foldStyle, row);
220
    
221
        if (!fw && this.startRegionRe.test(line))
222
            return "start"; // lineCommentRegionStart
223
    
224
        return fw;
225
    };
226

    
227
    this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
228
        var line = session.getLine(row);
229
        
230
        if (this.startRegionRe.test(line))
231
            return this.getCommentRegionBlock(session, line, row);
232
        
233
        var match = line.match(this.foldingStartMarker);
234
        if (match) {
235
            var i = match.index;
236

    
237
            if (match[1])
238
                return this.openingBracketBlock(session, match[1], row, i);
239
                
240
            var range = session.getCommentFoldRange(row, i + match[0].length, 1);
241
            
242
            if (range && !range.isMultiLine()) {
243
                if (forceMultiline) {
244
                    range = this.getSectionRange(session, row);
245
                } else if (foldStyle != "all")
246
                    range = null;
247
            }
248
            
249
            return range;
250
        }
251

    
252
        if (foldStyle === "markbegin")
253
            return;
254

    
255
        var match = line.match(this.foldingStopMarker);
256
        if (match) {
257
            var i = match.index + match[0].length;
258

    
259
            if (match[1])
260
                return this.closingBracketBlock(session, match[1], row, i);
261

    
262
            return session.getCommentFoldRange(row, i, -1);
263
        }
264
    };
265
    
266
    this.getSectionRange = function(session, row) {
267
        var line = session.getLine(row);
268
        var startIndent = line.search(/\S/);
269
        var startRow = row;
270
        var startColumn = line.length;
271
        row = row + 1;
272
        var endRow = row;
273
        var maxRow = session.getLength();
274
        while (++row < maxRow) {
275
            line = session.getLine(row);
276
            var indent = line.search(/\S/);
277
            if (indent === -1)
278
                continue;
279
            if  (startIndent > indent)
280
                break;
281
            var subRange = this.getFoldWidgetRange(session, "all", row);
282
            
283
            if (subRange) {
284
                if (subRange.start.row <= startRow) {
285
                    break;
286
                } else if (subRange.isMultiLine()) {
287
                    row = subRange.end.row;
288
                } else if (startIndent == indent) {
289
                    break;
290
                }
291
            }
292
            endRow = row;
293
        }
294
        
295
        return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
296
    };
297
    this.getCommentRegionBlock = function(session, line, row) {
298
        var startColumn = line.search(/\s*$/);
299
        var maxRow = session.getLength();
300
        var startRow = row;
301
        
302
        var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
303
        var depth = 1;
304
        while (++row < maxRow) {
305
            line = session.getLine(row);
306
            var m = re.exec(line);
307
            if (!m) continue;
308
            if (m[1]) depth--;
309
            else depth++;
310

    
311
            if (!depth) break;
312
        }
313

    
314
        var endRow = row;
315
        if (endRow > startRow) {
316
            return new Range(startRow, startColumn, endRow, line.length);
317
        }
318
    };
319

    
320
}).call(FoldMode.prototype);
321

    
322
});
323

    
324
ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
325
"use strict";
326

    
327
var Range = require("../range").Range;
328

    
329
var MatchingBraceOutdent = function() {};
330

    
331
(function() {
332

    
333
    this.checkOutdent = function(line, input) {
334
        if (! /^\s+$/.test(line))
335
            return false;
336

    
337
        return /^\s*\}/.test(input);
338
    };
339

    
340
    this.autoOutdent = function(doc, row) {
341
        var line = doc.getLine(row);
342
        var match = line.match(/^(\s*\})/);
343

    
344
        if (!match) return 0;
345

    
346
        var column = match[1].length;
347
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
348

    
349
        if (!openBracePos || openBracePos.row == row) return 0;
350

    
351
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
352
        doc.replace(new Range(row, 0, row, column-1), indent);
353
    };
354

    
355
    this.$getIndent = function(line) {
356
        return line.match(/^\s*/)[0];
357
    };
358

    
359
}).call(MatchingBraceOutdent.prototype);
360

    
361
exports.MatchingBraceOutdent = MatchingBraceOutdent;
362
});
363

    
364
ace.define("ace/mode/terraform",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/terraform_highlight_rules","ace/mode/behaviour/cstyle","ace/mode/folding/cstyle","ace/mode/matching_brace_outdent"], function (require, exports, module) {
365
"use strict";
366

    
367
var oop = require("../lib/oop");
368
var TextMode = require("./text").Mode;
369
var TerraformHighlightRules = require("./terraform_highlight_rules").TerraformHighlightRules;
370
var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
371
var CStyleFoldMode = require("./folding/cstyle").FoldMode;
372
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
373

    
374
var Mode = function () {
375
    TextMode.call(this);
376
    this.HighlightRules = TerraformHighlightRules;
377
    this.$outdent = new MatchingBraceOutdent();
378
    this.$behaviour = new CstyleBehaviour();
379
    this.foldingRules = new CStyleFoldMode();
380
};
381

    
382
oop.inherits(Mode, TextMode);
383

    
384

    
385
(function () {
386
    this.$id = "ace/mode/terraform";
387
}).call(Mode.prototype);
388

    
389
exports.Mode = Mode;
390
});                (function() {
391
                    ace.require(["ace/mode/terraform"], function(m) {
392
                        if (typeof module == "object" && typeof exports == "object" && module) {
393
                            module.exports = m;
394
                        }
395
                    });
396
                })();
397
            
(178-178/244)