golang.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. define(function(require, exports, module) {
  2. var oop = require("../lib/oop");
  3. var TextMode = require("./text").Mode;
  4. var GolangHighlightRules = require("./golang_highlight_rules").GolangHighlightRules;
  5. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  6. var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
  7. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  8. var Mode = function() {
  9. this.HighlightRules = GolangHighlightRules;
  10. this.$outdent = new MatchingBraceOutdent();
  11. this.foldingRules = new CStyleFoldMode();
  12. this.$behaviour = new CstyleBehaviour();
  13. };
  14. oop.inherits(Mode, TextMode);
  15. (function() {
  16. this.lineCommentStart = "//";
  17. this.blockComment = {start: "/*", end: "*/"};
  18. this.getNextLineIndent = function(state, line, tab) {
  19. var indent = this.$getIndent(line);
  20. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  21. var tokens = tokenizedLine.tokens;
  22. var endState = tokenizedLine.state;
  23. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  24. return indent;
  25. }
  26. if (state == "start") {
  27. var match = line.match(/^.*[\{\(\[]\s*$/);
  28. if (match) {
  29. indent += tab;
  30. }
  31. }
  32. return indent;
  33. };//end getNextLineIndent
  34. this.checkOutdent = function(state, line, input) {
  35. return this.$outdent.checkOutdent(line, input);
  36. };
  37. this.autoOutdent = function(state, doc, row) {
  38. this.$outdent.autoOutdent(doc, row);
  39. };
  40. this.$id = "ace/mode/golang";
  41. }).call(Mode.prototype);
  42. exports.Mode = Mode;
  43. });