1
/* ***** BEGIN LICENSE BLOCK *****
2
* Distributed under the BSD license:
4
* Copyright (c) 2010, Ajax.org B.V.
7
* Redistribution and use in source and binary forms, with or without
8
* modification, are permitted provided that the following conditions are met:
9
* * Redistributions of source code must retain the above copyright
10
* notice, this list of conditions and the following disclaimer.
11
* * Redistributions in binary form must reproduce the above copyright
12
* notice, this list of conditions and the following disclaimer in the
13
* documentation and/or other materials provided with the distribution.
14
* * Neither the name of Ajax.org B.V. nor the
15
* names of its contributors may be used to endorse or promote products
16
* derived from this software without specific prior written permission.
18
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
19
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
20
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
* DISCLAIMED. IN NO EVENT SHALL AJAX.ORG B.V. BE LIABLE FOR ANY
22
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
23
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
25
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
26
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
27
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
* ***** END LICENSE BLOCK ***** */
31
define('ace/mode/yaml', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text', 'ace/tokenizer', 'ace/mode/yaml_highlight_rules', 'ace/mode/matching_brace_outdent', 'ace/mode/folding/coffee'], function(require, exports, module) {
34
var oop = require("../lib/oop");
35
var TextMode = require("./text").Mode;
36
var Tokenizer = require("../tokenizer").Tokenizer;
37
var YamlHighlightRules = require("./yaml_highlight_rules").YamlHighlightRules;
38
var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
39
var FoldMode = require("./folding/coffee").FoldMode;
41
var Mode = function() {
42
this.$tokenizer = new Tokenizer(new YamlHighlightRules().getRules());
43
this.$outdent = new MatchingBraceOutdent();
44
this.foldingRules = new FoldMode();
46
oop.inherits(Mode, TextMode);
50
this.lineCommentStart = "#";
52
this.getNextLineIndent = function(state, line, tab) {
53
var indent = this.$getIndent(line);
55
if (state == "start") {
56
var match = line.match(/^.*[\{\(\[]\s*$/);
65
this.checkOutdent = function(state, line, input) {
66
return this.$outdent.checkOutdent(line, input);
69
this.autoOutdent = function(state, doc, row) {
70
this.$outdent.autoOutdent(doc, row);
74
}).call(Mode.prototype);
80
define('ace/mode/yaml_highlight_rules', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/text_highlight_rules'], function(require, exports, module) {
83
var oop = require("../lib/oop");
84
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
86
var YamlHighlightRules = function() {
93
token : "list.markup",
94
regex : /^(?:-{3}|\.{3})\s*(?=#|$)/
96
token : "list.markup",
97
regex : /^\s*[\-?](?:$|\s)/
102
token: "constant.language",
103
regex: "[&\\*][a-zA-Z0-9-_]+"
105
token: ["meta.tag", "keyword"],
106
regex: /^(\s*\w.*?)(\:(?:\s+|$))/
108
token: ["meta.tag", "keyword"],
109
regex: /(\w+?)(\s*\:(?:\s+|$))/
111
token : "keyword.operator",
112
regex : "<<\\w*:\\w*"
114
token : "keyword.operator",
115
regex : "-\\s*(?=[{])"
117
token : "string", // single line
118
regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
120
token : "string", // multi line string start
121
regex : '[\\|>]\\w*',
124
token : "string", // single quoted string
125
regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
127
token : "constant.numeric", // float
128
regex : /[+\-]?[\d_]+(?:(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)?\b/
130
token : "constant.numeric", // other number
131
regex : /[+\-]?\.inf\b|NaN\b|0x[\dA-Fa-f_]+|0b[10_]+/
133
token : "constant.language.boolean",
134
regex : "(?:true|false|TRUE|FALSE|True|False|yes|no)\\b"
136
token : "invalid.illegal", // comments are not allowed
139
token : "paren.lparen",
142
token : "paren.rparen",
149
regex : '(?=(?:(?:\\\\.)|(?:[^:]))*?:)',
159
oop.inherits(YamlHighlightRules, TextHighlightRules);
161
exports.YamlHighlightRules = YamlHighlightRules;
164
define('ace/mode/matching_brace_outdent', ['require', 'exports', 'module' , 'ace/range'], function(require, exports, module) {
167
var Range = require("../range").Range;
169
var MatchingBraceOutdent = function() {};
173
this.checkOutdent = function(line, input) {
174
if (! /^\s+$/.test(line))
177
return /^\s*\}/.test(input);
180
this.autoOutdent = function(doc, row) {
181
var line = doc.getLine(row);
182
var match = line.match(/^(\s*\})/);
184
if (!match) return 0;
186
var column = match[1].length;
187
var openBracePos = doc.findMatchingBracket({row: row, column: column});
189
if (!openBracePos || openBracePos.row == row) return 0;
191
var indent = this.$getIndent(doc.getLine(openBracePos.row));
192
doc.replace(new Range(row, 0, row, column-1), indent);
195
this.$getIndent = function(line) {
196
return line.match(/^\s*/)[0];
199
}).call(MatchingBraceOutdent.prototype);
201
exports.MatchingBraceOutdent = MatchingBraceOutdent;
204
define('ace/mode/folding/coffee', ['require', 'exports', 'module' , 'ace/lib/oop', 'ace/mode/folding/fold_mode', 'ace/range'], function(require, exports, module) {
207
var oop = require("../../lib/oop");
208
var BaseFoldMode = require("./fold_mode").FoldMode;
209
var Range = require("../../range").Range;
211
var FoldMode = exports.FoldMode = function() {};
212
oop.inherits(FoldMode, BaseFoldMode);
216
this.getFoldWidgetRange = function(session, foldStyle, row) {
217
var range = this.indentationBlock(session, row);
222
var line = session.getLine(row);
223
var startLevel = line.search(re);
224
if (startLevel == -1 || line[startLevel] != "#")
227
var startColumn = line.length;
228
var maxRow = session.getLength();
232
while (++row < maxRow) {
233
line = session.getLine(row);
234
var level = line.search(re);
239
if (line[level] != "#")
245
if (endRow > startRow) {
246
var endColumn = session.getLine(endRow).length;
247
return new Range(startRow, startColumn, endRow, endColumn);
250
this.getFoldWidget = function(session, foldStyle, row) {
251
var line = session.getLine(row);
252
var indent = line.search(/\S/);
253
var next = session.getLine(row + 1);
254
var prev = session.getLine(row - 1);
255
var prevIndent = prev.search(/\S/);
256
var nextIndent = next.search(/\S/);
259
session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
262
if (prevIndent == -1) {
263
if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
264
session.foldWidgets[row - 1] = "";
265
session.foldWidgets[row + 1] = "";
268
} else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
269
if (session.getLine(row - 2).search(/\S/) == -1) {
270
session.foldWidgets[row - 1] = "start";
271
session.foldWidgets[row + 1] = "";
276
if (prevIndent!= -1 && prevIndent < indent)
277
session.foldWidgets[row - 1] = "start";
279
session.foldWidgets[row - 1] = "";
281
if (indent < nextIndent)
287
}).call(FoldMode.prototype);