mode-praat.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468
  1. ace.define("ace/mode/praat_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 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*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
  113. }, {
  114. token : ["text", "keyword", "text", "keyword"],
  115. regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/
  116. }, {
  117. token : ["text", "support.function", "text"],
  118. regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/
  119. }, {
  120. token : "entity.name.type",
  121. regex : "(" + objectTypes + ")"
  122. }, {
  123. token : "variable.language",
  124. regex : "(" + predefinedVariables + ")"
  125. }, {
  126. token : ["support.function", "text"],
  127. regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())"
  128. }, {
  129. token : "keyword",
  130. regex : /(\bfor\b)/,
  131. next : "for"
  132. }, {
  133. token : "keyword",
  134. regex : "(\\b(?:" + keywords + ")\\b)"
  135. }, {
  136. token : "string",
  137. regex : /"[^"]*"/
  138. }, {
  139. token : "string",
  140. regex : /"[^"]*$/,
  141. next : "brokenstring"
  142. }, {
  143. token : ["text", "keyword", "text", "entity.name.section"],
  144. regex : /(^\s*)(\bform\b)(\s+)(.*)/,
  145. next : "form"
  146. }, {
  147. token : "constant.numeric",
  148. regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  149. }, {
  150. token : ["keyword", "text", "entity.name.function"],
  151. regex : /(procedure)(\s+)(\S+)/
  152. }, {
  153. token : ["entity.name.function", "text"],
  154. regex : /(@\S+)(:|\s*\()/
  155. }, {
  156. token : ["text", "keyword", "text", "entity.name.function"],
  157. regex : /(^\s*)(call)(\s+)(\S+)/
  158. }, {
  159. token : "comment",
  160. regex : /(^\s*#|;).*$/
  161. }, {
  162. token : "text",
  163. regex : /\s+/
  164. }
  165. ],
  166. "form" : [
  167. {
  168. token : ["keyword", "text", "constant.numeric"],
  169. regex : /((?:optionmenu|choice)\s+)(\S+:\s+)([0-9]+)/
  170. }, {
  171. token : ["keyword", "constant.numeric"],
  172. regex : /((?:option|button)\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  173. }, {
  174. token : ["keyword", "string"],
  175. regex : /((?:option|button)\s+)(.*)/
  176. }, {
  177. token : ["keyword", "text", "string"],
  178. regex : /((?:sentence|text)\s+)(\S+\s*)(.*)/
  179. }, {
  180. token : ["keyword", "text", "string", "invalid.illegal"],
  181. regex : /(word\s+)(\S+\s*)(\S+)?(\s.*)?/
  182. }, {
  183. token : ["keyword", "text", "constant.language"],
  184. regex : /(boolean\s+)(\S+\s*)(0|1|"?(?:yes|no)"?)/
  185. }, {
  186. token : ["keyword", "text", "constant.numeric"],
  187. regex : /((?:real|natural|positive|integer)\s+)(\S+\s*)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  188. }, {
  189. token : ["keyword", "string"],
  190. regex : /(comment\s+)(.*)/
  191. }, {
  192. token : "keyword",
  193. regex : 'endform',
  194. next : "start"
  195. }
  196. ],
  197. "for" : [
  198. {
  199. token : ["keyword", "text", "constant.numeric", "text"],
  200. regex : /(from|to)(\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?)(\s*)/
  201. }, {
  202. token : ["keyword", "text"],
  203. regex : /(from|to)(\s+\S+\s*)/
  204. }, {
  205. token : "text",
  206. regex : /$/,
  207. next : "start"
  208. }
  209. ],
  210. "brokenstring" : [
  211. {
  212. token : ["text", "string"],
  213. regex : /(\s*\.{3})([^"]*)/
  214. }, {
  215. token : "string",
  216. regex : /"/,
  217. next : "start"
  218. }
  219. ]
  220. };
  221. };
  222. oop.inherits(PraatHighlightRules, TextHighlightRules);
  223. exports.PraatHighlightRules = PraatHighlightRules;
  224. });
  225. ace.define("ace/mode/matching_brace_outdent",["require","exports","module","ace/range"], function(require, exports, module) {
  226. "use strict";
  227. var Range = require("../range").Range;
  228. var MatchingBraceOutdent = function() {};
  229. (function() {
  230. this.checkOutdent = function(line, input) {
  231. if (! /^\s+$/.test(line))
  232. return false;
  233. return /^\s*\}/.test(input);
  234. };
  235. this.autoOutdent = function(doc, row) {
  236. var line = doc.getLine(row);
  237. var match = line.match(/^(\s*\})/);
  238. if (!match) return 0;
  239. var column = match[1].length;
  240. var openBracePos = doc.findMatchingBracket({row: row, column: column});
  241. if (!openBracePos || openBracePos.row == row) return 0;
  242. var indent = this.$getIndent(doc.getLine(openBracePos.row));
  243. doc.replace(new Range(row, 0, row, column-1), indent);
  244. };
  245. this.$getIndent = function(line) {
  246. return line.match(/^\s*/)[0];
  247. };
  248. }).call(MatchingBraceOutdent.prototype);
  249. exports.MatchingBraceOutdent = MatchingBraceOutdent;
  250. });
  251. ace.define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module) {
  252. "use strict";
  253. var oop = require("../../lib/oop");
  254. var Range = require("../../range").Range;
  255. var BaseFoldMode = require("./fold_mode").FoldMode;
  256. var FoldMode = exports.FoldMode = function(commentRegex) {
  257. if (commentRegex) {
  258. this.foldingStartMarker = new RegExp(
  259. this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start)
  260. );
  261. this.foldingStopMarker = new RegExp(
  262. this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end)
  263. );
  264. }
  265. };
  266. oop.inherits(FoldMode, BaseFoldMode);
  267. (function() {
  268. this.foldingStartMarker = /(\{|\[)[^\}\]]*$|^\s*(\/\*)/;
  269. this.foldingStopMarker = /^[^\[\{]*(\}|\])|^[\s\*]*(\*\/)/;
  270. this.singleLineBlockCommentRe= /^\s*(\/\*).*\*\/\s*$/;
  271. this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
  272. this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
  273. this._getFoldWidgetBase = this.getFoldWidget;
  274. this.getFoldWidget = function(session, foldStyle, row) {
  275. var line = session.getLine(row);
  276. if (this.singleLineBlockCommentRe.test(line)) {
  277. if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
  278. return "";
  279. }
  280. var fw = this._getFoldWidgetBase(session, foldStyle, row);
  281. if (!fw && this.startRegionRe.test(line))
  282. return "start"; // lineCommentRegionStart
  283. return fw;
  284. };
  285. this.getFoldWidgetRange = function(session, foldStyle, row, forceMultiline) {
  286. var line = session.getLine(row);
  287. if (this.startRegionRe.test(line))
  288. return this.getCommentRegionBlock(session, line, row);
  289. var match = line.match(this.foldingStartMarker);
  290. if (match) {
  291. var i = match.index;
  292. if (match[1])
  293. return this.openingBracketBlock(session, match[1], row, i);
  294. var range = session.getCommentFoldRange(row, i + match[0].length, 1);
  295. if (range && !range.isMultiLine()) {
  296. if (forceMultiline) {
  297. range = this.getSectionRange(session, row);
  298. } else if (foldStyle != "all")
  299. range = null;
  300. }
  301. return range;
  302. }
  303. if (foldStyle === "markbegin")
  304. return;
  305. var match = line.match(this.foldingStopMarker);
  306. if (match) {
  307. var i = match.index + match[0].length;
  308. if (match[1])
  309. return this.closingBracketBlock(session, match[1], row, i);
  310. return session.getCommentFoldRange(row, i, -1);
  311. }
  312. };
  313. this.getSectionRange = function(session, row) {
  314. var line = session.getLine(row);
  315. var startIndent = line.search(/\S/);
  316. var startRow = row;
  317. var startColumn = line.length;
  318. row = row + 1;
  319. var endRow = row;
  320. var maxRow = session.getLength();
  321. while (++row < maxRow) {
  322. line = session.getLine(row);
  323. var indent = line.search(/\S/);
  324. if (indent === -1)
  325. continue;
  326. if (startIndent > indent)
  327. break;
  328. var subRange = this.getFoldWidgetRange(session, "all", row);
  329. if (subRange) {
  330. if (subRange.start.row <= startRow) {
  331. break;
  332. } else if (subRange.isMultiLine()) {
  333. row = subRange.end.row;
  334. } else if (startIndent == indent) {
  335. break;
  336. }
  337. }
  338. endRow = row;
  339. }
  340. return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
  341. };
  342. this.getCommentRegionBlock = function(session, line, row) {
  343. var startColumn = line.search(/\s*$/);
  344. var maxRow = session.getLength();
  345. var startRow = row;
  346. var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
  347. var depth = 1;
  348. while (++row < maxRow) {
  349. line = session.getLine(row);
  350. var m = re.exec(line);
  351. if (!m) continue;
  352. if (m[1]) depth--;
  353. else depth++;
  354. if (!depth) break;
  355. }
  356. var endRow = row;
  357. if (endRow > startRow) {
  358. return new Range(startRow, startColumn, endRow, line.length);
  359. }
  360. };
  361. }).call(FoldMode.prototype);
  362. });
  363. ace.define("ace/mode/praat",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/praat_highlight_rules","ace/mode/matching_brace_outdent","ace/mode/folding/cstyle"], function(require, exports, module) {
  364. "use strict";
  365. var oop = require("../lib/oop");
  366. var TextMode = require("./text").Mode;
  367. var PraatHighlightRules = require("./praat_highlight_rules").PraatHighlightRules;
  368. var MatchingBraceOutdent = require("./matching_brace_outdent").MatchingBraceOutdent;
  369. var CStyleFoldMode = require("./folding/cstyle").FoldMode;
  370. var Mode = function() {
  371. this.HighlightRules = PraatHighlightRules;
  372. this.$outdent = new MatchingBraceOutdent();
  373. this.foldingRules = new CStyleFoldMode();
  374. this.$behaviour = this.$defaultBehaviour;
  375. };
  376. oop.inherits(Mode, TextMode);
  377. (function() {
  378. this.lineCommentStart = "#";
  379. this.getNextLineIndent = function(state, line, tab) {
  380. var indent = this.$getIndent(line);
  381. var tokenizedLine = this.getTokenizer().getLineTokens(line, state);
  382. var tokens = tokenizedLine.tokens;
  383. if (tokens.length && tokens[tokens.length-1].type == "comment") {
  384. return indent;
  385. }
  386. if (state == "start") {
  387. var match = line.match(/^.*[\{\(\[:]\s*$/);
  388. if (match) {
  389. indent += tab;
  390. }
  391. }
  392. return indent;
  393. };
  394. this.checkOutdent = function(state, line, input) {
  395. return this.$outdent.checkOutdent(line, input);
  396. };
  397. this.autoOutdent = function(state, doc, row) {
  398. this.$outdent.autoOutdent(doc, row);
  399. };
  400. this.$id = "ace/mode/praat";
  401. }).call(Mode.prototype);
  402. exports.Mode = Mode;
  403. });