mode-alda.js 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. ace.define("ace/mode/alda_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 AldaHighlightRules = function() {
  6. this.$rules = {
  7. pitch: [{
  8. token: "variable.parameter.operator.pitch.alda",
  9. regex: /(?:[+\-]+|\=)/
  10. }, {
  11. token: "",
  12. regex: "",
  13. next: "timing"
  14. }],
  15. timing: [{
  16. token: "string.quoted.operator.timing.alda",
  17. regex: /\d+(?:s|ms)?/
  18. }, {
  19. token: "",
  20. regex: "",
  21. next: "start"
  22. }],
  23. start: [{
  24. token: [
  25. "constant.language.instrument.alda",
  26. "constant.language.instrument.alda",
  27. "meta.part.call.alda",
  28. "storage.type.nickname.alda",
  29. "meta.part.call.alda"
  30. ],
  31. regex: /^([a-zA-Z]{2}[\w\-+\'()]*)((?:\s*\/\s*[a-zA-Z]{2}[\w\-+\'()]*)*)(?:(\s*)(\"[a-zA-Z]{2}[\w\-+\'()]*\"))?(\s*:)/
  32. }, {
  33. token: [
  34. "text",
  35. "entity.other.inherited-class.voice.alda",
  36. "text"
  37. ],
  38. regex: /^(\s*)(V\d+)(:)/
  39. }, {
  40. token: "comment.line.number-sign.alda",
  41. regex: /#.*$/
  42. }, {
  43. token: "entity.name.function.pipe.measure.alda",
  44. regex: /\|/
  45. }, {
  46. token: "comment.block.inline.alda",
  47. regex: /\(comment\b/,
  48. push: [{
  49. token: "comment.block.inline.alda",
  50. regex: /\)/,
  51. next: "pop"
  52. }, {
  53. defaultToken: "comment.block.inline.alda"
  54. }]
  55. }, {
  56. token: "entity.name.function.marker.alda",
  57. regex: /%[a-zA-Z]{2}[\w\-+\'()]*/
  58. }, {
  59. token: "entity.name.function.at-marker.alda",
  60. regex: /@[a-zA-Z]{2}[\w\-+\'()]*/
  61. }, {
  62. token: "keyword.operator.octave-change.alda",
  63. regex: /\bo\d+\b/
  64. }, {
  65. token: "keyword.operator.octave-shift.alda",
  66. regex: /[><]/
  67. }, {
  68. token: "keyword.operator.repeat.alda",
  69. regex: /\*\s*\d+/
  70. }, {
  71. token: "string.quoted.operator.timing.alda",
  72. regex: /[.]|r\d*(?:s|ms)?/
  73. },{
  74. token: "text",
  75. regex: /([cdefgab])/,
  76. next: "pitch"
  77. }, {
  78. token: "string.quoted.operator.timing.alda",
  79. regex: /~/,
  80. next: "timing"
  81. }, {
  82. token: "punctuation.section.embedded.cram.alda",
  83. regex: /\}/,
  84. next: "timing"
  85. }, {
  86. token: "constant.numeric.subchord.alda",
  87. regex: /\//
  88. }, {
  89. todo: {
  90. token: "punctuation.section.embedded.cram.alda",
  91. regex: /\{/,
  92. push: [{
  93. token: "punctuation.section.embedded.cram.alda",
  94. regex: /\}/,
  95. next: "pop"
  96. }, {
  97. include: "$self"
  98. }]
  99. }
  100. }, {
  101. todo: {
  102. token: "keyword.control.sequence.alda",
  103. regex: /\[/,
  104. push: [{
  105. token: "keyword.control.sequence.alda",
  106. regex: /\]/,
  107. next: "pop"
  108. }, {
  109. include: "$self"
  110. }]
  111. }
  112. }, {
  113. token: "meta.inline.clojure.alda",
  114. regex: /\(/,
  115. push: [{
  116. token: "meta.inline.clojure.alda",
  117. regex: /\)/,
  118. next: "pop"
  119. }, {
  120. include: "source.clojure"
  121. }, {
  122. defaultToken: "meta.inline.clojure.alda"
  123. }]
  124. }]
  125. };
  126. this.normalizeRules();
  127. };
  128. AldaHighlightRules.metaData = {
  129. scopeName: "source.alda",
  130. fileTypes: ["alda"],
  131. name: "Alda"
  132. };
  133. oop.inherits(AldaHighlightRules, TextHighlightRules);
  134. exports.AldaHighlightRules = AldaHighlightRules;
  135. });
  136. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  137. "use strict";
  138. var oop = require("../../lib/oop");
  139. var Range = require("../../range").Range;
  140. var BaseFoldMode = require("./fold_mode").FoldMode;
  141. var FoldMode = exports.FoldMode = function(commentRegex) {
  142. if (commentRegex) {
  143. this.foldingStartMarker = new RegExp(
  144. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  145. );
  146. this.foldingStopMarker = new RegExp(
  147. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  148. );
  149. }
  150. };
  151. oop.inherits(FoldMode, BaseFoldMode);
  152. (function() {
  153. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  154. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  155. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  156. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  157. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  158. this._getFoldWidgetBase = this.getFoldWidget;
  159. this.getFoldWidget = function(session, foldStyle, row) {
  160. var line = session.getLine(row);
  161. if (this.singleLineBlockCommentRe.test(line)) {
  162. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  163. return "";
  164. }
  165. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  166. if (!fw && this.startRegionRe.test(line))
  167. return "start"; // lineCommentRegionStart
  168. return fw;
  169. };
  170. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  171. var line = session.getLine(row);
  172. if (this.startRegionRe.test(line))
  173. return this.getCommentRegionBlock(session, line, row);
  174. var match = line.match(this.foldingStartMarker);
  175. if (match) {
  176. var i = match.index;
  177. if (match[1])
  178. return this.openingBracketBlock(session, match[1], row, i);
  179. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  180. if (range && !range.isMultiLine()) {
  181. if (forceMultiline) {
  182. range = this.getSectionRange(session, row);
  183. } else if (foldStyle != "all")
  184. range = null;
  185. }
  186. return range;
  187. }
  188. if (foldStyle === "markbegin")
  189. return;
  190. var match = line.match(this.foldingStopMarker);
  191. if (match) {
  192. var i = match.index + match[0].length;
  193. if (match[1])
  194. return this.closingBracketBlock(session, match[1], row, i);
  195. return session.getCommentFoldRange(row, i, -1);
  196. }
  197. };
  198. this.getSectionRange = function(session, row) {
  199. var line = session.getLine(row);
  200. var startIndent = line.search(/\S/);
  201. var startRow = row;
  202. var startColumn = line.length;
  203. row = row + 1;
  204. var endRow = row;
  205. var maxRow = session.getLength();
  206. while (++row < maxRow) {
  207. line = session.getLine(row);
  208. var indent = line.search(/\S/);
  209. if (indent === -1)
  210. continue;
  211. if (startIndent > indent)
  212. break;
  213. var subRange = this.getFoldWidgetRange(session, "all", row);
  214. if (subRange) {
  215. if (subRange.start.row <= startRow) {
  216. break;
  217. } else if (subRange.isMultiLine()) {
  218. row = subRange.end.row;
  219. } else if (startIndent == indent) {
  220. break;
  221. }
  222. }
  223. endRow = row;
  224. }
  225. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  226. };
  227. this.getCommentRegionBlock = function(session, line, row) {
  228. var startColumn = line.search(/\s*$/);
  229. var maxRow = session.getLength();
  230. var startRow = row;
  231. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  232. var depth = 1;
  233. while (++row < maxRow) {
  234. line = session.getLine(row);
  235. var m = re.exec(line);
  236. if (!m) continue;
  237. if (m[1]) depth--;
  238. else depth++;
  239. if (!depth) break;
  240. }
  241. var endRow = row;
  242. if (endRow > startRow) {
  243. return new Range(startRow, startColumn, endRow, line.length);
  244. }
  245. };
  246. }).call(FoldMode.prototype);
  247. });
  248. ace.define("ace/mode/alda",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/alda_highlight_rules","ace/mode/folding/cstyle"], function(require, exports, module) {
  249. "use strict";
  250. var oop = require("../lib/oop");
  251. var TextMode = require("./text").Mode;
  252. var AldaHighlightRules = require("./alda_highlight_rules").AldaHighlightRules;
  253. var FoldMode = require("./folding/cstyle").FoldMode;
  254. var Mode = function() {
  255. this.HighlightRules = AldaHighlightRules;
  256. this.foldingRules = new FoldMode();
  257. };
  258. oop.inherits(Mode, TextMode);
  259. (function() {
  260. this.$id = "ace/mode/alda";
  261. }).call(Mode.prototype);
  262. exports.Mode = Mode;
  263. }); (function() {
  264. ace.require(["ace/mode/alda"], function(m) {
  265. if (typeof module == "object" && typeof exports == "object" && module) {
  266. module.exports = m;
  267. }
  268. });
  269. })();