PageRenderTime 55ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/files/ace/1.1.5/noconflict/mode-golang.js

https://gitlab.com/Mirros/jsdelivr
JavaScript | 701 lines | 641 code | 60 blank | 0 comment | 48 complexity | 9030c8ce08e619b540e85bb2bb46a368 MD5 | raw file
  1. ace.define("ace/mode/doc_comment_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var DocCommentHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [ {
  8. token : "comment.doc.tag",
  9. regex : "@[\\w\\d_]+" // TODO: fix email addresses
  10. }, {
  11. token : "comment.doc.tag",
  12. regex : "\\bTODO\\b"
  13. }, {
  14. defaultToken : "comment.doc"
  15. }]
  16. };
  17. };
  18. oop.inherits(DocCommentHighlightRules, TextHighlightRules);
  19. DocCommentHighlightRules.getStartRule = function(start) {
  20. return {
  21. token : "comment.doc", // doc comment
  22. regex : "\\/\\*(?=\\*)",
  23. next : start
  24. };
  25. };
  26. DocCommentHighlightRules.getEndRule = function (start) {
  27. return {
  28. token : "comment.doc", // closing comment
  29. regex : "\\*\\/",
  30. next : start
  31. };
  32. };
  33. exports.DocCommentHighlightRules = DocCommentHighlightRules;
  34. });
  35. 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) {
  36. var oop = require("../lib/oop");
  37. var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
  38. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  39. var GolangHighlightRules = function() {
  40. var keywords = (
  41. "else|break|case|return|goto|if|const|select|" +
  42. "continue|struct|default|switch|for|range|" +
  43. "func|import|package|chan|defer|fallthrough|go|interface|map|range|" +
  44. "select|type|var"
  45. );
  46. var builtinTypes = (
  47. "string|uint8|uint16|uint32|uint64|int8|int16|int32|int64|float32|" +
  48. "float64|complex64|complex128|byte|rune|uint|int|uintptr|bool|error"
  49. );
  50. var builtinFunctions = (
  51. "make|close|new|panic|recover"
  52. );
  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. }, "identifier");
  60. this.$rules = {
  61. "start" : [
  62. {
  63. token : "comment",
  64. regex : "\\/\\/.*$"
  65. },
  66. DocCommentHighlightRules.getStartRule("doc-start"),
  67. {
  68. token : "comment", // multi line comment
  69. regex : "\\/\\*",
  70. next : "comment"
  71. }, {
  72. token : "string", // single line
  73. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  74. }, {
  75. token : "string", // single line
  76. regex : '[`](?:[^`]*)[`]'
  77. }, {
  78. token : "string", // multi line string start
  79. merge : true,
  80. regex : '[`](?:[^`]*)$',
  81. next : "bqstring"
  82. }, {
  83. token : "constant.numeric", // rune
  84. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))[']"
  85. }, {
  86. token : "constant.numeric", // hex
  87. regex : "0[xX][0-9a-fA-F]+\\b"
  88. }, {
  89. token : "constant.numeric", // float
  90. regex : "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
  91. }, {
  92. token : keywordMapper,
  93. regex : "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
  94. }, {
  95. token : "keyword.operator",
  96. regex : "!|\\$|%|&|\\*|\\-\\-|\\-|\\+\\+|\\+|~|==|=|!=|<=|>=|<<=|>>=|>>>=|<>|<|>|!|&&|\\|\\||\\?\\:|\\*=|%=|\\+=|\\-=|&=|\\^="
  97. }, {
  98. token : "punctuation.operator",
  99. regex : "\\?|\\:|\\,|\\;|\\."
  100. }, {
  101. token : "paren.lparen",
  102. regex : "[[({]"
  103. }, {
  104. token : "paren.rparen",
  105. regex : "[\\])}]"
  106. }, {
  107. token : "text",
  108. regex : "\\s+"
  109. }
  110. ],
  111. "comment" : [
  112. {
  113. token : "comment", // closing comment
  114. regex : ".*?\\*\\/",
  115. next : "start"
  116. }, {
  117. token : "comment", // comment spanning whole line
  118. regex : ".+"
  119. }
  120. ],
  121. "bqstring" : [
  122. {
  123. token : "string",
  124. regex : '(?:[^`]*)`',
  125. next : "start"
  126. }, {
  127. token : "string",
  128. regex : '.+'
  129. }
  130. ]
  131. };
  132. this.embedRules(DocCommentHighlightRules, "doc-",
  133. [ DocCommentHighlightRules.getEndRule("start") ]);
  134. };
  135. oop.inherits(GolangHighlightRules, TextHighlightRules);
  136. exports.GolangHighlightRules = GolangHighlightRules;
  137. });
  138. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  139. "use strict";
  140. var Range = require("../range").Range;
  141. var MatchingBraceOutdent = function() {};
  142. (function() {
  143. this.checkOutdent = function(line, input) {
  144. if (! /^\s+$/.test(line))
  145. return false;
  146. return /^\s*\}/.test(input);
  147. };
  148. this.autoOutdent = function(doc, row) {
  149. var line = doc.getLine(row);
  150. var match = line.match(/^(\s*\})/);
  151. if (!match) return 0;
  152. var column = match[1].length;
  153. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  154. if (!openBracePos || openBracePos.row == row) return 0;
  155. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  156. doc.replace(new Range(row, 0, row, column-1), indent);
  157. };
  158. this.$getIndent = function(line) {
  159. return line.match(/^\s*/)[0];
  160. };
  161. }).call(MatchingBraceOutdent.prototype);
  162. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  163. });
  164. ace.define("ace/mode/behaviour/cstyle",["require","exports","module","ace/lib/oop","ace/mode/behaviour","ace/token_iterator","ace/lib/lang"], function(require, exports, module) {
  165. "use strict";
  166. var oop = require("../../lib/oop");
  167. var Behaviour = require("../behaviour").Behaviour;
  168. var TokenIterator = require("../../token_iterator").TokenIterator;
  169. var lang = require("../../lib/lang");
  170. var SAFE_INSERT_IN_TOKENS =
  171. ["text", "paren.rparen", "punctuation.operator"];
  172. var SAFE_INSERT_BEFORE_TOKENS =
  173. ["text", "paren.rparen", "punctuation.operator", "comment"];
  174. var context;
  175. var contextCache = {}
  176. var initContext = function(editor) {
  177. var id = -1;
  178. if (editor.multiSelect) {
  179. id = editor.selection.id;
  180. if (contextCache.rangeCount != editor.multiSelect.rangeCount)
  181. contextCache = {rangeCount: editor.multiSelect.rangeCount};
  182. }
  183. if (contextCache[id])
  184. return context = contextCache[id];
  185. context = contextCache[id] = {
  186. autoInsertedBrackets: 0,
  187. autoInsertedRow: -1,
  188. autoInsertedLineEnd: "",
  189. maybeInsertedBrackets: 0,
  190. maybeInsertedRow: -1,
  191. maybeInsertedLineStart: "",
  192. maybeInsertedLineEnd: ""
  193. };
  194. };
  195. var CstyleBehaviour = function() {
  196. this.add("braces", "insertion", function(state, action, editor, session, text) {
  197. var cursor = editor.getCursorPosition();
  198. var line = session.doc.getLine(cursor.row);
  199. if (text == '{') {
  200. initContext(editor);
  201. var selection = editor.getSelectionRange();
  202. var selected = session.doc.getTextRange(selection);
  203. if (selected !== "" && selected !== "{" && editor.getWrapBehavioursEnabled()) {
  204. return {
  205. text: '{' + selected + '}',
  206. selection: false
  207. };
  208. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  209. if (/[\]\}\)]/.test(line[cursor.column]) || editor.inMultiSelectMode) {
  210. CstyleBehaviour.recordAutoInsert(editor, session, "}");
  211. return {
  212. text: '{}',
  213. selection: [1, 1]
  214. };
  215. } else {
  216. CstyleBehaviour.recordMaybeInsert(editor, session, "{");
  217. return {
  218. text: '{',
  219. selection: [1, 1]
  220. };
  221. }
  222. }
  223. } else if (text == '}') {
  224. initContext(editor);
  225. var rightChar = line.substring(cursor.column, cursor.column + 1);
  226. if (rightChar == '}') {
  227. var matching = session.$findOpeningBracket('}', {column: cursor.column + 1, row: cursor.row});
  228. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  229. CstyleBehaviour.popAutoInsertedClosing();
  230. return {
  231. text: '',
  232. selection: [1, 1]
  233. };
  234. }
  235. }
  236. } else if (text == "\n" || text == "\r\n") {
  237. initContext(editor);
  238. var closing = "";
  239. if (CstyleBehaviour.isMaybeInsertedClosing(cursor, line)) {
  240. closing = lang.stringRepeat("}", context.maybeInsertedBrackets);
  241. CstyleBehaviour.clearMaybeInsertedClosing();
  242. }
  243. var rightChar = line.substring(cursor.column, cursor.column + 1);
  244. if (rightChar === '}') {
  245. var openBracePos = session.findMatchingBracket({row: cursor.row, column: cursor.column+1}, '}');
  246. if (!openBracePos)
  247. return null;
  248. var next_indent = this.$getIndent(session.getLine(openBracePos.row));
  249. } else if (closing) {
  250. var next_indent = this.$getIndent(line);
  251. } else {
  252. CstyleBehaviour.clearMaybeInsertedClosing();
  253. return;
  254. }
  255. var indent = next_indent + session.getTabString();
  256. return {
  257. text: '\n' + indent + '\n' + next_indent + closing,
  258. selection: [1, indent.length, 1, indent.length]
  259. };
  260. } else {
  261. CstyleBehaviour.clearMaybeInsertedClosing();
  262. }
  263. });
  264. this.add("braces", "deletion", function(state, action, editor, session, range) {
  265. var selected = session.doc.getTextRange(range);
  266. if (!range.isMultiLine() && selected == '{') {
  267. initContext(editor);
  268. var line = session.doc.getLine(range.start.row);
  269. var rightChar = line.substring(range.end.column, range.end.column + 1);
  270. if (rightChar == '}') {
  271. range.end.column++;
  272. return range;
  273. } else {
  274. context.maybeInsertedBrackets--;
  275. }
  276. }
  277. });
  278. this.add("parens", "insertion", function(state, action, editor, session, text) {
  279. if (text == '(') {
  280. initContext(editor);
  281. var selection = editor.getSelectionRange();
  282. var selected = session.doc.getTextRange(selection);
  283. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  284. return {
  285. text: '(' + selected + ')',
  286. selection: false
  287. };
  288. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  289. CstyleBehaviour.recordAutoInsert(editor, session, ")");
  290. return {
  291. text: '()',
  292. selection: [1, 1]
  293. };
  294. }
  295. } else if (text == ')') {
  296. initContext(editor);
  297. var cursor = editor.getCursorPosition();
  298. var line = session.doc.getLine(cursor.row);
  299. var rightChar = line.substring(cursor.column, cursor.column + 1);
  300. if (rightChar == ')') {
  301. var matching = session.$findOpeningBracket(')', {column: cursor.column + 1, row: cursor.row});
  302. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  303. CstyleBehaviour.popAutoInsertedClosing();
  304. return {
  305. text: '',
  306. selection: [1, 1]
  307. };
  308. }
  309. }
  310. }
  311. });
  312. this.add("parens", "deletion", function(state, action, editor, session, range) {
  313. var selected = session.doc.getTextRange(range);
  314. if (!range.isMultiLine() && selected == '(') {
  315. initContext(editor);
  316. var line = session.doc.getLine(range.start.row);
  317. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  318. if (rightChar == ')') {
  319. range.end.column++;
  320. return range;
  321. }
  322. }
  323. });
  324. this.add("brackets", "insertion", function(state, action, editor, session, text) {
  325. if (text == '[') {
  326. initContext(editor);
  327. var selection = editor.getSelectionRange();
  328. var selected = session.doc.getTextRange(selection);
  329. if (selected !== "" && editor.getWrapBehavioursEnabled()) {
  330. return {
  331. text: '[' + selected + ']',
  332. selection: false
  333. };
  334. } else if (CstyleBehaviour.isSaneInsertion(editor, session)) {
  335. CstyleBehaviour.recordAutoInsert(editor, session, "]");
  336. return {
  337. text: '[]',
  338. selection: [1, 1]
  339. };
  340. }
  341. } else if (text == ']') {
  342. initContext(editor);
  343. var cursor = editor.getCursorPosition();
  344. var line = session.doc.getLine(cursor.row);
  345. var rightChar = line.substring(cursor.column, cursor.column + 1);
  346. if (rightChar == ']') {
  347. var matching = session.$findOpeningBracket(']', {column: cursor.column + 1, row: cursor.row});
  348. if (matching !== null && CstyleBehaviour.isAutoInsertedClosing(cursor, line, text)) {
  349. CstyleBehaviour.popAutoInsertedClosing();
  350. return {
  351. text: '',
  352. selection: [1, 1]
  353. };
  354. }
  355. }
  356. }
  357. });
  358. this.add("brackets", "deletion", function(state, action, editor, session, range) {
  359. var selected = session.doc.getTextRange(range);
  360. if (!range.isMultiLine() && selected == '[') {
  361. initContext(editor);
  362. var line = session.doc.getLine(range.start.row);
  363. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  364. if (rightChar == ']') {
  365. range.end.column++;
  366. return range;
  367. }
  368. }
  369. });
  370. this.add("string_dquotes", "insertion", function(state, action, editor, session, text) {
  371. if (text == '"' || text == "'") {
  372. initContext(editor);
  373. var quote = text;
  374. var selection = editor.getSelectionRange();
  375. var selected = session.doc.getTextRange(selection);
  376. if (selected !== "" && selected !== "'" && selected != '"' && editor.getWrapBehavioursEnabled()) {
  377. return {
  378. text: quote + selected + quote,
  379. selection: false
  380. };
  381. } else {
  382. var cursor = editor.getCursorPosition();
  383. var line = session.doc.getLine(cursor.row);
  384. var leftChar = line.substring(cursor.column-1, cursor.column);
  385. if (leftChar == '\\') {
  386. return null;
  387. }
  388. var tokens = session.getTokens(selection.start.row);
  389. var col = 0, token;
  390. var quotepos = -1; // Track whether we're inside an open quote.
  391. for (var x = 0; x < tokens.length; x++) {
  392. token = tokens[x];
  393. if (token.type == "string") {
  394. quotepos = -1;
  395. } else if (quotepos < 0) {
  396. quotepos = token.value.indexOf(quote);
  397. }
  398. if ((token.value.length + col) > selection.start.column) {
  399. break;
  400. }
  401. col += tokens[x].value.length;
  402. }
  403. if (!token || (quotepos < 0 && token.type !== "comment" && (token.type !== "string" || ((selection.start.column !== token.value.length+col-1) && token.value.lastIndexOf(quote) === token.value.length-1)))) {
  404. if (!CstyleBehaviour.isSaneInsertion(editor, session))
  405. return;
  406. return {
  407. text: quote + quote,
  408. selection: [1,1]
  409. };
  410. } else if (token && token.type === "string") {
  411. var rightChar = line.substring(cursor.column, cursor.column + 1);
  412. if (rightChar == quote) {
  413. return {
  414. text: '',
  415. selection: [1, 1]
  416. };
  417. }
  418. }
  419. }
  420. }
  421. });
  422. this.add("string_dquotes", "deletion", function(state, action, editor, session, range) {
  423. var selected = session.doc.getTextRange(range);
  424. if (!range.isMultiLine() && (selected == '"' || selected == "'")) {
  425. initContext(editor);
  426. var line = session.doc.getLine(range.start.row);
  427. var rightChar = line.substring(range.start.column + 1, range.start.column + 2);
  428. if (rightChar == selected) {
  429. range.end.column++;
  430. return range;
  431. }
  432. }
  433. });
  434. };
  435. CstyleBehaviour.isSaneInsertion = function(editor, session) {
  436. var cursor = editor.getCursorPosition();
  437. var iterator = new TokenIterator(session, cursor.row, cursor.column);
  438. if (!this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS)) {
  439. var iterator2 = new TokenIterator(session, cursor.row, cursor.column + 1);
  440. if (!this.$matchTokenType(iterator2.getCurrentToken() || "text", SAFE_INSERT_IN_TOKENS))
  441. return false;
  442. }
  443. iterator.stepForward();
  444. return iterator.getCurrentTokenRow() !== cursor.row ||
  445. this.$matchTokenType(iterator.getCurrentToken() || "text", SAFE_INSERT_BEFORE_TOKENS);
  446. };
  447. CstyleBehaviour.$matchTokenType = function(token, types) {
  448. return types.indexOf(token.type || token) > -1;
  449. };
  450. CstyleBehaviour.recordAutoInsert = function(editor, session, bracket) {
  451. var cursor = editor.getCursorPosition();
  452. var line = session.doc.getLine(cursor.row);
  453. if (!this.isAutoInsertedClosing(cursor, line, context.autoInsertedLineEnd[0]))
  454. context.autoInsertedBrackets = 0;
  455. context.autoInsertedRow = cursor.row;
  456. context.autoInsertedLineEnd = bracket + line.substr(cursor.column);
  457. context.autoInsertedBrackets++;
  458. };
  459. CstyleBehaviour.recordMaybeInsert = function(editor, session, bracket) {
  460. var cursor = editor.getCursorPosition();
  461. var line = session.doc.getLine(cursor.row);
  462. if (!this.isMaybeInsertedClosing(cursor, line))
  463. context.maybeInsertedBrackets = 0;
  464. context.maybeInsertedRow = cursor.row;
  465. context.maybeInsertedLineStart = line.substr(0, cursor.column) + bracket;
  466. context.maybeInsertedLineEnd = line.substr(cursor.column);
  467. context.maybeInsertedBrackets++;
  468. };
  469. CstyleBehaviour.isAutoInsertedClosing = function(cursor, line, bracket) {
  470. return context.autoInsertedBrackets > 0 &&
  471. cursor.row === context.autoInsertedRow &&
  472. bracket === context.autoInsertedLineEnd[0] &&
  473. line.substr(cursor.column) === context.autoInsertedLineEnd;
  474. };
  475. CstyleBehaviour.isMaybeInsertedClosing = function(cursor, line) {
  476. return context.maybeInsertedBrackets > 0 &&
  477. cursor.row === context.maybeInsertedRow &&
  478. line.substr(cursor.column) === context.maybeInsertedLineEnd &&
  479. line.substr(0, cursor.column) == context.maybeInsertedLineStart;
  480. };
  481. CstyleBehaviour.popAutoInsertedClosing = function() {
  482. context.autoInsertedLineEnd = context.autoInsertedLineEnd.substr(1);
  483. context.autoInsertedBrackets--;
  484. };
  485. CstyleBehaviour.clearMaybeInsertedClosing = function() {
  486. if (context) {
  487. context.maybeInsertedBrackets = 0;
  488. context.maybeInsertedRow = -1;
  489. }
  490. };
  491. oop.inherits(CstyleBehaviour, Behaviour);
  492. exports.CstyleBehaviour = CstyleBehaviour;
  493. });
  494. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  495. "use strict";
  496. var oop = require("../../lib/oop");
  497. var Range = require("../../range").Range;
  498. var BaseFoldMode = require("./fold_mode").FoldMode;
  499. var FoldMode = exports.FoldMode = function(commentRegex) {
  500. if (commentRegex) {
  501. this.foldingStartMarker = new RegExp(
  502. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  503. );
  504. this.foldingStopMarker = new RegExp(
  505. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  506. );
  507. }
  508. };
  509. oop.inherits(FoldMode, BaseFoldMode);
  510. (function() {
  511. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  512. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  513. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  514. var line = session.getLine(row);
  515. var match = line.match(this.foldingStartMarker);
  516. if (match) {
  517. var i = match.index;
  518. if (match[1])
  519. return this.openingBracketBlock(session, match[1], row, i);
  520. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  521. if (range && !range.isMultiLine()) {
  522. if (forceMultiline) {
  523. range = this.getSectionRange(session, row);
  524. } else if (foldStyle != "all")
  525. range = null;
  526. }
  527. return range;
  528. }
  529. if (foldStyle === "markbegin")
  530. return;
  531. var match = line.match(this.foldingStopMarker);
  532. if (match) {
  533. var i = match.index + match[0].length;
  534. if (match[1])
  535. return this.closingBracketBlock(session, match[1], row, i);
  536. return session.getCommentFoldRange(row, i, -1);
  537. }
  538. };
  539. this.getSectionRange = function(session, row) {
  540. var line = session.getLine(row);
  541. var startIndent = line.search(/\S/);
  542. var startRow = row;
  543. var startColumn = line.length;
  544. row = row + 1;
  545. var endRow = row;
  546. var maxRow = session.getLength();
  547. while (++row < maxRow) {
  548. line = session.getLine(row);
  549. var indent = line.search(/\S/);
  550. if (indent === -1)
  551. continue;
  552. if (startIndent > indent)
  553. break;
  554. var subRange = this.getFoldWidgetRange(session, "all", row);
  555. if (subRange) {
  556. if (subRange.start.row <= startRow) {
  557. break;
  558. } else if (subRange.isMultiLine()) {
  559. row = subRange.end.row;
  560. } else if (startIndent == indent) {
  561. break;
  562. }
  563. }
  564. endRow = row;
  565. }
  566. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  567. };
  568. }).call(FoldMode.prototype);
  569. });
  570. 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/behaviour/cstyle","ace/mode/folding/cstyle"], function(require, exports, module) {
  571. var oop = require("../lib/oop");
  572. var TextMode = require("./text").Mode;
  573. var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
  574. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  575. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  576. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  577. var Mode = function() {
  578. this.HighlightRules = GolangHighlightRules;
  579. this.$outdent = new MatchingBraceOutdent();
  580. this.foldingRules = new CStyleFoldMode();
  581. };
  582. oop.inherits(Mode, TextMode);
  583. (function() {
  584. this.lineCommentStart = "//";
  585. this.blockComment = {start: "/*", end: "*/"};
  586. this.getNextLineIndent = function(state, line, tab) {
  587. var indent = this.$getIndent(line);
  588. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  589. var tokens = tokenizedLine.tokens;
  590. var endState = tokenizedLine.state;
  591. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  592. return indent;
  593. }
  594. if (state == "start") {
  595. var match = line.match(/^.*[\{\(\[]\s*$/);
  596. if (match) {
  597. indent += tab;
  598. }
  599. }
  600. return indent;
  601. };//end getNextLineIndent
  602. this.checkOutdent = function(state, line, input) {
  603. return this.$outdent.checkOutdent(line, input);
  604. };
  605. this.autoOutdent = function(state, doc, row) {
  606. this.$outdent.autoOutdent(doc, row);
  607. };
  608. this.$id = "ace/mode/golang";
  609. }).call(Mode.prototype);
  610. exports.Mode = Mode;
  611. });