Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/pygments/lexers/praat.py: 100%

17 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-06-07 06:16 +0000

1""" 

2 pygments.lexers.praat 

3 ~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexer for Praat 

6 

7 :copyright: Copyright 2006-2023 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, words, bygroups, include 

12from pygments.token import Name, Text, Comment, Keyword, String, Punctuation, \ 

13 Number, Operator, Whitespace 

14 

15__all__ = ['PraatLexer'] 

16 

17 

18class PraatLexer(RegexLexer): 

19 """ 

20 For Praat scripts. 

21 

22 .. versionadded:: 2.1 

23 """ 

24 

25 name = 'Praat' 

26 url = 'http://www.praat.org' 

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(Whitespace, Comment.Single)), 

122 (r'^#.*?$', Comment.Single), 

123 (r';[^\n]*', Comment.Single), 

124 (r'\s+', Whitespace), 

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, Whitespace, 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, Whitespace), 'string_unquoted'), 

140 

141 (r'(goto|label)(\s+)(\w+)', bygroups(Keyword, Whitespace, 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', Whitespace, '#pop'), 

161 ], 

162 'procedure_call': [ 

163 (r'\s+', Whitespace), 

164 (r'([\w.]+)(?:(:)|(?:(\s*)(\()))', 

165 bygroups(Name.Function, Punctuation, 

166 Text.Whitespace, Punctuation), '#pop'), 

167 (r'([\w.]+)', Name.Function, ('#pop', 'old_arguments')), 

168 ], 

169 'procedure_definition': [ 

170 (r'\s', Whitespace), 

171 (r'([\w.]+)(\s*?[(:])', 

172 bygroups(Name.Function, Whitespace), '#pop'), 

173 (r'([\w.]+)([^\n]*)', 

174 bygroups(Name.Function, Text), '#pop'), 

175 ], 

176 'function_call': [ 

177 (words(functions_string, suffix=r'\$(?=\s*[:(])'), Name.Function, 'function'), 

178 (words(functions_array, suffix=r'#(?=\s*[:(])'), Name.Function, 'function'), 

179 (words(functions_numeric, suffix=r'(?=\s*[:(])'), Name.Function, 'function'), 

180 ], 

181 'function': [ 

182 (r'\s+', Whitespace), 

183 (r':', Punctuation, ('#pop', 'comma_list')), 

184 (r'\s*\(', Punctuation, ('#pop', 'comma_list')), 

185 ], 

186 'comma_list': [ 

187 (r'(\s*\n\s*)(\.{3})', bygroups(Whitespace, Punctuation)), 

188 

189 (r'(\s*)(?:([)\]])|(\n))', bygroups( 

190 Whitespace, Punctuation, Whitespace), '#pop'), 

191 

192 (r'\s+', Whitespace), 

193 (r'"', String, 'string'), 

194 (r'\b(if|then|else|fi|endif)\b', Keyword), 

195 

196 include('function_call'), 

197 include('variable_name'), 

198 include('operator'), 

199 include('number'), 

200 

201 (r'[()]', Text), 

202 (r',', Punctuation), 

203 ], 

204 'old_arguments': [ 

205 (r'\n', Whitespace, '#pop'), 

206 

207 include('variable_name'), 

208 include('operator'), 

209 include('number'), 

210 

211 (r'"', String, 'string'), 

212 (r'[^\n]', Text), 

213 ], 

214 'number': [ 

215 (r'\n', Whitespace, '#pop'), 

216 (r'\b\d+(\.\d*)?([eE][-+]?\d+)?%?', Number), 

217 ], 

218 'object_reference': [ 

219 include('string_interpolated'), 

220 (r'([a-z][a-zA-Z0-9_]*|\d+)', Name.Builtin), 

221 

222 (words(object_attributes, prefix=r'\.'), Name.Builtin, '#pop'), 

223 

224 (r'\$', Name.Builtin), 

225 (r'\[', Text, '#pop'), 

226 ], 

227 'variable_name': [ 

228 include('operator'), 

229 include('number'), 

230 

231 (words(variables_string, suffix=r'\$'), Name.Variable.Global), 

232 (words(variables_numeric, 

233 suffix=r'(?=[^a-zA-Z0-9_."\'$#\[:(]|\s|^|$)'), 

234 Name.Variable.Global), 

235 

236 (words(objects, prefix=r'\b', suffix=r"(_)"), 

237 bygroups(Name.Builtin, Name.Builtin), 

238 'object_reference'), 

239 

240 (r'\.?_?[a-z][\w.]*(\$|#)?', Text), 

241 (r'[\[\]]', Punctuation, 'comma_list'), 

242 

243 include('string_interpolated'), 

244 ], 

245 'operator': [ 

246 (r'([+\/*<>=!-]=?|[&*|][&*|]?|\^|<>)', Operator), 

247 (r'(?<![\w.])(and|or|not|div|mod)(?![\w.])', Operator.Word), 

248 ], 

249 'string_interpolated': [ 

250 (r'\'[_a-z][^\[\]\'":]*(\[([\d,]+|"[\w,]+")\])?(:[0-9]+)?\'', 

251 String.Interpol), 

252 ], 

253 'string_unquoted': [ 

254 (r'(\n\s*)(\.{3})', bygroups(Whitespace, Punctuation)), 

255 

256 (r'\n', Whitespace, '#pop'), 

257 (r'\s', Whitespace), 

258 

259 include('string_interpolated'), 

260 

261 (r"'", String), 

262 (r"[^'\n]+", String), 

263 ], 

264 'string': [ 

265 (r'(\n\s*)(\.{3})', bygroups(Whitespace, Punctuation)), 

266 

267 (r'"', String, '#pop'), 

268 

269 include('string_interpolated'), 

270 

271 (r"'", String), 

272 (r'[^\'"\n]+', String), 

273 ], 

274 'old_form': [ 

275 (r'(\s+)(#.*?$)', bygroups(Whitespace, Comment.Single)), 

276 (r'\s+', Whitespace), 

277 

278 (r'(optionmenu|choice)([ \t]+)(\S+)(:)([ \t]+)', 

279 bygroups(Keyword, Whitespace, Text, Punctuation, Whitespace), 'number'), 

280 

281 (r'(option|button)([ \t]+)', 

282 bygroups(Keyword, Whitespace), 'string_unquoted'), 

283 

284 (r'(sentence|text)([ \t]+)(\S+)', 

285 bygroups(Keyword, Whitespace, String), 'string_unquoted'), 

286 

287 (r'(word)([ \t]+)(\S+)([ \t]*)(\S+)?(?:([ \t]+)(.*))?', 

288 bygroups(Keyword, Whitespace, Text, Whitespace, Text, Whitespace, Text)), 

289 

290 (r'(boolean)(\s+\S+\s*)(0|1|"?(?:yes|no)"?)', 

291 bygroups(Keyword, Whitespace, Name.Variable)), 

292 

293 # Ideally processing of the number would happen in the 'number' 

294 # but that doesn't seem to work 

295 (r'(real|natural|positive|integer)([ \t]+\S+[ \t]*)([+-]?)(\d+(?:\.\d*)?' 

296 r'(?:[eE][-+]?\d+)?%?)', 

297 bygroups(Keyword, Whitespace, Operator, Number)), 

298 

299 (r'(comment)(\s+)', 

300 bygroups(Keyword, Whitespace), 'string_unquoted'), 

301 

302 (r'\bendform\b', Keyword, '#pop'), 

303 ] 

304 }