/lenasys/trunk

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/lenasys/trunk

« back to all changes in this revision

Viewing changes to js/ace/mode-dot.js

  • Committer: Gustav Hatvigsson
  • Date: 2013-05-31 06:15:46 UTC
  • mfrom: (90.1.20 lenasys2)
  • Revision ID: gustav.hartvigsson@gmail.com-20130531061546-vj8z28sq375kvghq
Merged Jonsson:s changes:
Fixed the layout on cms index so the arrows and dots marks expanded objects.
Fixed so the course content is sorted by course occasion and not by name

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
define('ace/mode/dot', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/matching_brace_outdent', 'ace/mode/dot_highlight_rules', 'ace/mode/folding/cstyle'], function(require, exports, module) {
 
2
 
 
3
 
 
4
var oop = require("../lib/oop");
 
5
var TextMode = require("./text").Mode;
 
6
var Tokenizer = require("../tokenizer").Tokenizer;
 
7
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
 
8
var DotHighlightRules = require("./dot_highlight_rules").DotHighlightRules;
 
9
var DotFoldMode = require("./folding/cstyle").FoldMode;
 
10
 
 
11
var Mode = function() {
 
12
    var highlighter = new DotHighlightRules();
 
13
    this.$outdent = new MatchingBraceOutdent();
 
14
    this.foldingRules = new DotFoldMode();
 
15
    this.$tokenizer = new Tokenizer(highlighter.getRules());
 
16
};
 
17
oop.inherits(Mode, TextMode);
 
18
 
 
19
(function() {
 
20
 
 
21
    this.lineCommentStart = ["//", "#"];
 
22
    this.blockComment = {start: "/*", end: "*/"};
 
23
 
 
24
    this.getNextLineIndent = function(state, line, tab) {
 
25
        var indent = this.$getIndent(line);
 
26
 
 
27
        var tokenizedLine = this.$tokenizer.getLineTokens(line, state);
 
28
        var tokens = tokenizedLine.tokens;
 
29
        var endState = tokenizedLine.state;
 
30
 
 
31
        if (tokens.length && tokens[tokens.length-1].type == "comment") {
 
32
            return indent;
 
33
        }
 
34
 
 
35
        if (state == "start") {
 
36
            var match = line.match(/^.*(?:\bcase\b.*\:|[\{\(\[])\s*$/);
 
37
            if (match) {
 
38
                indent += tab;
 
39
            }
 
40
        }
 
41
 
 
42
        return indent;
 
43
    };
 
44
 
 
45
    this.checkOutdent = function(state, line, input) {
 
46
        return this.$outdent.checkOutdent(line, input);
 
47
    };
 
48
 
 
49
    this.autoOutdent = function(state, doc, row) {
 
50
        this.$outdent.autoOutdent(doc, row);
 
51
    };
 
52
 
 
53
}).call(Mode.prototype);
 
54
 
 
55
exports.Mode = Mode;
 
56
});
 
57
 
 
58
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
 
59
 
 
60
 
 
61
var Range = require("../range").Range;
 
62
 
 
63
var MatchingBraceOutdent = function() {};
 
64
 
 
65
(function() {
 
66
 
 
67
    this.checkOutdent = function(line, input) {
 
68
        if (! /^\s+$/.test(line))
 
69
            return false;
 
70
 
 
71
        return /^\s*\}/.test(input);
 
72
    };
 
73
 
 
74
    this.autoOutdent = function(doc, row) {
 
75
        var line = doc.getLine(row);
 
76
        var match = line.match(/^(\s*\})/);
 
77
 
 
78
        if (!match) return 0;
 
79
 
 
80
        var column = match[1].length;
 
81
        var openBracePos = doc.findMatchingBracket({row: row, column: column});
 
82
 
 
83
        if (!openBracePos || openBracePos.row == row) return 0;
 
84
 
 
85
        var indent = this.$getIndent(doc.getLine(openBracePos.row));
 
86
        doc.replace(new Range(row, 0, row, column-1), indent);
 
87
    };
 
88
 
 
89
    this.$getIndent = function(line) {
 
90
        return line.match(/^\s*/)[0];
 
91
    };
 
92
 
 
93
}).call(MatchingBraceOutdent.prototype);
 
94
 
 
95
exports.MatchingBraceOutdent = MatchingBraceOutdent;
 
96
});
 
97
define('ace/mode/dot_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/lib/lang', 'ace/mode/text_highlight_rules', 'ace/mode/doc_comment_highlight_rules'], function(require, exports, module) {
 
98
 
 
99
 
 
100
var oop = require("../lib/oop");
 
101
var lang = require("../lib/lang");
 
102
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
103
var DocCommentHighlightRules = require("./doc_comment_highlight_rules").DocCommentHighlightRules;
 
104
 
 
105
var DotHighlightRules = function() {
 
106
 
 
107
   var keywords = lang.arrayToMap(
 
108
        ("strict|node|edge|graph|digraph|subgraph").split("|")
 
109
   );
 
110
 
 
111
   var attributes = lang.arrayToMap(
 
112
        ("damping|k|url|area|arrowhead|arrowsize|arrowtail|aspect|bb|bgcolor|center|charset|clusterrank|color|colorscheme|comment|compound|concentrate|constraint|decorate|defaultdist|dim|dimen|dir|diredgeconstraints|distortion|dpi|edgeurl|edgehref|edgetarget|edgetooltip|epsilon|esep|fillcolor|fixedsize|fontcolor|fontname|fontnames|fontpath|fontsize|forcelabels|gradientangle|group|headurl|head_lp|headclip|headhref|headlabel|headport|headtarget|headtooltip|height|href|id|image|imagepath|imagescale|label|labelurl|label_scheme|labelangle|labeldistance|labelfloat|labelfontcolor|labelfontname|labelfontsize|labelhref|labeljust|labelloc|labeltarget|labeltooltip|landscape|layer|layerlistsep|layers|layerselect|layersep|layout|len|levels|levelsgap|lhead|lheight|lp|ltail|lwidth|margin|maxiter|mclimit|mindist|minlen|mode|model|mosek|nodesep|nojustify|normalize|nslimit|nslimit1|ordering|orientation|outputorder|overlap|overlap_scaling|pack|packmode|pad|page|pagedir|pencolor|penwidth|peripheries|pin|pos|quadtree|quantum|rank|rankdir|ranksep|ratio|rects|regular|remincross|repulsiveforce|resolution|root|rotate|rotation|samehead|sametail|samplepoints|scale|searchsize|sep|shape|shapefile|showboxes|sides|size|skew|smoothing|sortv|splines|start|style|stylesheet|tailurl|tail_lp|tailclip|tailhref|taillabel|tailport|tailtarget|tailtooltip|target|tooltip|truecolor|vertices|viewport|voro_margin|weight|width|xlabel|xlp|z").split("|")
 
113
   );
 
114
 
 
115
   this.$rules = {
 
116
        "start" : [
 
117
            {
 
118
                token : "comment",
 
119
                regex : /\/\/.*$/
 
120
            }, {
 
121
                token : "comment",
 
122
                regex : /#.*$/
 
123
            }, {
 
124
                token : "comment", // multi line comment
 
125
                merge : true,
 
126
                regex : /\/\*/,
 
127
                next : "comment"
 
128
            }, {
 
129
                token : "string",
 
130
                regex : "'(?=.)",
 
131
                next  : "qstring"
 
132
            }, {
 
133
                token : "string",
 
134
                regex : '"(?=.)',
 
135
                next  : "qqstring"
 
136
            }, {
 
137
                token : "constant.numeric",
 
138
                regex : /[+\-]?\d+(?:(?:\.\d*)?(?:[eE][+\-]?\d+)?)?\b/
 
139
            }, {
 
140
                token : "keyword.operator",
 
141
                regex : /\+|=|\->/
 
142
            }, {
 
143
                token : "punctuation.operator",
 
144
                regex : /,|;/
 
145
            }, {
 
146
                token : "paren.lparen",
 
147
                regex : /[\[{]/
 
148
            }, {
 
149
                token : "paren.rparen",
 
150
                regex : /[\]}]/
 
151
            }, {
 
152
                token: "comment",
 
153
                regex: /^#!.*$/
 
154
            }, {
 
155
                token: function(value) {
 
156
                    if (keywords.hasOwnProperty(value.toLowerCase())) {
 
157
                        return "keyword";
 
158
                    }
 
159
                    else if (attributes.hasOwnProperty(value.toLowerCase())) {
 
160
                        return "variable";
 
161
                    }
 
162
                    else {
 
163
                        return "text";
 
164
                    }
 
165
                },
 
166
                regex: "\\-?[a-zA-Z_][a-zA-Z0-9_\\-]*"
 
167
           }
 
168
        ],
 
169
        "comment" : [
 
170
            {
 
171
                token : "comment", // closing comment
 
172
                regex : ".*?\\*\\/",
 
173
                merge : true,
 
174
                next : "start"
 
175
            }, {
 
176
                token : "comment", // comment spanning whole line
 
177
                merge : true,
 
178
                regex : ".+"
 
179
            }
 
180
        ],
 
181
        "qqstring" : [
 
182
            {
 
183
                token : "string",
 
184
                regex : '[^"\\\\]+',
 
185
                merge : true
 
186
            }, {
 
187
                token : "string",
 
188
                regex : "\\\\$",
 
189
                next  : "qqstring",
 
190
                merge : true
 
191
            }, {
 
192
                token : "string",
 
193
                regex : '"|$',
 
194
                next  : "start",
 
195
                merge : true
 
196
            }
 
197
        ],
 
198
        "qstring" : [
 
199
            {
 
200
                token : "string",
 
201
                regex : "[^'\\\\]+",
 
202
                merge : true
 
203
            }, {
 
204
                token : "string",
 
205
                regex : "\\\\$",
 
206
                next  : "qstring",
 
207
                merge : true
 
208
            }, {
 
209
                token : "string",
 
210
                regex : "'|$",
 
211
                next  : "start",
 
212
                merge : true
 
213
            }
 
214
        ]
 
215
   };
 
216
};
 
217
 
 
218
oop.inherits(DotHighlightRules, TextHighlightRules);
 
219
 
 
220
exports.DotHighlightRules = DotHighlightRules;
 
221
 
 
222
});
 
223
 
 
224
define('ace/mode/doc_comment_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
 
225
 
 
226
 
 
227
var oop = require("../lib/oop");
 
228
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
 
229
 
 
230
var DocCommentHighlightRules = function() {
 
231
 
 
232
    this.$rules = {
 
233
        "start" : [ {
 
234
            token : "comment.doc.tag",
 
235
            regex : "@[\\w\\d_]+" // TODO: fix email addresses
 
236
        }, {
 
237
            token : "comment.doc.tag",
 
238
            regex : "\\bTODO\\b"
 
239
        }, {
 
240
            defaultToken : "comment.doc"
 
241
        }]
 
242
    };
 
243
};
 
244
 
 
245
oop.inherits(DocCommentHighlightRules, TextHighlightRules);
 
246
 
 
247
DocCommentHighlightRules.getStartRule = function(start) {
 
248
    return {
 
249
        token : "comment.doc", // doc comment
 
250
        regex : "\\/\\*(?=\\*)",
 
251
        next  : start
 
252
    };
 
253
};
 
254
 
 
255
DocCommentHighlightRules.getEndRule = function (start) {
 
256
    return {
 
257
        token : "comment.doc", // closing comment
 
258
        regex : "\\*\\/",
 
259
        next  : start
 
260
    };
 
261
};
 
262
 
 
263
 
 
264
exports.DocCommentHighlightRules = DocCommentHighlightRules;
 
265
 
 
266
});
 
267
 
 
268
define('ace/mode/folding/cstyle', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/range', 'ace/mode/folding/fold_mode'], function(require, exports, module) {
 
269
 
 
270
 
 
271
var oop = require("../../lib/oop");
 
272
var Range = require("../../range").Range;
 
273
var BaseFoldMode = require("./fold_mode").FoldMode;
 
274
 
 
275
var FoldMode = exports.FoldMode = function(commentRegex) {
 
276
    if (commentRegex) {
 
277
        this.foldingStartMarker = new RegExp(
 
278
            this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
 
279
        );
 
280
        this.foldingStopMarker = new RegExp(
 
281
            this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
 
282
        );
 
283
    }
 
284
};
 
285
oop.inherits(FoldMode, BaseFoldMode);
 
286
 
 
287
(function() {
 
288
 
 
289
    this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
 
290
    this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
 
291
 
 
292
    this.getFoldWidgetRange = function(session, foldStyle, row) {
 
293
        var line = session.getLine(row);
 
294
        var match = line.match(this.foldingStartMarker);
 
295
        if (match) {
 
296
            var i = match.index;
 
297
 
 
298
            if (match[1])
 
299
                return this.openingBracketBlock(session, match[1], row, i);
 
300
 
 
301
            return session.getCommentFoldRange(row, i + match[0].length, 1);
 
302
        }
 
303
 
 
304
        if (foldStyle !== "markbeginend")
 
305
            return;
 
306
 
 
307
        var match = line.match(this.foldingStopMarker);
 
308
        if (match) {
 
309
            var i = match.index + match[0].length;
 
310
 
 
311
            if (match[1])
 
312
                return this.closingBracketBlock(session, match[1], row, i);
 
313
 
 
314
            return session.getCommentFoldRange(row, i, -1);
 
315
        }
 
316
    };
 
317
 
 
318
}).call(FoldMode.prototype);
 
319
 
 
320
});