ThirdParty/Pygments/pygments/lexers/math.py

changeset 2426
da76c71624de
parent 1705
b0fbc9300f2b
child 2525
8b507a9a2d40
equal deleted inserted replaced
2425:ace8a08028f3 2426:da76c71624de
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-2012 by the Pygments team, see AUTHORS. 8 :copyright: Copyright 2006-2013 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.util import shebang_matches
15 from pygments.lexer import Lexer, RegexLexer, bygroups, include, \
16 combined, do_insertions
15 from pygments.token import Comment, String, Punctuation, Keyword, Name, \ 17 from pygments.token import Comment, String, Punctuation, Keyword, Name, \
16 Operator, Number, Text, Generic 18 Operator, Number, Text, Generic
17 19
18 from pygments.lexers.agile import PythonLexer 20 from pygments.lexers.agile import PythonLexer
19 from pygments.lexers import _scilab_builtins 21 from pygments.lexers import _scilab_builtins
20 22 from pygments.lexers import _stan_builtins
21 __all__ = ['MuPADLexer', 'MatlabLexer', 'MatlabSessionLexer', 'OctaveLexer', 23
22 'ScilabLexer', 'NumPyLexer', 'RConsoleLexer', 'SLexer'] 24 __all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
25 'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
26 'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
27 'IDLLexer', 'RdLexer']
28
29
30 class JuliaLexer(RegexLexer):
31 """
32 For `Julia <http://julialang.org/>`_ source code.
33
34 *New in Pygments 1.6.*
35 """
36 name = 'Julia'
37 aliases = ['julia','jl']
38 filenames = ['*.jl']
39 mimetypes = ['text/x-julia','application/x-julia']
40
41 builtins = [
42 'exit','whos','edit','load','is','isa','isequal','typeof','tuple',
43 'ntuple','uid','hash','finalizer','convert','promote','subtype',
44 'typemin','typemax','realmin','realmax','sizeof','eps','promote_type',
45 'method_exists','applicable','invoke','dlopen','dlsym','system',
46 'error','throw','assert','new','Inf','Nan','pi','im',
47 ]
48
49 tokens = {
50 'root': [
51 (r'\n', Text),
52 (r'[^\S\n]+', Text),
53 (r'#.*$', Comment),
54 (r'[]{}:(),;[@]', Punctuation),
55 (r'\\\n', Text),
56 (r'\\', Text),
57
58 # keywords
59 (r'(begin|while|for|in|return|break|continue|'
60 r'macro|quote|let|if|elseif|else|try|catch|end|'
61 r'bitstype|ccall|do|using|module|import|export|'
62 r'importall|baremodule)\b', Keyword),
63 (r'(local|global|const)\b', Keyword.Declaration),
64 (r'(Bool|Int|Int8|Int16|Int32|Int64|Uint|Uint8|Uint16|Uint32|Uint64'
65 r'|Float32|Float64|Complex64|Complex128|Any|Nothing|None)\b',
66 Keyword.Type),
67
68 # functions
69 (r'(function)((?:\s|\\\s)+)',
70 bygroups(Keyword,Name.Function), 'funcname'),
71
72 # types
73 (r'(type|typealias|abstract)((?:\s|\\\s)+)',
74 bygroups(Keyword,Name.Class), 'typename'),
75
76 # operators
77 (r'==|!=|<=|>=|->|&&|\|\||::|<:|[-~+/*%=<>&^|.?!$]', Operator),
78 (r'\.\*|\.\^|\.\\|\.\/|\\', Operator),
79
80 # builtins
81 ('(' + '|'.join(builtins) + r')\b', Name.Builtin),
82
83 # backticks
84 (r'`(?s).*?`', String.Backtick),
85
86 # chars
87 (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,3}|\\u[a-fA-F0-9]{1,4}|"
88 r"\\U[a-fA-F0-9]{1,6}|[^\\\'\n])'", String.Char),
89
90 # try to match trailing transpose
91 (r'(?<=[.\w\)\]])\'+', Operator),
92
93 # strings
94 (r'(?:[IL])"', String, 'string'),
95 (r'[E]?"', String, combined('stringescape', 'string')),
96
97 # names
98 (r'@[a-zA-Z0-9_.]+', Name.Decorator),
99 (r'[a-zA-Z_][a-zA-Z0-9_]*', Name),
100
101 # numbers
102 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
103 (r'\d+[eEf][+-]?[0-9]+', Number.Float),
104 (r'0b[01]+', Number.Binary),
105 (r'0o[0-7]+', Number.Oct),
106 (r'0x[a-fA-F0-9]+', Number.Hex),
107 (r'\d+', Number.Integer)
108 ],
109
110 'funcname': [
111 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop'),
112 ('\([^\s\w{]{1,2}\)', Operator, '#pop'),
113 ('[^\s\w{]{1,2}', Operator, '#pop'),
114 ],
115
116 'typename': [
117 ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
118 ],
119
120 'stringescape': [
121 (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
122 r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
123 ],
124
125 'string': [
126 (r'"', String, '#pop'),
127 (r'\\\\|\\"|\\\n', String.Escape), # included here for raw strings
128 (r'\$(\([a-zA-Z0-9_]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?',
129 String.Interpol),
130 (r'[^\\"$]+', String),
131 # quotes, dollar signs, and backslashes must be parsed one at a time
132 (r'["\\]', String),
133 # unhandled string formatting sign
134 (r'\$', String)
135 ],
136 }
137
138 def analyse_text(text):
139 return shebang_matches(text, r'julia')
140
141
142 line_re = re.compile('.*?\n')
143
144 class JuliaConsoleLexer(Lexer):
145 """
146 For Julia console sessions. Modeled after MatlabSessionLexer.
147
148 *New in Pygments 1.6.*
149 """
150 name = 'Julia console'
151 aliases = ['jlcon']
152
153 def get_tokens_unprocessed(self, text):
154 jllexer = JuliaLexer(**self.options)
155
156 curcode = ''
157 insertions = []
158
159 for match in line_re.finditer(text):
160 line = match.group()
161
162 if line.startswith('julia>'):
163 insertions.append((len(curcode),
164 [(0, Generic.Prompt, line[:3])]))
165 curcode += line[3:]
166
167 elif line.startswith(' '):
168
169 idx = len(curcode)
170
171 # without is showing error on same line as before...?
172 line = "\n" + line
173 token = (0, Generic.Traceback, line)
174 insertions.append((idx, [token]))
175
176 else:
177 if curcode:
178 for item in do_insertions(
179 insertions, jllexer.get_tokens_unprocessed(curcode)):
180 yield item
181 curcode = ''
182 insertions = []
183
184 yield match.start(), Generic.Output, line
185
186 if curcode: # or item:
187 for item in do_insertions(
188 insertions, jllexer.get_tokens_unprocessed(curcode)):
189 yield item
23 190
24 191
25 class MuPADLexer(RegexLexer): 192 class MuPADLexer(RegexLexer):
26 """ 193 """
27 A `MuPAD <http://www.mupad.com>`_ lexer. 194 A `MuPAD <http://www.mupad.com>`_ lexer.
94 261
95 262
96 class MatlabLexer(RegexLexer): 263 class MatlabLexer(RegexLexer):
97 """ 264 """
98 For Matlab source code. 265 For Matlab source code.
99 Contributed by Ken Schutte <kschutte@csail.mit.edu>.
100 266
101 *New in Pygments 0.10.* 267 *New in Pygments 0.10.*
102 """ 268 """
103 name = 'Matlab' 269 name = 'Matlab'
104 aliases = ['matlab'] 270 aliases = ['matlab']
149 tokens = { 315 tokens = {
150 'root': [ 316 'root': [
151 # line starting with '!' is sent as a system command. not sure what 317 # line starting with '!' is sent as a system command. not sure what
152 # label to use... 318 # label to use...
153 (r'^!.*', String.Other), 319 (r'^!.*', String.Other),
320 (r'%\{\s*\n', Comment.Multiline, 'blockcomment'),
154 (r'%.*$', Comment), 321 (r'%.*$', Comment),
155 (r'^\s*function', Keyword, 'deffunc'), 322 (r'^\s*function', Keyword, 'deffunc'),
156 323
157 # from 'iskeyword' on version 7.11 (R2010): 324 # from 'iskeyword' on version 7.11 (R2010):
158 (r'(break|case|catch|classdef|continue|else|elseif|end|enumerated|' 325 (r'(break|case|catch|classdef|continue|else|elseif|end|enumerated|'
159 r'events|for|function|global|if|methods|otherwise|parfor|' 326 r'events|for|function|global|if|methods|otherwise|parfor|'
160 r'persistent|properties|return|spmd|switch|try|while)\b', Keyword), 327 r'persistent|properties|return|spmd|switch|try|while)\b', Keyword),
161 328
162 ("(" + "|".join(elfun+specfun+elmat) + r')\b', Name.Builtin), 329 ("(" + "|".join(elfun+specfun+elmat) + r')\b', Name.Builtin),
163 330
331 # line continuation with following comment:
332 (r'\.\.\..*$', Comment),
333
164 # operators: 334 # operators:
165 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator), 335 (r'-|==|~=|<|>|<=|>=|&&|&|~|\|\|?', Operator),
166 # operators requiring escape for re: 336 # operators requiring escape for re:
167 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator), 337 (r'\.\*|\*|\+|\.\^|\.\\|\.\/|\/|\\', Operator),
168 338
172 342
173 # quote can be transpose, instead of string: 343 # quote can be transpose, instead of string:
174 # (not great, but handles common cases...) 344 # (not great, but handles common cases...)
175 (r'(?<=[\w\)\]])\'', Operator), 345 (r'(?<=[\w\)\]])\'', Operator),
176 346
347 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
348 (r'\d+[eEf][+-]?[0-9]+', Number.Float),
349 (r'\d+', Number.Integer),
350
177 (r'(?<![\w\)\]])\'', String, 'string'), 351 (r'(?<![\w\)\]])\'', String, 'string'),
178 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), 352 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
179 (r'.', Text), 353 (r'.', Text),
180 ], 354 ],
181 'string': [ 355 'string': [
182 (r'[^\']*\'', String, '#pop') 356 (r'[^\']*\'', String, '#pop')
357 ],
358 'blockcomment': [
359 (r'^\s*%\}', Comment.Multiline, '#pop'),
360 (r'^.*\n', Comment.Multiline),
361 (r'.', Comment.Multiline),
183 ], 362 ],
184 'deffunc': [ 363 'deffunc': [
185 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)', 364 (r'(\s*)(?:(.+)(\s*)(=)(\s*))?(.+)(\()(.*)(\))(\s*)',
186 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation, 365 bygroups(Text.Whitespace, Text, Text.Whitespace, Punctuation,
187 Text.Whitespace, Name.Function, Punctuation, Text, 366 Text.Whitespace, Name.Function, Punctuation, Text,
613 (r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation), 792 (r'\[|\]|\(|\)|\{|\}|:|@|\.|,', Punctuation),
614 (r'=|:|;', Punctuation), 793 (r'=|:|;', Punctuation),
615 794
616 (r'"[^"]*"', String), 795 (r'"[^"]*"', String),
617 796
797 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
798 (r'\d+[eEf][+-]?[0-9]+', Number.Float),
799 (r'\d+', Number.Integer),
800
618 # quote can be transpose, instead of string: 801 # quote can be transpose, instead of string:
619 # (not great, but handles common cases...) 802 # (not great, but handles common cases...)
620 (r'(?<=[\w\)\]])\'', Operator), 803 (r'(?<=[\w\)\]])\'', Operator),
621 (r'(?<![\w\)\]])\'', String, 'string'), 804 (r'(?<![\w\)\]])\'', String, 'string'),
622 805
634 ], 817 ],
635 } 818 }
636 819
637 def analyse_text(text): 820 def analyse_text(text):
638 if re.match('^\s*[%#]', text, re.M): #Comment 821 if re.match('^\s*[%#]', text, re.M): #Comment
639 return 0.9 822 return 0.1
640 return 0.1
641 823
642 824
643 class ScilabLexer(RegexLexer): 825 class ScilabLexer(RegexLexer):
644 """ 826 """
645 For Scilab source code. 827 For Scilab source code.
683 865
684 # quote can be transpose, instead of string: 866 # quote can be transpose, instead of string:
685 # (not great, but handles common cases...) 867 # (not great, but handles common cases...)
686 (r'(?<=[\w\)\]])\'', Operator), 868 (r'(?<=[\w\)\]])\'', Operator),
687 (r'(?<![\w\)\]])\'', String, 'string'), 869 (r'(?<![\w\)\]])\'', String, 'string'),
870
871 (r'(\d+\.\d*|\d*\.\d+)([eEf][+-]?[0-9]+)?', Number.Float),
872 (r'\d+[eEf][+-]?[0-9]+', Number.Float),
873 (r'\d+', Number.Integer),
688 874
689 ('[a-zA-Z_][a-zA-Z0-9_]*', Name), 875 ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
690 (r'.', Text), 876 (r'.', Text),
691 ], 877 ],
692 'string': [ 878 'string': [
845 *New in Pygments 0.10.* 1031 *New in Pygments 0.10.*
846 """ 1032 """
847 1033
848 name = 'S' 1034 name = 'S'
849 aliases = ['splus', 's', 'r'] 1035 aliases = ['splus', 's', 'r']
850 filenames = ['*.S', '*.R'] 1036 filenames = ['*.S', '*.R', '.Rhistory', '.Rprofile']
851 mimetypes = ['text/S-plus', 'text/S', 'text/R'] 1037 mimetypes = ['text/S-plus', 'text/S', 'text/x-r-source', 'text/x-r',
1038 'text/x-R', 'text/x-r-history', 'text/x-r-profile']
852 1039
853 tokens = { 1040 tokens = {
854 'comments': [ 1041 'comments': [
855 (r'#.*$', Comment.Single), 1042 (r'#.*$', Comment.Single),
856 ], 1043 ],
857 'valid_name': [ 1044 'valid_name': [
858 (r'[a-zA-Z][0-9a-zA-Z\._]+', Text), 1045 (r'[a-zA-Z][0-9a-zA-Z\._]*', Text),
859 (r'`.+`', String.Backtick), 1046 # can begin with ., but not if that is followed by a digit
1047 (r'\.[a-zA-Z_][0-9a-zA-Z\._]*', Text),
860 ], 1048 ],
861 'punctuation': [ 1049 'punctuation': [
862 (r'\[|\]|\[\[|\]\]|\$|\(|\)|@|:::?|;|,', Punctuation), 1050 (r'\[{1,2}|\]{1,2}|\(|\)|;|,', Punctuation),
863 ], 1051 ],
864 'keywords': [ 1052 'keywords': [
865 (r'for(?=\s*\()|while(?=\s*\()|if(?=\s*\()|(?<=\s)else|' 1053 (r'(if|else|for|while|repeat|in|next|break|return|switch|function)'
866 r'(?<=\s)break(?=;|$)|return(?=\s*\()|function(?=\s*\()', 1054 r'(?![0-9a-zA-Z\._])',
867 Keyword.Reserved) 1055 Keyword.Reserved)
868 ], 1056 ],
869 'operators': [ 1057 'operators': [
870 (r'<-|-|==|<=|>=|<|>|&&|&|!=|\|\|?', Operator), 1058 (r'<<?-|->>?|-|==|<=|>=|<|>|&&?|!=|\|\|?|\?', Operator),
871 (r'\*|\+|\^|/|%%|%/%|=', Operator), 1059 (r'\*|\+|\^|/|!|%[^%]*%|=|~|\$|@|:{1,3}', Operator)
872 (r'%in%|%*%', Operator)
873 ], 1060 ],
874 'builtin_symbols': [ 1061 'builtin_symbols': [
875 (r'(NULL|NA|TRUE|FALSE|NaN)\b', Keyword.Constant), 1062 (r'(NULL|NA(_(integer|real|complex|character)_)?|'
1063 r'Inf|TRUE|FALSE|NaN|\.\.(\.|[0-9]+))'
1064 r'(?![0-9a-zA-Z\._])',
1065 Keyword.Constant),
876 (r'(T|F)\b', Keyword.Variable), 1066 (r'(T|F)\b', Keyword.Variable),
877 ], 1067 ],
878 'numbers': [ 1068 'numbers': [
879 (r'(?<![0-9a-zA-Z\)\}\]`\"])(?=\s*)[-\+]?[0-9]+' 1069 # hex number
880 r'(\.[0-9]*)?(E[0-9][-\+]?(\.[0-9]*)?)?', Number), 1070 (r'0[xX][a-fA-F0-9]+([pP][0-9]+)?[Li]?', Number.Hex),
881 (r'\.[0-9]*(E[0-9][-\+]?(\.[0-9]*)?)?', Number), 1071 # decimal number
1072 (r'[+-]?([0-9]+(\.[0-9]+)?|\.[0-9]+)([eE][+-]?[0-9]+)?[Li]?',
1073 Number),
882 ], 1074 ],
883 'statements': [ 1075 'statements': [
884 include('comments'), 1076 include('comments'),
885 # whitespaces 1077 # whitespaces
886 (r'\s+', Text), 1078 (r'\s+', Text),
1079 (r'`.*?`', String.Backtick),
887 (r'\'', String, 'string_squote'), 1080 (r'\'', String, 'string_squote'),
888 (r'\"', String, 'string_dquote'), 1081 (r'\"', String, 'string_dquote'),
889 include('builtin_symbols'), 1082 include('builtin_symbols'),
890 include('numbers'), 1083 include('numbers'),
891 include('keywords'), 1084 include('keywords'),
904 # include('statements'), 1097 # include('statements'),
905 # ('\{', Punctuation, '#push'), 1098 # ('\{', Punctuation, '#push'),
906 # ('\}', Punctuation, '#pop') 1099 # ('\}', Punctuation, '#pop')
907 #], 1100 #],
908 'string_squote': [ 1101 'string_squote': [
909 (r'[^\']*\'', String, '#pop'), 1102 (r'([^\'\\]|\\.)*\'', String, '#pop'),
910 ], 1103 ],
911 'string_dquote': [ 1104 'string_dquote': [
912 (r'[^\"]*\"', String, '#pop'), 1105 (r'([^"\\]|\\.)*"', String, '#pop'),
913 ], 1106 ],
914 } 1107 }
915 1108
916 def analyse_text(text): 1109 def analyse_text(text):
917 return '<-' in text 1110 return '<-' in text
1111
1112
1113 class BugsLexer(RegexLexer):
1114 """
1115 Pygments Lexer for `OpenBugs <http://www.openbugs.info/w/>`_ and WinBugs
1116 models.
1117
1118 *New in Pygments 1.6.*
1119 """
1120
1121 name = 'BUGS'
1122 aliases = ['bugs', 'winbugs', 'openbugs']
1123 filenames = ['*.bug']
1124
1125 _FUNCTIONS = [
1126 # Scalar functions
1127 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
1128 'cloglog', 'cos', 'cosh', 'cumulative', 'cut', 'density', 'deviance',
1129 'equals', 'expr', 'gammap', 'ilogit', 'icloglog', 'integral', 'log',
1130 'logfact', 'loggam', 'logit', 'max', 'min', 'phi', 'post.p.value',
1131 'pow', 'prior.p.value', 'probit', 'replicate.post', 'replicate.prior',
1132 'round', 'sin', 'sinh', 'solution', 'sqrt', 'step', 'tan', 'tanh',
1133 'trunc',
1134 # Vector functions
1135 'inprod', 'interp.lin', 'inverse', 'logdet', 'mean', 'eigen.vals',
1136 'ode', 'prod', 'p.valueM', 'rank', 'ranked', 'replicate.postM',
1137 'sd', 'sort', 'sum',
1138 ## Special
1139 'D', 'I', 'F', 'T', 'C']
1140 """ OpenBUGS built-in functions
1141
1142 From http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAII
1143
1144 This also includes
1145
1146 - T, C, I : Truncation and censoring.
1147 ``T`` and ``C`` are in OpenBUGS. ``I`` in WinBUGS.
1148 - D : ODE
1149 - F : Functional http://www.openbugs.info/Examples/Functionals.html
1150
1151 """
1152
1153 _DISTRIBUTIONS = ['dbern', 'dbin', 'dcat', 'dnegbin', 'dpois',
1154 'dhyper', 'dbeta', 'dchisqr', 'ddexp', 'dexp',
1155 'dflat', 'dgamma', 'dgev', 'df', 'dggamma', 'dgpar',
1156 'dloglik', 'dlnorm', 'dlogis', 'dnorm', 'dpar',
1157 'dt', 'dunif', 'dweib', 'dmulti', 'ddirch', 'dmnorm',
1158 'dmt', 'dwish']
1159 """ OpenBUGS built-in distributions
1160
1161 Functions from
1162 http://www.openbugs.info/Manuals/ModelSpecification.html#ContentsAI
1163 """
1164
1165
1166 tokens = {
1167 'whitespace' : [
1168 (r"\s+", Text),
1169 ],
1170 'comments' : [
1171 # Comments
1172 (r'#.*$', Comment.Single),
1173 ],
1174 'root': [
1175 # Comments
1176 include('comments'),
1177 include('whitespace'),
1178 # Block start
1179 (r'(model)(\s+)({)',
1180 bygroups(Keyword.Namespace, Text, Punctuation)),
1181 # Reserved Words
1182 (r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
1183 # Built-in Functions
1184 (r'(%s)(?=\s*\()'
1185 % r'|'.join(_FUNCTIONS + _DISTRIBUTIONS),
1186 Name.Builtin),
1187 # Regular variable names
1188 (r'[A-Za-z][A-Za-z0-9_.]*', Name),
1189 # Number Literals
1190 (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
1191 # Punctuation
1192 (r'\[|\]|\(|\)|:|,|;', Punctuation),
1193 # Assignment operators
1194 # SLexer makes these tokens Operators.
1195 (r'<-|~', Operator),
1196 # Infix and prefix operators
1197 (r'\+|-|\*|/', Operator),
1198 # Block
1199 (r'[{}]', Punctuation),
1200 ]
1201 }
1202
1203 def analyse_text(text):
1204 if re.search(r"^\s*model\s*{", text, re.M):
1205 return 0.7
1206 else:
1207 return 0.0
1208
1209 class JagsLexer(RegexLexer):
1210 """
1211 Pygments Lexer for JAGS.
1212
1213 *New in Pygments 1.6.*
1214 """
1215
1216 name = 'JAGS'
1217 aliases = ['jags']
1218 filenames = ['*.jag', '*.bug']
1219
1220 ## JAGS
1221 _FUNCTIONS = [
1222 'abs', 'arccos', 'arccosh', 'arcsin', 'arcsinh', 'arctan', 'arctanh',
1223 'cos', 'cosh', 'cloglog',
1224 'equals', 'exp', 'icloglog', 'ifelse', 'ilogit', 'log', 'logfact',
1225 'loggam', 'logit', 'phi', 'pow', 'probit', 'round', 'sin', 'sinh',
1226 'sqrt', 'step', 'tan', 'tanh', 'trunc', 'inprod', 'interp.lin',
1227 'logdet', 'max', 'mean', 'min', 'prod', 'sum', 'sd', 'inverse',
1228 'rank', 'sort', 't', 'acos', 'acosh', 'asin', 'asinh', 'atan',
1229 # Truncation/Censoring (should I include)
1230 'T', 'I']
1231 # Distributions with density, probability and quartile functions
1232 _DISTRIBUTIONS = ['[dpq]%s' % x for x in
1233 ['bern', 'beta', 'dchiqsqr', 'ddexp', 'dexp',
1234 'df', 'gamma', 'gen.gamma', 'logis', 'lnorm',
1235 'negbin', 'nchisqr', 'norm', 'par', 'pois', 'weib']]
1236 # Other distributions without density and probability
1237 _OTHER_DISTRIBUTIONS = [
1238 'dt', 'dunif', 'dbetabin', 'dbern', 'dbin', 'dcat', 'dhyper',
1239 'ddirch', 'dmnorm', 'dwish', 'dmt', 'dmulti', 'dbinom', 'dchisq',
1240 'dnbinom', 'dweibull', 'ddirich']
1241
1242 tokens = {
1243 'whitespace' : [
1244 (r"\s+", Text),
1245 ],
1246 'names' : [
1247 # Regular variable names
1248 (r'[a-zA-Z][a-zA-Z0-9_.]*\b', Name),
1249 ],
1250 'comments' : [
1251 # do not use stateful comments
1252 (r'(?s)/\*.*?\*/', Comment.Multiline),
1253 # Comments
1254 (r'#.*$', Comment.Single),
1255 ],
1256 'root': [
1257 # Comments
1258 include('comments'),
1259 include('whitespace'),
1260 # Block start
1261 (r'(model|data)(\s+)({)',
1262 bygroups(Keyword.Namespace, Text, Punctuation)),
1263 (r'var(?![0-9a-zA-Z\._])', Keyword.Declaration),
1264 # Reserved Words
1265 (r'(for|in)(?![0-9a-zA-Z\._])', Keyword.Reserved),
1266 # Builtins
1267 # Need to use lookahead because . is a valid char
1268 (r'(%s)(?=\s*\()' % r'|'.join(_FUNCTIONS
1269 + _DISTRIBUTIONS
1270 + _OTHER_DISTRIBUTIONS),
1271 Name.Builtin),
1272 # Names
1273 include('names'),
1274 # Number Literals
1275 (r'[-+]?[0-9]*\.?[0-9]+([eE][-+]?[0-9]+)?', Number),
1276 (r'\[|\]|\(|\)|:|,|;', Punctuation),
1277 # Assignment operators
1278 (r'<-|~', Operator),
1279 # # JAGS includes many more than OpenBUGS
1280 (r'\+|-|\*|\/|\|\|[&]{2}|[<>=]=?|\^|%.*?%', Operator),
1281 (r'[{}]', Punctuation),
1282 ]
1283 }
1284
1285 def analyse_text(text):
1286 if re.search(r'^\s*model\s*\{', text, re.M):
1287 if re.search(r'^\s*data\s*\{', text, re.M):
1288 return 0.9
1289 elif re.search(r'^\s*var', text, re.M):
1290 return 0.9
1291 else:
1292 return 0.3
1293 else:
1294 return 0
1295
1296 class StanLexer(RegexLexer):
1297 """
1298 Pygments Lexer for Stan models.
1299
1300 *New in Pygments 1.6.*
1301 """
1302
1303 name = 'Stan'
1304 aliases = ['stan']
1305 filenames = ['*.stan']
1306
1307 _RESERVED = ('for', 'in', 'while', 'repeat', 'until', 'if',
1308 'then', 'else', 'true', 'false', 'T',
1309 'lower', 'upper', 'print')
1310
1311 _TYPES = ('int', 'real', 'vector', 'simplex', 'ordered', 'row_vector',
1312 'matrix', 'corr_matrix', 'cov_matrix', 'positive_ordered')
1313
1314 tokens = {
1315 'whitespace' : [
1316 (r"\s+", Text),
1317 ],
1318 'comments' : [
1319 (r'(?s)/\*.*?\*/', Comment.Multiline),
1320 # Comments
1321 (r'(//|#).*$', Comment.Single),
1322 ],
1323 'root': [
1324 # Stan is more restrictive on strings than this regex
1325 (r'"[^"]*"', String),
1326 # Comments
1327 include('comments'),
1328 # block start
1329 include('whitespace'),
1330 # Block start
1331 (r'(%s)(\s*)({)' %
1332 r'|'.join(('data', r'transformed\s+?data',
1333 'parameters', r'transformed\s+parameters',
1334 'model', r'generated\s+quantities')),
1335 bygroups(Keyword.Namespace, Text, Punctuation)),
1336 # Reserved Words
1337 (r'(%s)\b' % r'|'.join(_RESERVED), Keyword.Reserved),
1338 # Data types
1339 (r'(%s)\b' % r'|'.join(_TYPES), Keyword.Type),
1340 # Punctuation
1341 (r"[;:,\[\]()<>]", Punctuation),
1342 # Builtin
1343 (r'(%s)(?=\s*\()'
1344 % r'|'.join(_stan_builtins.FUNCTIONS
1345 + _stan_builtins.DISTRIBUTIONS),
1346 Name.Builtin),
1347 (r'(%s)(?=\s*\()'
1348 % r'|'.join(_stan_builtins.CONSTANTS), Keyword.Constant),
1349 # Special names ending in __, like lp__
1350 (r'[A-Za-z][A-Za-z0-9_]*__\b', Name.Builtin.Pseudo),
1351 # Regular variable names
1352 (r'[A-Za-z][A-Za-z0-9_]*\b', Name),
1353 # Real Literals
1354 (r'-?[0-9]+(\.[0-9]+)?[eE]-?[0-9]+', Number.Float),
1355 (r'-?[0-9]*\.[0-9]*', Number.Float),
1356 # Integer Literals
1357 (r'-?[0-9]+', Number.Integer),
1358 # Assignment operators
1359 # SLexer makes these tokens Operators.
1360 (r'<-|~', Operator),
1361 # Infix and prefix operators (and = )
1362 (r"\+|-|\.?\*|\.?/|\\|'|=", Operator),
1363 # Block delimiters
1364 (r'[{}]', Punctuation),
1365 ]
1366 }
1367
1368 def analyse_text(text):
1369 if re.search(r'^\s*parameters\s*\{', text, re.M):
1370 return 1.0
1371 else:
1372 return 0.0
1373
1374
1375 class IDLLexer(RegexLexer):
1376 """
1377 Pygments Lexer for IDL (Interactive Data Language).
1378
1379 *New in Pygments 1.6.*
1380 """
1381 name = 'IDL'
1382 aliases = ['idl']
1383 filenames = ['*.pro']
1384 mimetypes = ['text/idl']
1385
1386 _RESERVED = ['and', 'begin', 'break', 'case', 'common', 'compile_opt',
1387 'continue', 'do', 'else', 'end', 'endcase', 'elseelse',
1388 'endfor', 'endforeach', 'endif', 'endrep', 'endswitch',
1389 'endwhile', 'eq', 'for', 'foreach', 'forward_function',
1390 'function', 'ge', 'goto', 'gt', 'if', 'inherits', 'le',
1391 'lt', 'mod', 'ne', 'not', 'of', 'on_ioerror', 'or', 'pro',
1392 'repeat', 'switch', 'then', 'until', 'while', 'xor']
1393 """Reserved words from: http://www.exelisvis.com/docs/reswords.html"""
1394
1395 _BUILTIN_LIB = ['abs', 'acos', 'adapt_hist_equal', 'alog', 'alog10',
1396 'amoeba', 'annotate', 'app_user_dir', 'app_user_dir_query',
1397 'arg_present', 'array_equal', 'array_indices', 'arrow',
1398 'ascii_template', 'asin', 'assoc', 'atan', 'axis',
1399 'a_correlate', 'bandpass_filter', 'bandreject_filter',
1400 'barplot', 'bar_plot', 'beseli', 'beselj', 'beselk',
1401 'besely', 'beta', 'bilinear', 'binary_template', 'bindgen',
1402 'binomial', 'bin_date', 'bit_ffs', 'bit_population',
1403 'blas_axpy', 'blk_con', 'box_cursor', 'breakpoint',
1404 'broyden', 'butterworth', 'bytarr', 'byte', 'byteorder',
1405 'bytscl', 'caldat', 'calendar', 'call_external',
1406 'call_function', 'call_method', 'call_procedure', 'canny',
1407 'catch', 'cd', 'cdf_[0-9a-za-z_]*', 'ceil', 'chebyshev',
1408 'check_math',
1409 'chisqr_cvf', 'chisqr_pdf', 'choldc', 'cholsol', 'cindgen',
1410 'cir_3pnt', 'close', 'cluster', 'cluster_tree', 'clust_wts',
1411 'cmyk_convert', 'colorbar', 'colorize_sample',
1412 'colormap_applicable', 'colormap_gradient',
1413 'colormap_rotation', 'colortable', 'color_convert',
1414 'color_exchange', 'color_quan', 'color_range_map', 'comfit',
1415 'command_line_args', 'complex', 'complexarr', 'complexround',
1416 'compute_mesh_normals', 'cond', 'congrid', 'conj',
1417 'constrained_min', 'contour', 'convert_coord', 'convol',
1418 'convol_fft', 'coord2to3', 'copy_lun', 'correlate', 'cos',
1419 'cosh', 'cpu', 'cramer', 'create_cursor', 'create_struct',
1420 'create_view', 'crossp', 'crvlength', 'cti_test',
1421 'ct_luminance', 'cursor', 'curvefit', 'cvttobm', 'cv_coord',
1422 'cw_animate', 'cw_animate_getp', 'cw_animate_load',
1423 'cw_animate_run', 'cw_arcball', 'cw_bgroup', 'cw_clr_index',
1424 'cw_colorsel', 'cw_defroi', 'cw_field', 'cw_filesel',
1425 'cw_form', 'cw_fslider', 'cw_light_editor',
1426 'cw_light_editor_get', 'cw_light_editor_set', 'cw_orient',
1427 'cw_palette_editor', 'cw_palette_editor_get',
1428 'cw_palette_editor_set', 'cw_pdmenu', 'cw_rgbslider',
1429 'cw_tmpl', 'cw_zoom', 'c_correlate', 'dblarr', 'db_exists',
1430 'dcindgen', 'dcomplex', 'dcomplexarr', 'define_key',
1431 'define_msgblk', 'define_msgblk_from_file', 'defroi',
1432 'defsysv', 'delvar', 'dendrogram', 'dendro_plot', 'deriv',
1433 'derivsig', 'determ', 'device', 'dfpmin', 'diag_matrix',
1434 'dialog_dbconnect', 'dialog_message', 'dialog_pickfile',
1435 'dialog_printersetup', 'dialog_printjob',
1436 'dialog_read_image', 'dialog_write_image', 'digital_filter',
1437 'dilate', 'dindgen', 'dissolve', 'dist', 'distance_measure',
1438 'dlm_load', 'dlm_register', 'doc_library', 'double',
1439 'draw_roi', 'edge_dog', 'efont', 'eigenql', 'eigenvec',
1440 'ellipse', 'elmhes', 'emboss', 'empty', 'enable_sysrtn',
1441 'eof', 'eos_[0-9a-za-z_]*', 'erase', 'erf', 'erfc', 'erfcx',
1442 'erode', 'errorplot', 'errplot', 'estimator_filter',
1443 'execute', 'exit', 'exp', 'expand', 'expand_path', 'expint',
1444 'extrac', 'extract_slice', 'factorial', 'fft', 'filepath',
1445 'file_basename', 'file_chmod', 'file_copy', 'file_delete',
1446 'file_dirname', 'file_expand_path', 'file_info',
1447 'file_lines', 'file_link', 'file_mkdir', 'file_move',
1448 'file_poll_input', 'file_readlink', 'file_same',
1449 'file_search', 'file_test', 'file_which', 'findgen',
1450 'finite', 'fix', 'flick', 'float', 'floor', 'flow3',
1451 'fltarr', 'flush', 'format_axis_values', 'free_lun',
1452 'fstat', 'fulstr', 'funct', 'fv_test', 'fx_root',
1453 'fz_roots', 'f_cvf', 'f_pdf', 'gamma', 'gamma_ct',
1454 'gauss2dfit', 'gaussfit', 'gaussian_function', 'gaussint',
1455 'gauss_cvf', 'gauss_pdf', 'gauss_smooth', 'getenv',
1456 'getwindows', 'get_drive_list', 'get_dxf_objects',
1457 'get_kbrd', 'get_login_info', 'get_lun', 'get_screen_size',
1458 'greg2jul', 'grib_[0-9a-za-z_]*', 'grid3', 'griddata',
1459 'grid_input', 'grid_tps', 'gs_iter',
1460 'h5[adfgirst]_[0-9a-za-z_]*', 'h5_browser', 'h5_close',
1461 'h5_create', 'h5_get_libversion', 'h5_open', 'h5_parse',
1462 'hanning', 'hash', 'hdf_[0-9a-za-z_]*', 'heap_free',
1463 'heap_gc', 'heap_nosave', 'heap_refcount', 'heap_save',
1464 'help', 'hilbert', 'histogram', 'hist_2d', 'hist_equal',
1465 'hls', 'hough', 'hqr', 'hsv', 'h_eq_ct', 'h_eq_int',
1466 'i18n_multibytetoutf8', 'i18n_multibytetowidechar',
1467 'i18n_utf8tomultibyte', 'i18n_widechartomultibyte',
1468 'ibeta', 'icontour', 'iconvertcoord', 'idelete', 'identity',
1469 'idlexbr_assistant', 'idlitsys_createtool', 'idl_base64',
1470 'idl_validname', 'iellipse', 'igamma', 'igetcurrent',
1471 'igetdata', 'igetid', 'igetproperty', 'iimage', 'image',
1472 'image_cont', 'image_statistics', 'imaginary', 'imap',
1473 'indgen', 'intarr', 'interpol', 'interpolate',
1474 'interval_volume', 'int_2d', 'int_3d', 'int_tabulated',
1475 'invert', 'ioctl', 'iopen', 'iplot', 'ipolygon',
1476 'ipolyline', 'iputdata', 'iregister', 'ireset', 'iresolve',
1477 'irotate', 'ir_filter', 'isa', 'isave', 'iscale',
1478 'isetcurrent', 'isetproperty', 'ishft', 'isocontour',
1479 'isosurface', 'isurface', 'itext', 'itranslate', 'ivector',
1480 'ivolume', 'izoom', 'i_beta', 'journal', 'json_parse',
1481 'json_serialize', 'jul2greg', 'julday', 'keyword_set',
1482 'krig2d', 'kurtosis', 'kw_test', 'l64indgen', 'label_date',
1483 'label_region', 'ladfit', 'laguerre', 'laplacian',
1484 'la_choldc', 'la_cholmprove', 'la_cholsol', 'la_determ',
1485 'la_eigenproblem', 'la_eigenql', 'la_eigenvec', 'la_elmhes',
1486 'la_gm_linear_model', 'la_hqr', 'la_invert',
1487 'la_least_squares', 'la_least_square_equality',
1488 'la_linear_equation', 'la_ludc', 'la_lumprove', 'la_lusol',
1489 'la_svd', 'la_tridc', 'la_trimprove', 'la_triql',
1490 'la_trired', 'la_trisol', 'least_squares_filter', 'leefilt',
1491 'legend', 'legendre', 'linbcg', 'lindgen', 'linfit',
1492 'linkimage', 'list', 'll_arc_distance', 'lmfit', 'lmgr',
1493 'lngamma', 'lnp_test', 'loadct', 'locale_get',
1494 'logical_and', 'logical_or', 'logical_true', 'lon64arr',
1495 'lonarr', 'long', 'long64', 'lsode', 'ludc', 'lumprove',
1496 'lusol', 'lu_complex', 'machar', 'make_array', 'make_dll',
1497 'make_rt', 'map', 'mapcontinents', 'mapgrid', 'map_2points',
1498 'map_continents', 'map_grid', 'map_image', 'map_patch',
1499 'map_proj_forward', 'map_proj_image', 'map_proj_info',
1500 'map_proj_init', 'map_proj_inverse', 'map_set',
1501 'matrix_multiply', 'matrix_power', 'max', 'md_test',
1502 'mean', 'meanabsdev', 'mean_filter', 'median', 'memory',
1503 'mesh_clip', 'mesh_decimate', 'mesh_issolid', 'mesh_merge',
1504 'mesh_numtriangles', 'mesh_obj', 'mesh_smooth',
1505 'mesh_surfacearea', 'mesh_validate', 'mesh_volume',
1506 'message', 'min', 'min_curve_surf', 'mk_html_help',
1507 'modifyct', 'moment', 'morph_close', 'morph_distance',
1508 'morph_gradient', 'morph_hitormiss', 'morph_open',
1509 'morph_thin', 'morph_tophat', 'multi', 'm_correlate',
1510 'ncdf_[0-9a-za-z_]*', 'newton', 'noise_hurl', 'noise_pick',
1511 'noise_scatter', 'noise_slur', 'norm', 'n_elements',
1512 'n_params', 'n_tags', 'objarr', 'obj_class', 'obj_destroy',
1513 'obj_hasmethod', 'obj_isa', 'obj_new', 'obj_valid',
1514 'online_help', 'on_error', 'open', 'oplot', 'oploterr',
1515 'parse_url', 'particle_trace', 'path_cache', 'path_sep',
1516 'pcomp', 'plot', 'plot3d', 'ploterr', 'plots', 'plot_3dbox',
1517 'plot_field', 'pnt_line', 'point_lun', 'polarplot',
1518 'polar_contour', 'polar_surface', 'poly', 'polyfill',
1519 'polyfillv', 'polygon', 'polyline', 'polyshade', 'polywarp',
1520 'poly_2d', 'poly_area', 'poly_fit', 'popd', 'powell',
1521 'pref_commit', 'pref_get', 'pref_set', 'prewitt', 'primes',
1522 'print', 'printd', 'product', 'profile', 'profiler',
1523 'profiles', 'project_vol', 'psafm', 'pseudo',
1524 'ps_show_fonts', 'ptrarr', 'ptr_free', 'ptr_new',
1525 'ptr_valid', 'pushd', 'p_correlate', 'qgrid3', 'qhull',
1526 'qromb', 'qromo', 'qsimp', 'query_ascii', 'query_bmp',
1527 'query_csv', 'query_dicom', 'query_gif', 'query_image',
1528 'query_jpeg', 'query_jpeg2000', 'query_mrsid', 'query_pict',
1529 'query_png', 'query_ppm', 'query_srf', 'query_tiff',
1530 'query_wav', 'radon', 'randomn', 'randomu', 'ranks',
1531 'rdpix', 'read', 'reads', 'readu', 'read_ascii',
1532 'read_binary', 'read_bmp', 'read_csv', 'read_dicom',
1533 'read_gif', 'read_image', 'read_interfile', 'read_jpeg',
1534 'read_jpeg2000', 'read_mrsid', 'read_pict', 'read_png',
1535 'read_ppm', 'read_spr', 'read_srf', 'read_sylk',
1536 'read_tiff', 'read_wav', 'read_wave', 'read_x11_bitmap',
1537 'read_xwd', 'real_part', 'rebin', 'recall_commands',
1538 'recon3', 'reduce_colors', 'reform', 'region_grow',
1539 'register_cursor', 'regress', 'replicate',
1540 'replicate_inplace', 'resolve_all', 'resolve_routine',
1541 'restore', 'retall', 'return', 'reverse', 'rk4', 'roberts',
1542 'rot', 'rotate', 'round', 'routine_filepath',
1543 'routine_info', 'rs_test', 'r_correlate', 'r_test',
1544 'save', 'savgol', 'scale3', 'scale3d', 'scope_level',
1545 'scope_traceback', 'scope_varfetch', 'scope_varname',
1546 'search2d', 'search3d', 'sem_create', 'sem_delete',
1547 'sem_lock', 'sem_release', 'setenv', 'set_plot',
1548 'set_shading', 'sfit', 'shade_surf', 'shade_surf_irr',
1549 'shade_volume', 'shift', 'shift_diff', 'shmdebug', 'shmmap',
1550 'shmunmap', 'shmvar', 'show3', 'showfont', 'simplex', 'sin',
1551 'sindgen', 'sinh', 'size', 'skewness', 'skip_lun',
1552 'slicer3', 'slide_image', 'smooth', 'sobel', 'socket',
1553 'sort', 'spawn', 'spher_harm', 'sph_4pnt', 'sph_scat',
1554 'spline', 'spline_p', 'spl_init', 'spl_interp', 'sprsab',
1555 'sprsax', 'sprsin', 'sprstp', 'sqrt', 'standardize',
1556 'stddev', 'stop', 'strarr', 'strcmp', 'strcompress',
1557 'streamline', 'stregex', 'stretch', 'string', 'strjoin',
1558 'strlen', 'strlowcase', 'strmatch', 'strmessage', 'strmid',
1559 'strpos', 'strput', 'strsplit', 'strtrim', 'struct_assign',
1560 'struct_hide', 'strupcase', 'surface', 'surfr', 'svdc',
1561 'svdfit', 'svsol', 'swap_endian', 'swap_endian_inplace',
1562 'symbol', 'systime', 's_test', 't3d', 'tag_names', 'tan',
1563 'tanh', 'tek_color', 'temporary', 'tetra_clip',
1564 'tetra_surface', 'tetra_volume', 'text', 'thin', 'threed',
1565 'timegen', 'time_test2', 'tm_test', 'total', 'trace',
1566 'transpose', 'triangulate', 'trigrid', 'triql', 'trired',
1567 'trisol', 'tri_surf', 'truncate_lun', 'ts_coef', 'ts_diff',
1568 'ts_fcast', 'ts_smooth', 'tv', 'tvcrs', 'tvlct', 'tvrd',
1569 'tvscl', 'typename', 't_cvt', 't_pdf', 'uindgen', 'uint',
1570 'uintarr', 'ul64indgen', 'ulindgen', 'ulon64arr', 'ulonarr',
1571 'ulong', 'ulong64', 'uniq', 'unsharp_mask', 'usersym',
1572 'value_locate', 'variance', 'vector', 'vector_field', 'vel',
1573 'velovect', 'vert_t3d', 'voigt', 'voronoi', 'voxel_proj',
1574 'wait', 'warp_tri', 'watershed', 'wdelete', 'wf_draw',
1575 'where', 'widget_base', 'widget_button', 'widget_combobox',
1576 'widget_control', 'widget_displaycontextmen', 'widget_draw',
1577 'widget_droplist', 'widget_event', 'widget_info',
1578 'widget_label', 'widget_list', 'widget_propertysheet',
1579 'widget_slider', 'widget_tab', 'widget_table',
1580 'widget_text', 'widget_tree', 'widget_tree_move',
1581 'widget_window', 'wiener_filter', 'window', 'writeu',
1582 'write_bmp', 'write_csv', 'write_gif', 'write_image',
1583 'write_jpeg', 'write_jpeg2000', 'write_nrif', 'write_pict',
1584 'write_png', 'write_ppm', 'write_spr', 'write_srf',
1585 'write_sylk', 'write_tiff', 'write_wav', 'write_wave',
1586 'wset', 'wshow', 'wtn', 'wv_applet', 'wv_cwt',
1587 'wv_cw_wavelet', 'wv_denoise', 'wv_dwt', 'wv_fn_coiflet',
1588 'wv_fn_daubechies', 'wv_fn_gaussian', 'wv_fn_haar',
1589 'wv_fn_morlet', 'wv_fn_paul', 'wv_fn_symlet',
1590 'wv_import_data', 'wv_import_wavelet', 'wv_plot3d_wps',
1591 'wv_plot_multires', 'wv_pwt', 'wv_tool_denoise',
1592 'xbm_edit', 'xdisplayfile', 'xdxf', 'xfont',
1593 'xinteranimate', 'xloadct', 'xmanager', 'xmng_tmpl',
1594 'xmtool', 'xobjview', 'xobjview_rotate',
1595 'xobjview_write_image', 'xpalette', 'xpcolor', 'xplot3d',
1596 'xregistered', 'xroi', 'xsq_test', 'xsurface', 'xvaredit',
1597 'xvolume', 'xvolume_rotate', 'xvolume_write_image',
1598 'xyouts', 'zoom', 'zoom_24']
1599 """Functions from: http://www.exelisvis.com/docs/routines-1.html"""
1600
1601 tokens = {
1602 'root': [
1603 (r'^\s*;.*?\n', Comment.Singleline),
1604 (r'\b(' + '|'.join(_RESERVED) + r')\b', Keyword),
1605 (r'\b(' + '|'.join(_BUILTIN_LIB) + r')\b', Name.Builtin),
1606 (r'\+=|-=|\^=|\*=|/=|#=|##=|<=|>=|=', Operator),
1607 (r'\+\+|--|->|\+|-|##|#|\*|/|<|>|&&|\^|~|\|\|\?|:', Operator),
1608 (r'\b(mod=|lt=|le=|eq=|ne=|ge=|gt=|not=|and=|or=|xor=)', Operator),
1609 (r'\b(mod|lt|le|eq|ne|ge|gt|not|and|or|xor)\b', Operator),
1610 (r'\b[0-9](L|B|S|UL|ULL|LL)?\b', Number),
1611 (r'.', Text),
1612 ]
1613 }
1614
1615
1616 class RdLexer(RegexLexer):
1617 """
1618 Pygments Lexer for R documentation (Rd) files
1619
1620 This is a very minimal implementation, highlighting little more
1621 than the macros. A description of Rd syntax is found in `Writing R
1622 Extensions <http://cran.r-project.org/doc/manuals/R-exts.html>`_
1623 and `Parsing Rd files <developer.r-project.org/parseRd.pdf>`_.
1624
1625 *New in Pygments 1.6.*
1626 """
1627 name = 'Rd'
1628 aliases = ['rd']
1629 filenames = ['*.Rd']
1630 mimetypes = ['text/x-r-doc']
1631
1632 # To account for verbatim / LaTeX-like / and R-like areas
1633 # would require parsing.
1634 tokens = {
1635 'root' : [
1636 # catch escaped brackets and percent sign
1637 (r'\\[\\{}%]', String.Escape),
1638 # comments
1639 (r'%.*$', Comment),
1640 # special macros with no arguments
1641 (r'\\(?:cr|l?dots|R|tab)\b', Keyword.Constant),
1642 # macros
1643 (r'\\[a-zA-Z]+\b', Keyword),
1644 # special preprocessor macros
1645 (r'^\s*#(?:ifn?def|endif).*\b', Comment.Preproc),
1646 # non-escaped brackets
1647 (r'[{}]', Name.Builtin),
1648 # everything else
1649 (r'[^\\%\n{}]+', Text),
1650 (r'.', Text),
1651 ]
1652 }

eric ide

mercurial