ThirdParty/Pygments/pygments/lexers/csound.py

changeset 5713
6762afd9f963
parent 4697
c2e9bf425554
child 6651
e8f3b5568b21
equal deleted inserted replaced
5712:f0d08bdeacf4 5713:6762afd9f963
3 pygments.lexers.csound 3 pygments.lexers.csound
4 ~~~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for CSound languages. 6 Lexers for CSound languages.
7 7
8 :copyright: Copyright 2006-2015 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2017 by the Pygments team, see AUTHORS.
9 :license: BSD, see LICENSE for details. 9 :license: BSD, see LICENSE for details.
10 """ 10 """
11 11
12 import copy, re 12 import re
13 13
14 from pygments.lexer import RegexLexer, bygroups, default, include, using, words 14 from pygments.lexer import RegexLexer, bygroups, default, include, using, words
15 from pygments.token import Comment, Keyword, Name, Number, Operator, Punctuation, \ 15 from pygments.token import Comment, Keyword, Name, Number, Operator, Punctuation, \
16 String, Text 16 String, Text
17 from pygments.lexers._csound_builtins import OPCODES 17 from pygments.lexers._csound_builtins import OPCODES
19 from pygments.lexers.python import PythonLexer 19 from pygments.lexers.python import PythonLexer
20 from pygments.lexers.scripting import LuaLexer 20 from pygments.lexers.scripting import LuaLexer
21 21
22 __all__ = ['CsoundScoreLexer', 'CsoundOrchestraLexer', 'CsoundDocumentLexer'] 22 __all__ = ['CsoundScoreLexer', 'CsoundOrchestraLexer', 'CsoundDocumentLexer']
23 23
24 newline = (r'((?:;|//).*)*(\n)', bygroups(Comment.Single, Text)) 24 newline = (r'((?:(?:;|//).*)*)(\n)', bygroups(Comment.Single, Text))
25 25
26 26
27 class CsoundLexer(RegexLexer): 27 class CsoundLexer(RegexLexer):
28 # Subclasses must define a 'single-line string' state. 28 # Subclasses must define a 'single-line string' state.
29 tokens = { 29 tokens = {
175 (r'\b(0dbfs|k(r|smps)|nchnls(_i)?|sr)\b', Name.Variable.Global), 175 (r'\b(0dbfs|k(r|smps)|nchnls(_i)?|sr)\b', Name.Variable.Global),
176 (r'\d+e[+-]?\d+|(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?', Number.Float), 176 (r'\d+e[+-]?\d+|(\d+\.\d*|\d*\.\d+)(e[+-]?\d+)?', Number.Float),
177 (r'0[xX][a-fA-F0-9]+', Number.Hex), 177 (r'0[xX][a-fA-F0-9]+', Number.Hex),
178 (r'\d+', Number.Integer), 178 (r'\d+', Number.Integer),
179 (r'"', String, 'single-line string'), 179 (r'"', String, 'single-line string'),
180 (r'{{', String, 'multi-line string'), 180 (r'\{\{', String, 'multi-line string'),
181 (r'[+\-*/%^!=&|<>#~¬]', Operator), 181 (r'[+\-*/%^!=&|<>#~¬]', Operator),
182 (r'[](),?:[]', Punctuation), 182 (r'[](),?:[]', Punctuation),
183 (words(( 183 (words((
184 # Keywords 184 # Keywords
185 'do', 'else', 'elseif', 'endif', 'enduntil', 'fi', 'if', 'ithen', 'kthen', 185 'do', 'else', 'elseif', 'endif', 'enduntil', 'fi', 'if', 'ithen', 'kthen',
271 (r'%[!%nNrRtT]|[~^]|\\([\\aAbBnNrRtT"]|[0-7]{1,3})', String.Escape), 271 (r'%[!%nNrRtT]|[~^]|\\([\\aAbBnNrRtT"]|[0-7]{1,3})', String.Escape),
272 (r'[^\\"~$%\^\n]+', String), 272 (r'[^\\"~$%\^\n]+', String),
273 (r'[\\"~$%\^\n]', String) 273 (r'[\\"~$%\^\n]', String)
274 ], 274 ],
275 'multi-line string': [ 275 'multi-line string': [
276 (r'}}', String, '#pop'), 276 (r'\}\}', String, '#pop'),
277 (r'[^\}]+|\}(?!\})', String) 277 (r'[^}]+|\}(?!\})', String)
278 ], 278 ],
279 279
280 'scoreline opcode': [ 280 'scoreline opcode': [
281 include('whitespace or macro call'), 281 include('whitespace or macro call'),
282 (r'{{', String, 'scoreline'), 282 (r'\{\{', String, 'scoreline'),
283 default('#pop') 283 default('#pop')
284 ], 284 ],
285 'scoreline': [ 285 'scoreline': [
286 (r'}}', String, '#pop'), 286 (r'\}\}', String, '#pop'),
287 (r'([^\}]+)|\}(?!\})', using(CsoundScoreLexer)) 287 (r'([^}]+)|\}(?!\})', using(CsoundScoreLexer))
288 ], 288 ],
289 289
290 'python opcode': [ 290 'python opcode': [
291 include('whitespace or macro call'), 291 include('whitespace or macro call'),
292 (r'{{', String, 'python'), 292 (r'\{\{', String, 'python'),
293 default('#pop') 293 default('#pop')
294 ], 294 ],
295 'python': [ 295 'python': [
296 (r'}}', String, '#pop'), 296 (r'\}\}', String, '#pop'),
297 (r'([^\}]+)|\}(?!\})', using(PythonLexer)) 297 (r'([^}]+)|\}(?!\})', using(PythonLexer))
298 ], 298 ],
299 299
300 'lua opcode': [ 300 'lua opcode': [
301 include('whitespace or macro call'), 301 include('whitespace or macro call'),
302 (r'"', String, 'single-line string'), 302 (r'"', String, 'single-line string'),
303 (r'{{', String, 'lua'), 303 (r'\{\{', String, 'lua'),
304 (r',', Punctuation), 304 (r',', Punctuation),
305 default('#pop') 305 default('#pop')
306 ], 306 ],
307 'lua': [ 307 'lua': [
308 (r'}}', String, '#pop'), 308 (r'\}\}', String, '#pop'),
309 (r'([^\}]+)|\}(?!\})', using(LuaLexer)) 309 (r'([^}]+)|\}(?!\})', using(LuaLexer))
310 ] 310 ]
311 } 311 }
312 312
313 313
314 class CsoundDocumentLexer(RegexLexer): 314 class CsoundDocumentLexer(RegexLexer):
315 """ 315 """
316 For `Csound <http://csound.github.io>`_ documents. 316 For `Csound <http://csound.github.io>`_ documents.
317 317
318 318 .. versionadded:: 2.1
319 """ 319 """
320 320
321 name = 'Csound Document' 321 name = 'Csound Document'
322 aliases = ['csound-document', 'csound-csd'] 322 aliases = ['csound-document', 'csound-csd']
323 filenames = ['*.csd'] 323 filenames = ['*.csd']

eric ide

mercurial