ThirdParty/Pygments/pygments/lexers/math.py

changeset 1705
b0fbc9300f2b
parent 808
8f85926125ef
child 2426
da76c71624de
equal deleted inserted replaced
1704:02ae6c55b35b 1705:b0fbc9300f2b
3 pygments.lexers.math 3 pygments.lexers.math
4 ~~~~~~~~~~~~~~~~~~~~ 4 ~~~~~~~~~~~~~~~~~~~~
5 5
6 Lexers for math languages. 6 Lexers for math languages.
7 7
8 :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2012 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 re 12 import re
13 13
14 from pygments.lexer import Lexer, RegexLexer, bygroups, include, do_insertions 14 from pygments.lexer import Lexer, RegexLexer, bygroups, include, do_insertions
15 from pygments.token import Comment, String, Punctuation, Keyword, Name, \ 15 from pygments.token import Comment, String, Punctuation, Keyword, Name, \
16 Operator, Number, Text, Generic 16 Operator, Number, Text, Generic
17 17
18 from pygments.lexers.agile import PythonLexer 18 from pygments.lexers.agile import PythonLexer
19 19 from pygments.lexers import _scilab_builtins
20 __all__ = ['MuPADLexer', 'MatlabLexer', 'MatlabSessionLexer', 'NumPyLexer', 20
21 'RConsoleLexer', 'SLexer'] 21 __all__ = ['MuPADLexer', 'MatlabLexer', 'MatlabSessionLexer', 'OctaveLexer',
22 'ScilabLexer', 'NumPyLexer', 'RConsoleLexer', 'SLexer']
22 23
23 24
24 class MuPADLexer(RegexLexer): 25 class MuPADLexer(RegexLexer):
25 """ 26 """
26 A `MuPAD <http://www.mupad.com>`_ lexer. 27 A `MuPAD <http://www.mupad.com>`_ lexer.
72 Operator.Word), 73 Operator.Word),
73 (r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number), 74 (r'\b(?:I|RDN_INF|RD_NINF|RD_NAN)\b', Number),
74 #(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin), 75 #(r'\b(?:adt|linalg|newDomain|hold)\b', Name.Builtin),
75 (r'''(?x) 76 (r'''(?x)
76 ((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`) 77 ((?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
77 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)\s*([(])''', 78 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*)(\s*)([(])''',
78 bygroups(Name.Function, Punctuation)), 79 bygroups(Name.Function, Text, Punctuation)),
79 (r'''(?x) 80 (r'''(?x)
80 (?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`) 81 (?:[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)
81 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable), 82 (?:::[a-zA-Z_#][a-zA-Z_#0-9]*|`[^`]*`)*''', Name.Variable),
82 (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number), 83 (r'[0-9]+(?:\.[0-9]*)?(?:e[0-9]+)?', Number),
83 (r'\.[0-9]+(?:e[0-9]+)?', Number), 84 (r'\.[0-9]+(?:e[0-9]+)?', Number),
92 } 93 }
93 94
94 95
95 class MatlabLexer(RegexLexer): 96 class MatlabLexer(RegexLexer):
96 """ 97 """
97 For Matlab (or GNU Octave) source code. 98 For Matlab source code.
98 Contributed by Ken Schutte <kschutte@csail.mit.edu>. 99 Contributed by Ken Schutte <kschutte@csail.mit.edu>.
99 100
100 *New in Pygments 0.10.* 101 *New in Pygments 0.10.*
101 """ 102 """
102 name = 'Matlab' 103 name = 'Matlab'
103 aliases = ['matlab', 'octave'] 104 aliases = ['matlab']
104 filenames = ['*.m'] 105 filenames = ['*.m']
105 mimetypes = ['text/matlab'] 106 mimetypes = ['text/matlab']
106 107
107 # 108 #
108 # These lists are generated automatically. 109 # These lists are generated automatically.
193 return 0.9 194 return 0.9
194 elif re.match('^!\w+', text, re.M): # system cmd 195 elif re.match('^!\w+', text, re.M): # system cmd
195 return 0.9 196 return 0.9
196 return 0.1 197 return 0.1
197 198
199
198 line_re = re.compile('.*?\n') 200 line_re = re.compile('.*?\n')
199 201
200 class MatlabSessionLexer(Lexer): 202 class MatlabSessionLexer(Lexer):
201 """ 203 """
202 For Matlab (or GNU Octave) sessions. Modeled after PythonConsoleLexer. 204 For Matlab sessions. Modeled after PythonConsoleLexer.
203 Contributed by Ken Schutte <kschutte@csail.mit.edu>. 205 Contributed by Ken Schutte <kschutte@csail.mit.edu>.
204 206
205 *New in Pygments 0.10.* 207 *New in Pygments 0.10.*
206 """ 208 """
207 name = 'Matlab session' 209 name = 'Matlab session'
244 for item in do_insertions( 246 for item in do_insertions(
245 insertions, mlexer.get_tokens_unprocessed(curcode)): 247 insertions, mlexer.get_tokens_unprocessed(curcode)):
246 yield item 248 yield item
247 249
248 250
251 class OctaveLexer(RegexLexer):
252 """
253 For GNU Octave source code.
254
255 *New in Pygments 1.5.*
256 """
257 name = 'Octave'
258 aliases = ['octave']
259 filenames = ['*.m']
260 mimetypes = ['text/octave']
261
262 # These lists are generated automatically.
263 # Run the following in bash shell:
264 #
265 # First dump all of the Octave manual into a plain text file:
266 #
267 # $ info octave --subnodes -o octave-manual
268 #
269 # Now grep through it:
270
271 # for i in \
272 # "Built-in Function" "Command" "Function File" \
273 # "Loadable Function" "Mapping Function";
274 # do
275 # perl -e '@name = qw('"$i"');
276 # print lc($name[0]),"_kw = [\n"';
277 #
278 # perl -n -e 'print "\"$1\",\n" if /-- '"$i"': .* (\w*) \(/;' \
279 # octave-manual | sort | uniq ;
280 # echo "]" ;
281 # echo;
282 # done
283
284 # taken from Octave Mercurial changeset 8cc154f45e37 (30-jan-2011)
285
286 builtin_kw = [ "addlistener", "addpath", "addproperty", "all",
287 "and", "any", "argnames", "argv", "assignin",
288 "atexit", "autoload",
289 "available_graphics_toolkits", "beep_on_error",
290 "bitand", "bitmax", "bitor", "bitshift", "bitxor",
291 "cat", "cell", "cellstr", "char", "class", "clc",
292 "columns", "command_line_path",
293 "completion_append_char", "completion_matches",
294 "complex", "confirm_recursive_rmdir", "cputime",
295 "crash_dumps_octave_core", "ctranspose", "cumprod",
296 "cumsum", "debug_on_error", "debug_on_interrupt",
297 "debug_on_warning", "default_save_options",
298 "dellistener", "diag", "diff", "disp",
299 "doc_cache_file", "do_string_escapes", "double",
300 "drawnow", "e", "echo_executing_commands", "eps",
301 "eq", "errno", "errno_list", "error", "eval",
302 "evalin", "exec", "exist", "exit", "eye", "false",
303 "fclear", "fclose", "fcntl", "fdisp", "feof",
304 "ferror", "feval", "fflush", "fgetl", "fgets",
305 "fieldnames", "file_in_loadpath", "file_in_path",
306 "filemarker", "filesep", "find_dir_in_path",
307 "fixed_point_format", "fnmatch", "fopen", "fork",
308 "formula", "fprintf", "fputs", "fread", "freport",
309 "frewind", "fscanf", "fseek", "fskipl", "ftell",
310 "functions", "fwrite", "ge", "genpath", "get",
311 "getegid", "getenv", "geteuid", "getgid",
312 "getpgrp", "getpid", "getppid", "getuid", "glob",
313 "gt", "gui_mode", "history_control",
314 "history_file", "history_size",
315 "history_timestamp_format_string", "home",
316 "horzcat", "hypot", "ifelse",
317 "ignore_function_time_stamp", "inferiorto",
318 "info_file", "info_program", "inline", "input",
319 "intmax", "intmin", "ipermute",
320 "is_absolute_filename", "isargout", "isbool",
321 "iscell", "iscellstr", "ischar", "iscomplex",
322 "isempty", "isfield", "isfloat", "isglobal",
323 "ishandle", "isieee", "isindex", "isinteger",
324 "islogical", "ismatrix", "ismethod", "isnull",
325 "isnumeric", "isobject", "isreal",
326 "is_rooted_relative_filename", "issorted",
327 "isstruct", "isvarname", "kbhit", "keyboard",
328 "kill", "lasterr", "lasterror", "lastwarn",
329 "ldivide", "le", "length", "link", "linspace",
330 "logical", "lstat", "lt", "make_absolute_filename",
331 "makeinfo_program", "max_recursion_depth", "merge",
332 "methods", "mfilename", "minus", "mislocked",
333 "mkdir", "mkfifo", "mkstemp", "mldivide", "mlock",
334 "mouse_wheel_zoom", "mpower", "mrdivide", "mtimes",
335 "munlock", "nargin", "nargout",
336 "native_float_format", "ndims", "ne", "nfields",
337 "nnz", "norm", "not", "numel", "nzmax",
338 "octave_config_info", "octave_core_file_limit",
339 "octave_core_file_name",
340 "octave_core_file_options", "ones", "or",
341 "output_max_field_width", "output_precision",
342 "page_output_immediately", "page_screen_output",
343 "path", "pathsep", "pause", "pclose", "permute",
344 "pi", "pipe", "plus", "popen", "power",
345 "print_empty_dimensions", "printf",
346 "print_struct_array_contents", "prod",
347 "program_invocation_name", "program_name",
348 "putenv", "puts", "pwd", "quit", "rats", "rdivide",
349 "readdir", "readlink", "read_readline_init_file",
350 "realmax", "realmin", "rehash", "rename",
351 "repelems", "re_read_readline_init_file", "reset",
352 "reshape", "resize", "restoredefaultpath",
353 "rethrow", "rmdir", "rmfield", "rmpath", "rows",
354 "save_header_format_string", "save_precision",
355 "saving_history", "scanf", "set", "setenv",
356 "shell_cmd", "sighup_dumps_octave_core",
357 "sigterm_dumps_octave_core", "silent_functions",
358 "single", "size", "size_equal", "sizemax",
359 "sizeof", "sleep", "source", "sparse_auto_mutate",
360 "split_long_rows", "sprintf", "squeeze", "sscanf",
361 "stat", "stderr", "stdin", "stdout", "strcmp",
362 "strcmpi", "string_fill_char", "strncmp",
363 "strncmpi", "struct", "struct_levels_to_print",
364 "strvcat", "subsasgn", "subsref", "sum", "sumsq",
365 "superiorto", "suppress_verbose_help_message",
366 "symlink", "system", "tic", "tilde_expand",
367 "times", "tmpfile", "tmpnam", "toc", "toupper",
368 "transpose", "true", "typeinfo", "umask", "uminus",
369 "uname", "undo_string_escapes", "unlink", "uplus",
370 "upper", "usage", "usleep", "vec", "vectorize",
371 "vertcat", "waitpid", "warning", "warranty",
372 "whos_line_format", "yes_or_no", "zeros",
373 "inf", "Inf", "nan", "NaN"]
374
375 command_kw = [ "close", "load", "who", "whos", ]
376
377 function_kw = [ "accumarray", "accumdim", "acosd", "acotd",
378 "acscd", "addtodate", "allchild", "ancestor",
379 "anova", "arch_fit", "arch_rnd", "arch_test",
380 "area", "arma_rnd", "arrayfun", "ascii", "asctime",
381 "asecd", "asind", "assert", "atand",
382 "autoreg_matrix", "autumn", "axes", "axis", "bar",
383 "barh", "bartlett", "bartlett_test", "beep",
384 "betacdf", "betainv", "betapdf", "betarnd",
385 "bicgstab", "bicubic", "binary", "binocdf",
386 "binoinv", "binopdf", "binornd", "bitcmp",
387 "bitget", "bitset", "blackman", "blanks",
388 "blkdiag", "bone", "box", "brighten", "calendar",
389 "cast", "cauchy_cdf", "cauchy_inv", "cauchy_pdf",
390 "cauchy_rnd", "caxis", "celldisp", "center", "cgs",
391 "chisquare_test_homogeneity",
392 "chisquare_test_independence", "circshift", "cla",
393 "clabel", "clf", "clock", "cloglog", "closereq",
394 "colon", "colorbar", "colormap", "colperm",
395 "comet", "common_size", "commutation_matrix",
396 "compan", "compare_versions", "compass",
397 "computer", "cond", "condest", "contour",
398 "contourc", "contourf", "contrast", "conv",
399 "convhull", "cool", "copper", "copyfile", "cor",
400 "corrcoef", "cor_test", "cosd", "cotd", "cov",
401 "cplxpair", "cross", "cscd", "cstrcat", "csvread",
402 "csvwrite", "ctime", "cumtrapz", "curl", "cut",
403 "cylinder", "date", "datenum", "datestr",
404 "datetick", "datevec", "dblquad", "deal",
405 "deblank", "deconv", "delaunay", "delaunayn",
406 "delete", "demo", "detrend", "diffpara", "diffuse",
407 "dir", "discrete_cdf", "discrete_inv",
408 "discrete_pdf", "discrete_rnd", "display",
409 "divergence", "dlmwrite", "dos", "dsearch",
410 "dsearchn", "duplication_matrix", "durbinlevinson",
411 "ellipsoid", "empirical_cdf", "empirical_inv",
412 "empirical_pdf", "empirical_rnd", "eomday",
413 "errorbar", "etime", "etreeplot", "example",
414 "expcdf", "expinv", "expm", "exppdf", "exprnd",
415 "ezcontour", "ezcontourf", "ezmesh", "ezmeshc",
416 "ezplot", "ezpolar", "ezsurf", "ezsurfc", "factor",
417 "factorial", "fail", "fcdf", "feather", "fftconv",
418 "fftfilt", "fftshift", "figure", "fileattrib",
419 "fileparts", "fill", "findall", "findobj",
420 "findstr", "finv", "flag", "flipdim", "fliplr",
421 "flipud", "fpdf", "fplot", "fractdiff", "freqz",
422 "freqz_plot", "frnd", "fsolve",
423 "f_test_regression", "ftp", "fullfile", "fzero",
424 "gamcdf", "gaminv", "gampdf", "gamrnd", "gca",
425 "gcbf", "gcbo", "gcf", "genvarname", "geocdf",
426 "geoinv", "geopdf", "geornd", "getfield", "ginput",
427 "glpk", "gls", "gplot", "gradient",
428 "graphics_toolkit", "gray", "grid", "griddata",
429 "griddatan", "gtext", "gunzip", "gzip", "hadamard",
430 "hamming", "hankel", "hanning", "hggroup",
431 "hidden", "hilb", "hist", "histc", "hold", "hot",
432 "hotelling_test", "housh", "hsv", "hurst",
433 "hygecdf", "hygeinv", "hygepdf", "hygernd",
434 "idivide", "ifftshift", "image", "imagesc",
435 "imfinfo", "imread", "imshow", "imwrite", "index",
436 "info", "inpolygon", "inputname", "interpft",
437 "interpn", "intersect", "invhilb", "iqr", "isa",
438 "isdefinite", "isdir", "is_duplicate_entry",
439 "isequal", "isequalwithequalnans", "isfigure",
440 "ishermitian", "ishghandle", "is_leap_year",
441 "isletter", "ismac", "ismember", "ispc", "isprime",
442 "isprop", "isscalar", "issquare", "isstrprop",
443 "issymmetric", "isunix", "is_valid_file_id",
444 "isvector", "jet", "kendall",
445 "kolmogorov_smirnov_cdf",
446 "kolmogorov_smirnov_test", "kruskal_wallis_test",
447 "krylov", "kurtosis", "laplace_cdf", "laplace_inv",
448 "laplace_pdf", "laplace_rnd", "legend", "legendre",
449 "license", "line", "linkprop", "list_primes",
450 "loadaudio", "loadobj", "logistic_cdf",
451 "logistic_inv", "logistic_pdf", "logistic_rnd",
452 "logit", "loglog", "loglogerr", "logm", "logncdf",
453 "logninv", "lognpdf", "lognrnd", "logspace",
454 "lookfor", "ls_command", "lsqnonneg", "magic",
455 "mahalanobis", "manova", "matlabroot",
456 "mcnemar_test", "mean", "meansq", "median", "menu",
457 "mesh", "meshc", "meshgrid", "meshz", "mexext",
458 "mget", "mkpp", "mode", "moment", "movefile",
459 "mpoles", "mput", "namelengthmax", "nargchk",
460 "nargoutchk", "nbincdf", "nbininv", "nbinpdf",
461 "nbinrnd", "nchoosek", "ndgrid", "newplot", "news",
462 "nonzeros", "normcdf", "normest", "norminv",
463 "normpdf", "normrnd", "now", "nthroot", "null",
464 "ocean", "ols", "onenormest", "optimget",
465 "optimset", "orderfields", "orient", "orth",
466 "pack", "pareto", "parseparams", "pascal", "patch",
467 "pathdef", "pcg", "pchip", "pcolor", "pcr",
468 "peaks", "periodogram", "perl", "perms", "pie",
469 "pink", "planerot", "playaudio", "plot",
470 "plotmatrix", "plotyy", "poisscdf", "poissinv",
471 "poisspdf", "poissrnd", "polar", "poly",
472 "polyaffine", "polyarea", "polyderiv", "polyfit",
473 "polygcd", "polyint", "polyout", "polyreduce",
474 "polyval", "polyvalm", "postpad", "powerset",
475 "ppder", "ppint", "ppjumps", "ppplot", "ppval",
476 "pqpnonneg", "prepad", "primes", "print",
477 "print_usage", "prism", "probit", "qp", "qqplot",
478 "quadcc", "quadgk", "quadl", "quadv", "quiver",
479 "qzhess", "rainbow", "randi", "range", "rank",
480 "ranks", "rat", "reallog", "realpow", "realsqrt",
481 "record", "rectangle_lw", "rectangle_sw",
482 "rectint", "refresh", "refreshdata",
483 "regexptranslate", "repmat", "residue", "ribbon",
484 "rindex", "roots", "rose", "rosser", "rotdim",
485 "rref", "run", "run_count", "rundemos", "run_test",
486 "runtests", "saveas", "saveaudio", "saveobj",
487 "savepath", "scatter", "secd", "semilogx",
488 "semilogxerr", "semilogy", "semilogyerr",
489 "setaudio", "setdiff", "setfield", "setxor",
490 "shading", "shift", "shiftdim", "sign_test",
491 "sinc", "sind", "sinetone", "sinewave", "skewness",
492 "slice", "sombrero", "sortrows", "spaugment",
493 "spconvert", "spdiags", "spearman", "spectral_adf",
494 "spectral_xdf", "specular", "speed", "spencer",
495 "speye", "spfun", "sphere", "spinmap", "spline",
496 "spones", "sprand", "sprandn", "sprandsym",
497 "spring", "spstats", "spy", "sqp", "stairs",
498 "statistics", "std", "stdnormal_cdf",
499 "stdnormal_inv", "stdnormal_pdf", "stdnormal_rnd",
500 "stem", "stft", "strcat", "strchr", "strjust",
501 "strmatch", "strread", "strsplit", "strtok",
502 "strtrim", "strtrunc", "structfun", "studentize",
503 "subplot", "subsindex", "subspace", "substr",
504 "substruct", "summer", "surf", "surface", "surfc",
505 "surfl", "surfnorm", "svds", "swapbytes",
506 "sylvester_matrix", "symvar", "synthesis", "table",
507 "tand", "tar", "tcdf", "tempdir", "tempname",
508 "test", "text", "textread", "textscan", "tinv",
509 "title", "toeplitz", "tpdf", "trace", "trapz",
510 "treelayout", "treeplot", "triangle_lw",
511 "triangle_sw", "tril", "trimesh", "triplequad",
512 "triplot", "trisurf", "triu", "trnd", "tsearchn",
513 "t_test", "t_test_regression", "type", "unidcdf",
514 "unidinv", "unidpdf", "unidrnd", "unifcdf",
515 "unifinv", "unifpdf", "unifrnd", "union", "unique",
516 "unix", "unmkpp", "unpack", "untabify", "untar",
517 "unwrap", "unzip", "u_test", "validatestring",
518 "vander", "var", "var_test", "vech", "ver",
519 "version", "view", "voronoi", "voronoin",
520 "waitforbuttonpress", "wavread", "wavwrite",
521 "wblcdf", "wblinv", "wblpdf", "wblrnd", "weekday",
522 "welch_test", "what", "white", "whitebg",
523 "wienrnd", "wilcoxon_test", "wilkinson", "winter",
524 "xlabel", "xlim", "ylabel", "yulewalker", "zip",
525 "zlabel", "z_test", ]
526
527 loadable_kw = [ "airy", "amd", "balance", "besselh", "besseli",
528 "besselj", "besselk", "bessely", "bitpack",
529 "bsxfun", "builtin", "ccolamd", "cellfun",
530 "cellslices", "chol", "choldelete", "cholinsert",
531 "cholinv", "cholshift", "cholupdate", "colamd",
532 "colloc", "convhulln", "convn", "csymamd",
533 "cummax", "cummin", "daspk", "daspk_options",
534 "dasrt", "dasrt_options", "dassl", "dassl_options",
535 "dbclear", "dbdown", "dbstack", "dbstatus",
536 "dbstop", "dbtype", "dbup", "dbwhere", "det",
537 "dlmread", "dmperm", "dot", "eig", "eigs",
538 "endgrent", "endpwent", "etree", "fft", "fftn",
539 "fftw", "filter", "find", "full", "gcd",
540 "getgrent", "getgrgid", "getgrnam", "getpwent",
541 "getpwnam", "getpwuid", "getrusage", "givens",
542 "gmtime", "gnuplot_binary", "hess", "ifft",
543 "ifftn", "inv", "isdebugmode", "issparse", "kron",
544 "localtime", "lookup", "lsode", "lsode_options",
545 "lu", "luinc", "luupdate", "matrix_type", "max",
546 "min", "mktime", "pinv", "qr", "qrdelete",
547 "qrinsert", "qrshift", "qrupdate", "quad",
548 "quad_options", "qz", "rand", "rande", "randg",
549 "randn", "randp", "randperm", "rcond", "regexp",
550 "regexpi", "regexprep", "schur", "setgrent",
551 "setpwent", "sort", "spalloc", "sparse", "spparms",
552 "sprank", "sqrtm", "strfind", "strftime",
553 "strptime", "strrep", "svd", "svd_driver", "syl",
554 "symamd", "symbfact", "symrcm", "time", "tsearch",
555 "typecast", "urlread", "urlwrite", ]
556
557 mapping_kw = [ "abs", "acos", "acosh", "acot", "acoth", "acsc",
558 "acsch", "angle", "arg", "asec", "asech", "asin",
559 "asinh", "atan", "atanh", "beta", "betainc",
560 "betaln", "bincoeff", "cbrt", "ceil", "conj", "cos",
561 "cosh", "cot", "coth", "csc", "csch", "erf", "erfc",
562 "erfcx", "erfinv", "exp", "finite", "fix", "floor",
563 "fmod", "gamma", "gammainc", "gammaln", "imag",
564 "isalnum", "isalpha", "isascii", "iscntrl",
565 "isdigit", "isfinite", "isgraph", "isinf",
566 "islower", "isna", "isnan", "isprint", "ispunct",
567 "isspace", "isupper", "isxdigit", "lcm", "lgamma",
568 "log", "lower", "mod", "real", "rem", "round",
569 "roundb", "sec", "sech", "sign", "sin", "sinh",
570 "sqrt", "tan", "tanh", "toascii", "tolower", "xor",
571 ]
572
573 builtin_consts = [ "EDITOR", "EXEC_PATH", "I", "IMAGE_PATH", "NA",
574 "OCTAVE_HOME", "OCTAVE_VERSION", "PAGER",
575 "PAGER_FLAGS", "SEEK_CUR", "SEEK_END", "SEEK_SET",
576 "SIG", "S_ISBLK", "S_ISCHR", "S_ISDIR", "S_ISFIFO",
577 "S_ISLNK", "S_ISREG", "S_ISSOCK", "WCONTINUE",
578 "WCOREDUMP", "WEXITSTATUS", "WIFCONTINUED",
579 "WIFEXITED", "WIFSIGNALED", "WIFSTOPPED", "WNOHANG",
580 "WSTOPSIG", "WTERMSIG", "WUNTRACED", ]
581
582 tokens = {
583 'root': [
584 #We should look into multiline comments
585 (r'[%#].*$', Comment),
586 (r'^\s*function', Keyword, 'deffunc'),
587
588 # from 'iskeyword' on hg changeset 8cc154f45e37
589 (r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
590 r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
591 r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
592 r'endswitch|endwhile|events|for|function|get|global|if|methods|'
593 r'otherwise|persistent|properties|return|set|static|switch|try|'
594 r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
595
596 ("(" + "|".join( builtin_kw + command_kw
597 + function_kw + loadable_kw
598 + mapping_kw) + r')\b', Name.Builtin),
599
600 ("(" + "|".join(builtin_consts) + r')\b', Name.Constant),
601
602 # operators in Octave but not Matlab:
603 (r'-=|!=|!|/=|--', Operator),
604 # operators:
605 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
606 # operators in Octave but not Matlab requiring escape for re:
607 (r'\*=|\+=|\^=|\/=|\\=|\*\*|\+\+|\.\*\*',Operator),
608 # operators requiring escape for re:
609 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
610
611
612 # punctuation:
613 (r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
614 (r'=|:|;', Punctuation),
615
616 (r'"[^"]*"', String),
617
618 # quote can be transpose, instead of string:
619 # (not great, but handles common cases...)
620 (r'(?<=[\w\)\]])\'', Operator),
621 (r'(?<![\w\)\]])\'', String, 'string'),
622
623 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
624 (r'.', Text),
625 ],
626 'string': [
627 (r"[^']*'", String, '#pop'),
628 ],
629 'deffunc': [
630 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
631 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
632 Text.Whitespace, Name.Function, Punctuation, Text,
633 Punctuation, Text.Whitespace), '#pop'),
634 ],
635 }
636
637 def analyse_text(text):
638 if re.match('^\s*[%#]', text, re.M): #Comment
639 return 0.9
640 return 0.1
641
642
643 class ScilabLexer(RegexLexer):
644 """
645 For Scilab source code.
646
647 *New in Pygments 1.5.*
648 """
649 name = 'Scilab'
650 aliases = ['scilab']
651 filenames = ['*.sci', '*.sce', '*.tst']
652 mimetypes = ['text/scilab']
653
654 tokens = {
655 'root': [
656 (r'//.*?$', Comment.Single),
657 (r'^\s*function', Keyword, 'deffunc'),
658
659 (r'(__FILE__|__LINE__|break|case|catch|classdef|continue|do|else|'
660 r'elseif|end|end_try_catch|end_unwind_protect|endclassdef|'
661 r'endevents|endfor|endfunction|endif|endmethods|endproperties|'
662 r'endswitch|endwhile|events|for|function|get|global|if|methods|'
663 r'otherwise|persistent|properties|return|set|static|switch|try|'
664 r'until|unwind_protect|unwind_protect_cleanup|while)\b', Keyword),
665
666 ("(" + "|".join(_scilab_builtins.functions_kw +
667 _scilab_builtins.commands_kw +
668 _scilab_builtins.macros_kw
669 ) + r')\b', Name.Builtin),
670
671 (r'(%s)\b' % "|".join(map(re.escape, _scilab_builtins.builtin_consts)),
672 Name.Constant),
673
674 # operators:
675 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
676 # operators requiring escape for re:
677 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
678
679 # punctuation:
680 (r'[\[\](){}@.,=:;]', Punctuation),
681
682 (r'"[^"]*"', String),
683
684 # quote can be transpose, instead of string:
685 # (not great, but handles common cases...)
686 (r'(?<=[\w\)\]])\'', Operator),
687 (r'(?<![\w\)\]])\'', String, 'string'),
688
689 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
690 (r'.', Text),
691 ],
692 'string': [
693 (r"[^']*'", String, '#pop'),
694 (r'.', String, '#pop'),
695 ],
696 'deffunc': [
697 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
698 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
699 Text.Whitespace, Name.Function, Punctuation, Text,
700 Punctuation, Text.Whitespace), '#pop'),
701 ],
702 }
703
704
249 class NumPyLexer(PythonLexer): 705 class NumPyLexer(PythonLexer):
250 ''' 706 """
251 A Python lexer recognizing Numerical Python builtins. 707 A Python lexer recognizing Numerical Python builtins.
252 708
253 *New in Pygments 0.10.* 709 *New in Pygments 0.10.*
254 ''' 710 """
255 711
256 name = 'NumPy' 712 name = 'NumPy'
257 aliases = ['numpy'] 713 aliases = ['numpy']
258 714
259 # override the mimetypes to not inherit them from python 715 # override the mimetypes to not inherit them from python

eric ide

mercurial