mode-csound_score.js 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  1. ace.define("ace/mode/csound_preprocessor_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 CsoundPreprocessorHighlightRules = function() {
  6. this.semicolonComments = {
  7. token : "comment.line.semicolon.csound",
  8. regex : ";.*$"
  9. };
  10. this.comments = [
  11. {
  12. token : "punctuation.definition.comment.begin.csound",
  13. regex : "/\\*",
  14. push : [
  15. {
  16. token : "punctuation.definition.comment.end.csound",
  17. regex : "\\*/",
  18. next : "pop"
  19. }, {
  20. defaultToken: "comment.block.csound"
  21. }
  22. ]
  23. }, {
  24. token : "comment.line.double-slash.csound",
  25. regex : "//.*$"
  26. },
  27. this.semicolonComments
  28. ];
  29. this.macroUses = [
  30. {
  31. token : ["entity.name.function.preprocessor.csound", "punctuation.definition.macro-parameter-value-list.begin.csound"],
  32. regex : /(\$[A-Z_a-z]\w*\.?)(\()/,
  33. next : "macro parameter value list"
  34. }, {
  35. token : "entity.name.function.preprocessor.csound",
  36. regex : /\$[A-Z_a-z]\w*(?:\.|\b)/
  37. }
  38. ];
  39. this.numbers = [
  40. {
  41. token : "constant.numeric.float.csound",
  42. regex : /(?:\d+[Ee][+-]?\d+)|(?:\d+\.\d*|\d*\.\d+)(?:[Ee][+-]?\d+)?/
  43. }, {
  44. token : ["storage.type.number.csound", "constant.numeric.integer.hexadecimal.csound"],
  45. regex : /(0[Xx])([0-9A-Fa-f]+)/
  46. }, {
  47. token : "constant.numeric.integer.decimal.csound",
  48. regex : /\d+/
  49. }
  50. ];
  51. this.bracedStringContents = [
  52. {
  53. token : "constant.character.escape.csound",
  54. regex : /\\(?:[\\abnrt"]|[0-7]{1,3})/
  55. },
  56. {
  57. token : "constant.character.placeholder.csound",
  58. regex : /%[#0\- +]*\d*(?:\.\d+)?[diuoxXfFeEgGaAcs]/
  59. }, {
  60. token : "constant.character.escape.csound",
  61. regex : /%%/
  62. }
  63. ];
  64. this.quotedStringContents = [
  65. this.macroUses,
  66. this.bracedStringContents
  67. ];
  68. var start = [
  69. this.comments,
  70. {
  71. token : "keyword.preprocessor.csound",
  72. regex : /#(?:e(?:nd(?:if)?|lse)\b|##)|@@?[ \t]*\d+/
  73. }, {
  74. token : "keyword.preprocessor.csound",
  75. regex : /#include/,
  76. push : [
  77. this.comments,
  78. {
  79. token : "string.csound",
  80. regex : /([^ \t])(?:.*?\1)/,
  81. next : "pop"
  82. }
  83. ]
  84. }, {
  85. token : "keyword.preprocessor.csound",
  86. regex : /#[ \t]*define/,
  87. next : "define directive"
  88. }, {
  89. token : "keyword.preprocessor.csound",
  90. regex : /#(?:ifn?def|undef)\b/,
  91. next : "macro directive"
  92. },
  93. this.macroUses
  94. ];
  95. this.$rules = {
  96. "start": start,
  97. "define directive": [
  98. this.comments,
  99. {
  100. token : "entity.name.function.preprocessor.csound",
  101. regex : /[A-Z_a-z]\w*/
  102. }, {
  103. token : "punctuation.definition.macro-parameter-name-list.begin.csound",
  104. regex : /\(/,
  105. next : "macro parameter name list"
  106. }, {
  107. token : "punctuation.definition.macro.begin.csound",
  108. regex : /#/,
  109. next : "macro body"
  110. }
  111. ],
  112. "macro parameter name list": [
  113. {
  114. token : "variable.parameter.preprocessor.csound",
  115. regex : /[A-Z_a-z]\w*/
  116. }, {
  117. token : "punctuation.definition.macro-parameter-name-list.end.csound",
  118. regex : /\)/,
  119. next : "define directive"
  120. }
  121. ],
  122. "macro body": [
  123. {
  124. token : "constant.character.escape.csound",
  125. regex : /\\#/
  126. }, {
  127. token : "punctuation.definition.macro.end.csound",
  128. regex : /#/,
  129. next : "start"
  130. },
  131. start
  132. ],
  133. "macro directive": [
  134. this.comments,
  135. {
  136. token : "entity.name.function.preprocessor.csound",
  137. regex : /[A-Z_a-z]\w*/,
  138. next : "start"
  139. }
  140. ],
  141. "macro parameter value list": [
  142. {
  143. token : "punctuation.definition.macro-parameter-value-list.end.csound",
  144. regex : /\)/,
  145. next : "start"
  146. }, {
  147. token : "punctuation.definition.string.begin.csound",
  148. regex : /"/,
  149. next : "macro parameter value quoted string"
  150. }, this.pushRule({
  151. token : "punctuation.macro-parameter-value-parenthetical.begin.csound",
  152. regex : /\(/,
  153. next : "macro parameter value parenthetical"
  154. }), {
  155. token : "punctuation.macro-parameter-value-separator.csound",
  156. regex : "[#']"
  157. }
  158. ],
  159. "macro parameter value quoted string": [
  160. {
  161. token : "constant.character.escape.csound",
  162. regex : /\\[#'()]/
  163. }, {
  164. token : "invalid.illegal.csound",
  165. regex : /[#'()]/
  166. }, {
  167. token : "punctuation.definition.string.end.csound",
  168. regex : /"/,
  169. next : "macro parameter value list"
  170. },
  171. this.quotedStringContents,
  172. {
  173. defaultToken: "string.quoted.csound"
  174. }
  175. ],
  176. "macro parameter value parenthetical": [
  177. {
  178. token : "constant.character.escape.csound",
  179. regex : /\\\)/
  180. }, this.popRule({
  181. token : "punctuation.macro-parameter-value-parenthetical.end.csound",
  182. regex : /\)/
  183. }), this.pushRule({
  184. token : "punctuation.macro-parameter-value-parenthetical.begin.csound",
  185. regex : /\(/,
  186. next : "macro parameter value parenthetical"
  187. }),
  188. start
  189. ]
  190. };
  191. };
  192. oop.inherits(CsoundPreprocessorHighlightRules, TextHighlightRules);
  193. (function() {
  194. this.pushRule = function(params) {
  195. return {
  196. regex : params.regex, onMatch: function(value, currentState, stack, line) {
  197. if (stack.length === 0)
  198. stack.push(currentState);
  199. if (Array.isArray(params.next)) {
  200. for (var i = 0; i < params.next.length; i++) {
  201. stack.push(params.next[i]);
  202. }
  203. } else {
  204. stack.push(params.next);
  205. }
  206. this.next = stack[stack.length - 1];
  207. return params.token;
  208. },
  209. get next() { return Array.isArray(params.next) ? params.next[params.next.length - 1] : params.next; },
  210. set next(next) {
  211. if (Array.isArray(params.next)) {
  212. var oldNext = params.next[params.next.length - 1];
  213. var oldNextIndex = oldNext.length - 1;
  214. var newNextIndex = next.length - 1;
  215. if (newNextIndex > oldNextIndex) {
  216. while (oldNextIndex >= 0 && newNextIndex >= 0) {
  217. if (oldNext.charAt(oldNextIndex) !== next.charAt(newNextIndex)) {
  218. var prefix = next.substr(0, newNextIndex);
  219. for (var i = 0; i < params.next.length; i++) {
  220. params.next[i] = prefix + params.next[i];
  221. }
  222. break;
  223. }
  224. oldNextIndex--;
  225. newNextIndex--;
  226. }
  227. }
  228. } else {
  229. params.next = next;
  230. }
  231. },
  232. get token() { return params.token; }
  233. };
  234. };
  235. this.popRule = function(params) {
  236. return {
  237. regex : params.regex, onMatch: function(value, currentState, stack, line) {
  238. stack.pop();
  239. if (params.next) {
  240. stack.push(params.next);
  241. this.next = stack[stack.length - 1];
  242. } else {
  243. this.next = stack.length > 1 ? stack[stack.length - 1] : stack.pop();
  244. }
  245. return params.token;
  246. }
  247. };
  248. };
  249. }).call(CsoundPreprocessorHighlightRules.prototype);
  250. exports.CsoundPreprocessorHighlightRules = CsoundPreprocessorHighlightRules;
  251. });
  252. ace.define("ace/mode/csound_score_highlight_rules",[], function(require, exports, module) {
  253. "use strict";
  254. var oop = require("../lib/oop");
  255. var CsoundPreprocessorHighlightRules = require("./csound_preprocessor_highlight_rules").CsoundPreprocessorHighlightRules;
  256. var CsoundScoreHighlightRules = function() {
  257. CsoundPreprocessorHighlightRules.call(this);
  258. this.quotedStringContents.push({
  259. token : "invalid.illegal.csound-score",
  260. regex : /[^"]*$/
  261. });
  262. var start = this.$rules.start;
  263. start.push(
  264. {
  265. token : "keyword.control.csound-score",
  266. regex : /[abCdefiqstvxy]/
  267. }, {
  268. token : "invalid.illegal.csound-score",
  269. regex : /w/
  270. }, {
  271. token : "constant.numeric.language.csound-score",
  272. regex : /z/
  273. }, {
  274. token : ["keyword.control.csound-score", "constant.numeric.integer.decimal.csound-score"],
  275. regex : /([nNpP][pP])(\d+)/
  276. }, {
  277. token : "keyword.other.csound-score",
  278. regex : /[mn]/,
  279. push : [
  280. {
  281. token : "empty",
  282. regex : /$/,
  283. next : "pop"
  284. },
  285. this.comments,
  286. {
  287. token : "entity.name.label.csound-score",
  288. regex : /[A-Z_a-z]\w*/
  289. }
  290. ]
  291. }, {
  292. token : "keyword.preprocessor.csound-score",
  293. regex : /r\b/,
  294. next : "repeat section"
  295. },
  296. this.numbers,
  297. {
  298. token : "keyword.operator.csound-score",
  299. regex : "[!+\\-*/^%&|<>#~.]"
  300. },
  301. this.pushRule({
  302. token : "punctuation.definition.string.begin.csound-score",
  303. regex : /"/,
  304. next : "quoted string"
  305. }),
  306. this.pushRule({
  307. token : "punctuation.braced-loop.begin.csound-score",
  308. regex : /{/,
  309. next : "loop after left brace"
  310. })
  311. );
  312. this.addRules({
  313. "repeat section": [
  314. {
  315. token : "empty",
  316. regex : /$/,
  317. next : "start"
  318. },
  319. this.comments,
  320. {
  321. token : "constant.numeric.integer.decimal.csound-score",
  322. regex : /\d+/,
  323. next : "repeat section before label"
  324. }
  325. ],
  326. "repeat section before label": [
  327. {
  328. token : "empty",
  329. regex : /$/,
  330. next : "start"
  331. },
  332. this.comments,
  333. {
  334. token : "entity.name.label.csound-score",
  335. regex : /[A-Z_a-z]\w*/,
  336. next : "start"
  337. }
  338. ],
  339. "quoted string": [
  340. this.popRule({
  341. token : "punctuation.definition.string.end.csound-score",
  342. regex : /"/
  343. }),
  344. this.quotedStringContents,
  345. {
  346. defaultToken: "string.quoted.csound-score"
  347. }
  348. ],
  349. "loop after left brace": [
  350. this.popRule({
  351. token : "constant.numeric.integer.decimal.csound-score",
  352. regex : /\d+/,
  353. next : "loop after repeat count"
  354. }),
  355. this.comments,
  356. {
  357. token : "invalid.illegal.csound",
  358. regex : /\S.*/
  359. }
  360. ],
  361. "loop after repeat count": [
  362. this.popRule({
  363. token : "entity.name.function.preprocessor.csound-score",
  364. regex : /[A-Z_a-z]\w*\b/,
  365. next : "loop after macro name"
  366. }),
  367. this.comments,
  368. {
  369. token : "invalid.illegal.csound",
  370. regex : /\S.*/
  371. }
  372. ],
  373. "loop after macro name": [
  374. start,
  375. this.popRule({
  376. token : "punctuation.braced-loop.end.csound-score",
  377. regex : /}/
  378. })
  379. ]
  380. });
  381. this.normalizeRules();
  382. };
  383. oop.inherits(CsoundScoreHighlightRules, CsoundPreprocessorHighlightRules);
  384. exports.CsoundScoreHighlightRules = CsoundScoreHighlightRules;
  385. });
  386. ace.define("ace/mode/csound_score",[], function(require, exports, module) {
  387. "use strict";
  388. var oop = require("../lib/oop");
  389. var TextMode = require("./text").Mode;
  390. var CsoundScoreHighlightRules = require("./csound_score_highlight_rules").CsoundScoreHighlightRules;
  391. var Mode = function() {
  392. this.HighlightRules = CsoundScoreHighlightRules;
  393. };
  394. oop.inherits(Mode, TextMode);
  395. (function() {
  396. this.lineCommentStart = ";";
  397. this.blockComment = {start: "/*", end: "*/"};
  398. }).call(Mode.prototype);
  399. exports.Mode = Mode;
  400. });
  401. (function() {
  402. ace.require(["ace/mode/csound_score"], function(m) {
  403. if (typeof module == "object" && typeof exports == "object" && module) {
  404. module.exports = m;
  405. }
  406. });
  407. })();