Debian Codegraph @

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

raw symbols SCIP
1 ace.define("ace/mode/doc_comment_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 DocCommentHighlightRules = function () {
5 this.$rules = {
6 "start": [
7 {
8 token: "comment.doc.tag",
9 regex: "@\\w+(?=\\s|$)"
10 }, DocCommentHighlightRules.getTagRule(), {
11 defaultToken: "comment.doc",
12 caseInsensitive: true
13 }
14 ]
15 };
16 };
17 oop.inherits(DocCommentHighlightRules, TextHighlightRules);
18 DocCommentHighlightRules.getTagRule = function (start) {
19 return {
20 token: "comment.doc.tag.storage.type",
21 regex: "\\b(?:TODO|FIXME|XXX|HACK)\\b"
22 };
23 };
24 DocCommentHighlightRules.getStartRule = function (start) {
25 return {
26 token: "comment.doc", // doc comment
27 regex: "\\/\\*(?=\\*)",
28 next: start
29 };
30 };
31 DocCommentHighlightRules.getEndRule = function (start) {
32 return {
33 token: "comment.doc", // closing comment
34 regex: "\\*\\/",
35 next: start
36 };
37 };
38 exports.DocCommentHighlightRules = DocCommentHighlightRules;
39
40 });
41
42 ace.define("ace/mode/golang_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/doc_comment_highlight_rules","ace/mode/text_highlight_rules"], function(require, exports, module){var oop = require("../lib/oop");
43 var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
44 var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
45 var GolangHighlightRules = function () {
46 var keywords = ("else|break|case|return|goto|if|const|select|" +
47 "continue|struct|default|switch|for|range|" +
48 "func|import|package|chan|defer|fallthrough|go|interface|map|range|" +
49 "select|type|var");
50 var builtinTypes = ("string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" +
51 "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error");
52 var builtinFunctions = ("new|close|cap|copy|panic|panicln|print|println|len|make|delete|real|recover|imag|append");
53 var builtinConstants = ("nil|true|false|iota");
54 var keywordMapper = this.createKeywordMapper({
55 "keyword": keywords,
56 "constant.language": builtinConstants,
57 "support.function": builtinFunctions,
58 "support.type": builtinTypes
59 }, "");
60 var stringEscapeRe = "\\\\(?:[0-7]{3}|x\\h{2}|u{4}|U\\h{6}|[abfnrtv'\"\\\\])".replace(/\\h/g, "[a-fA-F\\d]");
61 this.$rules = {
62 "start": [
63 {
64 token: "comment",
65 regex: "\\/\\/.*$"
66 },
67 DocCommentHighlightRules.getStartRule("doc-start"),
68 {
69 token: "comment.start", // multi line comment
70 regex: "\\/\\*",
71 next: "comment"
72 }, {
73 token: "string", // single line
74 regex: /"(?:[^"\\]|\\.)*?"/
75 }, {
76 token: "string", // raw
77 regex: '`',
78 next: "bqstring"
79 }, {
80 token: "constant.numeric", // rune
81 regex: "'(?:[^\\'\uD800-\uDBFF]|[\uD800-\uDBFF][\uDC00-\uDFFF]|" + stringEscapeRe.replace('"', '') + ")'"
82 }, {
83 token: "constant.numeric", // hex
84 regex: "0[xX][0-9a-fA-F]+\\b"
85 }, {
86 token: "constant.numeric", // float
87 regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
88 }, {
89 token: ["keyword", "text", "entity.name.function"],
90 regex: "(func)(\\s+)([a-zA-Z_$][a-zA-Z0-9_$]*)\\b"
91 }, {
92 token: function (val) {
93 if (val[val.length - 1] == "(") {
94 return [{
95 type: keywordMapper(val.slice(0, -1)) || "support.function",
96 value: val.slice(0, -1)
97 }, {
98 type: "paren.lparen",
99 value: val.slice(-1)
100 }];
101 }
102 return keywordMapper(val) || "identifier";
103 },
104 regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b\\(?"
105 }, {
106 token: "keyword.operator",
107 regex: "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
108 }, {
109 token: "punctuation.operator",
110 regex: "\\?|\\:|\\,|\\;|\\."
111 }, {
112 token: "paren.lparen",
113 regex: "[[({]"
114 }, {
115 token: "paren.rparen",
116 regex: "[\\])}]"
117 }, {
118 token: "text",
119 regex: "\\s+"
120 }
121 ],
122 "comment": [
123 {
124 token: "comment.end",
125 regex: "\\*\\/",
126 next: "start"
127 }, {
128 defaultToken: "comment"
129 }
130 ],
131 "bqstring": [
132 {
133 token: "string",
134 regex: '`',
135 next: "start"
136 }, {
137 defaultToken: "string"
138 }
139 ]
140 };
141 this.embedRules(DocCommentHighlightRules, "doc-", [DocCommentHighlightRules.getEndRule("start")]);
142 };
143 oop.inherits(GolangHighlightRules, TextHighlightRules);
144 exports.GolangHighlightRules = GolangHighlightRules;
145
146 });
147
148 ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module){"use strict";
149 var Range = require("../range").Range;
150 var MatchingBraceOutdent = function () { };
151 (function () {
152 this.checkOutdent = function (line, input) {
153 if (!/^\s+$/.test(line))
154 return false;
155 return /^\s*\}/.test(input);
156 };
157 this.autoOutdent = function (doc, row) {
158 var line = doc.getLine(row);
159 var match = line.match(/^(\s*\})/);
160 if (!match)
161 return 0;
162 var column = match[1].length;
163 var openBracePos = doc.findMatchingBracket({ row: row, column: column });
164 if (!openBracePos || openBracePos.row == row)
165 return 0;
166 var indent = this.$getIndent(doc.getLine(openBracePos.row));
167 doc.replace(new Range(row, 0, row, column - 1), indent);
168 };
169 this.$getIndent = function (line) {
170 return line.match(/^\s*/)[0];
171 };
172 }).call(MatchingBraceOutdent.prototype);
173 exports.MatchingBraceOutdent = MatchingBraceOutdent;
174
175 });
176
177 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";
178 var oop = require("../../lib/oop");
179 var Range = require("../../range").Range;
180 var BaseFoldMode = require("./fold_mode").FoldMode;
181 var FoldMode = exports.FoldMode = function (commentRegex) {
182 if (commentRegex) {
183 this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
184 this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
185 }
186 };
187 oop.inherits(FoldMode, BaseFoldMode);
188 (function () {
189 this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
190 this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
191 this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
192 this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
193 this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
194 this._getFoldWidgetBase = this.getFoldWidget;
195 this.getFoldWidget = function (session, foldStyle, row) {
196 var line = session.getLine(row);
197 if (this.singleLineBlockCommentRe.test(line)) {
198 if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
199 return "";
200 }
201 var fw = this._getFoldWidgetBase(session, foldStyle, row);
202 if (!fw && this.startRegionRe.test(line))
203 return "start"; // lineCommentRegionStart
204 return fw;
205 };
206 this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
207 var line = session.getLine(row);
208 if (this.startRegionRe.test(line))
209 return this.getCommentRegionBlock(session, line, row);
210 var match = line.match(this.foldingStartMarker);
211 if (match) {
212 var i = match.index;
213 if (match[1])
214 return this.openingBracketBlock(session, match[1], row, i);
215 var range = session.getCommentFoldRange(row, i + match[0].length, 1);
216 if (range && !range.isMultiLine()) {
217 if (forceMultiline) {
218 range = this.getSectionRange(session, row);
219 }
220 else if (foldStyle != "all")
221 range = null;
222 }
223 return range;
224 }
225 if (foldStyle === "markbegin")
226 return;
227 var match = line.match(this.foldingStopMarker);
228 if (match) {
229 var i = match.index + match[0].length;
230 if (match[1])
231 return this.closingBracketBlock(session, match[1], row, i);
232 return session.getCommentFoldRange(row, i, -1);
233 }
234 };
235 this.getSectionRange = function (session, row) {
236 var line = session.getLine(row);
237 var startIndent = line.search(/\S/);
238 var startRow = row;
239 var startColumn = line.length;
240 row = row + 1;
241 var endRow = row;
242 var maxRow = session.getLength();
243 while (++row < maxRow) {
244 line = session.getLine(row);
245 var indent = line.search(/\S/);
246 if (indent === -1)
247 continue;
248 if (startIndent > indent)
249 break;
250 var subRange = this.getFoldWidgetRange(session, "all", row);
251 if (subRange) {
252 if (subRange.start.row <= startRow) {
253 break;
254 }
255 else if (subRange.isMultiLine()) {
256 row = subRange.end.row;
257 }
258 else if (startIndent == indent) {
259 break;
260 }
261 }
262 endRow = row;
263 }
264 return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
265 };
266 this.getCommentRegionBlock = function (session, line, row) {
267 var startColumn = line.search(/\s*$/);
268 var maxRow = session.getLength();
269 var startRow = row;
270 var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
271 var depth = 1;
272 while (++row < maxRow) {
273 line = session.getLine(row);
274 var m = re.exec(line);
275 if (!m)
276 continue;
277 if (m[1])
278 depth--;
279 else
280 depth++;
281 if (!depth)
282 break;
283 }
284 var endRow = row;
285 if (endRow > startRow) {
286 return new Range(startRow, startColumn, endRow, line.length);
287 }
288 };
289 }).call(FoldMode.prototype);
290
291 });
292
293 ace.define("ace/mode/golang",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/golang_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/cstyle"], function(require, exports, module){var oop = require("../lib/oop");
294 var TextMode = require("./text").Mode;
295 var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
296 var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
297 var CStyleFoldMode = require("./folding/cstyle").FoldMode;
298 var Mode = function () {
299 this.HighlightRules = GolangHighlightRules;
300 this.$outdent = new MatchingBraceOutdent();
301 this.foldingRules = new CStyleFoldMode();
302 this.$behaviour = this.$defaultBehaviour;
303 };
304 oop.inherits(Mode, TextMode);
305 (function () {
306 this.lineCommentStart = "//";
307 this.blockComment = { start: "/*", end: "*/" };
308 this.getNextLineIndent = function (state, line, tab) {
309 var indent = this.$getIndent(line);
310 var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
311 var tokens = tokenizedLine.tokens;
312 var endState = tokenizedLine.state;
313 if (tokens.length && tokens[tokens.length - 1].type == "comment") {
314 return indent;
315 }
316 if (state == "start") {
317 var match = line.match(/^.*[\{\(\[]\s*$/);
318 if (match) {
319 indent += tab;
320 }
321 }
322 return indent;
323 }; //end getNextLineIndent
324 this.checkOutdent = function (state, line, input) {
325 return this.$outdent.checkOutdent(line, input);
326 };
327 this.autoOutdent = function (state, doc, row) {
328 this.$outdent.autoOutdent(doc, row);
329 };
330 this.$id = "ace/mode/golang";
331 }).call(Mode.prototype);
332 exports.Mode = Mode;
333
334 }); (function() {
335 ace.require(["ace/mode/golang"], function(m) {
336 if (typeof module == "object" && typeof exports == "object" && module) {
337 module.exports = m;
338 }
339 });
340 })();
341