1 # -*- coding: utf-8 -*- |
1 # -*- coding: utf-8 -*- |
2 """ |
2 """ |
3 pygments.lexers.math |
3 pygments.lexers.math |
4 ~~~~~~~~~~~~~~~~~~~~ |
4 ~~~~~~~~~~~~~~~~~~~~ |
5 |
5 |
6 Lexers for math languages. |
6 Just export lexers that were contained in this module. |
7 |
7 |
8 :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS. |
8 :copyright: Copyright 2006-2014 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 from __future__ import unicode_literals |
12 from pygments.lexers.python import NumPyLexer |
|
13 from pygments.lexers.matlab import MatlabLexer, MatlabSessionLexer, \ |
|
14 OctaveLexer, ScilabLexer |
|
15 from pygments.lexers.julia import JuliaLexer, JuliaConsoleLexer |
|
16 from pygments.lexers.r import RConsoleLexer, SLexer, RdLexer |
|
17 from pygments.lexers.modeling import BugsLexer, JagsLexer, StanLexer |
|
18 from pygments.lexers.idl import IDLLexer |
|
19 from pygments.lexers.algebra import MuPADLexer |
13 |
20 |
14 import re |
21 __all__ = [] |
15 |
|
16 from pygments.util import shebang_matches |
|
17 from pygments.lexer import Lexer, RegexLexer, bygroups, include, \ |
|
18 combined, do_insertions |
|
19 from pygments.token import Comment, String, Punctuation, Keyword, Name, \ |
|
20 Operator, Number, Text, Generic |
|
21 |
|
22 from pygments.lexers.agile import PythonLexer |
|
23 from pygments.lexers import _scilab_builtins |
|
24 from pygments.lexers import _stan_builtins |
|
25 |
|
26 __all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer', |
|
27 'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer', |
|
28 'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer', |
|
29 'IDLLexer', 'RdLexer'] |
|
30 |
|
31 |
|
32 class JuliaLexer(RegexLexer): |
|
33 """ |
|
34 For `Julia <http://julialang.org/>`_ source code. |
|
35 |
|
36 *New in Pygments 1.6.* |
|
37 """ |
|
38 name = 'Julia' |
|
39 aliases = ['julia','jl'] |
|
40 filenames = ['*.jl'] |
|
41 mimetypes = ['text/x-julia','application/x-julia'] |
|
42 |
|
43 builtins = [ |
|
44 'exit','whos','edit','load','is','isa','isequal','typeof','tuple', |
|
45 'ntuple','uid','hash','finalizer','convert','promote','subtype', |
|
46 'typemin','typemax','realmin','realmax','sizeof','eps','promote_type', |
|
47 'method_exists','applicable','invoke','dlopen','dlsym','system', |
|
48 'error','throw','assert','new','Inf','Nan','pi','im', |
|
49 ] |
|
50 |
|
51 tokens = { |
|
52 'root': [ |
|
53 (r'\n', Text), |
|
54 (r'[^\S\n]+', Text), |
|
55 (r'#.*$', Comment), |
|
56 (r'[]{}:(),;[@]', Punctuation), |
|
57 (r'\\\n', Text), |
|
58 (r'\\', Text), |
|
59 |
|
60 # keywords |
|
61 (r'(begin|while|for|in|return|break|continue|' |
|
62 r'macro|quote|let|if|elseif|else|try|catch|end|' |
|
63 r'bitstype|ccall|do|using|module|import|export|' |
|
64 r'importall|baremodule)\b', Keyword), |
|
65 (r'(local|global|const)\b', Keyword.Declaration), |
|
66 (r'(Bool|Int|Int8|Int16|Int32|Int64|Uint|Uint8|Uint16|Uint32|Uint64' |
|
67 r'|Float32|Float64|Complex64|Complex128|Any|Nothing|None)\b', |
|
68 Keyword.Type), |
|
69 |
|
70 # functions |
|
71 (r'(function)((?:\s|\\\s)+)', |
|
72 bygroups(Keyword,Name.Function), 'funcname'), |
|
73 |
|
74 # types |
|
75 (r'(type|typealias|abstract)((?:\s|\\\s)+)', |
|
76 bygroups(Keyword,Name.Class), 'typename'), |
|
77 |
|
78 # operators |
|
79 (r'==|!=|<=|>=|->|&&|\|\||::|<:|[-~+/*%=<>&^|.?!$]', Operator), |
|
80 (r'\.\*|\.\^|\.\\|\.\/|\\', Operator), |
|
81 |
|
82 # builtins |
|
83 ('(' + '|'.join(builtins) + r')\b', Name.Builtin), |
|
84 |
|
85 # backticks |
|
86 (r'`(?s).*?`', String.Backtick), |
|
87 |
|
88 # chars |
|
89 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|" |
|
90 r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char), |
|
91 |
|
92 # try to match trailing transpose |
|
93 (r'(?<=[.\w\)\]])\'+', Operator), |
|
94 |
|
95 # strings |
|
96 (r'(?:[IL])"', String, 'string'), |
|
97 (r'[E]?"', String, combined('stringescape', 'string')), |
|
98 |
|
99 # names |
|
100 (r'@[a-zA-Z0-9_.]+', Name.Decorator), |
|
101 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
102 |
|
103 # numbers |
|
104 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float), |
|
105 (r'\d+[eEf][+-]?[0-9]+', Number.Float), |
|
106 (r'0b[01]+', Number.Binary), |
|
107 (r'0o[0-7]+', Number.Oct), |
|
108 (r'0x[a-fA-F0-9]+', Number.Hex), |
|
109 (r'\d+', Number.Integer) |
|
110 ], |
|
111 |
|
112 'funcname': [ |
|
113 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop'), |
|
114 ('\([^\s\w{]{1,2}\)', Operator, '#pop'), |
|
115 ('[^\s\w{]{1,2}', Operator, '#pop'), |
|
116 ], |
|
117 |
|
118 'typename': [ |
|
119 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop') |
|
120 ], |
|
121 |
|
122 'stringescape': [ |
|
123 (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|' |
|
124 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape) |
|
125 ], |
|
126 |
|
127 'string': [ |
|
128 (r'"', String, '#pop'), |
|
129 (r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings |
|
130 (r'\$(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?', |
|
131 String.Interpol), |
|
132 (r'[^\\"$]+', String), |
|
133 # quotes, dollar signs, and backslashes must be parsed one at a time |
|
134 (r'["\\]', String), |
|
135 # unhandled string formatting sign |
|
136 (r'\$', String) |
|
137 ], |
|
138 } |
|
139 |
|
140 def analyse_text(text): |
|
141 return shebang_matches(text, r'julia') |
|
142 |
|
143 |
|
144 line_re = re.compile('.*?\n') |
|
145 |
|
146 class JuliaConsoleLexer(Lexer): |
|
147 """ |
|
148 For Julia console sessions. Modeled after MatlabSessionLexer. |
|
149 |
|
150 *New in Pygments 1.6.* |
|
151 """ |
|
152 name = 'Julia console' |
|
153 aliases = ['jlcon'] |
|
154 |
|
155 def get_tokens_unprocessed(self, text): |
|
156 jllexer = JuliaLexer(**self.options) |
|
157 |
|
158 curcode = '' |
|
159 insertions = [] |
|
160 |
|
161 for match in line_re.finditer(text): |
|
162 line = match.group() |
|
163 |
|
164 if line.startswith('julia>'): |
|
165 insertions.append((len(curcode), |
|
166 [(0, Generic.Prompt, line[:3])])) |
|
167 curcode += line[3:] |
|
168 |
|
169 elif line.startswith(' '): |
|
170 |
|
171 idx = len(curcode) |
|
172 |
|
173 # without is showing error on same line as before...? |
|
174 line = "\n" + line |
|
175 token = (0, Generic.Traceback, line) |
|
176 insertions.append((idx, [token])) |
|
177 |
|
178 else: |
|
179 if curcode: |
|
180 for item in do_insertions( |
|
181 insertions, jllexer.get_tokens_unprocessed(curcode)): |
|
182 yield item |
|
183 curcode = '' |
|
184 insertions = [] |
|
185 |
|
186 yield match.start(), Generic.Output, line |
|
187 |
|
188 if curcode: # or item: |
|
189 for item in do_insertions( |
|
190 insertions, jllexer.get_tokens_unprocessed(curcode)): |
|
191 yield item |
|
192 |
|
193 |
|
194 class MuPADLexer(RegexLexer): |
|
195 """ |
|
196 A `MuPAD <http://www.mupad.com>`_ lexer. |
|
197 Contributed by Christopher Creutzig <christopher@creutzig.de>. |
|
198 |
|
199 *New in Pygments 0.8.* |
|
200 """ |
|
201 name = 'MuPAD' |
|
202 aliases = ['mupad'] |
|
203 filenames = ['*.mu'] |
|
204 |
|
205 tokens = { |
|
206 'root' : [ |
|
207 (r'//.*?$', Comment.Single), |
|
208 (r'/\*', Comment.Multiline, 'comment'), |
|
209 (r'"(?:[^"\\]|\\.)*"', String), |
|
210 (r'\(|\)|\[|\]|\{|\}', Punctuation), |
|
211 (r'''(?x)\b(?: |
|
212 next|break|end| |
|
213 axiom|end_axiom|category|end_category|domain|end_domain|inherits| |
|
214 if|%if|then|elif|else|end_if| |
|
215 case|of|do|otherwise|end_case| |
|
216 while|end_while| |
|
217 repeat|until|end_repeat| |
|
218 for|from|to|downto|step|end_for| |
|
219 proc|local|option|save|begin|end_proc| |
|
220 delete|frame |
|
221 )\b''', Keyword), |
|
222 (r'''(?x)\b(?: |
|
223 DOM_ARRAY|DOM_BOOL|DOM_COMPLEX|DOM_DOMAIN|DOM_EXEC|DOM_EXPR| |
|
224 DOM_FAIL|DOM_FLOAT|DOM_FRAME|DOM_FUNC_ENV|DOM_HFARRAY|DOM_IDENT| |
|
225 DOM_INT|DOM_INTERVAL|DOM_LIST|DOM_NIL|DOM_NULL|DOM_POLY|DOM_PROC| |
|
226 DOM_PROC_ENV|DOM_RAT|DOM_SET|DOM_STRING|DOM_TABLE|DOM_VAR |
|
227 )\b''', Name.Class), |
|
228 (r'''(?x)\b(?: |
|
229 PI|EULER|E|CATALAN| |
|
230 NIL|FAIL|undefined|infinity| |
|
231 TRUE|FALSE|UNKNOWN |
|
232 )\b''', |
|
233 Name.Constant), |
|
234 (r'\b(?:dom|procname)\b', Name.Builtin.Pseudo), |
|
235 (r'\.|,|:|;|=|\+|-|\*|/|\^|@|>|<|\$|\||!|\'|%|~=', Operator), |
|
236 (r'''(?x)\b(?: |
|
237 and|or|not|xor| |
|
238 assuming| |
|
239 div|mod| |
|
240 union|minus|intersect|in|subset |
|
241 )\b''', |
|
242 Operator.Word), |
|
243 (r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number), |
|
244 #(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin), |
|
245 (r'''(?x) |
|
246 ((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`) |
|
247 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)(\s*)([(])''', |
|
248 bygroups(Name.Function, Text, Punctuation)), |
|
249 (r'''(?x) |
|
250 (?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`) |
|
251 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable), |
|
252 (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number), |
|
253 (r'\.[0-9]+(?:e[0-9]+)?', Number), |
|
254 (r'.', Text) |
|
255 ], |
|
256 'comment' : [ |
|
257 (r'[^*/]', Comment.Multiline), |
|
258 (r'/\*', Comment.Multiline, '#push'), |
|
259 (r'\*/', Comment.Multiline, '#pop'), |
|
260 (r'[*/]', Comment.Multiline) |
|
261 ] |
|
262 } |
|
263 |
|
264 |
|
265 class MatlabLexer(RegexLexer): |
|
266 """ |
|
267 For Matlab source code. |
|
268 |
|
269 *New in Pygments 0.10.* |
|
270 """ |
|
271 name = 'Matlab' |
|
272 aliases = ['matlab'] |
|
273 filenames = ['*.m'] |
|
274 mimetypes = ['text/matlab'] |
|
275 |
|
276 # |
|
277 # These lists are generated automatically. |
|
278 # Run the following in bash shell: |
|
279 # |
|
280 # for f in elfun specfun elmat; do |
|
281 # echo -n "$f = " |
|
282 # matlab -nojvm -r "help $f;exit;" | perl -ne \ |
|
283 # 'push(@c,$1) if /^ (\w+)\s+-/; END {print q{["}.join(q{","},@c).qq{"]\n};}' |
|
284 # done |
|
285 # |
|
286 # elfun: Elementary math functions |
|
287 # specfun: Special Math functions |
|
288 # elmat: Elementary matrices and matrix manipulation |
|
289 # |
|
290 # taken from Matlab version 7.4.0.336 (R2007a) |
|
291 # |
|
292 elfun = ["sin","sind","sinh","asin","asind","asinh","cos","cosd","cosh", |
|
293 "acos","acosd","acosh","tan","tand","tanh","atan","atand","atan2", |
|
294 "atanh","sec","secd","sech","asec","asecd","asech","csc","cscd", |
|
295 "csch","acsc","acscd","acsch","cot","cotd","coth","acot","acotd", |
|
296 "acoth","hypot","exp","expm1","log","log1p","log10","log2","pow2", |
|
297 "realpow","reallog","realsqrt","sqrt","nthroot","nextpow2","abs", |
|
298 "angle","complex","conj","imag","real","unwrap","isreal","cplxpair", |
|
299 "fix","floor","ceil","round","mod","rem","sign"] |
|
300 specfun = ["airy","besselj","bessely","besselh","besseli","besselk","beta", |
|
301 "betainc","betaln","ellipj","ellipke","erf","erfc","erfcx", |
|
302 "erfinv","expint","gamma","gammainc","gammaln","psi","legendre", |
|
303 "cross","dot","factor","isprime","primes","gcd","lcm","rat", |
|
304 "rats","perms","nchoosek","factorial","cart2sph","cart2pol", |
|
305 "pol2cart","sph2cart","hsv2rgb","rgb2hsv"] |
|
306 elmat = ["zeros","ones","eye","repmat","rand","randn","linspace","logspace", |
|
307 "freqspace","meshgrid","accumarray","size","length","ndims","numel", |
|
308 "disp","isempty","isequal","isequalwithequalnans","cat","reshape", |
|
309 "diag","blkdiag","tril","triu","fliplr","flipud","flipdim","rot90", |
|
310 "find","end","sub2ind","ind2sub","bsxfun","ndgrid","permute", |
|
311 "ipermute","shiftdim","circshift","squeeze","isscalar","isvector", |
|
312 "ans","eps","realmax","realmin","pi","i","inf","nan","isnan", |
|
313 "isinf","isfinite","j","why","compan","gallery","hadamard","hankel", |
|
314 "hilb","invhilb","magic","pascal","rosser","toeplitz","vander", |
|
315 "wilkinson"] |
|
316 |
|
317 tokens = { |
|
318 'root': [ |
|
319 # line starting with '!' is sent as a system command. not sure what |
|
320 # label to use... |
|
321 (r'^!.*', String.Other), |
|
322 (r'%\{\s*\n', Comment.Multiline, 'blockcomment'), |
|
323 (r'%.*$', Comment), |
|
324 (r'^\s*function', Keyword, 'deffunc'), |
|
325 |
|
326 # from 'iskeyword' on version 7.11 (R2010): |
|
327 (r'(break|case|catch|classdef|continue|else|elseif|end|enumerated|' |
|
328 r'events|for|function|global|if|methods|otherwise|parfor|' |
|
329 r'persistent|properties|return|spmd|switch|try|while)\b', Keyword), |
|
330 |
|
331 ("(" + "|".join(elfun+specfun+elmat) + r')\b', Name.Builtin), |
|
332 |
|
333 # line continuation with following comment: |
|
334 (r'\.\.\..*$', Comment), |
|
335 |
|
336 # operators: |
|
337 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator), |
|
338 # operators requiring escape for re: |
|
339 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator), |
|
340 |
|
341 # punctuation: |
|
342 (r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation), |
|
343 (r'=|:|;', Punctuation), |
|
344 |
|
345 # quote can be transpose, instead of string: |
|
346 # (not great, but handles common cases...) |
|
347 (r'(?<=[\w\)\]])\'', Operator), |
|
348 |
|
349 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float), |
|
350 (r'\d+[eEf][+-]?[0-9]+', Number.Float), |
|
351 (r'\d+', Number.Integer), |
|
352 |
|
353 (r'(?<![\w\)\]])\'', String, 'string'), |
|
354 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
355 (r'.', Text), |
|
356 ], |
|
357 'string': [ |
|
358 (r'[^\']*\'', String, '#pop') |
|
359 ], |
|
360 'blockcomment': [ |
|
361 (r'^\s*%\}', Comment.Multiline, '#pop'), |
|
362 (r'^.*\n', Comment.Multiline), |
|
363 (r'.', Comment.Multiline), |
|
364 ], |
|
365 'deffunc': [ |
|
366 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)', |
|
367 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation, |
|
368 Text.Whitespace, Name.Function, Punctuation, Text, |
|
369 Punctuation, Text.Whitespace), '#pop'), |
|
370 ], |
|
371 } |
|
372 |
|
373 def analyse_text(text): |
|
374 if re.match('^\s*%', text, re.M): # comment |
|
375 return 0.9 |
|
376 elif re.match('^!\w+', text, re.M): # system cmd |
|
377 return 0.9 |
|
378 return 0.1 |
|
379 |
|
380 |
|
381 line_re = re.compile('.*?\n') |
|
382 |
|
383 class MatlabSessionLexer(Lexer): |
|
384 """ |
|
385 For Matlab sessions. Modeled after PythonConsoleLexer. |
|
386 Contributed by Ken Schutte <kschutte@csail.mit.edu>. |
|
387 |
|
388 *New in Pygments 0.10.* |
|
389 """ |
|
390 name = 'Matlab session' |
|
391 aliases = ['matlabsession'] |
|
392 |
|
393 def get_tokens_unprocessed(self, text): |
|
394 mlexer = MatlabLexer(**self.options) |
|
395 |
|
396 curcode = '' |
|
397 insertions = [] |
|
398 |
|
399 for match in line_re.finditer(text): |
|
400 line = match.group() |
|
401 |
|
402 if line.startswith('>>'): |
|
403 insertions.append((len(curcode), |
|
404 [(0, Generic.Prompt, line[:3])])) |
|
405 curcode += line[3:] |
|
406 |
|
407 elif line.startswith('???'): |
|
408 |
|
409 idx = len(curcode) |
|
410 |
|
411 # without is showing error on same line as before...? |
|
412 line = "\n" + line |
|
413 token = (0, Generic.Traceback, line) |
|
414 insertions.append((idx, [token])) |
|
415 |
|
416 else: |
|
417 if curcode: |
|
418 for item in do_insertions( |
|
419 insertions, mlexer.get_tokens_unprocessed(curcode)): |
|
420 yield item |
|
421 curcode = '' |
|
422 insertions = [] |
|
423 |
|
424 yield match.start(), Generic.Output, line |
|
425 |
|
426 if curcode: # or item: |
|
427 for item in do_insertions( |
|
428 insertions, mlexer.get_tokens_unprocessed(curcode)): |
|
429 yield item |
|
430 |
|
431 |
|
432 class OctaveLexer(RegexLexer): |
|
433 """ |
|
434 For GNU Octave source code. |
|
435 |
|
436 *New in Pygments 1.5.* |
|
437 """ |
|
438 name = 'Octave' |
|
439 aliases = ['octave'] |
|
440 filenames = ['*.m'] |
|
441 mimetypes = ['text/octave'] |
|
442 |
|
443 # These lists are generated automatically. |
|
444 # Run the following in bash shell: |
|
445 # |
|
446 # First dump all of the Octave manual into a plain text file: |
|
447 # |
|
448 # $ info octave --subnodes -o octave-manual |
|
449 # |
|
450 # Now grep through it: |
|
451 |
|
452 # for i in \ |
|
453 # "Built-in Function" "Command" "Function File" \ |
|
454 # "Loadable Function" "Mapping Function"; |
|
455 # do |
|
456 # perl -e '@name = qw('"$i"'); |
|
457 # print lc($name[0]),"_kw = [\n"'; |
|
458 # |
|
459 # perl -n -e 'print "\"$1\",\n" if /-- '"$i"': .* (\w*) \(/;' \ |
|
460 # octave-manual | sort | uniq ; |
|
461 # echo "]" ; |
|
462 # echo; |
|
463 # done |
|
464 |
|
465 # taken from Octave Mercurial changeset 8cc154f45e37 (30-jan-2011) |
|
466 |
|
467 builtin_kw = [ "addlistener", "addpath", "addproperty", "all", |
|
468 "and", "any", "argnames", "argv", "assignin", |
|
469 "atexit", "autoload", |
|
470 "available_graphics_toolkits", "beep_on_error", |
|
471 "bitand", "bitmax", "bitor", "bitshift", "bitxor", |
|
472 "cat", "cell", "cellstr", "char", "class", "clc", |
|
473 "columns", "command_line_path", |
|
474 "completion_append_char", "completion_matches", |
|
475 "complex", "confirm_recursive_rmdir", "cputime", |
|
476 "crash_dumps_octave_core", "ctranspose", "cumprod", |
|
477 "cumsum", "debug_on_error", "debug_on_interrupt", |
|
478 "debug_on_warning", "default_save_options", |
|
479 "dellistener", "diag", "diff", "disp", |
|
480 "doc_cache_file", "do_string_escapes", "double", |
|
481 "drawnow", "e", "echo_executing_commands", "eps", |
|
482 "eq", "errno", "errno_list", "error", "eval", |
|
483 "evalin", "exec", "exist", "exit", "eye", "false", |
|
484 "fclear", "fclose", "fcntl", "fdisp", "feof", |
|
485 "ferror", "feval", "fflush", "fgetl", "fgets", |
|
486 "fieldnames", "file_in_loadpath", "file_in_path", |
|
487 "filemarker", "filesep", "find_dir_in_path", |
|
488 "fixed_point_format", "fnmatch", "fopen", "fork", |
|
489 "formula", "fprintf", "fputs", "fread", "freport", |
|
490 "frewind", "fscanf", "fseek", "fskipl", "ftell", |
|
491 "functions", "fwrite", "ge", "genpath", "get", |
|
492 "getegid", "getenv", "geteuid", "getgid", |
|
493 "getpgrp", "getpid", "getppid", "getuid", "glob", |
|
494 "gt", "gui_mode", "history_control", |
|
495 "history_file", "history_size", |
|
496 "history_timestamp_format_string", "home", |
|
497 "horzcat", "hypot", "ifelse", |
|
498 "ignore_function_time_stamp", "inferiorto", |
|
499 "info_file", "info_program", "inline", "input", |
|
500 "intmax", "intmin", "ipermute", |
|
501 "is_absolute_filename", "isargout", "isbool", |
|
502 "iscell", "iscellstr", "ischar", "iscomplex", |
|
503 "isempty", "isfield", "isfloat", "isglobal", |
|
504 "ishandle", "isieee", "isindex", "isinteger", |
|
505 "islogical", "ismatrix", "ismethod", "isnull", |
|
506 "isnumeric", "isobject", "isreal", |
|
507 "is_rooted_relative_filename", "issorted", |
|
508 "isstruct", "isvarname", "kbhit", "keyboard", |
|
509 "kill", "lasterr", "lasterror", "lastwarn", |
|
510 "ldivide", "le", "length", "link", "linspace", |
|
511 "logical", "lstat", "lt", "make_absolute_filename", |
|
512 "makeinfo_program", "max_recursion_depth", "merge", |
|
513 "methods", "mfilename", "minus", "mislocked", |
|
514 "mkdir", "mkfifo", "mkstemp", "mldivide", "mlock", |
|
515 "mouse_wheel_zoom", "mpower", "mrdivide", "mtimes", |
|
516 "munlock", "nargin", "nargout", |
|
517 "native_float_format", "ndims", "ne", "nfields", |
|
518 "nnz", "norm", "not", "numel", "nzmax", |
|
519 "octave_config_info", "octave_core_file_limit", |
|
520 "octave_core_file_name", |
|
521 "octave_core_file_options", "ones", "or", |
|
522 "output_max_field_width", "output_precision", |
|
523 "page_output_immediately", "page_screen_output", |
|
524 "path", "pathsep", "pause", "pclose", "permute", |
|
525 "pi", "pipe", "plus", "popen", "power", |
|
526 "print_empty_dimensions", "printf", |
|
527 "print_struct_array_contents", "prod", |
|
528 "program_invocation_name", "program_name", |
|
529 "putenv", "puts", "pwd", "quit", "rats", "rdivide", |
|
530 "readdir", "readlink", "read_readline_init_file", |
|
531 "realmax", "realmin", "rehash", "rename", |
|
532 "repelems", "re_read_readline_init_file", "reset", |
|
533 "reshape", "resize", "restoredefaultpath", |
|
534 "rethrow", "rmdir", "rmfield", "rmpath", "rows", |
|
535 "save_header_format_string", "save_precision", |
|
536 "saving_history", "scanf", "set", "setenv", |
|
537 "shell_cmd", "sighup_dumps_octave_core", |
|
538 "sigterm_dumps_octave_core", "silent_functions", |
|
539 "single", "size", "size_equal", "sizemax", |
|
540 "sizeof", "sleep", "source", "sparse_auto_mutate", |
|
541 "split_long_rows", "sprintf", "squeeze", "sscanf", |
|
542 "stat", "stderr", "stdin", "stdout", "strcmp", |
|
543 "strcmpi", "string_fill_char", "strncmp", |
|
544 "strncmpi", "struct", "struct_levels_to_print", |
|
545 "strvcat", "subsasgn", "subsref", "sum", "sumsq", |
|
546 "superiorto", "suppress_verbose_help_message", |
|
547 "symlink", "system", "tic", "tilde_expand", |
|
548 "times", "tmpfile", "tmpnam", "toc", "toupper", |
|
549 "transpose", "true", "typeinfo", "umask", "uminus", |
|
550 "uname", "undo_string_escapes", "unlink", "uplus", |
|
551 "upper", "usage", "usleep", "vec", "vectorize", |
|
552 "vertcat", "waitpid", "warning", "warranty", |
|
553 "whos_line_format", "yes_or_no", "zeros", |
|
554 "inf", "Inf", "nan", "NaN"] |
|
555 |
|
556 command_kw = [ "close", "load", "who", "whos", ] |
|
557 |
|
558 function_kw = [ "accumarray", "accumdim", "acosd", "acotd", |
|
559 "acscd", "addtodate", "allchild", "ancestor", |
|
560 "anova", "arch_fit", "arch_rnd", "arch_test", |
|
561 "area", "arma_rnd", "arrayfun", "ascii", "asctime", |
|
562 "asecd", "asind", "assert", "atand", |
|
563 "autoreg_matrix", "autumn", "axes", "axis", "bar", |
|
564 "barh", "bartlett", "bartlett_test", "beep", |
|
565 "betacdf", "betainv", "betapdf", "betarnd", |
|
566 "bicgstab", "bicubic", "binary", "binocdf", |
|
567 "binoinv", "binopdf", "binornd", "bitcmp", |
|
568 "bitget", "bitset", "blackman", "blanks", |
|
569 "blkdiag", "bone", "box", "brighten", "calendar", |
|
570 "cast", "cauchy_cdf", "cauchy_inv", "cauchy_pdf", |
|
571 "cauchy_rnd", "caxis", "celldisp", "center", "cgs", |
|
572 "chisquare_test_homogeneity", |
|
573 "chisquare_test_independence", "circshift", "cla", |
|
574 "clabel", "clf", "clock", "cloglog", "closereq", |
|
575 "colon", "colorbar", "colormap", "colperm", |
|
576 "comet", "common_size", "commutation_matrix", |
|
577 "compan", "compare_versions", "compass", |
|
578 "computer", "cond", "condest", "contour", |
|
579 "contourc", "contourf", "contrast", "conv", |
|
580 "convhull", "cool", "copper", "copyfile", "cor", |
|
581 "corrcoef", "cor_test", "cosd", "cotd", "cov", |
|
582 "cplxpair", "cross", "cscd", "cstrcat", "csvread", |
|
583 "csvwrite", "ctime", "cumtrapz", "curl", "cut", |
|
584 "cylinder", "date", "datenum", "datestr", |
|
585 "datetick", "datevec", "dblquad", "deal", |
|
586 "deblank", "deconv", "delaunay", "delaunayn", |
|
587 "delete", "demo", "detrend", "diffpara", "diffuse", |
|
588 "dir", "discrete_cdf", "discrete_inv", |
|
589 "discrete_pdf", "discrete_rnd", "display", |
|
590 "divergence", "dlmwrite", "dos", "dsearch", |
|
591 "dsearchn", "duplication_matrix", "durbinlevinson", |
|
592 "ellipsoid", "empirical_cdf", "empirical_inv", |
|
593 "empirical_pdf", "empirical_rnd", "eomday", |
|
594 "errorbar", "etime", "etreeplot", "example", |
|
595 "expcdf", "expinv", "expm", "exppdf", "exprnd", |
|
596 "ezcontour", "ezcontourf", "ezmesh", "ezmeshc", |
|
597 "ezplot", "ezpolar", "ezsurf", "ezsurfc", "factor", |
|
598 "factorial", "fail", "fcdf", "feather", "fftconv", |
|
599 "fftfilt", "fftshift", "figure", "fileattrib", |
|
600 "fileparts", "fill", "findall", "findobj", |
|
601 "findstr", "finv", "flag", "flipdim", "fliplr", |
|
602 "flipud", "fpdf", "fplot", "fractdiff", "freqz", |
|
603 "freqz_plot", "frnd", "fsolve", |
|
604 "f_test_regression", "ftp", "fullfile", "fzero", |
|
605 "gamcdf", "gaminv", "gampdf", "gamrnd", "gca", |
|
606 "gcbf", "gcbo", "gcf", "genvarname", "geocdf", |
|
607 "geoinv", "geopdf", "geornd", "getfield", "ginput", |
|
608 "glpk", "gls", "gplot", "gradient", |
|
609 "graphics_toolkit", "gray", "grid", "griddata", |
|
610 "griddatan", "gtext", "gunzip", "gzip", "hadamard", |
|
611 "hamming", "hankel", "hanning", "hggroup", |
|
612 "hidden", "hilb", "hist", "histc", "hold", "hot", |
|
613 "hotelling_test", "housh", "hsv", "hurst", |
|
614 "hygecdf", "hygeinv", "hygepdf", "hygernd", |
|
615 "idivide", "ifftshift", "image", "imagesc", |
|
616 "imfinfo", "imread", "imshow", "imwrite", "index", |
|
617 "info", "inpolygon", "inputname", "interpft", |
|
618 "interpn", "intersect", "invhilb", "iqr", "isa", |
|
619 "isdefinite", "isdir", "is_duplicate_entry", |
|
620 "isequal", "isequalwithequalnans", "isfigure", |
|
621 "ishermitian", "ishghandle", "is_leap_year", |
|
622 "isletter", "ismac", "ismember", "ispc", "isprime", |
|
623 "isprop", "isscalar", "issquare", "isstrprop", |
|
624 "issymmetric", "isunix", "is_valid_file_id", |
|
625 "isvector", "jet", "kendall", |
|
626 "kolmogorov_smirnov_cdf", |
|
627 "kolmogorov_smirnov_test", "kruskal_wallis_test", |
|
628 "krylov", "kurtosis", "laplace_cdf", "laplace_inv", |
|
629 "laplace_pdf", "laplace_rnd", "legend", "legendre", |
|
630 "license", "line", "linkprop", "list_primes", |
|
631 "loadaudio", "loadobj", "logistic_cdf", |
|
632 "logistic_inv", "logistic_pdf", "logistic_rnd", |
|
633 "logit", "loglog", "loglogerr", "logm", "logncdf", |
|
634 "logninv", "lognpdf", "lognrnd", "logspace", |
|
635 "lookfor", "ls_command", "lsqnonneg", "magic", |
|
636 "mahalanobis", "manova", "matlabroot", |
|
637 "mcnemar_test", "mean", "meansq", "median", "menu", |
|
638 "mesh", "meshc", "meshgrid", "meshz", "mexext", |
|
639 "mget", "mkpp", "mode", "moment", "movefile", |
|
640 "mpoles", "mput", "namelengthmax", "nargchk", |
|
641 "nargoutchk", "nbincdf", "nbininv", "nbinpdf", |
|
642 "nbinrnd", "nchoosek", "ndgrid", "newplot", "news", |
|
643 "nonzeros", "normcdf", "normest", "norminv", |
|
644 "normpdf", "normrnd", "now", "nthroot", "null", |
|
645 "ocean", "ols", "onenormest", "optimget", |
|
646 "optimset", "orderfields", "orient", "orth", |
|
647 "pack", "pareto", "parseparams", "pascal", "patch", |
|
648 "pathdef", "pcg", "pchip", "pcolor", "pcr", |
|
649 "peaks", "periodogram", "perl", "perms", "pie", |
|
650 "pink", "planerot", "playaudio", "plot", |
|
651 "plotmatrix", "plotyy", "poisscdf", "poissinv", |
|
652 "poisspdf", "poissrnd", "polar", "poly", |
|
653 "polyaffine", "polyarea", "polyderiv", "polyfit", |
|
654 "polygcd", "polyint", "polyout", "polyreduce", |
|
655 "polyval", "polyvalm", "postpad", "powerset", |
|
656 "ppder", "ppint", "ppjumps", "ppplot", "ppval", |
|
657 "pqpnonneg", "prepad", "primes", "print", |
|
658 "print_usage", "prism", "probit", "qp", "qqplot", |
|
659 "quadcc", "quadgk", "quadl", "quadv", "quiver", |
|
660 "qzhess", "rainbow", "randi", "range", "rank", |
|
661 "ranks", "rat", "reallog", "realpow", "realsqrt", |
|
662 "record", "rectangle_lw", "rectangle_sw", |
|
663 "rectint", "refresh", "refreshdata", |
|
664 "regexptranslate", "repmat", "residue", "ribbon", |
|
665 "rindex", "roots", "rose", "rosser", "rotdim", |
|
666 "rref", "run", "run_count", "rundemos", "run_test", |
|
667 "runtests", "saveas", "saveaudio", "saveobj", |
|
668 "savepath", "scatter", "secd", "semilogx", |
|
669 "semilogxerr", "semilogy", "semilogyerr", |
|
670 "setaudio", "setdiff", "setfield", "setxor", |
|
671 "shading", "shift", "shiftdim", "sign_test", |
|
672 "sinc", "sind", "sinetone", "sinewave", "skewness", |
|
673 "slice", "sombrero", "sortrows", "spaugment", |
|
674 "spconvert", "spdiags", "spearman", "spectral_adf", |
|
675 "spectral_xdf", "specular", "speed", "spencer", |
|
676 "speye", "spfun", "sphere", "spinmap", "spline", |
|
677 "spones", "sprand", "sprandn", "sprandsym", |
|
678 "spring", "spstats", "spy", "sqp", "stairs", |
|
679 "statistics", "std", "stdnormal_cdf", |
|
680 "stdnormal_inv", "stdnormal_pdf", "stdnormal_rnd", |
|
681 "stem", "stft", "strcat", "strchr", "strjust", |
|
682 "strmatch", "strread", "strsplit", "strtok", |
|
683 "strtrim", "strtrunc", "structfun", "studentize", |
|
684 "subplot", "subsindex", "subspace", "substr", |
|
685 "substruct", "summer", "surf", "surface", "surfc", |
|
686 "surfl", "surfnorm", "svds", "swapbytes", |
|
687 "sylvester_matrix", "symvar", "synthesis", "table", |
|
688 "tand", "tar", "tcdf", "tempdir", "tempname", |
|
689 "test", "text", "textread", "textscan", "tinv", |
|
690 "title", "toeplitz", "tpdf", "trace", "trapz", |
|
691 "treelayout", "treeplot", "triangle_lw", |
|
692 "triangle_sw", "tril", "trimesh", "triplequad", |
|
693 "triplot", "trisurf", "triu", "trnd", "tsearchn", |
|
694 "t_test", "t_test_regression", "type", "unidcdf", |
|
695 "unidinv", "unidpdf", "unidrnd", "unifcdf", |
|
696 "unifinv", "unifpdf", "unifrnd", "union", "unique", |
|
697 "unix", "unmkpp", "unpack", "untabify", "untar", |
|
698 "unwrap", "unzip", "u_test", "validatestring", |
|
699 "vander", "var", "var_test", "vech", "ver", |
|
700 "version", "view", "voronoi", "voronoin", |
|
701 "waitforbuttonpress", "wavread", "wavwrite", |
|
702 "wblcdf", "wblinv", "wblpdf", "wblrnd", "weekday", |
|
703 "welch_test", "what", "white", "whitebg", |
|
704 "wienrnd", "wilcoxon_test", "wilkinson", "winter", |
|
705 "xlabel", "xlim", "ylabel", "yulewalker", "zip", |
|
706 "zlabel", "z_test", ] |
|
707 |
|
708 loadable_kw = [ "airy", "amd", "balance", "besselh", "besseli", |
|
709 "besselj", "besselk", "bessely", "bitpack", |
|
710 "bsxfun", "builtin", "ccolamd", "cellfun", |
|
711 "cellslices", "chol", "choldelete", "cholinsert", |
|
712 "cholinv", "cholshift", "cholupdate", "colamd", |
|
713 "colloc", "convhulln", "convn", "csymamd", |
|
714 "cummax", "cummin", "daspk", "daspk_options", |
|
715 "dasrt", "dasrt_options", "dassl", "dassl_options", |
|
716 "dbclear", "dbdown", "dbstack", "dbstatus", |
|
717 "dbstop", "dbtype", "dbup", "dbwhere", "det", |
|
718 "dlmread", "dmperm", "dot", "eig", "eigs", |
|
719 "endgrent", "endpwent", "etree", "fft", "fftn", |
|
720 "fftw", "filter", "find", "full", "gcd", |
|
721 "getgrent", "getgrgid", "getgrnam", "getpwent", |
|
722 "getpwnam", "getpwuid", "getrusage", "givens", |
|
723 "gmtime", "gnuplot_binary", "hess", "ifft", |
|
724 "ifftn", "inv", "isdebugmode", "issparse", "kron", |
|
725 "localtime", "lookup", "lsode", "lsode_options", |
|
726 "lu", "luinc", "luupdate", "matrix_type", "max", |
|
727 "min", "mktime", "pinv", "qr", "qrdelete", |
|
728 "qrinsert", "qrshift", "qrupdate", "quad", |
|
729 "quad_options", "qz", "rand", "rande", "randg", |
|
730 "randn", "randp", "randperm", "rcond", "regexp", |
|
731 "regexpi", "regexprep", "schur", "setgrent", |
|
732 "setpwent", "sort", "spalloc", "sparse", "spparms", |
|
733 "sprank", "sqrtm", "strfind", "strftime", |
|
734 "strptime", "strrep", "svd", "svd_driver", "syl", |
|
735 "symamd", "symbfact", "symrcm", "time", "tsearch", |
|
736 "typecast", "urlread", "urlwrite", ] |
|
737 |
|
738 mapping_kw = [ "abs", "acos", "acosh", "acot", "acoth", "acsc", |
|
739 "acsch", "angle", "arg", "asec", "asech", "asin", |
|
740 "asinh", "atan", "atanh", "beta", "betainc", |
|
741 "betaln", "bincoeff", "cbrt", "ceil", "conj", "cos", |
|
742 "cosh", "cot", "coth", "csc", "csch", "erf", "erfc", |
|
743 "erfcx", "erfinv", "exp", "finite", "fix", "floor", |
|
744 "fmod", "gamma", "gammainc", "gammaln", "imag", |
|
745 "isalnum", "isalpha", "isascii", "iscntrl", |
|
746 "isdigit", "isfinite", "isgraph", "isinf", |
|
747 "islower", "isna", "isnan", "isprint", "ispunct", |
|
748 "isspace", "isupper", "isxdigit", "lcm", "lgamma", |
|
749 "log", "lower", "mod", "real", "rem", "round", |
|
750 "roundb", "sec", "sech", "sign", "sin", "sinh", |
|
751 "sqrt", "tan", "tanh", "toascii", "tolower", "xor", |
|
752 ] |
|
753 |
|
754 builtin_consts = [ "EDITOR", "EXEC_PATH", "I", "IMAGE_PATH", "NA", |
|
755 "OCTAVE_HOME", "OCTAVE_VERSION", "PAGER", |
|
756 "PAGER_FLAGS", "SEEK_CUR", "SEEK_END", "SEEK_SET", |
|
757 "SIG", "S_ISBLK", "S_ISCHR", "S_ISDIR", "S_ISFIFO", |
|
758 "S_ISLNK", "S_ISREG", "S_ISSOCK", "WCONTINUE", |
|
759 "WCOREDUMP", "WEXITSTATUS", "WIFCONTINUED", |
|
760 "WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG", |
|
761 "WSTOPSIG", "WTERMSIG", "WUNTRACED", ] |
|
762 |
|
763 tokens = { |
|
764 'root': [ |
|
765 #We should look into multiline comments |
|
766 (r'[%#].*$', Comment), |
|
767 (r'^\s*function', Keyword, 'deffunc'), |
|
768 |
|
769 # from 'iskeyword' on hg changeset 8cc154f45e37 |
|
770 (r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|' |
|
771 r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|' |
|
772 r'endevents|endfor|endfunction|endif|endmethods|endproperties|' |
|
773 r'endswitch|endwhile|events|for|function|get|global|if|methods|' |
|
774 r'otherwise|persistent|properties|return|set|static|switch|try|' |
|
775 r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword), |
|
776 |
|
777 ("(" + "|".join( builtin_kw + command_kw |
|
778 + function_kw + loadable_kw |
|
779 + mapping_kw) + r')\b', Name.Builtin), |
|
780 |
|
781 ("(" + "|".join(builtin_consts) + r')\b', Name.Constant), |
|
782 |
|
783 # operators in Octave but not Matlab: |
|
784 (r'-=|!=|!|/=|--', Operator), |
|
785 # operators: |
|
786 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator), |
|
787 # operators in Octave but not Matlab requiring escape for re: |
|
788 (r'\*=|\+=|\^=|\/=|\\=|\*\*|\+\+|\.\*\*',Operator), |
|
789 # operators requiring escape for re: |
|
790 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator), |
|
791 |
|
792 |
|
793 # punctuation: |
|
794 (r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation), |
|
795 (r'=|:|;', Punctuation), |
|
796 |
|
797 (r'"[^"]*"', String), |
|
798 |
|
799 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float), |
|
800 (r'\d+[eEf][+-]?[0-9]+', Number.Float), |
|
801 (r'\d+', Number.Integer), |
|
802 |
|
803 # quote can be transpose, instead of string: |
|
804 # (not great, but handles common cases...) |
|
805 (r'(?<=[\w\)\]])\'', Operator), |
|
806 (r'(?<![\w\)\]])\'', String, 'string'), |
|
807 |
|
808 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
809 (r'.', Text), |
|
810 ], |
|
811 'string': [ |
|
812 (r"[^']*'", String, '#pop'), |
|
813 ], |
|
814 'deffunc': [ |
|
815 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)', |
|
816 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation, |
|
817 Text.Whitespace, Name.Function, Punctuation, Text, |
|
818 Punctuation, Text.Whitespace), '#pop'), |
|
819 ], |
|
820 } |
|
821 |
|
822 def analyse_text(text): |
|
823 if re.match('^\s*[%#]', text, re.M): #Comment |
|
824 return 0.1 |
|
825 |
|
826 |
|
827 class ScilabLexer(RegexLexer): |
|
828 """ |
|
829 For Scilab source code. |
|
830 |
|
831 *New in Pygments 1.5.* |
|
832 """ |
|
833 name = 'Scilab' |
|
834 aliases = ['scilab'] |
|
835 filenames = ['*.sci', '*.sce', '*.tst'] |
|
836 mimetypes = ['text/scilab'] |
|
837 |
|
838 tokens = { |
|
839 'root': [ |
|
840 (r'//.*?$', Comment.Single), |
|
841 (r'^\s*function', Keyword, 'deffunc'), |
|
842 |
|
843 (r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|' |
|
844 r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|' |
|
845 r'endevents|endfor|endfunction|endif|endmethods|endproperties|' |
|
846 r'endswitch|endwhile|events|for|function|get|global|if|methods|' |
|
847 r'otherwise|persistent|properties|return|set|static|switch|try|' |
|
848 r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword), |
|
849 |
|
850 ("(" + "|".join(_scilab_builtins.functions_kw + |
|
851 _scilab_builtins.commands_kw + |
|
852 _scilab_builtins.macros_kw |
|
853 ) + r')\b', Name.Builtin), |
|
854 |
|
855 (r'(%s)\b' % "|".join(map(re.escape, _scilab_builtins.builtin_consts)), |
|
856 Name.Constant), |
|
857 |
|
858 # operators: |
|
859 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator), |
|
860 # operators requiring escape for re: |
|
861 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator), |
|
862 |
|
863 # punctuation: |
|
864 (r'[\[\](){}@.,=:;]', Punctuation), |
|
865 |
|
866 (r'"[^"]*"', String), |
|
867 |
|
868 # quote can be transpose, instead of string: |
|
869 # (not great, but handles common cases...) |
|
870 (r'(?<=[\w\)\]])\'', Operator), |
|
871 (r'(?<![\w\)\]])\'', String, 'string'), |
|
872 |
|
873 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float), |
|
874 (r'\d+[eEf][+-]?[0-9]+', Number.Float), |
|
875 (r'\d+', Number.Integer), |
|
876 |
|
877 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), |
|
878 (r'.', Text), |
|
879 ], |
|
880 'string': [ |
|
881 (r"[^']*'", String, '#pop'), |
|
882 (r'.', String, '#pop'), |
|
883 ], |
|
884 'deffunc': [ |
|
885 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)', |
|
886 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation, |
|
887 Text.Whitespace, Name.Function, Punctuation, Text, |
|
888 Punctuation, Text.Whitespace), '#pop'), |
|
889 ], |
|
890 } |
|
891 |
|
892 |
|
893 class NumPyLexer(PythonLexer): |
|
894 """ |
|
895 A Python lexer recognizing Numerical Python builtins. |
|
896 |
|
897 *New in Pygments 0.10.* |
|
898 """ |
|
899 |
|
900 name = 'NumPy' |
|
901 aliases = ['numpy'] |
|
902 |
|
903 # override the mimetypes to not inherit them from python |
|
904 mimetypes = [] |
|
905 filenames = [] |
|
906 |
|
907 EXTRA_KEYWORDS = set([ |
|
908 'abs', 'absolute', 'accumulate', 'add', 'alen', 'all', 'allclose', |
|
909 'alltrue', 'alterdot', 'amax', 'amin', 'angle', 'any', 'append', |
|
910 'apply_along_axis', 'apply_over_axes', 'arange', 'arccos', 'arccosh', |
|
911 'arcsin', 'arcsinh', 'arctan', 'arctan2', 'arctanh', 'argmax', 'argmin', |
|
912 'argsort', 'argwhere', 'around', 'array', 'array2string', 'array_equal', |
|
913 'array_equiv', 'array_repr', 'array_split', 'array_str', 'arrayrange', |
|
914 'asanyarray', 'asarray', 'asarray_chkfinite', 'ascontiguousarray', |
|
915 'asfarray', 'asfortranarray', 'asmatrix', 'asscalar', 'astype', |
|
916 'atleast_1d', 'atleast_2d', 'atleast_3d', 'average', 'bartlett', |
|
917 'base_repr', 'beta', 'binary_repr', 'bincount', 'binomial', |
|
918 'bitwise_and', 'bitwise_not', 'bitwise_or', 'bitwise_xor', 'blackman', |
|
919 'bmat', 'broadcast', 'byte_bounds', 'bytes', 'byteswap', 'c_', |
|
920 'can_cast', 'ceil', 'choose', 'clip', 'column_stack', 'common_type', |
|
921 'compare_chararrays', 'compress', 'concatenate', 'conj', 'conjugate', |
|
922 'convolve', 'copy', 'corrcoef', 'correlate', 'cos', 'cosh', 'cov', |
|
923 'cross', 'cumprod', 'cumproduct', 'cumsum', 'delete', 'deprecate', |
|
924 'diag', 'diagflat', 'diagonal', 'diff', 'digitize', 'disp', 'divide', |
|
925 'dot', 'dsplit', 'dstack', 'dtype', 'dump', 'dumps', 'ediff1d', 'empty', |
|
926 'empty_like', 'equal', 'exp', 'expand_dims', 'expm1', 'extract', 'eye', |
|
927 'fabs', 'fastCopyAndTranspose', 'fft', 'fftfreq', 'fftshift', 'fill', |
|
928 'finfo', 'fix', 'flat', 'flatnonzero', 'flatten', 'fliplr', 'flipud', |
|
929 'floor', 'floor_divide', 'fmod', 'frexp', 'fromarrays', 'frombuffer', |
|
930 'fromfile', 'fromfunction', 'fromiter', 'frompyfunc', 'fromstring', |
|
931 'generic', 'get_array_wrap', 'get_include', 'get_numarray_include', |
|
932 'get_numpy_include', 'get_printoptions', 'getbuffer', 'getbufsize', |
|
933 'geterr', 'geterrcall', 'geterrobj', 'getfield', 'gradient', 'greater', |
|
934 'greater_equal', 'gumbel', 'hamming', 'hanning', 'histogram', |
|
935 'histogram2d', 'histogramdd', 'hsplit', 'hstack', 'hypot', 'i0', |
|
936 'identity', 'ifft', 'imag', 'index_exp', 'indices', 'inf', 'info', |
|
937 'inner', 'insert', 'int_asbuffer', 'interp', 'intersect1d', |
|
938 'intersect1d_nu', 'inv', 'invert', 'iscomplex', 'iscomplexobj', |
|
939 'isfinite', 'isfortran', 'isinf', 'isnan', 'isneginf', 'isposinf', |
|
940 'isreal', 'isrealobj', 'isscalar', 'issctype', 'issubclass_', |
|
941 'issubdtype', 'issubsctype', 'item', 'itemset', 'iterable', 'ix_', |
|
942 'kaiser', 'kron', 'ldexp', 'left_shift', 'less', 'less_equal', 'lexsort', |
|
943 'linspace', 'load', 'loads', 'loadtxt', 'log', 'log10', 'log1p', 'log2', |
|
944 'logical_and', 'logical_not', 'logical_or', 'logical_xor', 'logspace', |
|
945 'lstsq', 'mat', 'matrix', 'max', 'maximum', 'maximum_sctype', |
|
946 'may_share_memory', 'mean', 'median', 'meshgrid', 'mgrid', 'min', |
|
947 'minimum', 'mintypecode', 'mod', 'modf', 'msort', 'multiply', 'nan', |
|
948 'nan_to_num', 'nanargmax', 'nanargmin', 'nanmax', 'nanmin', 'nansum', |
|
949 'ndenumerate', 'ndim', 'ndindex', 'negative', 'newaxis', 'newbuffer', |
|
950 'newbyteorder', 'nonzero', 'not_equal', 'obj2sctype', 'ogrid', 'ones', |
|
951 'ones_like', 'outer', 'permutation', 'piecewise', 'pinv', 'pkgload', |
|
952 'place', 'poisson', 'poly', 'poly1d', 'polyadd', 'polyder', 'polydiv', |
|
953 'polyfit', 'polyint', 'polymul', 'polysub', 'polyval', 'power', 'prod', |
|
954 'product', 'ptp', 'put', 'putmask', 'r_', 'randint', 'random_integers', |
|
955 'random_sample', 'ranf', 'rank', 'ravel', 'real', 'real_if_close', |
|
956 'recarray', 'reciprocal', 'reduce', 'remainder', 'repeat', 'require', |
|
957 'reshape', 'resize', 'restoredot', 'right_shift', 'rint', 'roll', |
|
958 'rollaxis', 'roots', 'rot90', 'round', 'round_', 'row_stack', 's_', |
|
959 'sample', 'savetxt', 'sctype2char', 'searchsorted', 'seed', 'select', |
|
960 'set_numeric_ops', 'set_printoptions', 'set_string_function', |
|
961 'setbufsize', 'setdiff1d', 'seterr', 'seterrcall', 'seterrobj', |
|
962 'setfield', 'setflags', 'setmember1d', 'setxor1d', 'shape', |
|
963 'show_config', 'shuffle', 'sign', 'signbit', 'sin', 'sinc', 'sinh', |
|
964 'size', 'slice', 'solve', 'sometrue', 'sort', 'sort_complex', 'source', |
|
965 'split', 'sqrt', 'square', 'squeeze', 'standard_normal', 'std', |
|
966 'subtract', 'sum', 'svd', 'swapaxes', 'take', 'tan', 'tanh', 'tensordot', |
|
967 'test', 'tile', 'tofile', 'tolist', 'tostring', 'trace', 'transpose', |
|
968 'trapz', 'tri', 'tril', 'trim_zeros', 'triu', 'true_divide', 'typeDict', |
|
969 'typename', 'uniform', 'union1d', 'unique', 'unique1d', 'unravel_index', |
|
970 'unwrap', 'vander', 'var', 'vdot', 'vectorize', 'view', 'vonmises', |
|
971 'vsplit', 'vstack', 'weibull', 'where', 'who', 'zeros', 'zeros_like' |
|
972 ]) |
|
973 |
|
974 def get_tokens_unprocessed(self, text): |
|
975 for index, token, value in \ |
|
976 PythonLexer.get_tokens_unprocessed(self, text): |
|
977 if token is Name and value in self.EXTRA_KEYWORDS: |
|
978 yield index, Keyword.Pseudo, value |
|
979 else: |
|
980 yield index, token, value |
|
981 |
|
982 |
|
983 class RConsoleLexer(Lexer): |
|
984 """ |
|
985 For R console transcripts or R CMD BATCH output files. |
|
986 """ |
|
987 |
|
988 name = 'RConsole' |
|
989 aliases = ['rconsole', 'rout'] |
|
990 filenames = ['*.Rout'] |
|
991 |
|
992 def get_tokens_unprocessed(self, text): |
|
993 slexer = SLexer(**self.options) |
|
994 |
|
995 current_code_block = '' |
|
996 insertions = [] |
|
997 |
|
998 for match in line_re.finditer(text): |
|
999 line = match.group() |
|
1000 if line.startswith('>') or line.startswith('+'): |
|
1001 # Colorize the prompt as such, |
|
1002 # then put rest of line into current_code_block |
|
1003 insertions.append((len(current_code_block), |
|
1004 [(0, Generic.Prompt, line[:2])])) |
|
1005 current_code_block += line[2:] |
|
1006 else: |
|
1007 # We have reached a non-prompt line! |
|
1008 # If we have stored prompt lines, need to process them first. |
|
1009 if current_code_block: |
|
1010 # Weave together the prompts and highlight code. |
|
1011 for item in do_insertions(insertions, |
|
1012 slexer.get_tokens_unprocessed(current_code_block)): |
|
1013 yield item |
|
1014 # Reset vars for next code block. |
|
1015 current_code_block = '' |
|
1016 insertions = [] |
|
1017 # Now process the actual line itself, this is output from R. |
|
1018 yield match.start(), Generic.Output, line |
|
1019 |
|
1020 # If we happen to end on a code block with nothing after it, need to |
|
1021 # process the last code block. This is neither elegant nor DRY so |
|
1022 # should be changed. |
|
1023 if current_code_block: |
|
1024 for item in do_insertions(insertions, |
|
1025 slexer.get_tokens_unprocessed(current_code_block)): |
|
1026 yield item |
|
1027 |
|
1028 |
|
1029 class SLexer(RegexLexer): |
|
1030 """ |
|
1031 For S, S-plus, and R source code. |
|
1032 |
|
1033 *New in Pygments 0.10.* |
|
1034 """ |
|
1035 |
|
1036 name = 'S' |
|
1037 aliases = ['splus', 's', 'r'] |
|
1038 filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile'] |
|
1039 mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r', |
|
1040 'text/x-R', 'text/x-r-history', 'text/x-r-profile'] |
|
1041 |
|
1042 tokens = { |
|
1043 'comments': [ |
|
1044 (r'#.*$', Comment.Single), |
|
1045 ], |
|
1046 'valid_name': [ |
|
1047 (r'[a-zA-Z][0-9a-zA-Z\._]*', Text), |
|
1048 # can begin with ., but not if that is followed by a digit |
|
1049 (r'\.[a-zA-Z_][0-9a-zA-Z\._]*', Text), |
|
1050 ], |
|
1051 'punctuation': [ |
|
1052 (r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation), |
|
1053 ], |
|
1054 'keywords': [ |
|
1055 (r'(if|else|for|while|repeat|in|next|break|return|switch|function)' |
|
1056 r'(?![0-9a-zA-Z\._])', |
|
1057 Keyword.Reserved) |
|
1058 ], |
|
1059 'operators': [ |
|
1060 (r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator), |
|
1061 (r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator) |
|
1062 ], |
|
1063 'builtin_symbols': [ |
|
1064 (r'(NULL|NA(_(integer|real|complex|character)_)?|' |
|
1065 r'Inf|TRUE|FALSE|NaN|\.\.(\.|[0-9]+))' |
|
1066 r'(?![0-9a-zA-Z\._])', |
|
1067 Keyword.Constant), |
|
1068 (r'(T|F)\b', Keyword.Variable), |
|
1069 ], |
|
1070 'numbers': [ |
|
1071 # hex number |
|
1072 (r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex), |
|
1073 # decimal number |
|
1074 (r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?', |
|
1075 Number), |
|
1076 ], |
|
1077 'statements': [ |
|
1078 include('comments'), |
|
1079 # whitespaces |
|
1080 (r'\s+', Text), |
|
1081 (r'`.*?`', String.Backtick), |
|
1082 (r'\'', String, 'string_squote'), |
|
1083 (r'\"', String, 'string_dquote'), |
|
1084 include('builtin_symbols'), |
|
1085 include('numbers'), |
|
1086 include('keywords'), |
|
1087 include('punctuation'), |
|
1088 include('operators'), |
|
1089 include('valid_name'), |
|
1090 ], |
|
1091 'root': [ |
|
1092 include('statements'), |
|
1093 # blocks: |
|
1094 (r'\{|\}', Punctuation), |
|
1095 #(r'\{', Punctuation, 'block'), |
|
1096 (r'.', Text), |
|
1097 ], |
|
1098 #'block': [ |
|
1099 # include('statements'), |
|
1100 # ('\{', Punctuation, '#push'), |
|
1101 # ('\}', Punctuation, '#pop') |
|
1102 #], |
|
1103 'string_squote': [ |
|
1104 (r'([^\'\\]|\\.)*\'', String, '#pop'), |
|
1105 ], |
|
1106 'string_dquote': [ |
|
1107 (r'([^"\\]|\\.)*"', String, '#pop'), |
|
1108 ], |
|
1109 } |
|
1110 |
|
1111 def analyse_text(text): |
|
1112 return '<-' in text |
|
1113 |
|
1114 |
|
1115 class BugsLexer(RegexLexer): |
|
1116 """ |
|
1117 Pygments Lexer for `OpenBugs <http://www.openbugs.info/w/>`_ and WinBugs |
|
1118 models. |
|
1119 |
|
1120 *New in Pygments 1.6.* |
|
1121 """ |
|
1122 |
|
1123 name = 'BUGS' |
|
1124 aliases = ['bugs', 'winbugs', 'openbugs'] |
|
1125 filenames = ['*.bug'] |
|
1126 |
|
1127 _FUNCTIONS = [ |
|
1128 # Scalar functions |
|
1129 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', |
|
1130 'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance', |
|
1131 'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log', |
|
1132 'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value', |
|
1133 'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior', |
|
1134 'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh', |
|
1135 'trunc', |
|
1136 # Vector functions |
|
1137 'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals', |
|
1138 'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM', |
|
1139 'sd', 'sort', 'sum', |
|
1140 ## Special |
|
1141 'D', 'I', 'F', 'T', 'C'] |
|
1142 """ OpenBUGS built-in functions |
|
1143 |
|
1144 From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII |
|
1145 |
|
1146 This also includes |
|
1147 |
|
1148 - T, C, I : Truncation and censoring. |
|
1149 ``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS. |
|
1150 - D : ODE |
|
1151 - F : Functional http://www.openbugs.info/Examples/Functionals.html |
|
1152 |
|
1153 """ |
|
1154 |
|
1155 _DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois', |
|
1156 'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp', |
|
1157 'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar', |
|
1158 'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar', |
|
1159 'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm', |
|
1160 'dmt', 'dwish'] |
|
1161 """ OpenBUGS built-in distributions |
|
1162 |
|
1163 Functions from |
|
1164 http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI |
|
1165 """ |
|
1166 |
|
1167 |
|
1168 tokens = { |
|
1169 'whitespace' : [ |
|
1170 (r"\s+", Text), |
|
1171 ], |
|
1172 'comments' : [ |
|
1173 # Comments |
|
1174 (r'#.*$', Comment.Single), |
|
1175 ], |
|
1176 'root': [ |
|
1177 # Comments |
|
1178 include('comments'), |
|
1179 include('whitespace'), |
|
1180 # Block start |
|
1181 (r'(model)(\s+)({)', |
|
1182 bygroups(Keyword.Namespace, Text, Punctuation)), |
|
1183 # Reserved Words |
|
1184 (r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved), |
|
1185 # Built-in Functions |
|
1186 (r'(%s)(?=\s*\()' |
|
1187 % r'|'.join(_FUNCTIONS + _DISTRIBUTIONS), |
|
1188 Name.Builtin), |
|
1189 # Regular variable names |
|
1190 (r'[A-Za-z][A-Za-z0-9_.]*', Name), |
|
1191 # Number Literals |
|
1192 (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), |
|
1193 # Punctuation |
|
1194 (r'\[|\]|\(|\)|:|,|;', Punctuation), |
|
1195 # Assignment operators |
|
1196 # SLexer makes these tokens Operators. |
|
1197 (r'<-|~', Operator), |
|
1198 # Infix and prefix operators |
|
1199 (r'\+|-|\*|/', Operator), |
|
1200 # Block |
|
1201 (r'[{}]', Punctuation), |
|
1202 ] |
|
1203 } |
|
1204 |
|
1205 def analyse_text(text): |
|
1206 if re.search(r"^\s*model\s*{", text, re.M): |
|
1207 return 0.7 |
|
1208 else: |
|
1209 return 0.0 |
|
1210 |
|
1211 class JagsLexer(RegexLexer): |
|
1212 """ |
|
1213 Pygments Lexer for JAGS. |
|
1214 |
|
1215 *New in Pygments 1.6.* |
|
1216 """ |
|
1217 |
|
1218 name = 'JAGS' |
|
1219 aliases = ['jags'] |
|
1220 filenames = ['*.jag', '*.bug'] |
|
1221 |
|
1222 ## JAGS |
|
1223 _FUNCTIONS = [ |
|
1224 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh', |
|
1225 'cos', 'cosh', 'cloglog', |
|
1226 'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact', |
|
1227 'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh', |
|
1228 'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin', |
|
1229 'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse', |
|
1230 'rank', 'sort', 't', 'acos', 'acosh', 'asin', 'asinh', 'atan', |
|
1231 # Truncation/Censoring (should I include) |
|
1232 'T', 'I'] |
|
1233 # Distributions with density, probability and quartile functions |
|
1234 _DISTRIBUTIONS = ['[dpq]%s' % x for x in |
|
1235 ['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp', |
|
1236 'df', 'gamma', 'gen.gamma', 'logis', 'lnorm', |
|
1237 'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']] |
|
1238 # Other distributions without density and probability |
|
1239 _OTHER_DISTRIBUTIONS = [ |
|
1240 'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper', |
|
1241 'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq', |
|
1242 'dnbinom', 'dweibull', 'ddirich'] |
|
1243 |
|
1244 tokens = { |
|
1245 'whitespace' : [ |
|
1246 (r"\s+", Text), |
|
1247 ], |
|
1248 'names' : [ |
|
1249 # Regular variable names |
|
1250 (r'[a-zA-Z][a-zA-Z0-9_.]*\b', Name), |
|
1251 ], |
|
1252 'comments' : [ |
|
1253 # do not use stateful comments |
|
1254 (r'(?s)/\*.*?\*/', Comment.Multiline), |
|
1255 # Comments |
|
1256 (r'#.*$', Comment.Single), |
|
1257 ], |
|
1258 'root': [ |
|
1259 # Comments |
|
1260 include('comments'), |
|
1261 include('whitespace'), |
|
1262 # Block start |
|
1263 (r'(model|data)(\s+)({)', |
|
1264 bygroups(Keyword.Namespace, Text, Punctuation)), |
|
1265 (r'var(?![0-9a-zA-Z\._])', Keyword.Declaration), |
|
1266 # Reserved Words |
|
1267 (r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved), |
|
1268 # Builtins |
|
1269 # Need to use lookahead because . is a valid char |
|
1270 (r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS |
|
1271 + _DISTRIBUTIONS |
|
1272 + _OTHER_DISTRIBUTIONS), |
|
1273 Name.Builtin), |
|
1274 # Names |
|
1275 include('names'), |
|
1276 # Number Literals |
|
1277 (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number), |
|
1278 (r'\[|\]|\(|\)|:|,|;', Punctuation), |
|
1279 # Assignment operators |
|
1280 (r'<-|~', Operator), |
|
1281 # # JAGS includes many more than OpenBUGS |
|
1282 (r'\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%', Operator), |
|
1283 (r'[{}]', Punctuation), |
|
1284 ] |
|
1285 } |
|
1286 |
|
1287 def analyse_text(text): |
|
1288 if re.search(r'^\s*model\s*\{', text, re.M): |
|
1289 if re.search(r'^\s*data\s*\{', text, re.M): |
|
1290 return 0.9 |
|
1291 elif re.search(r'^\s*var', text, re.M): |
|
1292 return 0.9 |
|
1293 else: |
|
1294 return 0.3 |
|
1295 else: |
|
1296 return 0 |
|
1297 |
|
1298 class StanLexer(RegexLexer): |
|
1299 """ |
|
1300 Pygments Lexer for Stan models. |
|
1301 |
|
1302 *New in Pygments 1.6.* |
|
1303 """ |
|
1304 |
|
1305 name = 'Stan' |
|
1306 aliases = ['stan'] |
|
1307 filenames = ['*.stan'] |
|
1308 |
|
1309 _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if', |
|
1310 'then', 'else', 'true', 'false', 'T', |
|
1311 'lower', 'upper', 'print') |
|
1312 |
|
1313 _TYPES = ('int', 'real', 'vector', 'simplex', 'ordered', 'row_vector', |
|
1314 'matrix', 'corr_matrix', 'cov_matrix', 'positive_ordered') |
|
1315 |
|
1316 tokens = { |
|
1317 'whitespace' : [ |
|
1318 (r"\s+", Text), |
|
1319 ], |
|
1320 'comments' : [ |
|
1321 (r'(?s)/\*.*?\*/', Comment.Multiline), |
|
1322 # Comments |
|
1323 (r'(//|#).*$', Comment.Single), |
|
1324 ], |
|
1325 'root': [ |
|
1326 # Stan is more restrictive on strings than this regex |
|
1327 (r'"[^"]*"', String), |
|
1328 # Comments |
|
1329 include('comments'), |
|
1330 # block start |
|
1331 include('whitespace'), |
|
1332 # Block start |
|
1333 (r'(%s)(\s*)({)' % |
|
1334 r'|'.join(('data', r'transformed\s+?data', |
|
1335 'parameters', r'transformed\s+parameters', |
|
1336 'model', r'generated\s+quantities')), |
|
1337 bygroups(Keyword.Namespace, Text, Punctuation)), |
|
1338 # Reserved Words |
|
1339 (r'(%s)\b' % r'|'.join(_RESERVED), Keyword.Reserved), |
|
1340 # Data types |
|
1341 (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type), |
|
1342 # Punctuation |
|
1343 (r"[;:,\[\]()<>]", Punctuation), |
|
1344 # Builtin |
|
1345 (r'(%s)(?=\s*\()' |
|
1346 % r'|'.join(_stan_builtins.FUNCTIONS |
|
1347 + _stan_builtins.DISTRIBUTIONS), |
|
1348 Name.Builtin), |
|
1349 (r'(%s)(?=\s*\()' |
|
1350 % r'|'.join(_stan_builtins.CONSTANTS), Keyword.Constant), |
|
1351 # Special names ending in __, like lp__ |
|
1352 (r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo), |
|
1353 # Regular variable names |
|
1354 (r'[A-Za-z][A-Za-z0-9_]*\b', Name), |
|
1355 # Real Literals |
|
1356 (r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float), |
|
1357 (r'-?[0-9]*\.[0-9]*', Number.Float), |
|
1358 # Integer Literals |
|
1359 (r'-?[0-9]+', Number.Integer), |
|
1360 # Assignment operators |
|
1361 # SLexer makes these tokens Operators. |
|
1362 (r'<-|~', Operator), |
|
1363 # Infix and prefix operators (and = ) |
|
1364 (r"\+|-|\.?\*|\.?/|\\|'|=", Operator), |
|
1365 # Block delimiters |
|
1366 (r'[{}]', Punctuation), |
|
1367 ] |
|
1368 } |
|
1369 |
|
1370 def analyse_text(text): |
|
1371 if re.search(r'^\s*parameters\s*\{', text, re.M): |
|
1372 return 1.0 |
|
1373 else: |
|
1374 return 0.0 |
|
1375 |
|
1376 |
|
1377 class IDLLexer(RegexLexer): |
|
1378 """ |
|
1379 Pygments Lexer for IDL (Interactive Data Language). |
|
1380 |
|
1381 *New in Pygments 1.6.* |
|
1382 """ |
|
1383 name = 'IDL' |
|
1384 aliases = ['idl'] |
|
1385 filenames = ['*.pro'] |
|
1386 mimetypes = ['text/idl'] |
|
1387 |
|
1388 _RESERVED = ['and', 'begin', 'break', 'case', 'common', 'compile_opt', |
|
1389 'continue', 'do', 'else', 'end', 'endcase', 'elseelse', |
|
1390 'endfor', 'endforeach', 'endif', 'endrep', 'endswitch', |
|
1391 'endwhile', 'eq', 'for', 'foreach', 'forward_function', |
|
1392 'function', 'ge', 'goto', 'gt', 'if', 'inherits', 'le', |
|
1393 'lt', 'mod', 'ne', 'not', 'of', 'on_ioerror', 'or', 'pro', |
|
1394 'repeat', 'switch', 'then', 'until', 'while', 'xor'] |
|
1395 """Reserved words from: http://www.exelisvis.com/docs/reswords.html""" |
|
1396 |
|
1397 _BUILTIN_LIB = ['abs', 'acos', 'adapt_hist_equal', 'alog', 'alog10', |
|
1398 'amoeba', 'annotate', 'app_user_dir', 'app_user_dir_query', |
|
1399 'arg_present', 'array_equal', 'array_indices', 'arrow', |
|
1400 'ascii_template', 'asin', 'assoc', 'atan', 'axis', |
|
1401 'a_correlate', 'bandpass_filter', 'bandreject_filter', |
|
1402 'barplot', 'bar_plot', 'beseli', 'beselj', 'beselk', |
|
1403 'besely', 'beta', 'bilinear', 'binary_template', 'bindgen', |
|
1404 'binomial', 'bin_date', 'bit_ffs', 'bit_population', |
|
1405 'blas_axpy', 'blk_con', 'box_cursor', 'breakpoint', |
|
1406 'broyden', 'butterworth', 'bytarr', 'byte', 'byteorder', |
|
1407 'bytscl', 'caldat', 'calendar', 'call_external', |
|
1408 'call_function', 'call_method', 'call_procedure', 'canny', |
|
1409 'catch', 'cd', 'cdf_[0-9a-za-z_]*', 'ceil', 'chebyshev', |
|
1410 'check_math', |
|
1411 'chisqr_cvf', 'chisqr_pdf', 'choldc', 'cholsol', 'cindgen', |
|
1412 'cir_3pnt', 'close', 'cluster', 'cluster_tree', 'clust_wts', |
|
1413 'cmyk_convert', 'colorbar', 'colorize_sample', |
|
1414 'colormap_applicable', 'colormap_gradient', |
|
1415 'colormap_rotation', 'colortable', 'color_convert', |
|
1416 'color_exchange', 'color_quan', 'color_range_map', 'comfit', |
|
1417 'command_line_args', 'complex', 'complexarr', 'complexround', |
|
1418 'compute_mesh_normals', 'cond', 'congrid', 'conj', |
|
1419 'constrained_min', 'contour', 'convert_coord', 'convol', |
|
1420 'convol_fft', 'coord2to3', 'copy_lun', 'correlate', 'cos', |
|
1421 'cosh', 'cpu', 'cramer', 'create_cursor', 'create_struct', |
|
1422 'create_view', 'crossp', 'crvlength', 'cti_test', |
|
1423 'ct_luminance', 'cursor', 'curvefit', 'cvttobm', 'cv_coord', |
|
1424 'cw_animate', 'cw_animate_getp', 'cw_animate_load', |
|
1425 'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index', |
|
1426 'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel', |
|
1427 'cw_form', 'cw_fslider', 'cw_light_editor', |
|
1428 'cw_light_editor_get', 'cw_light_editor_set', 'cw_orient', |
|
1429 'cw_palette_editor', 'cw_palette_editor_get', |
|
1430 'cw_palette_editor_set', 'cw_pdmenu', 'cw_rgbslider', |
|
1431 'cw_tmpl', 'cw_zoom', 'c_correlate', 'dblarr', 'db_exists', |
|
1432 'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key', |
|
1433 'define_msgblk', 'define_msgblk_from_file', 'defroi', |
|
1434 'defsysv', 'delvar', 'dendrogram', 'dendro_plot', 'deriv', |
|
1435 'derivsig', 'determ', 'device', 'dfpmin', 'diag_matrix', |
|
1436 'dialog_dbconnect', 'dialog_message', 'dialog_pickfile', |
|
1437 'dialog_printersetup', 'dialog_printjob', |
|
1438 'dialog_read_image', 'dialog_write_image', 'digital_filter', |
|
1439 'dilate', 'dindgen', 'dissolve', 'dist', 'distance_measure', |
|
1440 'dlm_load', 'dlm_register', 'doc_library', 'double', |
|
1441 'draw_roi', 'edge_dog', 'efont', 'eigenql', 'eigenvec', |
|
1442 'ellipse', 'elmhes', 'emboss', 'empty', 'enable_sysrtn', |
|
1443 'eof', 'eos_[0-9a-za-z_]*', 'erase', 'erf', 'erfc', 'erfcx', |
|
1444 'erode', 'errorplot', 'errplot', 'estimator_filter', |
|
1445 'execute', 'exit', 'exp', 'expand', 'expand_path', 'expint', |
|
1446 'extrac', 'extract_slice', 'factorial', 'fft', 'filepath', |
|
1447 'file_basename', 'file_chmod', 'file_copy', 'file_delete', |
|
1448 'file_dirname', 'file_expand_path', 'file_info', |
|
1449 'file_lines', 'file_link', 'file_mkdir', 'file_move', |
|
1450 'file_poll_input', 'file_readlink', 'file_same', |
|
1451 'file_search', 'file_test', 'file_which', 'findgen', |
|
1452 'finite', 'fix', 'flick', 'float', 'floor', 'flow3', |
|
1453 'fltarr', 'flush', 'format_axis_values', 'free_lun', |
|
1454 'fstat', 'fulstr', 'funct', 'fv_test', 'fx_root', |
|
1455 'fz_roots', 'f_cvf', 'f_pdf', 'gamma', 'gamma_ct', |
|
1456 'gauss2dfit', 'gaussfit', 'gaussian_function', 'gaussint', |
|
1457 'gauss_cvf', 'gauss_pdf', 'gauss_smooth', 'getenv', |
|
1458 'getwindows', 'get_drive_list', 'get_dxf_objects', |
|
1459 'get_kbrd', 'get_login_info', 'get_lun', 'get_screen_size', |
|
1460 'greg2jul', 'grib_[0-9a-za-z_]*', 'grid3', 'griddata', |
|
1461 'grid_input', 'grid_tps', 'gs_iter', |
|
1462 'h5[adfgirst]_[0-9a-za-z_]*', 'h5_browser', 'h5_close', |
|
1463 'h5_create', 'h5_get_libversion', 'h5_open', 'h5_parse', |
|
1464 'hanning', 'hash', 'hdf_[0-9a-za-z_]*', 'heap_free', |
|
1465 'heap_gc', 'heap_nosave', 'heap_refcount', 'heap_save', |
|
1466 'help', 'hilbert', 'histogram', 'hist_2d', 'hist_equal', |
|
1467 'hls', 'hough', 'hqr', 'hsv', 'h_eq_ct', 'h_eq_int', |
|
1468 'i18n_multibytetoutf8', 'i18n_multibytetowidechar', |
|
1469 'i18n_utf8tomultibyte', 'i18n_widechartomultibyte', |
|
1470 'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity', |
|
1471 'idlexbr_assistant', 'idlitsys_createtool', 'idl_base64', |
|
1472 'idl_validname', 'iellipse', 'igamma', 'igetcurrent', |
|
1473 'igetdata', 'igetid', 'igetproperty', 'iimage', 'image', |
|
1474 'image_cont', 'image_statistics', 'imaginary', 'imap', |
|
1475 'indgen', 'intarr', 'interpol', 'interpolate', |
|
1476 'interval_volume', 'int_2d', 'int_3d', 'int_tabulated', |
|
1477 'invert', 'ioctl', 'iopen', 'iplot', 'ipolygon', |
|
1478 'ipolyline', 'iputdata', 'iregister', 'ireset', 'iresolve', |
|
1479 'irotate', 'ir_filter', 'isa', 'isave', 'iscale', |
|
1480 'isetcurrent', 'isetproperty', 'ishft', 'isocontour', |
|
1481 'isosurface', 'isurface', 'itext', 'itranslate', 'ivector', |
|
1482 'ivolume', 'izoom', 'i_beta', 'journal', 'json_parse', |
|
1483 'json_serialize', 'jul2greg', 'julday', 'keyword_set', |
|
1484 'krig2d', 'kurtosis', 'kw_test', 'l64indgen', 'label_date', |
|
1485 'label_region', 'ladfit', 'laguerre', 'laplacian', |
|
1486 'la_choldc', 'la_cholmprove', 'la_cholsol', 'la_determ', |
|
1487 'la_eigenproblem', 'la_eigenql', 'la_eigenvec', 'la_elmhes', |
|
1488 'la_gm_linear_model', 'la_hqr', 'la_invert', |
|
1489 'la_least_squares', 'la_least_square_equality', |
|
1490 'la_linear_equation', 'la_ludc', 'la_lumprove', 'la_lusol', |
|
1491 'la_svd', 'la_tridc', 'la_trimprove', 'la_triql', |
|
1492 'la_trired', 'la_trisol', 'least_squares_filter', 'leefilt', |
|
1493 'legend', 'legendre', 'linbcg', 'lindgen', 'linfit', |
|
1494 'linkimage', 'list', 'll_arc_distance', 'lmfit', 'lmgr', |
|
1495 'lngamma', 'lnp_test', 'loadct', 'locale_get', |
|
1496 'logical_and', 'logical_or', 'logical_true', 'lon64arr', |
|
1497 'lonarr', 'long', 'long64', 'lsode', 'ludc', 'lumprove', |
|
1498 'lusol', 'lu_complex', 'machar', 'make_array', 'make_dll', |
|
1499 'make_rt', 'map', 'mapcontinents', 'mapgrid', 'map_2points', |
|
1500 'map_continents', 'map_grid', 'map_image', 'map_patch', |
|
1501 'map_proj_forward', 'map_proj_image', 'map_proj_info', |
|
1502 'map_proj_init', 'map_proj_inverse', 'map_set', |
|
1503 'matrix_multiply', 'matrix_power', 'max', 'md_test', |
|
1504 'mean', 'meanabsdev', 'mean_filter', 'median', 'memory', |
|
1505 'mesh_clip', 'mesh_decimate', 'mesh_issolid', 'mesh_merge', |
|
1506 'mesh_numtriangles', 'mesh_obj', 'mesh_smooth', |
|
1507 'mesh_surfacearea', 'mesh_validate', 'mesh_volume', |
|
1508 'message', 'min', 'min_curve_surf', 'mk_html_help', |
|
1509 'modifyct', 'moment', 'morph_close', 'morph_distance', |
|
1510 'morph_gradient', 'morph_hitormiss', 'morph_open', |
|
1511 'morph_thin', 'morph_tophat', 'multi', 'm_correlate', |
|
1512 'ncdf_[0-9a-za-z_]*', 'newton', 'noise_hurl', 'noise_pick', |
|
1513 'noise_scatter', 'noise_slur', 'norm', 'n_elements', |
|
1514 'n_params', 'n_tags', 'objarr', 'obj_class', 'obj_destroy', |
|
1515 'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid', |
|
1516 'online_help', 'on_error', 'open', 'oplot', 'oploterr', |
|
1517 'parse_url', 'particle_trace', 'path_cache', 'path_sep', |
|
1518 'pcomp', 'plot', 'plot3d', 'ploterr', 'plots', 'plot_3dbox', |
|
1519 'plot_field', 'pnt_line', 'point_lun', 'polarplot', |
|
1520 'polar_contour', 'polar_surface', 'poly', 'polyfill', |
|
1521 'polyfillv', 'polygon', 'polyline', 'polyshade', 'polywarp', |
|
1522 'poly_2d', 'poly_area', 'poly_fit', 'popd', 'powell', |
|
1523 'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes', |
|
1524 'print', 'printd', 'product', 'profile', 'profiler', |
|
1525 'profiles', 'project_vol', 'psafm', 'pseudo', |
|
1526 'ps_show_fonts', 'ptrarr', 'ptr_free', 'ptr_new', |
|
1527 'ptr_valid', 'pushd', 'p_correlate', 'qgrid3', 'qhull', |
|
1528 'qromb', 'qromo', 'qsimp', 'query_ascii', 'query_bmp', |
|
1529 'query_csv', 'query_dicom', 'query_gif', 'query_image', |
|
1530 'query_jpeg', 'query_jpeg2000', 'query_mrsid', 'query_pict', |
|
1531 'query_png', 'query_ppm', 'query_srf', 'query_tiff', |
|
1532 'query_wav', 'radon', 'randomn', 'randomu', 'ranks', |
|
1533 'rdpix', 'read', 'reads', 'readu', 'read_ascii', |
|
1534 'read_binary', 'read_bmp', 'read_csv', 'read_dicom', |
|
1535 'read_gif', 'read_image', 'read_interfile', 'read_jpeg', |
|
1536 'read_jpeg2000', 'read_mrsid', 'read_pict', 'read_png', |
|
1537 'read_ppm', 'read_spr', 'read_srf', 'read_sylk', |
|
1538 'read_tiff', 'read_wav', 'read_wave', 'read_x11_bitmap', |
|
1539 'read_xwd', 'real_part', 'rebin', 'recall_commands', |
|
1540 'recon3', 'reduce_colors', 'reform', 'region_grow', |
|
1541 'register_cursor', 'regress', 'replicate', |
|
1542 'replicate_inplace', 'resolve_all', 'resolve_routine', |
|
1543 'restore', 'retall', 'return', 'reverse', 'rk4', 'roberts', |
|
1544 'rot', 'rotate', 'round', 'routine_filepath', |
|
1545 'routine_info', 'rs_test', 'r_correlate', 'r_test', |
|
1546 'save', 'savgol', 'scale3', 'scale3d', 'scope_level', |
|
1547 'scope_traceback', 'scope_varfetch', 'scope_varname', |
|
1548 'search2d', 'search3d', 'sem_create', 'sem_delete', |
|
1549 'sem_lock', 'sem_release', 'setenv', 'set_plot', |
|
1550 'set_shading', 'sfit', 'shade_surf', 'shade_surf_irr', |
|
1551 'shade_volume', 'shift', 'shift_diff', 'shmdebug', 'shmmap', |
|
1552 'shmunmap', 'shmvar', 'show3', 'showfont', 'simplex', 'sin', |
|
1553 'sindgen', 'sinh', 'size', 'skewness', 'skip_lun', |
|
1554 'slicer3', 'slide_image', 'smooth', 'sobel', 'socket', |
|
1555 'sort', 'spawn', 'spher_harm', 'sph_4pnt', 'sph_scat', |
|
1556 'spline', 'spline_p', 'spl_init', 'spl_interp', 'sprsab', |
|
1557 'sprsax', 'sprsin', 'sprstp', 'sqrt', 'standardize', |
|
1558 'stddev', 'stop', 'strarr', 'strcmp', 'strcompress', |
|
1559 'streamline', 'stregex', 'stretch', 'string', 'strjoin', |
|
1560 'strlen', 'strlowcase', 'strmatch', 'strmessage', 'strmid', |
|
1561 'strpos', 'strput', 'strsplit', 'strtrim', 'struct_assign', |
|
1562 'struct_hide', 'strupcase', 'surface', 'surfr', 'svdc', |
|
1563 'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace', |
|
1564 'symbol', 'systime', 's_test', 't3d', 'tag_names', 'tan', |
|
1565 'tanh', 'tek_color', 'temporary', 'tetra_clip', |
|
1566 'tetra_surface', 'tetra_volume', 'text', 'thin', 'threed', |
|
1567 'timegen', 'time_test2', 'tm_test', 'total', 'trace', |
|
1568 'transpose', 'triangulate', 'trigrid', 'triql', 'trired', |
|
1569 'trisol', 'tri_surf', 'truncate_lun', 'ts_coef', 'ts_diff', |
|
1570 'ts_fcast', 'ts_smooth', 'tv', 'tvcrs', 'tvlct', 'tvrd', |
|
1571 'tvscl', 'typename', 't_cvt', 't_pdf', 'uindgen', 'uint', |
|
1572 'uintarr', 'ul64indgen', 'ulindgen', 'ulon64arr', 'ulonarr', |
|
1573 'ulong', 'ulong64', 'uniq', 'unsharp_mask', 'usersym', |
|
1574 'value_locate', 'variance', 'vector', 'vector_field', 'vel', |
|
1575 'velovect', 'vert_t3d', 'voigt', 'voronoi', 'voxel_proj', |
|
1576 'wait', 'warp_tri', 'watershed', 'wdelete', 'wf_draw', |
|
1577 'where', 'widget_base', 'widget_button', 'widget_combobox', |
|
1578 'widget_control', 'widget_displaycontextmen', 'widget_draw', |
|
1579 'widget_droplist', 'widget_event', 'widget_info', |
|
1580 'widget_label', 'widget_list', 'widget_propertysheet', |
|
1581 'widget_slider', 'widget_tab', 'widget_table', |
|
1582 'widget_text', 'widget_tree', 'widget_tree_move', |
|
1583 'widget_window', 'wiener_filter', 'window', 'writeu', |
|
1584 'write_bmp', 'write_csv', 'write_gif', 'write_image', |
|
1585 'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict', |
|
1586 'write_png', 'write_ppm', 'write_spr', 'write_srf', |
|
1587 'write_sylk', 'write_tiff', 'write_wav', 'write_wave', |
|
1588 'wset', 'wshow', 'wtn', 'wv_applet', 'wv_cwt', |
|
1589 'wv_cw_wavelet', 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet', |
|
1590 'wv_fn_daubechies', 'wv_fn_gaussian', 'wv_fn_haar', |
|
1591 'wv_fn_morlet', 'wv_fn_paul', 'wv_fn_symlet', |
|
1592 'wv_import_data', 'wv_import_wavelet', 'wv_plot3d_wps', |
|
1593 'wv_plot_multires', 'wv_pwt', 'wv_tool_denoise', |
|
1594 'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont', |
|
1595 'xinteranimate', 'xloadct', 'xmanager', 'xmng_tmpl', |
|
1596 'xmtool', 'xobjview', 'xobjview_rotate', |
|
1597 'xobjview_write_image', 'xpalette', 'xpcolor', 'xplot3d', |
|
1598 'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit', |
|
1599 'xvolume', 'xvolume_rotate', 'xvolume_write_image', |
|
1600 'xyouts', 'zoom', 'zoom_24'] |
|
1601 """Functions from: http://www.exelisvis.com/docs/routines-1.html""" |
|
1602 |
|
1603 tokens = { |
|
1604 'root': [ |
|
1605 (r'^\s*;.*?\n', Comment.Singleline), |
|
1606 (r'\b(' + '|'.join(_RESERVED) + r')\b', Keyword), |
|
1607 (r'\b(' + '|'.join(_BUILTIN_LIB) + r')\b', Name.Builtin), |
|
1608 (r'\+=|-=|\^=|\*=|/=|#=|##=|<=|>=|=', Operator), |
|
1609 (r'\+\+|--|->|\+|-|##|#|\*|/|<|>|&&|\^|~|\|\|\?|:', Operator), |
|
1610 (r'\b(mod=|lt=|le=|eq=|ne=|ge=|gt=|not=|and=|or=|xor=)', Operator), |
|
1611 (r'\b(mod|lt|le|eq|ne|ge|gt|not|and|or|xor)\b', Operator), |
|
1612 (r'\b[0-9](L|B|S|UL|ULL|LL)?\b', Number), |
|
1613 (r'.', Text), |
|
1614 ] |
|
1615 } |
|
1616 |
|
1617 |
|
1618 class RdLexer(RegexLexer): |
|
1619 """ |
|
1620 Pygments Lexer for R documentation (Rd) files |
|
1621 |
|
1622 This is a very minimal implementation, highlighting little more |
|
1623 than the macros. A description of Rd syntax is found in `Writing R |
|
1624 Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_ |
|
1625 and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_. |
|
1626 |
|
1627 *New in Pygments 1.6.* |
|
1628 """ |
|
1629 name = 'Rd' |
|
1630 aliases = ['rd'] |
|
1631 filenames = ['*.Rd'] |
|
1632 mimetypes = ['text/x-r-doc'] |
|
1633 |
|
1634 # To account for verbatim / LaTeX-like / and R-like areas |
|
1635 # would require parsing. |
|
1636 tokens = { |
|
1637 'root' : [ |
|
1638 # catch escaped brackets and percent sign |
|
1639 (r'\\[\\{}%]', String.Escape), |
|
1640 # comments |
|
1641 (r'%.*$', Comment), |
|
1642 # special macros with no arguments |
|
1643 (r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant), |
|
1644 # macros |
|
1645 (r'\\[a-zA-Z]+\b', Keyword), |
|
1646 # special preprocessor macros |
|
1647 (r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc), |
|
1648 # non-escaped brackets |
|
1649 (r'[{}]', Name.Builtin), |
|
1650 # everything else |
|
1651 (r'[^\\%\n{}]+', Text), |
|
1652 (r'.', Text), |
|
1653 ] |
|
1654 } |
|