mode-yaml.js 8.9 KB

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