Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

mode-praat.js 17KB

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