praat_highlight_rules.js 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. define(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. // What is "endSendPraat"? Function? Directive?
  23. var directives = (
  24. "clearinfo|endSendPraat"
  25. );
  26. var functions = (
  27. // Info functions
  28. "writeInfo|writeInfoLine|appendInfo|appendInfoLine|info\\$|" +
  29. "writeFile|writeFileLine|appendFile|appendFileLine|" +
  30. // Math functions
  31. "abs|round|floor|ceiling|min|max|imin|imax|" +
  32. "sqrt|sin|cos|tan|arcsin|arccos|arctan|arctan2|sinc|sincpi|" +
  33. "exp|ln|lnBeta|lnGamma|log10|log2|" +
  34. "sinh|cosh|tanh|arcsinh|arccosh|arctanh|" +
  35. "sigmoid|invSigmoid|erf|erfc|" +
  36. "random(?:Uniform|Integer|Gauss|Poisson|Binomial)|" +
  37. "gaussP|gaussQ|invGaussQ|incompleteGammaP|incompleteBeta|" +
  38. "chiSquareP|chiSquareQ|invChiSquareQ|studentP|studentQ|invStudentQ|" +
  39. "fisherP|fisherQ|invFisherQ|" +
  40. "binomialP|binomialQ|invBinomialP|invBinomialQ|" +
  41. "hertzToBark|barkToHerz|" +
  42. "hertzToMel|melToHertz|" +
  43. "hertzToSemitones|semitonesToHerz|" +
  44. "erb|hertzToErb|erbToHertz|" +
  45. "phonToDifferenceLimens|differenceLimensToPhon|" +
  46. "soundPressureToPhon|" +
  47. "beta|beta2|besselI|besselK|" +
  48. "numberOfColumns|numberOfRows|" +
  49. // String functions
  50. "selected|selected\\$|numberOfSelected|variableExists|"+
  51. "index|rindex|startsWith|endsWith|"+
  52. "index_regex|rindex_regex|replace_regex\\$|"+
  53. "length|extractWord\\$|extractLine\\$|extractNumber|" +
  54. "left\\$|right\\$|mid\\$|replace\\$|" +
  55. "date\\$|fixed\\$|percent\\$|" +
  56. // Array functions
  57. "zero#|linear#|randomUniform#|randomInteger#|randomGauss#|" +
  58. // Pause functions
  59. "beginPause|endPause|" +
  60. // Demo functions
  61. "demoShow|demoWindowTitle|demoInput|demoWaitForInput|" +
  62. "demoClicked|demoClickedIn|demoX|demoY|" +
  63. "demoKeyPressed|demoKey\\$|" +
  64. "demoExtraControlKeyPressed|demoShiftKeyPressed|"+
  65. "demoCommandKeyPressed|demoOptionKeyPressed|" +
  66. // File functions
  67. "environment\\$|chooseReadFile\\$|" +
  68. "chooseDirectory\\$|createDirectory|fileReadable|deleteFile|" +
  69. "selectObject|removeObject|plusObject|minusObject|" +
  70. "runScript|exitScript|" +
  71. // sendpraat functions
  72. "beginSendPraat|endSendPraat|" +
  73. // Other
  74. "objectsAreIdentical"
  75. );
  76. var objectTypes = (
  77. "Activation|AffineTransform|AmplitudeTier|Art|Artword|Autosegment|" +
  78. "BarkFilter|CCA|Categories|Cepstrum|Cepstrumc|ChebyshevSeries|" +
  79. "ClassificationTable|Cochleagram|Collection|Configuration|" +
  80. "Confusion|ContingencyTable|Corpus|Correlation|Covariance|" +
  81. "CrossCorrelationTable|CrossCorrelationTables|DTW|Diagonalizer|" +
  82. "Discriminant|Dissimilarity|Distance|Distributions|DurationTier|" +
  83. "EEG|ERP|ERPTier|Eigen|Excitation|Excitations|ExperimentMFC|FFNet|" +
  84. "FeatureWeights|Formant|FormantFilter|FormantGrid|FormantPoint|" +
  85. "FormantTier|GaussianMixture|HMM|HMM_Observation|" +
  86. "HMM_ObservationSequence|HMM_State|HMM_StateSequence|Harmonicity|" +
  87. "ISpline|Index|Intensity|IntensityTier|IntervalTier|KNN|KlattGrid|" +
  88. "KlattTable|LFCC|LPC|Label|LegendreSeries|LinearRegression|" +
  89. "LogisticRegression|LongSound|Ltas|MFCC|MSpline|ManPages|" +
  90. "Manipulation|Matrix|MelFilter|MixingMatrix|Movie|Network|" +
  91. "OTGrammar|OTHistory|OTMulti|PCA|PairDistribution|ParamCurve|" +
  92. "Pattern|Permutation|Pitch|PitchTier|PointProcess|Polygon|" +
  93. "Polynomial|Procrustes|RealPoint|RealTier|ResultsMFC|Roots|SPINET|" +
  94. "SSCP|SVD|Salience|ScalarProduct|Similarity|SimpleString|" +
  95. "SortedSetOfString|Sound|Speaker|Spectrogram|Spectrum|SpectrumTier|" +
  96. "SpeechSynthesizer|SpellingChecker|Strings|StringsIndex|Table|" +
  97. "TableOfReal|TextGrid|TextInterval|TextPoint|TextTier|Tier|" +
  98. "Transition|VocalTract|Weight|WordList"
  99. );
  100. // regexp must not have capturing parentheses. Use (?:) instead.
  101. // regexps are ordered -> the first match is used
  102. this.$rules = {
  103. "start" : [
  104. {
  105. // Interpolated strings
  106. token : "string.interpolated",
  107. regex : /'((?:[a-z][a-zA-Z0-9_]*)(?:\$|#|:[0-9]+)?)'/
  108. }, {
  109. // stopwatch
  110. token : ["text", "text", "keyword.operator", "text", "keyword"],
  111. regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(stopwatch)/
  112. }, {
  113. // Directives which introduce unquoted strings
  114. token : ["text", "keyword", "text", "string"],
  115. regex : /(^\s*)(print(?:line|tab)?|echo|exit|pause|send(?:praat|socket)|include|execute|system(?:_nocheck)?)(\s+)(.*)/
  116. }, {
  117. // Directives with no arguments
  118. token : ["text", "keyword"],
  119. regex : "(^\\s*)(" + directives + ")$"
  120. }, {
  121. // Operators
  122. token : ["text", "keyword.operator", "text"],
  123. regex : /(\s+)((?:\+|-|\/|\*|<|>)=?|==?|!=|%|\^|\||and|or|not)(\s+)/
  124. }, {
  125. // Commands
  126. token : ["text", "text", "keyword.operator", "text", "keyword", "text", "keyword"],
  127. regex : /(^\s*)(?:([a-z][a-zA-Z0-9_]*\$?\s+)(=)(\s+))?(?:((?:no)?warn|(?:unix_)?nocheck|noprogress)(\s+))?((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
  128. }, {
  129. // Demo commands
  130. token : ["text", "keyword", "text", "keyword"],
  131. regex : /(^\s*)(?:(demo)?(\s+))((?:[A-Z][^.:"]+)(?:$|(?:\.{3}|:)))/
  132. }, {
  133. // Font-sizing commands
  134. token : ["text", "keyword", "text", "keyword"],
  135. regex : /^(\s*)(?:(demo)(\s+))?(10|12|14|16|24)$/
  136. }, {
  137. // do-style command calls
  138. token : ["text", "support.function", "text"],
  139. regex : /(\s*)(do\$?)(\s*:\s*|\s*\(\s*)/
  140. }, {
  141. // Object types
  142. token : "entity.name.type",
  143. regex : "(" + objectTypes + ")"
  144. }, {
  145. // Predefined variables
  146. token : "variable.language",
  147. regex : "(" + predefinedVariables + ")"
  148. }, {
  149. // Functions
  150. token : ["support.function", "text"],
  151. regex : "((?:" + functions + ")\\$?)(\\s*(?::|\\())"
  152. }, {
  153. // For-loop declarations
  154. token : "keyword",
  155. regex : /(\bfor\b)/,
  156. next : "for"
  157. }, {
  158. // Generic keywords
  159. token : "keyword",
  160. regex : "(\\b(?:" + keywords + ")\\b)"
  161. }, {
  162. // Generic strings
  163. token : "string",
  164. regex : /"[^"]*"/
  165. }, {
  166. // Multiline quoted strings
  167. token : "string",
  168. regex : /"[^"]*$/,
  169. next : "brokenstring"
  170. }, {
  171. // Form declarations
  172. token : ["text", "keyword", "text", "entity.name.section"],
  173. regex : /(^\s*)(\bform\b)(\s+)(.*)/,
  174. next : "form"
  175. }, {
  176. // Numeric constants
  177. token : "constant.numeric",
  178. regex : /\b[+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b/
  179. }, {
  180. // Procedure declarations
  181. token : ["keyword", "text", "entity.name.function"],
  182. regex : /(procedure)(\s+)(\S+)/
  183. }, {
  184. // New-style procedure calls
  185. token : ["entity.name.function", "text"],
  186. regex : /(@\S+)(:|\s*\()/
  187. }, {
  188. // Old-style procedure calls
  189. token : ["text", "keyword", "text", "entity.name.function"],
  190. regex : /(^\s*)(call)(\s+)(\S+)/
  191. }, {
  192. // Comments
  193. token : "comment",
  194. regex : /(^\s*#|;).*$/
  195. }, {
  196. token : "text",
  197. regex : /\s+/
  198. }
  199. ],
  200. "form" : [
  201. {
  202. token : ["keyword", "text", "constant.numeric"],
  203. regex : /((?:optionmenu|choice)\s+)(\S+:\s+)([0-9]+)/
  204. }, {
  205. token : ["keyword", "constant.numeric"],
  206. regex : /((?:option|button)\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  207. }, {
  208. token : ["keyword", "string"],
  209. regex : /((?:option|button)\s+)(.*)/
  210. }, {
  211. token : ["keyword", "text", "string"],
  212. regex : /((?:sentence|text)\s+)(\S+\s*)(.*)/
  213. }, {
  214. token : ["keyword", "text", "string", "invalid.illegal"],
  215. regex : /(word\s+)(\S+\s*)(\S+)?(\s.*)?/
  216. }, {
  217. token : ["keyword", "text", "constant.language"],
  218. regex : /(boolean\s+)(\S+\s*)(0|1|"?(?:yes|no)"?)/
  219. }, {
  220. token : ["keyword", "text", "constant.numeric"],
  221. regex : /((?:real|natural|positive|integer)\s+)(\S+\s*)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?\b)/
  222. }, {
  223. token : ["keyword", "string"],
  224. regex : /(comment\s+)(.*)/
  225. }, {
  226. token : "keyword",
  227. regex : 'endform',
  228. next : "start"
  229. }
  230. ],
  231. "for" : [
  232. {
  233. token : ["keyword", "text", "constant.numeric", "text"],
  234. regex : /(from|to)(\s+)([+-]?\d+(?:(?:\.\d*)?(?:[eE][+-]?\d+)?)?)(\s*)/
  235. }, {
  236. token : ["keyword", "text"],
  237. regex : /(from|to)(\s+\S+\s*)/
  238. }, {
  239. token : "text",
  240. regex : /$/,
  241. next : "start"
  242. }
  243. ],
  244. "brokenstring" : [
  245. {
  246. token : ["text", "string"],
  247. regex : /(\s*\.{3})([^"]*)/
  248. }, {
  249. token : "string",
  250. regex : /"/,
  251. next : "start"
  252. }
  253. ],
  254. };
  255. };
  256. oop.inherits(PraatHighlightRules, TextHighlightRules);
  257. exports.PraatHighlightRules = PraatHighlightRules;
  258. });