Debian Codegraph @

extensions/CodeEditor/modules/lib/ace/mode-sh.js

raw symbols SCIP
1 ace.define("ace/mode/sh_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
2 var oop = require("../lib/oop");
3 var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
4 var reservedKeywords = exports.reservedKeywords = ('!|{|}|case|do|done|elif|else|' +
5 'esac|fi|for|if|in|then|until|while|' +
6 '&|;|export|local|read|typeset|unset|' +
7 'elif|select|set|function|declare|readonly');
8 var languageConstructs = exports.languageConstructs = ('[|]|alias|bg|bind|break|builtin|' +
9 'cd|command|compgen|complete|continue|' +
10 'dirs|disown|echo|enable|eval|exec|' +
11 'exit|fc|fg|getopts|hash|help|history|' +
12 'jobs|kill|let|logout|popd|printf|pushd|' +
13 'pwd|return|set|shift|shopt|source|' +
14 'suspend|test|times|trap|type|ulimit|' +
15 'umask|unalias|wait');
16 var ShHighlightRules = function () {
17 var keywordMapper = this.createKeywordMapper({
18 "keyword": reservedKeywords,
19 "support.function.builtin": languageConstructs,
20 "invalid.deprecated": "debugger"
21 }, "identifier");
22 var integer = "(?:(?:[1-9]\\d*)|(?:0))";
23 var fraction = "(?:\\.\\d+)";
24 var intPart = "(?:\\d+)";
25 var pointFloat = "(?:(?:" + intPart + "?" + fraction + ")|(?:" + intPart + "\\.))";
26 var exponentFloat = "(?:(?:" + pointFloat + "|" + intPart + ")" + ")";
27 var floatNumber = "(?:" + exponentFloat + "|" + pointFloat + ")";
28 var fileDescriptor = "(?:&" + intPart + ")";
29 var variableName = "[a-zA-Z_][a-zA-Z0-9_]*";
30 var variable = "(?:" + variableName + "(?==))";
31 var builtinVariable = "(?:\\$(?:SHLVL|\\$|\\!|\\?))";
32 var func = "(?:" + variableName + "\\s*\\(\\))";
33 this.$rules = {
34 "start": [{
35 token: "constant",
36 regex: /\\./
37 }, {
38 token: ["text", "comment"],
39 regex: /(^|\s)(#.*)$/
40 }, {
41 token: "string.start",
42 regex: '"',
43 push: [{
44 token: "constant.language.escape",
45 regex: /\\(?:[$`"\\]|$)/
46 }, {
47 include: "variables"
48 }, {
49 token: "keyword.operator",
50 regex: /`/ // TODO highlight `
51 }, {
52 token: "string.end",
53 regex: '"',
54 next: "pop"
55 }, {
56 defaultToken: "string"
57 }]
58 }, {
59 token: "string",
60 regex: "\\$'",
61 push: [{
62 token: "constant.language.escape",
63 regex: /\\(?:[abeEfnrtv\\'"]|x[a-fA-F\d]{1,2}|u[a-fA-F\d]{4}([a-fA-F\d]{4})?|c.|\d{1,3})/
64 }, {
65 token: "string",
66 regex: "'",
67 next: "pop"
68 }, {
69 defaultToken: "string"
70 }]
71 }, {
72 regex: "<<<",
73 token: "keyword.operator"
74 }, {
75 stateName: "heredoc",
76 regex: "(<<-?)(\\s*)(['\"`]?)([\\w\\-]+)(['\"`]?)",
77 onMatch: function (value, currentState, stack) {
78 var next = value[2] == '-' ? "indentedHeredoc" : "heredoc";
79 var tokens = value.split(this.splitRegex);
80 stack.push(next, tokens[4]);
81 return [
82 { type: "constant", value: tokens[1] },
83 { type: "text", value: tokens[2] },
84 { type: "string", value: tokens[3] },
85 { type: "support.class", value: tokens[4] },
86 { type: "string", value: tokens[5] }
87 ];
88 },
89 rules: {
90 heredoc: [{
91 onMatch: function (value, currentState, stack) {
92 if (value === stack[1]) {
93 stack.shift();
94 stack.shift();
95 this.next = stack[0] || "start";
96 return "support.class";
97 }
98 this.next = "";
99 return "string";
100 },
101 regex: ".*$",
102 next: "start"
103 }],
104 indentedHeredoc: [{
105 token: "string",
106 regex: "^\t+"
107 }, {
108 onMatch: function (value, currentState, stack) {
109 if (value === stack[1]) {
110 stack.shift();
111 stack.shift();
112 this.next = stack[0] || "start";
113 return "support.class";
114 }
115 this.next = "";
116 return "string";
117 },
118 regex: ".*$",
119 next: "start"
120 }]
121 }
122 }, {
123 regex: "$",
124 token: "empty",
125 next: function (currentState, stack) {
126 if (stack[0] === "heredoc" || stack[0] === "indentedHeredoc")
127 return stack[0];
128 return currentState;
129 }
130 }, {
131 token: ["keyword", "text", "text", "text", "variable"],
132 regex: /(declare|local|readonly)(\s+)(?:(-[fixar]+)(\s+))?([a-zA-Z_][a-zA-Z0-9_]*\b)/
133 }, {
134 token: "variable.language",
135 regex: builtinVariable
136 }, {
137 token: "variable",
138 regex: variable
139 }, {
140 include: "variables"
141 }, {
142 token: "support.function",
143 regex: func
144 }, {
145 token: "support.function",
146 regex: fileDescriptor
147 }, {
148 token: "string", // ' string
149 start: "'", end: "'"
150 }, {
151 token: "constant.numeric", // float
152 regex: floatNumber
153 }, {
154 token: "constant.numeric", // integer
155 regex: integer + "\\b"
156 }, {
157 token: keywordMapper,
158 regex: "[a-zA-Z_][a-zA-Z0-9_]*\\b"
159 }, {
160 token: "keyword.operator",
161 regex: "\\+|\\-|\\*|\\*\\*|\\/|\\/\\/|~|<|>|<=|=>|=|!=|[%&|`]"
162 }, {
163 token: "punctuation.operator",
164 regex: ";"
165 }, {
166 token: "paren.lparen",
167 regex: "[\\[\\(\\{]"
168 }, {
169 token: "paren.rparen",
170 regex: "[\\]]"
171 }, {
172 token: "paren.rparen",
173 regex: "[\\)\\}]",
174 next: "pop"
175 }],
176 variables: [{
177 token: "variable",
178 regex: /(\$)(\w+)/
179 }, {
180 token: ["variable", "paren.lparen"],
181 regex: /(\$)(\()/,
182 push: "start"
183 }, {
184 token: ["variable", "paren.lparen", "keyword.operator", "variable", "keyword.operator"],
185 regex: /(\$)(\{)([#!]?)(\w+|[*@#?\-$!0_])(:[?+\-=]?|##?|%%?|,,?\/|\^\^?)?/,
186 push: "start"
187 }, {
188 token: "variable",
189 regex: /\$[*@#?\-$!0_]/
190 }, {
191 token: ["variable", "paren.lparen"],
192 regex: /(\$)(\{)/,
193 push: "start"
194 }]
195 };
196 this.normalizeRules();
197 };
198 oop.inherits(ShHighlightRules, TextHighlightRules);
199 exports.ShHighlightRules = ShHighlightRules;
200
201 });
202
203 ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
204 var oop = require("../../lib/oop");
205 var Range = require("../../range").Range;
206 var BaseFoldMode = require("./fold_mode").FoldMode;
207 var FoldMode = exports.FoldMode = function (commentRegex) {
208 if (commentRegex) {
209 this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
210 this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
211 }
212 };
213 oop.inherits(FoldMode, BaseFoldMode);
214 (function () {
215 this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
216 this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
217 this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
218 this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
219 this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
220 this._getFoldWidgetBase = this.getFoldWidget;
221 this.getFoldWidget = function (session, foldStyle, row) {
222 var line = session.getLine(row);
223 if (this.singleLineBlockCommentRe.test(line)) {
224 if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
225 return "";
226 }
227 var fw = this._getFoldWidgetBase(session, foldStyle, row);
228 if (!fw && this.startRegionRe.test(line))
229 return "start"; // lineCommentRegionStart
230 return fw;
231 };
232 this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
233 var line = session.getLine(row);
234 if (this.startRegionRe.test(line))
235 return this.getCommentRegionBlock(session, line, row);
236 var match = line.match(this.foldingStartMarker);
237 if (match) {
238 var i = match.index;
239 if (match[1])
240 return this.openingBracketBlock(session, match[1], row, i);
241 var range = session.getCommentFoldRange(row, i + match[0].length, 1);
242 if (range && !range.isMultiLine()) {
243 if (forceMultiline) {
244 range = this.getSectionRange(session, row);
245 }
246 else if (foldStyle != "all")
247 range = null;
248 }
249 return range;
250 }
251 if (foldStyle === "markbegin")
252 return;
253 var match = line.match(this.foldingStopMarker);
254 if (match) {
255 var i = match.index + match[0].length;
256 if (match[1])
257 return this.closingBracketBlock(session, match[1], row, i);
258 return session.getCommentFoldRange(row, i, -1);
259 }
260 };
261 this.getSectionRange = function (session, row) {
262 var line = session.getLine(row);
263 var startIndent = line.search(/\S/);
264 var startRow = row;
265 var startColumn = line.length;
266 row = row + 1;
267 var endRow = row;
268 var maxRow = session.getLength();
269 while (++row < maxRow) {
270 line = session.getLine(row);
271 var indent = line.search(/\S/);
272 if (indent === -1)
273 continue;
274 if (startIndent > indent)
275 break;
276 var subRange = this.getFoldWidgetRange(session, "all", row);
277 if (subRange) {
278 if (subRange.start.row <= startRow) {
279 break;
280 }
281 else if (subRange.isMultiLine()) {
282 row = subRange.end.row;
283 }
284 else if (startIndent == indent) {
285 break;
286 }
287 }
288 endRow = row;
289 }
290 return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
291 };
292 this.getCommentRegionBlock = function (session, line, row) {
293 var startColumn = line.search(/\s*$/);
294 var maxRow = session.getLength();
295 var startRow = row;
296 var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
297 var depth = 1;
298 while (++row < maxRow) {
299 line = session.getLine(row);
300 var m = re.exec(line);
301 if (!m)
302 continue;
303 if (m[1])
304 depth--;
305 else
306 depth++;
307 if (!depth)
308 break;
309 }
310 var endRow = row;
311 if (endRow > startRow) {
312 return new Range(startRow, startColumn, endRow, line.length);
313 }
314 };
315 }).call(FoldMode.prototype);
316
317 });
318
319 ace.define("ace/mode/sh",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/sh_highlight_rules","ace/range","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
320 var oop = require("../lib/oop");
321 var TextMode = require("./text").Mode;
322 var ShHighlightRules = require("./sh_highlight_rules").ShHighlightRules;
323 var Range = require("../range").Range;
324 var CStyleFoldMode = require("./folding/cstyle").FoldMode;
325 var Mode = function () {
326 this.HighlightRules = ShHighlightRules;
327 this.foldingRules = new CStyleFoldMode();
328 this.$behaviour = this.$defaultBehaviour;
329 };
330 oop.inherits(Mode, TextMode);
331 (function () {
332 this.lineCommentStart = "#";
333 this.getNextLineIndent = function (state, line, tab) {
334 var indent = this.$getIndent(line);
335 var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
336 var tokens = tokenizedLine.tokens;
337 if (tokens.length && tokens[tokens.length - 1].type == "comment") {
338 return indent;
339 }
340 if (state == "start") {
341 var match = line.match(/^.*[\{\(\[:]\s*$/);
342 if (match) {
343 indent += tab;
344 }
345 }
346 return indent;
347 };
348 var outdents = {
349 "pass": 1,
350 "return": 1,
351 "raise": 1,
352 "break": 1,
353 "continue": 1
354 };
355 this.checkOutdent = function (state, line, input) {
356 if (input !== "\r\n" && input !== "\r" && input !== "\n")
357 return false;
358 var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
359 if (!tokens)
360 return false;
361 do {
362 var last = tokens.pop();
363 } while (last && (last.type == "comment" || (last.type == "text" && last.value.match(/^\s+$/))));
364 if (!last)
365 return false;
366 return (last.type == "keyword" && outdents[last.value]);
367 };
368 this.autoOutdent = function (state, doc, row) {
369 row += 1;
370 var indent = this.$getIndent(doc.getLine(row));
371 var tab = doc.getTabString();
372 if (indent.slice(-tab.length) == tab)
373 doc.remove(new Range(row, indent.length - tab.length, row, indent.length));
374 };
375 this.$id = "ace/mode/sh";
376 this.snippetFileId = "ace/snippets/sh";
377 }).call(Mode.prototype);
378 exports.Mode = Mode;
379
380 }); (function() {
381 ace.require(["ace/mode/sh"], function(m) {
382 if (typeof module == "object" && typeof exports == "object" && module) {
383 module.exports = m;
384 }
385 });
386 })();
387