Added sources files.
[nit.git] / contrib / online_ide / sources / nit_mode_for_ace / lib_ace_mode / nit.js
1 define(function(require, exports, module) {
2 "use strict";
3
4 var oop = require("../lib/oop");
5 // defines the parent mode
6 var TextMode = require("./text").Mode;
7 var Tokenizer = require("../tokenizer").Tokenizer;
8 var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
9 var CstyleBehaviour = require("./behaviour/cstyle").CstyleBehaviour;
10
11 // defines the language specific highlighters and folding rules
12 var NitHighlightRules = require("./nit_highlight_rules").NitHighlightRules;
13 //var NitFoldMode = require("./folding/nit").NitFoldMode;
14
15 var Mode = function() {
16 // set everything up
17 this.HighlightRules = NitHighlightRules;
18 this.$outdent = new MatchingBraceOutdent();
19 this.$behaviour = new CstyleBehaviour();
20 //this.foldingRules = new NitFoldMode();
21 };
22 oop.inherits(Mode, TextMode);
23
24 (function() {
25 // configure comment start/end characters
26 this.lineCommentStart = "#";
27 //this.blockComment = {start: "/*", end: "*/"};
28
29 // special logic for indent/outdent.
30 // By default ace keeps indentation of previous line
31 this.getNextLineIndent = function(state, line, tab) {
32 var indent = this.$getIndent(line);
33
34 var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
35 var tokens = tokenizedLine.tokens;
36
37 if (tokens.length && tokens[tokens.length-1].type == "comment") {
38 return indent;
39 }
40
41 if (state == "start") {
42 //var match = line.match(/^.*[\{\(\[]\s*$/);
43 var match = line.match(/(^class| class | if | else | else|do$)/);
44 if (match) {
45 indent += tab + tab;
46 }
47 }
48 return indent;
49 };
50 this.checkOutdent = function(state, line, input) {
51 return this.$outdent.checkOutdent(line, input);
52 };
53 this.autoOutdent = function(state, doc, row) {
54 this.$outdent.autoOutdent(doc, row);
55 };
56
57 // create worker for live syntax checking
58 this.createWorker = function(session) {
59 /*var worker = new WorkerClient(["ace"], "ace/mode/nit_worker", "NitWorker");
60 worker.attachToDocument(session.getDocument());
61 worker.on("errors", function(e) {
62 session.setAnnotations(e.data);
63 });
64 return worker;*/
65 return null;
66 };
67
68 this.$id = "ace/mode/nit";
69 }).call(Mode.prototype);
70
71 exports.Mode = Mode;
72 });