eric6/ThirdParty/Pygments/pygments/lexers/praat.py

changeset 8258
82b608e352ec
parent 8257
28146736bbfc
child 8259
2bbec88047dd
equal deleted inserted replaced
8257:28146736bbfc 8258:82b608e352ec
1 # -*- coding: utf-8 -*-
2 """
3 pygments.lexers.praat
4 ~~~~~~~~~~~~~~~~~~~~~
5
6 Lexer for Praat
7
8 :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details.
10 """
11
12 from pygments.lexer import RegexLexer, words, bygroups, include
13 from pygments.token import Name, Text, Comment, Keyword, String, Punctuation, Number, \
14 Operator
15
16 __all__ = ['PraatLexer']
17
18
19 class PraatLexer(RegexLexer):
20 """
21 For `Praat <http://www.praat.org>`_ scripts.
22
23 .. versionadded:: 2.1
24 """
25
26 name = 'Praat'
27 aliases = ['praat']
28 filenames = ['*.praat', '*.proc', '*.psc']
29
30 keywords = (
31 'if', 'then', 'else', 'elsif', 'elif', 'endif', 'fi', 'for', 'from', 'to',
32 'endfor', 'endproc', 'while', 'endwhile', 'repeat', 'until', 'select', 'plus',
33 'minus', 'demo', 'assert', 'stopwatch', 'nocheck', 'nowarn', 'noprogress',
34 'editor', 'endeditor', 'clearinfo',
35 )
36
37 functions_string = (
38 'backslashTrigraphsToUnicode', 'chooseDirectory', 'chooseReadFile',
39 'chooseWriteFile', 'date', 'demoKey', 'do', 'environment', 'extractLine',
40 'extractWord', 'fixed', 'info', 'left', 'mid', 'percent', 'readFile', 'replace',
41 'replace_regex', 'right', 'selected', 'string', 'unicodeToBackslashTrigraphs',
42 )
43
44 functions_numeric = (
45 'abs', 'appendFile', 'appendFileLine', 'appendInfo', 'appendInfoLine', 'arccos',
46 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'barkToHertz',
47 'beginPause', 'beginSendPraat', 'besselI', 'besselK', 'beta', 'beta2',
48 'binomialP', 'binomialQ', 'boolean', 'ceiling', 'chiSquareP', 'chiSquareQ',
49 'choice', 'comment', 'cos', 'cosh', 'createDirectory', 'deleteFile',
50 'demoClicked', 'demoClickedIn', 'demoCommandKeyPressed',
51 'demoExtraControlKeyPressed', 'demoInput', 'demoKeyPressed',
52 'demoOptionKeyPressed', 'demoShiftKeyPressed', 'demoShow', 'demoWaitForInput',
53 'demoWindowTitle', 'demoX', 'demoY', 'differenceLimensToPhon', 'do', 'editor',
54 'endPause', 'endSendPraat', 'endsWith', 'erb', 'erbToHertz', 'erf', 'erfc',
55 'exitScript', 'exp', 'extractNumber', 'fileReadable', 'fisherP', 'fisherQ',
56 'floor', 'gaussP', 'gaussQ', 'hertzToBark', 'hertzToErb', 'hertzToMel',
57 'hertzToSemitones', 'imax', 'imin', 'incompleteBeta', 'incompleteGammaP', 'index',
58 'index_regex', 'integer', 'invBinomialP', 'invBinomialQ', 'invChiSquareQ', 'invFisherQ',
59 'invGaussQ', 'invSigmoid', 'invStudentQ', 'length', 'ln', 'lnBeta', 'lnGamma',
60 'log10', 'log2', 'max', 'melToHertz', 'min', 'minusObject', 'natural', 'number',
61 'numberOfColumns', 'numberOfRows', 'numberOfSelected', 'objectsAreIdentical',
62 'option', 'optionMenu', 'pauseScript', 'phonToDifferenceLimens', 'plusObject',
63 'positive', 'randomBinomial', 'randomGauss', 'randomInteger', 'randomPoisson',
64 'randomUniform', 'real', 'readFile', 'removeObject', 'rindex', 'rindex_regex',
65 'round', 'runScript', 'runSystem', 'runSystem_nocheck', 'selectObject',
66 'selected', 'semitonesToHertz', 'sentence', 'sentencetext', 'sigmoid', 'sin', 'sinc',
67 'sincpi', 'sinh', 'soundPressureToPhon', 'sqrt', 'startsWith', 'studentP',
68 'studentQ', 'tan', 'tanh', 'text', 'variableExists', 'word', 'writeFile', 'writeFileLine',
69 'writeInfo', 'writeInfoLine',
70 )
71
72 functions_array = (
73 'linear', 'randomGauss', 'randomInteger', 'randomUniform', 'zero',
74 )
75
76 objects = (
77 'Activation', 'AffineTransform', 'AmplitudeTier', 'Art', 'Artword',
78 'Autosegment', 'BarkFilter', 'BarkSpectrogram', 'CCA', 'Categories',
79 'Cepstrogram', 'Cepstrum', 'Cepstrumc', 'ChebyshevSeries', 'ClassificationTable',
80 'Cochleagram', 'Collection', 'ComplexSpectrogram', 'Configuration', 'Confusion',
81 'ContingencyTable', 'Corpus', 'Correlation', 'Covariance',
82 'CrossCorrelationTable', 'CrossCorrelationTables', 'DTW', 'DataModeler',
83 'Diagonalizer', 'Discriminant', 'Dissimilarity', 'Distance', 'Distributions',
84 'DurationTier', 'EEG', 'ERP', 'ERPTier', 'EditCostsTable', 'EditDistanceTable',
85 'Eigen', 'Excitation', 'Excitations', 'ExperimentMFC', 'FFNet', 'FeatureWeights',
86 'FileInMemory', 'FilesInMemory', 'Formant', 'FormantFilter', 'FormantGrid',
87 'FormantModeler', 'FormantPoint', 'FormantTier', 'GaussianMixture', 'HMM',
88 'HMM_Observation', 'HMM_ObservationSequence', 'HMM_State', 'HMM_StateSequence',
89 'Harmonicity', 'ISpline', 'Index', 'Intensity', 'IntensityTier', 'IntervalTier',
90 'KNN', 'KlattGrid', 'KlattTable', 'LFCC', 'LPC', 'Label', 'LegendreSeries',
91 'LinearRegression', 'LogisticRegression', 'LongSound', 'Ltas', 'MFCC', 'MSpline',
92 'ManPages', 'Manipulation', 'Matrix', 'MelFilter', 'MelSpectrogram',
93 'MixingMatrix', 'Movie', 'Network', 'Object', 'OTGrammar', 'OTHistory', 'OTMulti',
94 'PCA', 'PairDistribution', 'ParamCurve', 'Pattern', 'Permutation', 'Photo',
95 'Pitch', 'PitchModeler', 'PitchTier', 'PointProcess', 'Polygon', 'Polynomial',
96 'PowerCepstrogram', 'PowerCepstrum', 'Procrustes', 'RealPoint', 'RealTier',
97 'ResultsMFC', 'Roots', 'SPINET', 'SSCP', 'SVD', 'Salience', 'ScalarProduct',
98 'Similarity', 'SimpleString', 'SortedSetOfString', 'Sound', 'Speaker',
99 'Spectrogram', 'Spectrum', 'SpectrumTier', 'SpeechSynthesizer', 'SpellingChecker',
100 'Strings', 'StringsIndex', 'Table', 'TableOfReal', 'TextGrid', 'TextInterval',
101 'TextPoint', 'TextTier', 'Tier', 'Transition', 'VocalTract', 'VocalTractTier',
102 'Weight', 'WordList',
103 )
104
105 variables_numeric = (
106 'macintosh', 'windows', 'unix', 'praatVersion', 'pi', 'e', 'undefined',
107 )
108
109 variables_string = (
110 'praatVersion', 'tab', 'shellDirectory', 'homeDirectory',
111 'preferencesDirectory', 'newline', 'temporaryDirectory',
112 'defaultDirectory',
113 )
114
115 object_attributes = (
116 'ncol', 'nrow', 'xmin', 'ymin', 'xmax', 'ymax', 'nx', 'ny', 'dx', 'dy',
117 )
118
119 tokens = {
120 'root': [
121 (r'(\s+)(#.*?$)', bygroups(Text, Comment.Single)),
122 (r'^#.*?$', Comment.Single),
123 (r';[^\n]*', Comment.Single),
124 (r'\s+', Text),
125
126 (r'\bprocedure\b', Keyword, 'procedure_definition'),
127 (r'\bcall\b', Keyword, 'procedure_call'),
128 (r'@', Name.Function, 'procedure_call'),
129
130 include('function_call'),
131
132 (words(keywords, suffix=r'\b'), Keyword),
133
134 (r'(\bform\b)(\s+)([^\n]+)',
135 bygroups(Keyword, Text, String), 'old_form'),
136
137 (r'(print(?:line|tab)?|echo|exit|asserterror|pause|send(?:praat|socket)|'
138 r'include|execute|system(?:_nocheck)?)(\s+)',
139 bygroups(Keyword, Text), 'string_unquoted'),
140
141 (r'(goto|label)(\s+)(\w+)', bygroups(Keyword, Text, Name.Label)),
142
143 include('variable_name'),
144 include('number'),
145
146 (r'"', String, 'string'),
147
148 (words((objects), suffix=r'(?=\s+\S+\n)'), Name.Class, 'string_unquoted'),
149
150 (r'\b[A-Z]', Keyword, 'command'),
151 (r'(\.{3}|[)(,])', Punctuation),
152 ],
153 'command': [
154 (r'( ?[\w()-]+ ?)', Keyword),
155
156 include('string_interpolated'),
157
158 (r'\.{3}', Keyword, ('#pop', 'old_arguments')),
159 (r':', Keyword, ('#pop', 'comma_list')),
160 (r'\s', Text, '#pop'),
161 ],
162 'procedure_call': [
163 (r'\s+', Text),
164 (r'([\w.]+)(:|\s*\()',
165 bygroups(Name.Function, Text), '#pop'),
166 (r'([\w.]+)', Name.Function, ('#pop', 'old_arguments')),
167 ],
168 'procedure_definition': [
169 (r'\s', Text),
170 (r'([\w.]+)(\s*?[(:])',
171 bygroups(Name.Function, Text), '#pop'),
172 (r'([\w.]+)([^\n]*)',
173 bygroups(Name.Function, Text), '#pop'),
174 ],
175 'function_call': [
176 (words(functions_string, suffix=r'\$(?=\s*[:(])'), Name.Function, 'function'),
177 (words(functions_array, suffix=r'#(?=\s*[:(])'), Name.Function, 'function'),
178 (words(functions_numeric, suffix=r'(?=\s*[:(])'), Name.Function, 'function'),
179 ],
180 'function': [
181 (r'\s+', Text),
182 (r':', Punctuation, ('#pop', 'comma_list')),
183 (r'\s*\(', Punctuation, ('#pop', 'comma_list')),
184 ],
185 'comma_list': [
186 (r'(\s*\n\s*)(\.{3})', bygroups(Text, Punctuation)),
187
188 (r'(\s*[])\n])', Text, '#pop'),
189
190 (r'\s+', Text),
191 (r'"', String, 'string'),
192 (r'\b(if|then|else|fi|endif)\b', Keyword),
193
194 include('function_call'),
195 include('variable_name'),
196 include('operator'),
197 include('number'),
198
199 (r'[()]', Text),
200 (r',', Punctuation),
201 ],
202 'old_arguments': [
203 (r'\n', Text, '#pop'),
204
205 include('variable_name'),
206 include('operator'),
207 include('number'),
208
209 (r'"', String, 'string'),
210 (r'[^\n]', Text),
211 ],
212 'number': [
213 (r'\n', Text, '#pop'),
214 (r'\b\d+(\.\d*)?([eE][-+]?\d+)?%?', Number),
215 ],
216 'object_reference': [
217 include('string_interpolated'),
218 (r'([a-z][a-zA-Z0-9_]*|\d+)', Name.Builtin),
219
220 (words(object_attributes, prefix=r'\.'), Name.Builtin, '#pop'),
221
222 (r'\$', Name.Builtin),
223 (r'\[', Text, '#pop'),
224 ],
225 'variable_name': [
226 include('operator'),
227 include('number'),
228
229 (words(variables_string, suffix=r'\$'), Name.Variable.Global),
230 (words(variables_numeric,
231 suffix=r'(?=[^a-zA-Z0-9_."\'$#\[:(]|\s|^|$)'),
232 Name.Variable.Global),
233
234 (words(objects, prefix=r'\b', suffix=r"(_)"),
235 bygroups(Name.Builtin, Name.Builtin),
236 'object_reference'),
237
238 (r'\.?_?[a-z][\w.]*(\$|#)?', Text),
239 (r'[\[\]]', Punctuation, 'comma_list'),
240
241 include('string_interpolated'),
242 ],
243 'operator': [
244 (r'([+\/*<>=!-]=?|[&*|][&*|]?|\^|<>)', Operator),
245 (r'(?<![\w.])(and|or|not|div|mod)(?![\w.])', Operator.Word),
246 ],
247 'string_interpolated': [
248 (r'\'[_a-z][^\[\]\'":]*(\[([\d,]+|"[\w,]+")\])?(:[0-9]+)?\'',
249 String.Interpol),
250 ],
251 'string_unquoted': [
252 (r'(\n\s*)(\.{3})', bygroups(Text, Punctuation)),
253
254 (r'\n', Text, '#pop'),
255 (r'\s', Text),
256
257 include('string_interpolated'),
258
259 (r"'", String),
260 (r"[^'\n]+", String),
261 ],
262 'string': [
263 (r'(\n\s*)(\.{3})', bygroups(Text, Punctuation)),
264
265 (r'"', String, '#pop'),
266
267 include('string_interpolated'),
268
269 (r"'", String),
270 (r'[^\'"\n]+', String),
271 ],
272 'old_form': [
273 (r'(\s+)(#.*?$)', bygroups(Text, Comment.Single)),
274 (r'\s+', Text),
275
276 (r'(optionmenu|choice)([ \t]+\S+:[ \t]+)',
277 bygroups(Keyword, Text), 'number'),
278
279 (r'(option|button)([ \t]+)',
280 bygroups(Keyword, Text), 'string_unquoted'),
281
282 (r'(sentence|text)([ \t]+\S+)',
283 bygroups(Keyword, Text), 'string_unquoted'),
284
285 (r'(word)([ \t]+\S+[ \t]*)(\S+)?([ \t]+.*)?',
286 bygroups(Keyword, Text, String, Text)),
287
288 (r'(boolean)(\s+\S+\s*)(0|1|"?(?:yes|no)"?)',
289 bygroups(Keyword, Text, Name.Variable)),
290
291 # Ideally processing of the number would happend in the 'number'
292 # but that doesn't seem to work
293 (r'(real|natural|positive|integer)([ \t]+\S+[ \t]*)([+-]?)(\d+(?:\.\d*)?'
294 r'(?:[eE][-+]?\d+)?%?)',
295 bygroups(Keyword, Text, Operator, Number)),
296
297 (r'(comment)(\s+)',
298 bygroups(Keyword, Text), 'string_unquoted'),
299
300 (r'\bendform\b', Keyword, '#pop'),
301 ]
302 }

eric ide

mercurial