mode-yaml.js 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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. 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_]+)?)/
  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. ],
  77. "mlString" : [
  78. {
  79. token : "indent",
  80. regex : /^\s*$/
  81. }, {
  82. token : "indent",
  83. regex : /^\s*/,
  84. onMatch: function(val, state, stack) {
  85. var curIndent = stack[1];
  86. if (curIndent >= val.length) {
  87. this.next = "start";
  88. stack.splice(0);
  89. }
  90. else {
  91. this.next = "mlString";
  92. }
  93. return this.token;
  94. },
  95. next : "mlString"
  96. }, {
  97. token : "string",
  98. regex : '.+'
  99. }
  100. ]};
  101. this.normalizeRules();
  102. };
  103. oop.inherits(YamlHighlightRules, TextHighlightRules);
  104. exports.YamlHighlightRules = YamlHighlightRules;
  105. });
  106. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  107. "use strict";
  108. var Range = require("../range").Range;
  109. var MatchingBraceOutdent = function() {};
  110. (function() {
  111. this.checkOutdent = function(line, input) {
  112. if (! /^\s+$/.test(line))
  113. return false;
  114. return /^\s*\}/.test(input);
  115. };
  116. this.autoOutdent = function(doc, row) {
  117. var line = doc.getLine(row);
  118. var match = line.match(/^(\s*\})/);
  119. if (!match) return 0;
  120. var column = match[1].length;
  121. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  122. if (!openBracePos || openBracePos.row == row) return 0;
  123. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  124. doc.replace(new Range(row, 0, row, column-1), indent);
  125. };
  126. this.$getIndent = function(line) {
  127. return line.match(/^\s*/)[0];
  128. };
  129. }).call(MatchingBraceOutdent.prototype);
  130. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  131. });
  132. ace.define("ace/mode/folding/coffee",["require","exports","module","ace/lib/oop","ace/mode/folding/fold_mode","ace/range"], function(require, exports, module) {
  133. "use strict";
  134. var oop = require("../../lib/oop");
  135. var BaseFoldMode = require("./fold_mode").FoldMode;
  136. var Range = require("../../range").Range;
  137. var FoldMode = exports.FoldMode = function() {};
  138. oop.inherits(FoldMode, BaseFoldMode);
  139. (function() {
  140. this.getFoldWidgetRange = function(session, foldStyle, row) {
  141. var range = this.indentationBlock(session, row);
  142. if (range)
  143. return range;
  144. var re = /\S/;
  145. var line = session.getLine(row);
  146. var startLevel = line.search(re);
  147. if (startLevel == -1 || line[startLevel] != "#")
  148. return;
  149. var startColumn = line.length;
  150. var maxRow = session.getLength();
  151. var startRow = row;
  152. var endRow = row;
  153. while (++row < maxRow) {
  154. line = session.getLine(row);
  155. var level = line.search(re);
  156. if (level == -1)
  157. continue;
  158. if (line[level] != "#")
  159. break;
  160. endRow = row;
  161. }
  162. if (endRow > startRow) {
  163. var endColumn = session.getLine(endRow).length;
  164. return new Range(startRow, startColumn, endRow, endColumn);
  165. }
  166. };
  167. this.getFoldWidget = function(session, foldStyle, row) {
  168. var line = session.getLine(row);
  169. var indent = line.search(/\S/);
  170. var next = session.getLine(row + 1);
  171. var prev = session.getLine(row - 1);
  172. var prevIndent = prev.search(/\S/);
  173. var nextIndent = next.search(/\S/);
  174. if (indent == -1) {
  175. session.foldWidgets[row - 1] = prevIndent!= -1 && prevIndent < nextIndent ? "start" : "";
  176. return "";
  177. }
  178. if (prevIndent == -1) {
  179. if (indent == nextIndent && line[indent] == "#" && next[indent] == "#") {
  180. session.foldWidgets[row - 1] = "";
  181. session.foldWidgets[row + 1] = "";
  182. return "start";
  183. }
  184. } else if (prevIndent == indent && line[indent] == "#" && prev[indent] == "#") {
  185. if (session.getLine(row - 2).search(/\S/) == -1) {
  186. session.foldWidgets[row - 1] = "start";
  187. session.foldWidgets[row + 1] = "";
  188. return "";
  189. }
  190. }
  191. if (prevIndent!= -1 && prevIndent < indent)
  192. session.foldWidgets[row - 1] = "start";
  193. else
  194. session.foldWidgets[row - 1] = "";
  195. if (indent < nextIndent)
  196. return "start";
  197. else
  198. return "";
  199. };
  200. }).call(FoldMode.prototype);
  201. });
  202. 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) {
  203. "use strict";
  204. var oop = require("../lib/oop");
  205. var TextMode = require("./text").Mode;
  206. var YamlHighlightRules = require("./yaml_highlight_rules").YamlHighlightRules;
  207. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  208. var FoldMode = require("./folding/coffee").FoldMode;
  209. var Mode = function() {
  210. this.HighlightRules = YamlHighlightRules;
  211. this.$outdent = new MatchingBraceOutdent();
  212. this.foldingRules = new FoldMode();
  213. this.$behaviour = this.$defaultBehaviour;
  214. };
  215. oop.inherits(Mode, TextMode);
  216. (function() {
  217. this.lineCommentStart = "#";
  218. this.getNextLineIndent = function(state, line, tab) {
  219. var indent = this.$getIndent(line);
  220. if (state == "start") {
  221. var match = line.match(/^.*[\{\(\[]\s*$/);
  222. if (match) {
  223. indent += tab;
  224. }
  225. }
  226. return indent;
  227. };
  228. this.checkOutdent = function(state, line, input) {
  229. return this.$outdent.checkOutdent(line, input);
  230. };
  231. this.autoOutdent = function(state, doc, row) {
  232. this.$outdent.autoOutdent(doc, row);
  233. };
  234. this.$id = "ace/mode/yaml";
  235. }).call(Mode.prototype);
  236. exports.Mode = Mode;
  237. });