1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
|
# -*- coding: utf-8 -*- #
# frozen_string_literal: true
module Rouge
module Lexers
class Praat < RegexLexer
title "Praat"
desc "The Praat scripting language (praat.org)"
tag 'praat'
filenames '*.praat', '*.proc', '*.psc'
def self.detect?(text)
return true if text.shebang? 'praat'
end
def self.keywords
@keywords ||= %w(
if then else elsif elif endif fi for from to endfor endproc while
endwhile repeat until select plus minus demo assert stopwatch
nocheck nowarn noprogress editor endeditor clearinfo
)
end
def self.functions_string
@functions_string ||= %w(
backslashTrigraphsToUnicode$ chooseDirectory$ chooseReadFile$
chooseWriteFile$ date$ demoKey$ do$ environment$ extractLine$ extractWord$
fixed$ info$ left$ mid$ percent$ readFile$ replace$ replace_regex$ right$
selected$ string$ unicodeToBackslashTrigraphs$
)
end
def self.functions_numeric
@functions_numeric ||= %w(
abs appendFile appendFileLine appendInfo appendInfoLine arccos arccosh
arcsin arcsinh arctan arctan2 arctanh barkToHertz beginPause
beginSendPraat besselI besselK beta beta2 binomialP binomialQ boolean
ceiling chiSquareP chiSquareQ choice comment cos cosh createDirectory
deleteFile demoClicked demoClickedIn demoCommandKeyPressed
demoExtraControlKeyPressed demoInput demoKeyPressed
demoOptionKeyPressed demoShiftKeyPressed demoShow demoWaitForInput
demoWindowTitle demoX demoY differenceLimensToPhon do editor endPause
endSendPraat endsWith erb erbToHertz erf erfc exitScript exp
extractNumber fileReadable fisherP fisherQ floor gaussP gaussQ hash
hertzToBark hertzToErb hertzToMel hertzToSemitones imax imin
incompleteBeta incompleteGammaP index index_regex integer invBinomialP
invBinomialQ invChiSquareQ invFisherQ invGaussQ invSigmoid invStudentQ
length ln lnBeta lnGamma log10 log2 max melToHertz min minusObject
natural number numberOfColumns numberOfRows numberOfSelected
objectsAreIdentical option optionMenu pauseScript
phonToDifferenceLimens plusObject positive randomBinomial randomGauss
randomInteger randomPoisson randomUniform real readFile removeObject
rindex rindex_regex round runScript runSystem runSystem_nocheck
selectObject selected semitonesToHertz sentence sentencetext sigmoid
sin sinc sincpi sinh soundPressureToPhon sqrt startsWith studentP
studentQ tan tanh text variableExists word writeFile writeFileLine
writeInfo writeInfoLine
)
end
def self.functions_array
@functions_array ||= %w(
linear# randomGauss# randomInteger# randomUniform# zero#
)
end
def self.functions_matrix
@functions_matrix ||= %w(
linear## mul## mul_fast## mul_metal## mul_nt## mul_tn## mul_tt## outer## peaks##
randomGamma## randomGauss## randomInteger## randomUniform## softmaxPerRow##
solve## transpose## zero##
)
end
def self.functions_string_vector
@functions_string_vector ||= %w(
empty$# fileNames$# folderNames$# readLinesFromFile$# splitByWhitespace$#
)
end
def self.functions_builtin
@functions_builtin ||=
self.functions_string |
self.functions_numeric |
self.functions_array |
self.functions_matrix |
self.functions_string_vector
end
def self.objects
@objects ||= %w(
Activation AffineTransform AmplitudeTier Art Artword Autosegment
BarkFilter BarkSpectrogram CCA Categories Cepstrogram Cepstrum
Cepstrumc ChebyshevSeries ClassificationTable Cochleagram Collection
ComplexSpectrogram Configuration Confusion ContingencyTable Corpus
Correlation Covariance CrossCorrelationTable CrossCorrelationTableList
CrossCorrelationTables DTW DataModeler Diagonalizer Discriminant
Dissimilarity Distance Distributions DurationTier EEG ERP ERPTier
EditCostsTable EditDistanceTable Eigen Excitation Excitations
ExperimentMFC FFNet FeatureWeights FileInMemory FilesInMemory Formant
FormantFilter FormantGrid FormantModeler FormantPoint FormantTier
GaussianMixture HMM HMM_Observation HMM_ObservationSequence HMM_State
HMM_StateSequence HMMObservation HMMObservationSequence HMMState
HMMStateSequence Harmonicity ISpline Index Intensity IntensityTier
IntervalTier KNN KlattGrid KlattTable LFCC LPC Label LegendreSeries
LinearRegression LogisticRegression LongSound Ltas MFCC MSpline ManPages
Manipulation Matrix MelFilter MelSpectrogram MixingMatrix Movie Network
OTGrammar OTHistory OTMulti PCA PairDistribution ParamCurve Pattern
Permutation Photo Pitch PitchModeler PitchTier PointProcess Polygon
Polynomial PowerCepstrogram PowerCepstrum Procrustes RealPoint RealTier
ResultsMFC Roots SPINET SSCP SVD Salience ScalarProduct Similarity
SimpleString SortedSetOfString Sound Speaker Spectrogram Spectrum
SpectrumTier SpeechSynthesizer SpellingChecker Strings StringsIndex
Table TableOfReal TextGrid TextInterval TextPoint TextTier Tier
Transition VocalTract VocalTractTier Weight WordList
)
end
def self.variables_numeric
@variables_numeric ||= %w(
all average e left macintosh mono pi praatVersion right stereo
undefined unix windows
)
end
def self.variables_string
@variables_string ||= %w(
praatVersion$ tab$ shellDirectory$ homeDirectory$
preferencesDirectory$ newline$ temporaryDirectory$
defaultDirectory$
)
end
def self.object_attributes
@object_attributes ||= %w(
ncol nrow xmin ymin xmax ymax nx ny dx dy
)
end
state :root do
rule %r/(\s+)(#.*?$)/ do
groups Text, Comment::Single
end
rule %r/^#.*?$/, Comment::Single
rule %r/;[^\n]*/, Comment::Single
rule %r/\s+/, Text
rule %r/(\bprocedure)(\s+)/ do
groups Keyword, Text
push :procedure_definition
end
rule %r/(\bcall)(\s+)/ do
groups Keyword, Text
push :procedure_call
end
rule %r/@/, Name::Function, :procedure_call
mixin :function_call
rule %r/\b(?:select all)\b/, Keyword
rule %r/(\bform\b)(\s+)([^\n]+)/ do
groups Keyword, Text, Literal::String
push :old_form
end
rule %r/(print(?:line|tab)?|echo|exit|asserterror|pause|send(?:praat|socket)|include|execute|system(?:_nocheck)?)(\s+)/ do
groups Keyword, Text
push :string_unquoted
end
rule %r/(goto|label)(\s+)(\w+)/ do
groups Keyword, Text, Name::Label
end
mixin :variable_name
mixin :number
mixin :vector_literal
rule %r/"/, Literal::String, :string
rule %r/\b([A-Z][a-zA-Z0-9]+)(?=\s+\S+\n)/ do |m|
match = m[0]
if self.class.objects.include?(match)
token Name::Class
push :string_unquoted
else
token Keyword
end
end
rule %r/\b(?=[A-Z])/, Text, :command
rule %r/(\.{3}|[)(,\$])/, Punctuation
rule %r/[a_z]+/ do |m|
match = m[0]
if self.class.keywords.include?(match)
token Keyword
else
token Text
end
end
end
state :command do
rule %r/( ?([^\s:\.'])+ ?)/, Keyword
mixin :string_interpolated
rule %r/\.{3}/ do
token Keyword
pop!
push :old_arguments
end
rule %r/:/ do
token Keyword
pop!
push :comma_list
end
rule %r/[\s]/, Text, :pop!
end
state :procedure_call do
mixin :string_interpolated
rule %r/(:|\s*\()/, Punctuation, :pop!
rule %r/'/, Name::Function
rule %r/[^:\('\s]+/, Name::Function
rule %r/(?=\s+)/ do
token Text
pop!
push :old_arguments
end
end
state :procedure_definition do
rule %r/(:|\s*\()/, Punctuation, :pop!
rule %r/[^:\(\s]+/, Name::Function
rule %r/(\s+)/, Text, :pop!
end
state :function_call do
rule %r/\b([a-z][a-zA-Z0-9_.]+)(\$#|##|\$|#)?(?=\s*[:(])/ do |m|
match = m[0]
if self.class.functions_builtin.include?(match)
token Name::Function
push :function
elsif self.class.keywords.include?(match)
token Keyword
else
token Operator::Word
end
end
end
state :function do
rule %r/\s+/, Text
rule %r/(?::|\s*\()/ do
token Text
pop!
push :comma_list
end
end
state :comma_list do
rule %r/(\s*\n\s*)(\.{3})/ do
groups Text, Punctuation
end
rule %r/\s*[\]\})\n]/, Text, :pop!
rule %r/\s+/, Text
rule %r/"/, Literal::String, :string
rule %r/\b(if|then|else|fi|endif)\b/, Keyword
mixin :function_call
mixin :variable_name
mixin :operator
mixin :number
mixin :vector_literal
rule %r/[()]/, Text
rule %r/,/, Punctuation
end
state :old_arguments do
rule %r/\n/, Text, :pop!
mixin :variable_name
mixin :operator
mixin :number
rule %r/"/, Literal::String, :string
rule %r/[^\n]/, Text
end
state :number do
rule %r/\n/, Text, :pop!
rule %r/\b\d+(\.\d*)?([eE][-+]?\d+)?%?/, Literal::Number
end
state :variable_name do
mixin :operator
mixin :number
rule %r/\b([A-Z][a-zA-Z0-9]+)_/ do |m|
match = m[1]
if (['Object'] | self.class.objects).include?(match)
token Name::Builtin
push :object_reference
else
token Name::Variable
end
end
rule %r/\.?[a-z][a-zA-Z0-9_.]*(\$#|##|\$|#)?/ do |m|
match = m[0]
if self.class.variables_string.include?(match) ||
self.class.variables_numeric.include?(match)
token Name::Builtin
elsif self.class.keywords.include?(match)
token Keyword
else
token Name::Variable
end
end
rule %r/[\[\]]/, Text, :comma_list
mixin :string_interpolated
end
state :vector_literal do
rule %r/(\{)/, Text, :comma_list
end
state :object_reference do
mixin :string_interpolated
rule %r/([a-z][a-zA-Z0-9_]*|\d+)/, Name::Builtin
rule %r/\.([a-z]+)\b/ do |m|
match = m[1]
if self.class.object_attributes.include?(match)
token Name::Builtin
pop!
end
end
rule %r/\$/, Name::Builtin
rule %r/\[/, Text, :pop!
end
state :operator do
# This rule incorrectly matches === or +++++, which are not operators
rule %r/([+\/*<>=!-]=?|[&*|][&*|]?|\^|<>)/, Operator
rule %r/(?<![\w.])(and|or|not|div|mod)(?![\w.])/, Operator::Word
end
state :string_interpolated do
rule %r/'[\._a-z][^\[\]'":]*(\[([\d,]+|"[\w,]+")\])?(:[0-9]+)?'/, Literal::String::Interpol
end
state :string_unquoted do
rule %r/\n\s*\.{3}/, Punctuation
rule %r/\n/, Text, :pop!
rule %r/\s/, Text
mixin :string_interpolated
rule %r/'/, Literal::String
rule %r/[^'\n]+/, Literal::String
end
state :string do
rule %r/\n\s*\.{3}/, Punctuation
rule %r/"/, Literal::String, :pop!
mixin :string_interpolated
rule %r/'/, Literal::String
rule %r/[^'"\n]+/, Literal::String
end
state :old_form do
rule %r/(\s+)(#.*?$)/ do
groups Text, Comment::Single
end
rule %r/\s+/, Text
rule %r/(optionmenu|choice)([ \t]+\S+:[ \t]+)/ do
groups Keyword, Text
push :number
end
rule %r/(option|button)([ \t]+)/ do
groups Keyword, Text
push :string_unquoted
end
rule %r/(sentence|text)([ \t]+\S+)/ do
groups Keyword, Text
push :string_unquoted
end
rule %r/(word)([ \t]+\S+[ \t]*)(\S+)?([ \t]+.*)?/ do
groups Keyword, Text, Literal::String, Text
end
rule %r/(boolean)(\s+\S+\s*)(0|1|"?(?:yes|no)"?)/ do
groups Keyword, Text, Name::Variable
end
rule %r/(real|natural|positive|integer)([ \t]+\S+[ \t]*)([+-]?)/ do
groups Keyword, Text, Operator
push :number
end
rule %r/(comment)(\s+)/ do
groups Keyword, Text
push :string_unquoted
end
rule %r/\bendform\b/, Keyword, :pop!
end
end
end
end
|