33 (r'(\\)(\n)', bygroups(Whitespace, Text)) |
33 (r'(\\)(\n)', bygroups(Whitespace, Text)) |
34 ], |
34 ], |
35 |
35 |
36 'preprocessor directives': [ |
36 'preprocessor directives': [ |
37 (r'#(?:e(?:nd(?:if)?|lse)\b|##)|@@?[ \t]*\d+', Comment.Preproc), |
37 (r'#(?:e(?:nd(?:if)?|lse)\b|##)|@@?[ \t]*\d+', Comment.Preproc), |
|
38 (r'#includestr', Comment.Preproc, 'includestr directive'), |
38 (r'#include', Comment.Preproc, 'include directive'), |
39 (r'#include', Comment.Preproc, 'include directive'), |
39 (r'#[ \t]*define', Comment.Preproc, 'define directive'), |
40 (r'#[ \t]*define', Comment.Preproc, 'define directive'), |
40 (r'#(?:ifn?def|undef)\b', Comment.Preproc, 'macro directive') |
41 (r'#(?:ifn?def|undef)\b', Comment.Preproc, 'macro directive') |
41 ], |
42 ], |
42 |
43 |
43 'include directive': [ |
44 'include directive': [ |
44 include('whitespace'), |
45 include('whitespace'), |
45 (r'([^ \t]).*?\1', String, '#pop') |
46 (r'([^ \t]).*?\1', String, '#pop') |
|
47 ], |
|
48 'includestr directive': [ |
|
49 include('whitespace'), |
|
50 (r'"', String, ('#pop', 'quoted string')) |
46 ], |
51 ], |
47 |
52 |
48 'define directive': [ |
53 'define directive': [ |
49 (r'\n', Text), |
54 (r'\n', Text), |
50 include('whitespace'), |
55 include('whitespace'), |
112 (r'\d+[Ee][+-]?\d+|(\d+\.\d*|\d*\.\d+)([Ee][+-]?\d+)?', Number.Float), |
117 (r'\d+[Ee][+-]?\d+|(\d+\.\d*|\d*\.\d+)([Ee][+-]?\d+)?', Number.Float), |
113 (r'(0[Xx])([0-9A-Fa-f]+)', bygroups(Keyword.Type, Number.Hex)), |
118 (r'(0[Xx])([0-9A-Fa-f]+)', bygroups(Keyword.Type, Number.Hex)), |
114 (r'\d+', Number.Integer) |
119 (r'\d+', Number.Integer) |
115 ], |
120 ], |
116 |
121 |
|
122 'quoted string': [ |
|
123 (r'"', String, '#pop'), |
|
124 (r'[^"$]+', String), |
|
125 include('macro uses'), |
|
126 (r'[$]', String) |
|
127 ], |
|
128 |
117 'braced string': [ |
129 'braced string': [ |
118 # Do nothing. This must be defined in subclasses. |
130 # Do nothing. This must be defined in subclasses. |
119 ] |
131 ] |
120 } |
132 } |
121 |
133 |
122 |
134 |
123 class CsoundScoreLexer(CsoundLexer): |
135 class CsoundScoreLexer(CsoundLexer): |
124 """ |
136 """ |
125 For `Csound <https://csound.github.io>`_ scores. |
137 For `Csound <https://csound.com>`_ scores. |
126 |
138 |
127 .. versionadded:: 2.1 |
139 .. versionadded:: 2.1 |
128 """ |
140 """ |
129 |
141 |
130 name = 'Csound Score' |
142 name = 'Csound Score' |
142 # used; see https://github.com/csound/csound/issues/750. |
154 # used; see https://github.com/csound/csound/issues/750. |
143 |
155 |
144 (r'z', Keyword.Constant), |
156 (r'z', Keyword.Constant), |
145 # z is a constant equal to 800,000,000,000. 800 billion seconds is about |
157 # z is a constant equal to 800,000,000,000. 800 billion seconds is about |
146 # 25,367.8 years. See also |
158 # 25,367.8 years. See also |
147 # https://csound.github.io/docs/manual/ScoreTop.html and |
159 # https://csound.com/docs/manual/ScoreTop.html and |
148 # https://github.com/csound/csound/search?q=stof+path%3AEngine+filename%3Asread.c. |
160 # https://github.com/csound/csound/search?q=stof+path%3AEngine+filename%3Asread.c. |
149 |
161 |
150 (r'([nNpP][pP])(\d+)', bygroups(Keyword, Number.Integer)), |
162 (r'([nNpP][pP])(\d+)', bygroups(Keyword, Number.Integer)), |
151 |
163 |
152 (r'[mn]', Keyword, 'mark statement'), |
164 (r'[mn]', Keyword, 'mark statement'), |
162 include('whitespace and macro uses'), |
174 include('whitespace and macro uses'), |
163 (r'[A-Z_a-z]\w*', Name.Label), |
175 (r'[A-Z_a-z]\w*', Name.Label), |
164 (r'\n', Text, '#pop') |
176 (r'\n', Text, '#pop') |
165 ], |
177 ], |
166 |
178 |
167 'quoted string': [ |
|
168 (r'"', String, '#pop'), |
|
169 (r'[^"$]+', String), |
|
170 include('macro uses'), |
|
171 (r'[$]', String) |
|
172 ], |
|
173 |
|
174 'loop after left brace': [ |
179 'loop after left brace': [ |
175 include('whitespace and macro uses'), |
180 include('whitespace and macro uses'), |
176 (r'\d+', Number.Integer, ('#pop', 'loop after repeat count')), |
181 (r'\d+', Number.Integer, ('#pop', 'loop after repeat count')), |
177 ], |
182 ], |
178 'loop after repeat count': [ |
183 'loop after repeat count': [ |
182 'loop': [ |
187 'loop': [ |
183 (r'\}', Comment.Preproc, '#pop'), |
188 (r'\}', Comment.Preproc, '#pop'), |
184 include('root') |
189 include('root') |
185 ], |
190 ], |
186 |
191 |
187 # Braced strings are not allowed in Csound scores, but this is needed |
192 # Braced strings are not allowed in Csound scores, but this is needed because the |
188 # because the superclass includes it. |
193 # superclass includes it. |
189 'braced string': [ |
194 'braced string': [ |
190 (r'\}\}', String, '#pop'), |
195 (r'\}\}', String, '#pop'), |
191 (r'[^}]|\}(?!\})', String) |
196 (r'[^}]|\}(?!\})', String) |
192 ] |
197 ] |
193 } |
198 } |
194 |
199 |
195 |
200 |
196 class CsoundOrchestraLexer(CsoundLexer): |
201 class CsoundOrchestraLexer(CsoundLexer): |
197 """ |
202 """ |
198 For `Csound <https://csound.github.io>`_ orchestras. |
203 For `Csound <https://csound.com>`_ orchestras. |
199 |
204 |
200 .. versionadded:: 2.1 |
205 .. versionadded:: 2.1 |
201 """ |
206 """ |
202 |
207 |
203 name = 'Csound Orchestra' |
208 name = 'Csound Orchestra' |
210 opcode = match.group(0) |
215 opcode = match.group(0) |
211 lexer.user_defined_opcodes.add(opcode) |
216 lexer.user_defined_opcodes.add(opcode) |
212 yield match.start(), Name.Function, opcode |
217 yield match.start(), Name.Function, opcode |
213 |
218 |
214 def name_callback(lexer, match): |
219 def name_callback(lexer, match): |
|
220 type_annotation_token = Keyword.Type |
|
221 |
215 name = match.group(1) |
222 name = match.group(1) |
216 if name in OPCODES or name in DEPRECATED_OPCODES: |
223 if name in OPCODES or name in DEPRECATED_OPCODES: |
217 yield match.start(), Name.Builtin, name |
224 yield match.start(), Name.Builtin, name |
218 if match.group(2): |
|
219 yield match.start(2), Punctuation, match.group(2) |
|
220 yield match.start(3), Keyword.Type, match.group(3) |
|
221 elif name in lexer.user_defined_opcodes: |
225 elif name in lexer.user_defined_opcodes: |
222 yield match.start(), Name.Function, name |
226 yield match.start(), Name.Function, name |
223 else: |
227 else: |
224 nameMatch = re.search(r'^(g?[afikSw])(\w+)', name) |
228 type_annotation_token = Name |
225 if nameMatch: |
229 name_match = re.search(r'^(g?[afikSw])(\w+)', name) |
226 yield nameMatch.start(1), Keyword.Type, nameMatch.group(1) |
230 if name_match: |
227 yield nameMatch.start(2), Name, nameMatch.group(2) |
231 yield name_match.start(1), Keyword.Type, name_match.group(1) |
|
232 yield name_match.start(2), Name, name_match.group(2) |
228 else: |
233 else: |
229 yield match.start(), Name, name |
234 yield match.start(), Name, name |
230 if match.group(2): |
235 |
231 yield match.start(2), Punctuation, match.group(2) |
236 if match.group(2): |
232 yield match.start(3), Name, match.group(3) |
237 yield match.start(2), Punctuation, match.group(2) |
|
238 yield match.start(3), type_annotation_token, match.group(3) |
233 |
239 |
234 tokens = { |
240 tokens = { |
235 'root': [ |
241 'root': [ |
236 (r'\n', Text), |
242 (r'\n', Text), |
237 |
243 |
322 'escape sequences': [ |
328 'escape sequences': [ |
323 # https://github.com/csound/csound/search?q=unquote_string+path%3AEngine+filename%3Acsound_orc_compile.c |
329 # https://github.com/csound/csound/search?q=unquote_string+path%3AEngine+filename%3Acsound_orc_compile.c |
324 (r'\\(?:[\\abnrt"]|[0-7]{1,3})', String.Escape) |
330 (r'\\(?:[\\abnrt"]|[0-7]{1,3})', String.Escape) |
325 ], |
331 ], |
326 # Format specifiers are highlighted in all strings, even though only |
332 # Format specifiers are highlighted in all strings, even though only |
327 # fprintks https://csound.github.io/docs/manual/fprintks.html |
333 # fprintks https://csound.com/docs/manual/fprintks.html |
328 # fprints https://csound.github.io/docs/manual/fprints.html |
334 # fprints https://csound.com/docs/manual/fprints.html |
329 # printf/printf_i https://csound.github.io/docs/manual/printf.html |
335 # printf/printf_i https://csound.com/docs/manual/printf.html |
330 # printks https://csound.github.io/docs/manual/printks.html |
336 # printks https://csound.com/docs/manual/printks.html |
331 # prints https://csound.github.io/docs/manual/prints.html |
337 # prints https://csound.com/docs/manual/prints.html |
332 # sprintf https://csound.github.io/docs/manual/sprintf.html |
338 # sprintf https://csound.com/docs/manual/sprintf.html |
333 # sprintfk https://csound.github.io/docs/manual/sprintfk.html |
339 # sprintfk https://csound.com/docs/manual/sprintfk.html |
334 # work with strings that contain format specifiers. In addition, these |
340 # work with strings that contain format specifiers. In addition, these opcodes’ |
335 # opcodes’ handling of format specifiers is inconsistent: |
341 # handling of format specifiers is inconsistent: |
336 # - fprintks, fprints, printks, and prints do accept %a and %A |
342 # - fprintks, fprints, printks, and prints do accept %a and %A |
337 # specifiers, but can’t accept %s specifiers. |
343 # specifiers, but can’t accept %s specifiers. |
338 # - printf, printf_i, sprintf, and sprintfk don’t accept %a and %A |
344 # - printf, printf_i, sprintf, and sprintfk don’t accept %a and %A |
339 # specifiers, but can accept %s specifiers. |
345 # specifiers, but can accept %s specifiers. |
340 # See https://github.com/csound/csound/issues/747 for more information. |
346 # See https://github.com/csound/csound/issues/747 for more information. |
365 include('quoted string') |
371 include('quoted string') |
366 ], |
372 ], |
367 |
373 |
368 'Csound score opcode': [ |
374 'Csound score opcode': [ |
369 include('whitespace and macro uses'), |
375 include('whitespace and macro uses'), |
|
376 (r'"', String, 'quoted string'), |
370 (r'\{\{', String, 'Csound score'), |
377 (r'\{\{', String, 'Csound score'), |
371 (r'\n', Text, '#pop') |
378 (r'\n', Text, '#pop') |
372 ], |
379 ], |
373 'Csound score': [ |
380 'Csound score': [ |
374 (r'\}\}', String, '#pop'), |
381 (r'\}\}', String, '#pop'), |
375 (r'([^}]+)|\}(?!\})', using(CsoundScoreLexer)) |
382 (r'([^}]+)|\}(?!\})', using(CsoundScoreLexer)) |
376 ], |
383 ], |
377 |
384 |
378 'Python opcode': [ |
385 'Python opcode': [ |
379 include('whitespace and macro uses'), |
386 include('whitespace and macro uses'), |
|
387 (r'"', String, 'quoted string'), |
380 (r'\{\{', String, 'Python'), |
388 (r'\{\{', String, 'Python'), |
381 (r'\n', Text, '#pop') |
389 (r'\n', Text, '#pop') |
382 ], |
390 ], |
383 'Python': [ |
391 'Python': [ |
384 (r'\}\}', String, '#pop'), |
392 (r'\}\}', String, '#pop'), |
385 (r'([^}]+)|\}(?!\})', using(PythonLexer)) |
393 (r'([^}]+)|\}(?!\})', using(PythonLexer)) |
386 ], |
394 ], |
387 |
395 |
388 'Lua opcode': [ |
396 'Lua opcode': [ |
389 include('whitespace and macro uses'), |
397 include('whitespace and macro uses'), |
|
398 (r'"', String, 'quoted string'), |
390 (r'\{\{', String, 'Lua'), |
399 (r'\{\{', String, 'Lua'), |
391 (r'\n', Text, '#pop') |
400 (r'\n', Text, '#pop') |
392 ], |
401 ], |
393 'Lua': [ |
402 'Lua': [ |
394 (r'\}\}', String, '#pop'), |
403 (r'\}\}', String, '#pop'), |