mode-csound_score.js 14 KB

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