main
js 82 lines 2.46 KB
Raw
1
2 "use strict";
3
4 var oop = require("../lib/oop");
5 var TextMode = require("./text").Mode;
6 var JavaScriptHighlightRules = require("./javascript_highlight_rules").JavaScriptHighlightRules;
7 var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
8 var WorkerClient = require("../worker/worker_client").WorkerClient;
9 var JavaScriptBehaviour = require("./behaviour/javascript").JavaScriptBehaviour;
10 var JavaScriptFoldMode = require("./folding/javascript").FoldMode;
11
12 var Mode = function() {
13 this.HighlightRules = JavaScriptHighlightRules;
14
15 this.$outdent = new MatchingBraceOutdent();
16 this.$behaviour = new JavaScriptBehaviour();
17 this.foldingRules = new JavaScriptFoldMode();
18 };
19 oop.inherits(Mode, TextMode);
20
21 (function() {
22
23 this.lineCommentStart = "//";
24 this.blockComment = {start: "/*", end: "*/"};
25 this.$quotes = {'"': '"', "'": "'", "`": "`"};
26 this.$pairQuotesAfter = {
27 "`": /\w/
28 };
29
30 this.getNextLineIndent = function(state, line, tab) {
31 var indent = this.$getIndent(line);
32
33 var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
34 var tokens = tokenizedLine.tokens;
35 var endState = tokenizedLine.state;
36
37 if (tokens.length && tokens[tokens.length-1].type == "comment") {
38 return indent;
39 }
40
41 if (state == "start" || state == "no_regex") {
42 var match = line.match(/^.*(?:\bcase\b.*:|[\{\(\[])\s*$/);
43 if (match) {
44 indent += tab;
45 }
46 } else if (state == "doc-start") {
47 if (endState == "start" || endState == "no_regex") {
48 return "";
49 }
50 }
51
52 return indent;
53 };
54
55 this.checkOutdent = function(state, line, input) {
56 return this.$outdent.checkOutdent(line, input);
57 };
58
59 this.autoOutdent = function(state, doc, row) {
60 this.$outdent.autoOutdent(doc, row);
61 };
62
63 this.createWorker = function(session) {
64 var worker = new WorkerClient(["ace"], "ace/mode/javascript_worker", "JavaScriptWorker");
65 worker.attachToDocument(session.getDocument());
66
67 worker.on("annotate", function(results) {
68 session.setAnnotations(results.data);
69 });
70
71 worker.on("terminate", function() {
72 session.clearAnnotations();
73 });
74
75 return worker;
76 };
77
78 this.$id = "ace/mode/javascript";
79 this.snippetFileId = "ace/snippets/javascript";
80 }).call(Mode.prototype);
81
82 exports.Mode = Mode;