mode-yaml.js 7.7 KB

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