mode-abc.js 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  1. ace.define("ace/mode/abc_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 ABCHighlightRules = function () {
  6. this.$rules = {
  7. start: [
  8. {
  9. token: ['zupfnoter.information.comment.line.percentage', 'information.keyword', 'in formation.keyword.embedded'],
  10. regex: '(%%%%)(hn\\.[a-z]*)(.*)',
  11. comment: 'Instruction Comment'
  12. },
  13. {
  14. token: ['information.comment.line.percentage', 'information.keyword.embedded'],
  15. regex: '(%%)(.*)',
  16. comment: 'Instruction Comment'
  17. },
  18. {
  19. token: 'comment.line.percentage',
  20. regex: '%.*',
  21. comment: 'Comments'
  22. },
  23. {
  24. token: 'barline.keyword.operator',
  25. regex: '[\\[:]*[|:][|\\]:]*(?:\\[?[0-9]+)?|\\[[0-9]+',
  26. comment: 'Bar lines'
  27. },
  28. {
  29. token: ['information.keyword.embedded', 'information.argument.string.unquoted'],
  30. regex: '(\\[[A-Za-z]:)([^\\]]*\\])',
  31. comment: 'embedded Header lines'
  32. },
  33. {
  34. token: ['information.keyword', 'information.argument.string.unquoted'],
  35. regex: '^([A-Za-z]:)([^%\\\\]*)',
  36. comment: 'Header lines'
  37. },
  38. {
  39. token: ['text', 'entity.name.function', 'string.unquoted', 'text'],
  40. regex: '(\\[)([A-Z]:)(.*?)(\\])',
  41. comment: 'Inline fields'
  42. },
  43. {
  44. token: ['accent.constant.language', 'pitch.constant.numeric', 'duration.constant.numeric'],
  45. regex: '([\\^=_]*)([A-Ga-gz][,\']*)([0-9]*/*[><0-9]*)',
  46. comment: 'Notes'
  47. },
  48. {
  49. token: 'zupfnoter.jumptarget.string.quoted',
  50. regex: '[\\"!]\\^\\:.*?[\\"!]',
  51. comment: 'Zupfnoter jumptarget'
  52. }, {
  53. token: 'zupfnoter.goto.string.quoted',
  54. regex: '[\\"!]\\^\\@.*?[\\"!]',
  55. comment: 'Zupfnoter goto'
  56. },
  57. {
  58. token: 'zupfnoter.annotation.string.quoted',
  59. regex: '[\\"!]\\^\\!.*?[\\"!]',
  60. comment: 'Zupfnoter annoation'
  61. },
  62. {
  63. token: 'zupfnoter.annotationref.string.quoted',
  64. regex: '[\\"!]\\^\\#.*?[\\"!]',
  65. comment: 'Zupfnoter annotation reference'
  66. },
  67. {
  68. token: 'chordname.string.quoted',
  69. regex: '[\\"!]\\^.*?[\\"!]',
  70. comment: 'abc chord'
  71. },
  72. {
  73. token: 'string.quoted',
  74. regex: '[\\"!].*?[\\"!]',
  75. comment: 'abc annotation'
  76. }
  77. ]
  78. };
  79. this.normalizeRules();
  80. };
  81. ABCHighlightRules.metaData = {
  82. fileTypes: ['abc'],
  83. name: 'ABC',
  84. scopeName: 'text.abcnotation'
  85. };
  86. oop.inherits(ABCHighlightRules, TextHighlightRules);
  87. exports.ABCHighlightRules = ABCHighlightRules;
  88. });
  89. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  90. "use strict";
  91. var oop = require("../../lib/oop");
  92. var Range = require("../../range").Range;
  93. var BaseFoldMode = require("./fold_mode").FoldMode;
  94. var FoldMode = exports.FoldMode = function(commentRegex) {
  95. if (commentRegex) {
  96. this.foldingStartMarker = new RegExp(
  97. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  98. );
  99. this.foldingStopMarker = new RegExp(
  100. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  101. );
  102. }
  103. };
  104. oop.inherits(FoldMode, BaseFoldMode);
  105. (function() {
  106. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  107. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  108. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  109. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  110. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  111. this._getFoldWidgetBase = this.getFoldWidget;
  112. this.getFoldWidget = function(session, foldStyle, row) {
  113. var line = session.getLine(row);
  114. if (this.singleLineBlockCommentRe.test(line)) {
  115. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  116. return "";
  117. }
  118. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  119. if (!fw && this.startRegionRe.test(line))
  120. return "start"; // lineCommentRegionStart
  121. return fw;
  122. };
  123. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  124. var line = session.getLine(row);
  125. if (this.startRegionRe.test(line))
  126. return this.getCommentRegionBlock(session, line, row);
  127. var match = line.match(this.foldingStartMarker);
  128. if (match) {
  129. var i = match.index;
  130. if (match[1])
  131. return this.openingBracketBlock(session, match[1], row, i);
  132. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  133. if (range && !range.isMultiLine()) {
  134. if (forceMultiline) {
  135. range = this.getSectionRange(session, row);
  136. } else if (foldStyle != "all")
  137. range = null;
  138. }
  139. return range;
  140. }
  141. if (foldStyle === "markbegin")
  142. return;
  143. var match = line.match(this.foldingStopMarker);
  144. if (match) {
  145. var i = match.index + match[0].length;
  146. if (match[1])
  147. return this.closingBracketBlock(session, match[1], row, i);
  148. return session.getCommentFoldRange(row, i, -1);
  149. }
  150. };
  151. this.getSectionRange = function(session, row) {
  152. var line = session.getLine(row);
  153. var startIndent = line.search(/\S/);
  154. var startRow = row;
  155. var startColumn = line.length;
  156. row = row + 1;
  157. var endRow = row;
  158. var maxRow = session.getLength();
  159. while (++row < maxRow) {
  160. line = session.getLine(row);
  161. var indent = line.search(/\S/);
  162. if (indent === -1)
  163. continue;
  164. if (startIndent > indent)
  165. break;
  166. var subRange = this.getFoldWidgetRange(session, "all", row);
  167. if (subRange) {
  168. if (subRange.start.row <= startRow) {
  169. break;
  170. } else if (subRange.isMultiLine()) {
  171. row = subRange.end.row;
  172. } else if (startIndent == indent) {
  173. break;
  174. }
  175. }
  176. endRow = row;
  177. }
  178. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  179. };
  180. this.getCommentRegionBlock = function(session, line, row) {
  181. var startColumn = line.search(/\s*$/);
  182. var maxRow = session.getLength();
  183. var startRow = row;
  184. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  185. var depth = 1;
  186. while (++row < maxRow) {
  187. line = session.getLine(row);
  188. var m = re.exec(line);
  189. if (!m) continue;
  190. if (m[1]) depth--;
  191. else depth++;
  192. if (!depth) break;
  193. }
  194. var endRow = row;
  195. if (endRow > startRow) {
  196. return new Range(startRow, startColumn, endRow, line.length);
  197. }
  198. };
  199. }).call(FoldMode.prototype);
  200. });
  201. ace.define("ace/mode/abc",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/abc_highlight_rules","ace/mode/folding/cstyle"], function (require, exports, module) {
  202. "use strict";
  203. var oop = require("../lib/oop");
  204. var TextMode = require("./text").Mode;
  205. var ABCHighlightRules = require("./abc_highlight_rules").ABCHighlightRules;
  206. var FoldMode = require("./folding/cstyle").FoldMode;
  207. var Mode = function () {
  208. this.HighlightRules = ABCHighlightRules;
  209. this.foldingRules = new FoldMode();
  210. this.$behaviour = this.$defaultBehaviour;
  211. };
  212. oop.inherits(Mode, TextMode);
  213. (function () {
  214. this.$id = "ace/mode/abc"
  215. }).call(Mode.prototype);
  216. exports.Mode = Mode;
  217. });