mode-praat.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. ace.define("ace/mode/praat_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 PraatHighlightRules = function() {
  6. var keywords = (
  7. "if|then|else|elsif|elif|endif|fi|" +
  8. "endfor|endproc|" + // related keywords specified below
  9. "while|endwhile|" +
  10. "repeat|until|" +
  11. "select|plus|minus|" +
  12. "assert|asserterror"
  13. );
  14. var predefinedVariables = (
  15. "macintosh|windows|unix|" +
  16. "praatVersion|praatVersion\\$" +
  17. "pi|undefined|" +
  18. "newline\\$|tab\\$|" +
  19. "shellDirectory\\$|homeDirectory\\$|preferencesDirectory\\$|" +
  20. "temporaryDirectory\\$|defaultDirectory\\$"
  21. );
  22. var directives = (
  23. "clearinfo|endSendPraat"
  24. );
  25. var functions = (
  26. "writeInfo|writeInfoLine|appendInfo|appendInfoLine|info\\$|" +
  27. "writeFile|writeFileLine|appendFile|appendFileLine|" +
  28. "abs|round|floor|ceiling|min|max|imin|imax|" +
  29. "sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" +
  30. "exp|ln|lnBeta|lnGamma|log10|log2|" +
  31. "sinh|cosh|tanh|arcsinh|arccosh|arctanh|" +
  32. "sigmoid|invSigmoid|erf|erfc|" +
  33. "random(?:Uniform|Integer|Gauss|Poisson|Binomial)|" +
  34. "gaussP|gaussQ|invGaussQ|incompleteGammaP|incompleteBeta|" +
  35. "chiSquareP|chiSquareQ|invChiSquareQ|studentP|studentQ|invStudentQ|" +
  36. "fisherP|fisherQ|invFisherQ|" +
  37. "binomialP|binomialQ|invBinomialP|invBinomialQ|" +
  38. "hertzToBark|barkToHerz|" +
  39. "hertzToMel|melToHertz|" +
  40. "hertzToSemitones|semitonesToHerz|" +
  41. "erb|hertzToErb|erbToHertz|" +
  42. "phonToDifferenceLimens|differenceLimensToPhon|" +
  43. "soundPressureToPhon|" +
  44. "beta|beta2|besselI|besselK|" +
  45. "numberOfColumns|numberOfRows|" +
  46. "selected|selected\\$|numberOfSelected|variableExists|"+
  47. "index|rindex|startsWith|endsWith|"+
  48. "index_regex|rindex_regex|replace_regex\\$|"+
  49. "length|extractWord\\$|extractLine\\$|extractNumber|" +
  50. "left\\$|right\\$|mid\\$|replace\\$|" +
  51. "date\\$|fixed\\$|percent\\$|" +
  52. "zero#|linear#|randomUniform#|randomInteger#|randomGauss#|" +
  53. "beginPause|endPause|" +
  54. "demoShow|demoWindowTitle|demoInput|demoWaitForInput|" +
  55. "demoClicked|demoClickedIn|demoX|demoY|" +
  56. "demoKeyPressed|demoKey\\$|" +
  57. "demoExtraControlKeyPressed|demoShiftKeyPressed|"+
  58. "demoCommandKeyPressed|demoOptionKeyPressed|" +
  59. "environment\\$|chooseReadFile\\$|" +
  60. "chooseDirectory\\$|createDirectory|fileReadable|deleteFile|" +
  61. "selectObject|removeObject|plusObject|minusObject|" +
  62. "runScript|exitScript|" +
  63. "beginSendPraat|endSendPraat|" +
  64. "objectsAreIdentical"
  65. );
  66. var objectTypes = (
  67. "Activation|AffineTransform|AmplitudeTier|Art|Artword|Autosegment|" +
  68. "BarkFilter|CCA|Categories|Cepstrum|Cepstrumc|ChebyshevSeries|" +
  69. "ClassificationTable|Cochleagram|Collection|Configuration|" +
  70. "Confusion|ContingencyTable|Corpus|Correlation|Covariance|" +
  71. "CrossCorrelationTable|CrossCorrelationTables|DTW|Diagonalizer|" +
  72. "Discriminant|Dissimilarity|Distance|Distributions|DurationTier|" +
  73. "EEG|ERP|ERPTier|Eigen|Excitation|Excitations|ExperimentMFC|FFNet|" +
  74. "FeatureWeights|Formant|FormantFilter|FormantGrid|FormantPoint|" +
  75. "FormantTier|GaussianMixture|HMM|HMM_Observation|" +
  76. "HMM_ObservationSequence|HMM_State|HMM_StateSequence|Harmonicity|" +
  77. "ISpline|Index|Intensity|IntensityTier|IntervalTier|KNN|KlattGrid|" +
  78. "KlattTable|LFCC|LPC|Label|LegendreSeries|LinearRegression|" +
  79. "LogisticRegression|LongSound|Ltas|MFCC|MSpline|ManPages|" +
  80. "Manipulation|Matrix|MelFilter|MixingMatrix|Movie|Network|" +
  81. "OTGrammar|OTHistory|OTMulti|PCA|PairDistribution|ParamCurve|" +
  82. "Pattern|Permutation|Pitch|PitchTier|PointProcess|Polygon|" +
  83. "Polynomial|Procrustes|RealPoint|RealTier|ResultsMFC|Roots|SPINET|" +
  84. "SSCP|SVD|Salience|ScalarProduct|Similarity|SimpleString|" +
  85. "SortedSetOfString|Sound|Speaker|Spectrogram|Spectrum|SpectrumTier|" +
  86. "SpeechSynthesizer|SpellingChecker|Strings|StringsIndex|Table|" +
  87. "TableOfReal|TextGrid|TextInterval|TextPoint|TextTier|Tier|" +
  88. "Transition|VocalTract|Weight|WordList"
  89. );
  90. this.$rules = {
  91. "start" : [
  92. {
  93. token : "string.interpolated",
  94. regex : /'((?:\.?[a-z][a-zA-Z0-9_.]*)(?:\$|#|:[0-9]+)?)'/
  95. }, {
  96. token : ["text", "text", "keyword.operator", "text", "keyword"],
  97. regex : /(^\s*)(?:(\.?[a-z][a-zA-Z0-9_.]*\$?\s+)(=)(\s+))?(stopwatch)/
  98. }, {
  99. token : ["text", "keyword", "text", "string"],
  100. regex : /(^\s*)(print(?:line|tab)?|echo|exit|pause|send(?:praat|socket)|include|execute|system(?:_nocheck)?)(\s+)(.*)/
  101. }, {
  102. token : ["text", "keyword"],
  103. regex : "(^\\s*)(" + directives + ")$"
  104. }, {
  105. token : ["text", "keyword.operator", "text"],
  106. regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/
  107. }, {
  108. token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"],
  109. regex : /(^\s*)(?:(\.?[a-z][a-zA-Z0-9_.]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|(?:unix_)?nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
  110. }, {
  111. token : ["text", "keyword", "text", "keyword"],
  112. regex : /(^\s*)((?:no(?:warn|check))?)(\s*)(\b(?:editor(?::?)|endeditor)\b)/
  113. }, {
  114. token : ["text", "keyword", "text", "keyword"],
  115. regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
  116. }, {
  117. token : ["text", "keyword", "text", "keyword"],
  118. regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/
  119. }, {
  120. token : ["text", "support.function", "text"],
  121. regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/
  122. }, {
  123. token : "entity.name.type",
  124. regex : "(" + objectTypes + ")"
  125. }, {
  126. token : "variable.language",
  127. regex : "(" + predefinedVariables + ")"
  128. }, {
  129. token : ["support.function", "text"],
  130. regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())"
  131. }, {
  132. token : "keyword",
  133. regex : /(\bfor\b)/,
  134. next : "for"
  135. }, {
  136. token : "keyword",
  137. regex : "(\\b(?:" + keywords + ")\\b)"
  138. }, {
  139. token : "string",
  140. regex : /"[^"]*"/
  141. }, {
  142. token : "string",
  143. regex : /"[^"]*$/,
  144. next : "brokenstring"
  145. }, {
  146. token : ["text", "keyword", "text", "entity.name.section"],
  147. regex : /(^\s*)(\bform\b)(\s+)(.*)/,
  148. next : "form"
  149. }, {
  150. token : "constant.numeric",
  151. regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  152. }, {
  153. token : ["keyword", "text", "entity.name.function"],
  154. regex : /(procedure)(\s+)([^:\s]+)/
  155. }, {
  156. token : ["entity.name.function", "text"],
  157. regex : /(@\S+)(:|\s*\()/
  158. }, {
  159. token : ["text", "keyword", "text", "entity.name.function"],
  160. regex : /(^\s*)(call)(\s+)(\S+)/
  161. }, {
  162. token : "comment",
  163. regex : /(^\s*#|;).*$/
  164. }, {
  165. token : "text",
  166. regex : /\s+/
  167. }
  168. ],
  169. "form" : [
  170. {
  171. token : ["keyword", "text", "constant.numeric"],
  172. regex : /((?:optionmenu|choice)\s+)(\S+:\s+)([0-9]+)/
  173. }, {
  174. token : ["keyword", "constant.numeric"],
  175. regex : /((?:option|button)\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  176. }, {
  177. token : ["keyword", "string"],
  178. regex : /((?:option|button)\s+)(.*)/
  179. }, {
  180. token : ["keyword", "text", "string"],
  181. regex : /((?:sentence|text)\s+)(\S+\s*)(.*)/
  182. }, {
  183. token : ["keyword", "text", "string", "invalid.illegal"],
  184. regex : /(word\s+)(\S+\s*)(\S+)?(\s.*)?/
  185. }, {
  186. token : ["keyword", "text", "constant.language"],
  187. regex : /(boolean\s+)(\S+\s*)(0|1|"?(?:yes|no)"?)/
  188. }, {
  189. token : ["keyword", "text", "constant.numeric"],
  190. regex : /((?:real|natural|positive|integer)\s+)(\S+\s*)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  191. }, {
  192. token : ["keyword", "string"],
  193. regex : /(comment\s+)(.*)/
  194. }, {
  195. token : "keyword",
  196. regex : 'endform',
  197. next : "start"
  198. }
  199. ],
  200. "for" : [
  201. {
  202. token : ["keyword", "text", "constant.numeric", "text"],
  203. regex : /(from|to)(\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?)(\s*)/
  204. }, {
  205. token : ["keyword", "text"],
  206. regex : /(from|to)(\s+\S+\s*)/
  207. }, {
  208. token : "text",
  209. regex : /$/,
  210. next : "start"
  211. }
  212. ],
  213. "brokenstring" : [
  214. {
  215. token : ["text", "string"],
  216. regex : /(\s*\.{3})([^"]*)/
  217. }, {
  218. token : "string",
  219. regex : /"/,
  220. next : "start"
  221. }
  222. ]
  223. };
  224. };
  225. oop.inherits(PraatHighlightRules, TextHighlightRules);
  226. exports.PraatHighlightRules = PraatHighlightRules;
  227. });
  228. ace.define("ace/mode/matching_brace_outdent",[], function(require, exports, module) {
  229. "use strict";
  230. var Range = require("../range").Range;
  231. var MatchingBraceOutdent = function() {};
  232. (function() {
  233. this.checkOutdent = function(line, input) {
  234. if (! /^\s+$/.test(line))
  235. return false;
  236. return /^\s*\}/.test(input);
  237. };
  238. this.autoOutdent = function(doc, row) {
  239. var line = doc.getLine(row);
  240. var match = line.match(/^(\s*\})/);
  241. if (!match) return 0;
  242. var column = match[1].length;
  243. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  244. if (!openBracePos || openBracePos.row == row) return 0;
  245. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  246. doc.replace(new Range(row, 0, row, column-1), indent);
  247. };
  248. this.$getIndent = function(line) {
  249. return line.match(/^\s*/)[0];
  250. };
  251. }).call(MatchingBraceOutdent.prototype);
  252. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  253. });
  254. ace.define("ace/mode/folding/cstyle",[], function(require, exports, module) {
  255. "use strict";
  256. var oop = require("../../lib/oop");
  257. var Range = require("../../range").Range;
  258. var BaseFoldMode = require("./fold_mode").FoldMode;
  259. var FoldMode = exports.FoldMode = function(commentRegex) {
  260. if (commentRegex) {
  261. this.foldingStartMarker = new RegExp(
  262. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  263. );
  264. this.foldingStopMarker = new RegExp(
  265. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  266. );
  267. }
  268. };
  269. oop.inherits(FoldMode, BaseFoldMode);
  270. (function() {
  271. this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
  272. this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
  273. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  274. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  275. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  276. this._getFoldWidgetBase = this.getFoldWidget;
  277. this.getFoldWidget = function(session, foldStyle, row) {
  278. var line = session.getLine(row);
  279. if (this.singleLineBlockCommentRe.test(line)) {
  280. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  281. return "";
  282. }
  283. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  284. if (!fw && this.startRegionRe.test(line))
  285. return "start"; // lineCommentRegionStart
  286. return fw;
  287. };
  288. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  289. var line = session.getLine(row);
  290. if (this.startRegionRe.test(line))
  291. return this.getCommentRegionBlock(session, line, row);
  292. var match = line.match(this.foldingStartMarker);
  293. if (match) {
  294. var i = match.index;
  295. if (match[1])
  296. return this.openingBracketBlock(session, match[1], row, i);
  297. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  298. if (range && !range.isMultiLine()) {
  299. if (forceMultiline) {
  300. range = this.getSectionRange(session, row);
  301. } else if (foldStyle != "all")
  302. range = null;
  303. }
  304. return range;
  305. }
  306. if (foldStyle === "markbegin")
  307. return;
  308. var match = line.match(this.foldingStopMarker);
  309. if (match) {
  310. var i = match.index + match[0].length;
  311. if (match[1])
  312. return this.closingBracketBlock(session, match[1], row, i);
  313. return session.getCommentFoldRange(row, i, -1);
  314. }
  315. };
  316. this.getSectionRange = function(session, row) {
  317. var line = session.getLine(row);
  318. var startIndent = line.search(/\S/);
  319. var startRow = row;
  320. var startColumn = line.length;
  321. row = row + 1;
  322. var endRow = row;
  323. var maxRow = session.getLength();
  324. while (++row < maxRow) {
  325. line = session.getLine(row);
  326. var indent = line.search(/\S/);
  327. if (indent === -1)
  328. continue;
  329. if (startIndent > indent)
  330. break;
  331. var subRange = this.getFoldWidgetRange(session, "all", row);
  332. if (subRange) {
  333. if (subRange.start.row <= startRow) {
  334. break;
  335. } else if (subRange.isMultiLine()) {
  336. row = subRange.end.row;
  337. } else if (startIndent == indent) {
  338. break;
  339. }
  340. }
  341. endRow = row;
  342. }
  343. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  344. };
  345. this.getCommentRegionBlock = function(session, line, row) {
  346. var startColumn = line.search(/\s*$/);
  347. var maxRow = session.getLength();
  348. var startRow = row;
  349. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  350. var depth = 1;
  351. while (++row < maxRow) {
  352. line = session.getLine(row);
  353. var m = re.exec(line);
  354. if (!m) continue;
  355. if (m[1]) depth--;
  356. else depth++;
  357. if (!depth) break;
  358. }
  359. var endRow = row;
  360. if (endRow > startRow) {
  361. return new Range(startRow, startColumn, endRow, line.length);
  362. }
  363. };
  364. }).call(FoldMode.prototype);
  365. });
  366. ace.define("ace/mode/praat",[], function(require, exports, module) {
  367. "use strict";
  368. var oop = require("../lib/oop");
  369. var TextMode = require("./text").Mode;
  370. var PraatHighlightRules = require("./praat_highlight_rules").PraatHighlightRules;
  371. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  372. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  373. var Mode = function() {
  374. this.HighlightRules = PraatHighlightRules;
  375. this.$outdent = new MatchingBraceOutdent();
  376. this.foldingRules = new CStyleFoldMode();
  377. this.$behaviour = this.$defaultBehaviour;
  378. };
  379. oop.inherits(Mode, TextMode);
  380. (function() {
  381. this.lineCommentStart = "#";
  382. this.getNextLineIndent = function(state, line, tab) {
  383. var indent = this.$getIndent(line);
  384. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  385. var tokens = tokenizedLine.tokens;
  386. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  387. return indent;
  388. }
  389. if (state == "start") {
  390. var match = line.match(/^.*[\{\(\[:]\s*$/);
  391. if (match) {
  392. indent += tab;
  393. }
  394. }
  395. return indent;
  396. };
  397. this.checkOutdent = function(state, line, input) {
  398. return this.$outdent.checkOutdent(line, input);
  399. };
  400. this.autoOutdent = function(state, doc, row) {
  401. this.$outdent.autoOutdent(doc, row);
  402. };
  403. this.$id = "ace/mode/praat";
  404. }).call(Mode.prototype);
  405. exports.Mode = Mode;
  406. });
  407. (function() {
  408. ace.require(["ace/mode/praat"], function(m) {
  409. if (typeof module == "object" && typeof exports == "object" && module) {
  410. module.exports = m;
  411. }
  412. });
  413. })();