mode-yaml.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330
  1. ace.define("ace/mode/yaml_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module) {
  2. "use strict";
  3. var oop = require("../lib/oop");
  4. var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
  5. var YamlHighlightRules = function() {
  6. this.$rules = {
  7. "start" : [
  8. {
  9. token : "comment",
  10. regex : "#.*$"
  11. }, {
  12. token : "list.markup",
  13. regex : /^(?:-{3}|\.{3})\s*(?=#|$)/
  14. }, {
  15. token : "list.markup",
  16. regex : /^\s*[\-?](?:$|\s)/
  17. }, {
  18. token: "constant",
  19. regex: "!![\\w//]+"
  20. }, {
  21. token: "constant.language",
  22. regex: "[&\\*][a-zA-Z0-9-_]+"
  23. }, {
  24. token: ["meta.tag", "keyword"],
  25. regex: /^(\s*\w.*?)(:(?=\s|$))/
  26. },{
  27. token: ["meta.tag", "keyword"],
  28. regex: /(\w+?)(\s*:(?=\s|$))/
  29. }, {
  30. token : "keyword.operator",
  31. regex : "<<\\w*:\\w*"
  32. }, {
  33. token : "keyword.operator",
  34. regex : "-\\s*(?=[{])"
  35. }, {
  36. token : "string", // single line
  37. regex : '["](?:(?:\\\\.)|(?:[^"\\\\]))*?["]'
  38. }, {
  39. token : "string", // multi line string start
  40. regex : /[|>][-+\d]*(?:$|\s+(?:$|#))/,
  41. onMatch: function(val, state, stack, line) {
  42. line = line.replace(/ #.*/, "");
  43. var indent = /^ *((:\s*)?-(\s*[^|>])?)?/.exec(line)[0]
  44. .replace(/\S\s*$/, "").length;
  45. var indentationIndicator = parseInt(/\d+[\s+-]*$/.exec(line));
  46. if (indentationIndicator) {
  47. indent += indentationIndicator - 1;
  48. this.next = "mlString";
  49. } else {
  50. this.next = "mlStringPre";
  51. }
  52. if (!stack.length) {
  53. stack.push(this.next);
  54. stack.push(indent);
  55. } else {
  56. stack[0] = this.next;
  57. stack[1] = indent;
  58. }
  59. return this.token;
  60. },
  61. next : "mlString"
  62. }, {
  63. token : "string", // single quoted string
  64. regex : "['](?:(?:\\\\.)|(?:[^'\\\\]))*?[']"
  65. }, {
  66. token : "constant.numeric", // float
  67. regex : /(\b|[+\-\.])[\d_]+(?:(?:\.[\d_]*)?(?:[eE][+\-]?[\d_]+)?)(?=[^\d-\w]|$)/
  68. }, {
  69. token : "constant.numeric", // other number
  70. regex : /[+\-]?\.inf\b|NaN\b|0x[\dA-Fa-f_]+|0b[10_]+/
  71. }, {
  72. token : "constant.language.boolean",
  73. regex : "\\b(?:true|false|TRUE|FALSE|True|False|yes|no)\\b"
  74. }, {
  75. token : "paren.lparen",
  76. regex : "[[({]"
  77. }, {
  78. token : "paren.rparen",
  79. regex : "[\\])}]"
  80. }, {
  81. token : "text",
  82. regex : /[^\s,:\[\]\{\}]+/
  83. }
  84. ],
  85. "mlStringPre" : [
  86. {
  87. token : "indent",
  88. regex : /^ *$/
  89. }, {
  90. token : "indent",
  91. regex : /^ */,
  92. onMatch: function(val, state, stack) {
  93. var curIndent = stack[1];
  94. if (curIndent >= val.length) {
  95. this.next = "start";
  96. stack.shift();
  97. stack.shift();
  98. }
  99. else {
  100. stack[1] = val.length - 1;
  101. this.next = stack[0] = "mlString";
  102. }
  103. return this.token;
  104. },
  105. next : "mlString"
  106. }, {
  107. defaultToken : "string"
  108. }
  109. ],
  110. "mlString" : [
  111. {
  112. token : "indent",
  113. regex : /^ *$/
  114. }, {
  115. token : "indent",
  116. regex : /^ */,
  117. onMatch: function(val, state, stack) {
  118. var curIndent = stack[1];
  119. if (curIndent >= val.length) {
  120. this.next = "start";
  121. stack.splice(0);
  122. }
  123. else {
  124. this.next = "mlString";
  125. }
  126. return this.token;
  127. },
  128. next : "mlString"
  129. }, {
  130. token : "string",
  131. regex : '.+'
  132. }
  133. ]};
  134. this.normalizeRules();
  135. };
  136. oop.inherits(YamlHighlightRules, TextHighlightRules);
  137. exports.YamlHighlightRules = YamlHighlightRules;
  138. });
  139. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  140. "use strict";
  141. var Range = require("../range").Range;
  142. var MatchingBraceOutdent = function() {};
  143. (function() {
  144. this.checkOutdent = function(line, input) {
  145. if (! /^\s+$/.test(line))
  146. return false;
  147. return /^\s*\}/.test(input);
  148. };
  149. this.autoOutdent = function(doc, row) {
  150. var line = doc.getLine(row);
  151. var match = line.match(/^(\s*\})/);
  152. if (!match) return 0;
  153. var column = match[1].length;
  154. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  155. if (!openBracePos || openBracePos.row == row) return 0;
  156. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  157. doc.replace(new Range(row, 0, row, column-1), indent);
  158. };
  159. this.$getIndent = function(line) {
  160. return line.match(/^\s*/)[0];
  161. };
  162. }).call(MatchingBraceOutdent.prototype);
  163. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  164. });
  165. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  166. "use strict";
  167. var oop = require("../../lib/oop");
  168. var BaseFoldMode = require("./fold_mode").FoldMode;
  169. var Range = require("../../range").Range;
  170. var FoldMode = exports.FoldMode = function() {};
  171. oop.inherits(FoldMode, BaseFoldMode);
  172. (function() {
  173. this.getFoldWidgetRange = function(session, foldStyle, row) {
  174. var range = this.indentationBlock(session, row);
  175. if (range)
  176. return range;
  177. var re = /\S/;
  178. var line = session.getLine(row);
  179. var startLevel = line.search(re);
  180. if (startLevel == -1 || line[startLevel] != "#")
  181. return;
  182. var startColumn = line.length;
  183. var maxRow = session.getLength();
  184. var startRow = row;
  185. var endRow = row;
  186. while (++row < maxRow) {
  187. line = session.getLine(row);
  188. var level = line.search(re);
  189. if (level == -1)
  190. continue;
  191. if (line[level] != "#")
  192. break;
  193. endRow = row;
  194. }
  195. if (endRow > startRow) {
  196. var endColumn = session.getLine(endRow).length;
  197. return new Range(startRow, startColumn, endRow, endColumn);
  198. }
  199. };
  200. this.getFoldWidget = function(session, foldStyle, row) {
  201. var line = session.getLine(row);
  202. var indent = line.search(/\S/);
  203. var next = session.getLine(row + 1);
  204. var prev = session.getLine(row - 1);
  205. var prevIndent = prev.search(/\S/);
  206. var nextIndent = next.search(/\S/);
  207. if (indent == -1) {
  208. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  209. return "";
  210. }
  211. if (prevIndent == -1) {
  212. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  213. session.foldWidgets[row - 1] = "";
  214. session.foldWidgets[row + 1] = "";
  215. return "start";
  216. }
  217. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  218. if (session.getLine(row - 2).search(/\S/) == -1) {
  219. session.foldWidgets[row - 1] = "start";
  220. session.foldWidgets[row + 1] = "";
  221. return "";
  222. }
  223. }
  224. if (prevIndent!= -1 && prevIndent < indent)
  225. session.foldWidgets[row - 1] = "start";
  226. else
  227. session.foldWidgets[row - 1] = "";
  228. if (indent < nextIndent)
  229. return "start";
  230. else
  231. return "";
  232. };
  233. }).call(FoldMode.prototype);
  234. });
  235. ace.define("ace/mode/yaml",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/yaml_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/coffee"], function(require, exports, module) {
  236. "use strict";
  237. var oop = require("../lib/oop");
  238. var TextMode = require("./text").Mode;
  239. var YamlHighlightRules = require("./yaml_highlight_rules").YamlHighlightRules;
  240. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  241. var FoldMode = require("./folding/coffee").FoldMode;
  242. var Mode = function() {
  243. this.HighlightRules = YamlHighlightRules;
  244. this.$outdent = new MatchingBraceOutdent();
  245. this.foldingRules = new FoldMode();
  246. this.$behaviour = this.$defaultBehaviour;
  247. };
  248. oop.inherits(Mode, TextMode);
  249. (function() {
  250. this.lineCommentStart = ["#"];
  251. this.getNextLineIndent = function(state, line, tab) {
  252. var indent = this.$getIndent(line);
  253. if (state == "start") {
  254. var match = line.match(/^.*[\{\(\[]\s*$/);
  255. if (match) {
  256. indent += tab;
  257. }
  258. }
  259. return indent;
  260. };
  261. this.checkOutdent = function(state, line, input) {
  262. return this.$outdent.checkOutdent(line, input);
  263. };
  264. this.autoOutdent = function(state, doc, row) {
  265. this.$outdent.autoOutdent(doc, row);
  266. };
  267. this.$id = "ace/mode/yaml";
  268. }).call(Mode.prototype);
  269. exports.Mode = Mode;
  270. }); (function() {
  271. ace.require(["ace/mode/yaml"], function(m) {
  272. if (typeof module == "object" && typeof exports == "object" && module) {
  273. module.exports = m;
  274. }
  275. });
  276. })();