|
1 # -*- coding: utf-8 -*- |
|
2 """ |
|
3 pygments.lexers.graphics |
|
4 ~~~~~~~~~~~~~~~~~~~~~~~~ |
|
5 |
|
6 Lexers for computer graphics and plotting related languages. |
|
7 |
|
8 :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. |
|
9 :license: BSD, see LICENSE for details. |
|
10 """ |
|
11 |
|
12 from pygments.lexer import RegexLexer, words, include, bygroups, using, \ |
|
13 this, default |
|
14 from pygments.token import Text, Comment, Operator, Keyword, Name, \ |
|
15 Number, Punctuation, String |
|
16 |
|
17 __all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer', |
|
18 'PovrayLexer'] |
|
19 |
|
20 |
|
21 class GLShaderLexer(RegexLexer): |
|
22 """ |
|
23 GLSL (OpenGL Shader) lexer. |
|
24 |
|
25 .. versionadded:: 1.1 |
|
26 """ |
|
27 name = 'GLSL' |
|
28 aliases = ['glsl'] |
|
29 filenames = ['*.vert', '*.frag', '*.geo'] |
|
30 mimetypes = ['text/x-glslsrc'] |
|
31 |
|
32 tokens = { |
|
33 'root': [ |
|
34 (r'^#.*', Comment.Preproc), |
|
35 (r'//.*', Comment.Single), |
|
36 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), |
|
37 (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?', |
|
38 Operator), |
|
39 (r'[?:]', Operator), # quick hack for ternary |
|
40 (r'\bdefined\b', Operator), |
|
41 (r'[;{}(),\[\]]', Punctuation), |
|
42 # FIXME when e is present, no decimal point needed |
|
43 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), |
|
44 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float), |
|
45 (r'0[xX][0-9a-fA-F]*', Number.Hex), |
|
46 (r'0[0-7]*', Number.Oct), |
|
47 (r'[1-9][0-9]*', Number.Integer), |
|
48 (words(( |
|
49 'attribute', 'const', 'uniform', 'varying', 'centroid', 'break', |
|
50 'continue', 'do', 'for', 'while', 'if', 'else', 'in', 'out', |
|
51 'inout', 'float', 'int', 'void', 'bool', 'true', 'false', |
|
52 'invariant', 'discard', 'return', 'mat2', 'mat3' 'mat4', |
|
53 'mat2x2', 'mat3x2', 'mat4x2', 'mat2x3', 'mat3x3', 'mat4x3', |
|
54 'mat2x4', 'mat3x4', 'mat4x4', 'vec2', 'vec3', 'vec4', |
|
55 'ivec2', 'ivec3', 'ivec4', 'bvec2', 'bvec3', 'bvec4', |
|
56 'sampler1D', 'sampler2D', 'sampler3D' 'samplerCube', |
|
57 'sampler1DShadow', 'sampler2DShadow', 'struct'), |
|
58 prefix=r'\b', suffix=r'\b'), |
|
59 Keyword), |
|
60 (words(( |
|
61 'asm', 'class', 'union', 'enum', 'typedef', 'template', 'this', |
|
62 'packed', 'goto', 'switch', 'default', 'inline', 'noinline', |
|
63 'volatile', 'public', 'static', 'extern', 'external', 'interface', |
|
64 'long', 'short', 'double', 'half', 'fixed', 'unsigned', 'lowp', |
|
65 'mediump', 'highp', 'precision', 'input', 'output', |
|
66 'hvec2', 'hvec3', 'hvec4', 'dvec2', 'dvec3', 'dvec4', |
|
67 'fvec2', 'fvec3', 'fvec4', 'sampler2DRect', 'sampler3DRect', |
|
68 'sampler2DRectShadow', 'sizeof', 'cast', 'namespace', 'using'), |
|
69 prefix=r'\b', suffix=r'\b'), |
|
70 Keyword), # future use |
|
71 (r'[a-zA-Z_]\w*', Name), |
|
72 (r'\.', Punctuation), |
|
73 (r'\s+', Text), |
|
74 ], |
|
75 } |
|
76 |
|
77 |
|
78 class PostScriptLexer(RegexLexer): |
|
79 """ |
|
80 Lexer for PostScript files. |
|
81 |
|
82 The PostScript Language Reference published by Adobe at |
|
83 <http://partners.adobe.com/public/developer/en/ps/PLRM.pdf> |
|
84 is the authority for this. |
|
85 |
|
86 .. versionadded:: 1.4 |
|
87 """ |
|
88 name = 'PostScript' |
|
89 aliases = ['postscript', 'postscr'] |
|
90 filenames = ['*.ps', '*.eps'] |
|
91 mimetypes = ['application/postscript'] |
|
92 |
|
93 delimiter = r'()<>\[\]{}/%\s' |
|
94 delimiter_end = r'(?=[%s])' % delimiter |
|
95 |
|
96 valid_name_chars = r'[^%s]' % delimiter |
|
97 valid_name = r"%s+%s" % (valid_name_chars, delimiter_end) |
|
98 |
|
99 tokens = { |
|
100 'root': [ |
|
101 # All comment types |
|
102 (r'^%!.+\n', Comment.Preproc), |
|
103 (r'%%.*\n', Comment.Special), |
|
104 (r'(^%.*\n){2,}', Comment.Multiline), |
|
105 (r'%.*\n', Comment.Single), |
|
106 |
|
107 # String literals are awkward; enter separate state. |
|
108 (r'\(', String, 'stringliteral'), |
|
109 |
|
110 (r'[{}<>\[\]]', Punctuation), |
|
111 |
|
112 # Numbers |
|
113 (r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex), |
|
114 # Slight abuse: use Oct to signify any explicit base system |
|
115 (r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)' |
|
116 r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct), |
|
117 (r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?' |
|
118 + delimiter_end, Number.Float), |
|
119 (r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer), |
|
120 |
|
121 # References |
|
122 (r'\/%s' % valid_name, Name.Variable), |
|
123 |
|
124 # Names |
|
125 (valid_name, Name.Function), # Anything else is executed |
|
126 |
|
127 # These keywords taken from |
|
128 # <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf> |
|
129 # Is there an authoritative list anywhere that doesn't involve |
|
130 # trawling documentation? |
|
131 |
|
132 (r'(false|true)' + delimiter_end, Keyword.Constant), |
|
133 |
|
134 # Conditionals / flow control |
|
135 (r'(eq|ne|g[et]|l[et]|and|or|not|if(?:else)?|for(?:all)?)' |
|
136 + delimiter_end, Keyword.Reserved), |
|
137 |
|
138 (words(( |
|
139 'abs', 'add', 'aload', 'arc', 'arcn', 'array', 'atan', 'begin', |
|
140 'bind', 'ceiling', 'charpath', 'clip', 'closepath', 'concat', |
|
141 'concatmatrix', 'copy', 'cos', 'currentlinewidth', 'currentmatrix', |
|
142 'currentpoint', 'curveto', 'cvi', 'cvs', 'def', 'defaultmatrix', |
|
143 'dict', 'dictstackoverflow', 'div', 'dtransform', 'dup', 'end', |
|
144 'exch', 'exec', 'exit', 'exp', 'fill', 'findfont', 'floor', 'get', |
|
145 'getinterval', 'grestore', 'gsave', 'gt', 'identmatrix', 'idiv', |
|
146 'idtransform', 'index', 'invertmatrix', 'itransform', 'length', |
|
147 'lineto', 'ln', 'load', 'log', 'loop', 'matrix', 'mod', 'moveto', |
|
148 'mul', 'neg', 'newpath', 'pathforall', 'pathbbox', 'pop', 'print', |
|
149 'pstack', 'put', 'quit', 'rand', 'rangecheck', 'rcurveto', 'repeat', |
|
150 'restore', 'rlineto', 'rmoveto', 'roll', 'rotate', 'round', 'run', |
|
151 'save', 'scale', 'scalefont', 'setdash', 'setfont', 'setgray', |
|
152 'setlinecap', 'setlinejoin', 'setlinewidth', 'setmatrix', |
|
153 'setrgbcolor', 'shfill', 'show', 'showpage', 'sin', 'sqrt', |
|
154 'stack', 'stringwidth', 'stroke', 'strokepath', 'sub', 'syntaxerror', |
|
155 'transform', 'translate', 'truncate', 'typecheck', 'undefined', |
|
156 'undefinedfilename', 'undefinedresult'), suffix=delimiter_end), |
|
157 Name.Builtin), |
|
158 |
|
159 (r'\s+', Text), |
|
160 ], |
|
161 |
|
162 'stringliteral': [ |
|
163 (r'[^()\\]+', String), |
|
164 (r'\\', String.Escape, 'escape'), |
|
165 (r'\(', String, '#push'), |
|
166 (r'\)', String, '#pop'), |
|
167 ], |
|
168 |
|
169 'escape': [ |
|
170 (r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', String.Escape, '#pop'), |
|
171 default('#pop'), |
|
172 ], |
|
173 } |
|
174 |
|
175 |
|
176 class AsymptoteLexer(RegexLexer): |
|
177 """ |
|
178 For `Asymptote <http://asymptote.sf.net/>`_ source code. |
|
179 |
|
180 .. versionadded:: 1.2 |
|
181 """ |
|
182 name = 'Asymptote' |
|
183 aliases = ['asy', 'asymptote'] |
|
184 filenames = ['*.asy'] |
|
185 mimetypes = ['text/x-asymptote'] |
|
186 |
|
187 #: optional Comment or Whitespace |
|
188 _ws = r'(?:\s|//.*?\n|/\*.*?\*/)+' |
|
189 |
|
190 tokens = { |
|
191 'whitespace': [ |
|
192 (r'\n', Text), |
|
193 (r'\s+', Text), |
|
194 (r'\\\n', Text), # line continuation |
|
195 (r'//(\n|(.|\n)*?[^\\]\n)', Comment), |
|
196 (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment), |
|
197 ], |
|
198 'statements': [ |
|
199 # simple string (TeX friendly) |
|
200 (r'"(\\\\|\\"|[^"])*"', String), |
|
201 # C style string (with character escapes) |
|
202 (r"'", String, 'string'), |
|
203 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), |
|
204 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), |
|
205 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), |
|
206 (r'0[0-7]+[Ll]?', Number.Oct), |
|
207 (r'\d+[Ll]?', Number.Integer), |
|
208 (r'[~!%^&*+=|?:<>/-]', Operator), |
|
209 (r'[()\[\],.]', Punctuation), |
|
210 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)), |
|
211 (r'(and|controls|tension|atleast|curl|if|else|while|for|do|' |
|
212 r'return|break|continue|struct|typedef|new|access|import|' |
|
213 r'unravel|from|include|quote|static|public|private|restricted|' |
|
214 r'this|explicit|true|false|null|cycle|newframe|operator)\b', Keyword), |
|
215 # Since an asy-type-name can be also an asy-function-name, |
|
216 # in the following we test if the string " [a-zA-Z]" follows |
|
217 # the Keyword.Type. |
|
218 # Of course it is not perfect ! |
|
219 (r'(Braid|FitResult|Label|Legend|TreeNode|abscissa|arc|arrowhead|' |
|
220 r'binarytree|binarytreeNode|block|bool|bool3|bounds|bqe|circle|' |
|
221 r'conic|coord|coordsys|cputime|ellipse|file|filltype|frame|grid3|' |
|
222 r'guide|horner|hsv|hyperbola|indexedTransform|int|inversion|key|' |
|
223 r'light|line|linefit|marginT|marker|mass|object|pair|parabola|path|' |
|
224 r'path3|pen|picture|point|position|projection|real|revolution|' |
|
225 r'scaleT|scientific|segment|side|slice|splitface|string|surface|' |
|
226 r'tensionSpecifier|ticklocate|ticksgridT|tickvalues|transform|' |
|
227 r'transformation|tree|triangle|trilinear|triple|vector|' |
|
228 r'vertex|void)(?=\s+[a-zA-Z])', Keyword.Type), |
|
229 # Now the asy-type-name which are not asy-function-name |
|
230 # except yours ! |
|
231 # Perhaps useless |
|
232 (r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|' |
|
233 r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|' |
|
234 r'picture|position|real|revolution|slice|splitface|ticksgridT|' |
|
235 r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type), |
|
236 ('[a-zA-Z_]\w*:(?!:)', Name.Label), |
|
237 ('[a-zA-Z_]\w*', Name), |
|
238 ], |
|
239 'root': [ |
|
240 include('whitespace'), |
|
241 # functions |
|
242 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments |
|
243 r'([a-zA-Z_]\w*)' # method name |
|
244 r'(\s*\([^;]*?\))' # signature |
|
245 r'(' + _ws + r')(\{)', |
|
246 bygroups(using(this), Name.Function, using(this), using(this), |
|
247 Punctuation), |
|
248 'function'), |
|
249 # function declarations |
|
250 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments |
|
251 r'([a-zA-Z_]\w*)' # method name |
|
252 r'(\s*\([^;]*?\))' # signature |
|
253 r'(' + _ws + r')(;)', |
|
254 bygroups(using(this), Name.Function, using(this), using(this), |
|
255 Punctuation)), |
|
256 default('statement'), |
|
257 ], |
|
258 'statement': [ |
|
259 include('whitespace'), |
|
260 include('statements'), |
|
261 ('[{}]', Punctuation), |
|
262 (';', Punctuation, '#pop'), |
|
263 ], |
|
264 'function': [ |
|
265 include('whitespace'), |
|
266 include('statements'), |
|
267 (';', Punctuation), |
|
268 (r'\{', Punctuation, '#push'), |
|
269 (r'\}', Punctuation, '#pop'), |
|
270 ], |
|
271 'string': [ |
|
272 (r"'", String, '#pop'), |
|
273 (r'\\([\\abfnrtv"\'?]|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
274 (r'\n', String), |
|
275 (r"[^\\'\n]+", String), # all other characters |
|
276 (r'\\\n', String), |
|
277 (r'\\n', String), # line continuation |
|
278 (r'\\', String), # stray backslash |
|
279 ], |
|
280 } |
|
281 |
|
282 def get_tokens_unprocessed(self, text): |
|
283 from pygments.lexers._asy_builtins import ASYFUNCNAME, ASYVARNAME |
|
284 for index, token, value in \ |
|
285 RegexLexer.get_tokens_unprocessed(self, text): |
|
286 if token is Name and value in ASYFUNCNAME: |
|
287 token = Name.Function |
|
288 elif token is Name and value in ASYVARNAME: |
|
289 token = Name.Variable |
|
290 yield index, token, value |
|
291 |
|
292 |
|
293 def _shortened(word): |
|
294 dpos = word.find('$') |
|
295 return '|'.join(word[:dpos] + word[dpos+1:i] + r'\b' |
|
296 for i in range(len(word), dpos, -1)) |
|
297 |
|
298 |
|
299 def _shortened_many(*words): |
|
300 return '|'.join(map(_shortened, words)) |
|
301 |
|
302 |
|
303 class GnuplotLexer(RegexLexer): |
|
304 """ |
|
305 For `Gnuplot <http://gnuplot.info/>`_ plotting scripts. |
|
306 |
|
307 .. versionadded:: 0.11 |
|
308 """ |
|
309 |
|
310 name = 'Gnuplot' |
|
311 aliases = ['gnuplot'] |
|
312 filenames = ['*.plot', '*.plt'] |
|
313 mimetypes = ['text/x-gnuplot'] |
|
314 |
|
315 tokens = { |
|
316 'root': [ |
|
317 include('whitespace'), |
|
318 (_shortened('bi$nd'), Keyword, 'bind'), |
|
319 (_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'), |
|
320 (_shortened('f$it'), Keyword, 'fit'), |
|
321 (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'), |
|
322 (r'else\b', Keyword), |
|
323 (_shortened('pa$use'), Keyword, 'pause'), |
|
324 (_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'), |
|
325 (_shortened('sa$ve'), Keyword, 'save'), |
|
326 (_shortened('se$t'), Keyword, ('genericargs', 'optionarg')), |
|
327 (_shortened_many('sh$ow', 'uns$et'), |
|
328 Keyword, ('noargs', 'optionarg')), |
|
329 (_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear', |
|
330 'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int', |
|
331 'pwd$', 're$read', 'res$et', 'scr$eendump', |
|
332 'she$ll', 'sy$stem', 'up$date'), |
|
333 Keyword, 'genericargs'), |
|
334 (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump', |
|
335 'she$ll', 'test$'), |
|
336 Keyword, 'noargs'), |
|
337 ('([a-zA-Z_]\w*)(\s*)(=)', |
|
338 bygroups(Name.Variable, Text, Operator), 'genericargs'), |
|
339 ('([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)', |
|
340 bygroups(Name.Function, Text, Operator), 'genericargs'), |
|
341 (r'@[a-zA-Z_]\w*', Name.Constant), # macros |
|
342 (r';', Keyword), |
|
343 ], |
|
344 'comment': [ |
|
345 (r'[^\\\n]', Comment), |
|
346 (r'\\\n', Comment), |
|
347 (r'\\', Comment), |
|
348 # don't add the newline to the Comment token |
|
349 default('#pop'), |
|
350 ], |
|
351 'whitespace': [ |
|
352 ('#', Comment, 'comment'), |
|
353 (r'[ \t\v\f]+', Text), |
|
354 ], |
|
355 'noargs': [ |
|
356 include('whitespace'), |
|
357 # semicolon and newline end the argument list |
|
358 (r';', Punctuation, '#pop'), |
|
359 (r'\n', Text, '#pop'), |
|
360 ], |
|
361 'dqstring': [ |
|
362 (r'"', String, '#pop'), |
|
363 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), |
|
364 (r'[^\\"\n]+', String), # all other characters |
|
365 (r'\\\n', String), # line continuation |
|
366 (r'\\', String), # stray backslash |
|
367 (r'\n', String, '#pop'), # newline ends the string too |
|
368 ], |
|
369 'sqstring': [ |
|
370 (r"''", String), # escaped single quote |
|
371 (r"'", String, '#pop'), |
|
372 (r"[^\\'\n]+", String), # all other characters |
|
373 (r'\\\n', String), # line continuation |
|
374 (r'\\', String), # normal backslash |
|
375 (r'\n', String, '#pop'), # newline ends the string too |
|
376 ], |
|
377 'genericargs': [ |
|
378 include('noargs'), |
|
379 (r'"', String, 'dqstring'), |
|
380 (r"'", String, 'sqstring'), |
|
381 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), |
|
382 (r'(\d+\.\d*|\.\d+)', Number.Float), |
|
383 (r'-?\d+', Number.Integer), |
|
384 ('[,.~!%^&*+=|?:<>/-]', Operator), |
|
385 ('[{}()\[\]]', Punctuation), |
|
386 (r'(eq|ne)\b', Operator.Word), |
|
387 (r'([a-zA-Z_]\w*)(\s*)(\()', |
|
388 bygroups(Name.Function, Text, Punctuation)), |
|
389 (r'[a-zA-Z_]\w*', Name), |
|
390 (r'@[a-zA-Z_]\w*', Name.Constant), # macros |
|
391 (r'\\\n', Text), |
|
392 ], |
|
393 'optionarg': [ |
|
394 include('whitespace'), |
|
395 (_shortened_many( |
|
396 "a$ll", "an$gles", "ar$row", "au$toscale", "b$ars", "bor$der", |
|
397 "box$width", "cl$abel", "c$lip", "cn$trparam", "co$ntour", "da$ta", |
|
398 "data$file", "dg$rid3d", "du$mmy", "enc$oding", "dec$imalsign", |
|
399 "fit$", "font$path", "fo$rmat", "fu$nction", "fu$nctions", "g$rid", |
|
400 "hid$den3d", "his$torysize", "is$osamples", "k$ey", "keyt$itle", |
|
401 "la$bel", "li$nestyle", "ls$", "loa$dpath", "loc$ale", "log$scale", |
|
402 "mac$ros", "map$ping", "map$ping3d", "mar$gin", "lmar$gin", |
|
403 "rmar$gin", "tmar$gin", "bmar$gin", "mo$use", "multi$plot", |
|
404 "mxt$ics", "nomxt$ics", "mx2t$ics", "nomx2t$ics", "myt$ics", |
|
405 "nomyt$ics", "my2t$ics", "nomy2t$ics", "mzt$ics", "nomzt$ics", |
|
406 "mcbt$ics", "nomcbt$ics", "of$fsets", "or$igin", "o$utput", |
|
407 "pa$rametric", "pm$3d", "pal$ette", "colorb$ox", "p$lot", |
|
408 "poi$ntsize", "pol$ar", "pr$int", "obj$ect", "sa$mples", "si$ze", |
|
409 "st$yle", "su$rface", "table$", "t$erminal", "termo$ptions", "ti$cs", |
|
410 "ticsc$ale", "ticsl$evel", "timef$mt", "tim$estamp", "tit$le", |
|
411 "v$ariables", "ve$rsion", "vi$ew", "xyp$lane", "xda$ta", "x2da$ta", |
|
412 "yda$ta", "y2da$ta", "zda$ta", "cbda$ta", "xl$abel", "x2l$abel", |
|
413 "yl$abel", "y2l$abel", "zl$abel", "cbl$abel", "xti$cs", "noxti$cs", |
|
414 "x2ti$cs", "nox2ti$cs", "yti$cs", "noyti$cs", "y2ti$cs", "noy2ti$cs", |
|
415 "zti$cs", "nozti$cs", "cbti$cs", "nocbti$cs", "xdti$cs", "noxdti$cs", |
|
416 "x2dti$cs", "nox2dti$cs", "ydti$cs", "noydti$cs", "y2dti$cs", |
|
417 "noy2dti$cs", "zdti$cs", "nozdti$cs", "cbdti$cs", "nocbdti$cs", |
|
418 "xmti$cs", "noxmti$cs", "x2mti$cs", "nox2mti$cs", "ymti$cs", |
|
419 "noymti$cs", "y2mti$cs", "noy2mti$cs", "zmti$cs", "nozmti$cs", |
|
420 "cbmti$cs", "nocbmti$cs", "xr$ange", "x2r$ange", "yr$ange", |
|
421 "y2r$ange", "zr$ange", "cbr$ange", "rr$ange", "tr$ange", "ur$ange", |
|
422 "vr$ange", "xzeroa$xis", "x2zeroa$xis", "yzeroa$xis", "y2zeroa$xis", |
|
423 "zzeroa$xis", "zeroa$xis", "z$ero"), Name.Builtin, '#pop'), |
|
424 ], |
|
425 'bind': [ |
|
426 ('!', Keyword, '#pop'), |
|
427 (_shortened('all$windows'), Name.Builtin), |
|
428 include('genericargs'), |
|
429 ], |
|
430 'quit': [ |
|
431 (r'gnuplot\b', Keyword), |
|
432 include('noargs'), |
|
433 ], |
|
434 'fit': [ |
|
435 (r'via\b', Name.Builtin), |
|
436 include('plot'), |
|
437 ], |
|
438 'if': [ |
|
439 (r'\)', Punctuation, '#pop'), |
|
440 include('genericargs'), |
|
441 ], |
|
442 'pause': [ |
|
443 (r'(mouse|any|button1|button2|button3)\b', Name.Builtin), |
|
444 (_shortened('key$press'), Name.Builtin), |
|
445 include('genericargs'), |
|
446 ], |
|
447 'plot': [ |
|
448 (_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex', |
|
449 'mat$rix', 's$mooth', 'thru$', 't$itle', |
|
450 'not$itle', 'u$sing', 'w$ith'), |
|
451 Name.Builtin), |
|
452 include('genericargs'), |
|
453 ], |
|
454 'save': [ |
|
455 (_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'), |
|
456 Name.Builtin), |
|
457 include('genericargs'), |
|
458 ], |
|
459 } |
|
460 |
|
461 |
|
462 class PovrayLexer(RegexLexer): |
|
463 """ |
|
464 For `Persistence of Vision Raytracer <http://www.povray.org/>`_ files. |
|
465 |
|
466 .. versionadded:: 0.11 |
|
467 """ |
|
468 name = 'POVRay' |
|
469 aliases = ['pov'] |
|
470 filenames = ['*.pov', '*.inc'] |
|
471 mimetypes = ['text/x-povray'] |
|
472 |
|
473 tokens = { |
|
474 'root': [ |
|
475 (r'/\*[\w\W]*?\*/', Comment.Multiline), |
|
476 (r'//.*\n', Comment.Single), |
|
477 (r'(?s)"(?:\\.|[^"\\])+"', String.Double), |
|
478 (words(( |
|
479 'break', 'case', 'debug', 'declare', 'default', 'define', 'else', |
|
480 'elseif', 'end', 'error', 'fclose', 'fopen', 'for', 'if', 'ifdef', |
|
481 'ifndef', 'include', 'local', 'macro', 'range', 'read', 'render', |
|
482 'statistics', 'switch', 'undef', 'version', 'warning', 'while', |
|
483 'write'), prefix=r'#', suffix=r'\b'), |
|
484 Comment.Preproc), |
|
485 (words(( |
|
486 'aa_level', 'aa_threshold', 'abs', 'acos', 'acosh', 'adaptive', 'adc_bailout', |
|
487 'agate', 'agate_turb', 'all', 'alpha', 'ambient', 'ambient_light', 'angle', |
|
488 'aperture', 'arc_angle', 'area_light', 'asc', 'asin', 'asinh', 'assumed_gamma', |
|
489 'atan', 'atan2', 'atanh', 'atmosphere', 'atmospheric_attenuation', |
|
490 'attenuating', 'average', 'background', 'black_hole', 'blue', 'blur_samples', |
|
491 'bounded_by', 'box_mapping', 'bozo', 'break', 'brick', 'brick_size', |
|
492 'brightness', 'brilliance', 'bumps', 'bumpy1', 'bumpy2', 'bumpy3', 'bump_map', |
|
493 'bump_size', 'case', 'caustics', 'ceil', 'checker', 'chr', 'clipped_by', 'clock', |
|
494 'color', 'color_map', 'colour', 'colour_map', 'component', 'composite', 'concat', |
|
495 'confidence', 'conic_sweep', 'constant', 'control0', 'control1', 'cos', 'cosh', |
|
496 'count', 'crackle', 'crand', 'cube', 'cubic_spline', 'cylindrical_mapping', |
|
497 'debug', 'declare', 'default', 'degrees', 'dents', 'diffuse', 'direction', |
|
498 'distance', 'distance_maximum', 'div', 'dust', 'dust_type', 'eccentricity', |
|
499 'else', 'emitting', 'end', 'error', 'error_bound', 'exp', 'exponent', |
|
500 'fade_distance', 'fade_power', 'falloff', 'falloff_angle', 'false', |
|
501 'file_exists', 'filter', 'finish', 'fisheye', 'flatness', 'flip', 'floor', |
|
502 'focal_point', 'fog', 'fog_alt', 'fog_offset', 'fog_type', 'frequency', 'gif', |
|
503 'global_settings', 'glowing', 'gradient', 'granite', 'gray_threshold', |
|
504 'green', 'halo', 'hexagon', 'hf_gray_16', 'hierarchy', 'hollow', 'hypercomplex', |
|
505 'if', 'ifdef', 'iff', 'image_map', 'incidence', 'include', 'int', 'interpolate', |
|
506 'inverse', 'ior', 'irid', 'irid_wavelength', 'jitter', 'lambda', 'leopard', |
|
507 'linear', 'linear_spline', 'linear_sweep', 'location', 'log', 'looks_like', |
|
508 'look_at', 'low_error_factor', 'mandel', 'map_type', 'marble', 'material_map', |
|
509 'matrix', 'max', 'max_intersections', 'max_iteration', 'max_trace_level', |
|
510 'max_value', 'metallic', 'min', 'minimum_reuse', 'mod', 'mortar', |
|
511 'nearest_count', 'no', 'normal', 'normal_map', 'no_shadow', 'number_of_waves', |
|
512 'octaves', 'off', 'offset', 'omega', 'omnimax', 'on', 'once', 'onion', 'open', |
|
513 'orthographic', 'panoramic', 'pattern1', 'pattern2', 'pattern3', |
|
514 'perspective', 'pgm', 'phase', 'phong', 'phong_size', 'pi', 'pigment', |
|
515 'pigment_map', 'planar_mapping', 'png', 'point_at', 'pot', 'pow', 'ppm', |
|
516 'precision', 'pwr', 'quadratic_spline', 'quaternion', 'quick_color', |
|
517 'quick_colour', 'quilted', 'radial', 'radians', 'radiosity', 'radius', 'rainbow', |
|
518 'ramp_wave', 'rand', 'range', 'reciprocal', 'recursion_limit', 'red', |
|
519 'reflection', 'refraction', 'render', 'repeat', 'rgb', 'rgbf', 'rgbft', 'rgbt', |
|
520 'right', 'ripples', 'rotate', 'roughness', 'samples', 'scale', 'scallop_wave', |
|
521 'scattering', 'seed', 'shadowless', 'sin', 'sine_wave', 'sinh', 'sky', 'sky_sphere', |
|
522 'slice', 'slope_map', 'smooth', 'specular', 'spherical_mapping', 'spiral', |
|
523 'spiral1', 'spiral2', 'spotlight', 'spotted', 'sqr', 'sqrt', 'statistics', 'str', |
|
524 'strcmp', 'strength', 'strlen', 'strlwr', 'strupr', 'sturm', 'substr', 'switch', 'sys', |
|
525 't', 'tan', 'tanh', 'test_camera_1', 'test_camera_2', 'test_camera_3', |
|
526 'test_camera_4', 'texture', 'texture_map', 'tga', 'thickness', 'threshold', |
|
527 'tightness', 'tile2', 'tiles', 'track', 'transform', 'translate', 'transmit', |
|
528 'triangle_wave', 'true', 'ttf', 'turbulence', 'turb_depth', 'type', |
|
529 'ultra_wide_angle', 'up', 'use_color', 'use_colour', 'use_index', 'u_steps', |
|
530 'val', 'variance', 'vaxis_rotate', 'vcross', 'vdot', 'version', 'vlength', |
|
531 'vnormalize', 'volume_object', 'volume_rendered', 'vol_with_light', |
|
532 'vrotate', 'v_steps', 'warning', 'warp', 'water_level', 'waves', 'while', 'width', |
|
533 'wood', 'wrinkles', 'yes'), prefix=r'\b', suffix=r'\b'), |
|
534 Keyword), |
|
535 (words(( |
|
536 'bicubic_patch', 'blob', 'box', 'camera', 'cone', 'cubic', 'cylinder', 'difference', |
|
537 'disc', 'height_field', 'intersection', 'julia_fractal', 'lathe', |
|
538 'light_source', 'merge', 'mesh', 'object', 'plane', 'poly', 'polygon', 'prism', |
|
539 'quadric', 'quartic', 'smooth_triangle', 'sor', 'sphere', 'superellipsoid', |
|
540 'text', 'torus', 'triangle', 'union'), suffix=r'\b'), |
|
541 Name.Builtin), |
|
542 # TODO: <=, etc |
|
543 (r'[\[\](){}<>;,]', Punctuation), |
|
544 (r'[-+*/=]', Operator), |
|
545 (r'\b(x|y|z|u|v)\b', Name.Builtin.Pseudo), |
|
546 (r'[a-zA-Z_]\w*', Name), |
|
547 (r'[0-9]+\.[0-9]*', Number.Float), |
|
548 (r'\.[0-9]+', Number.Float), |
|
549 (r'[0-9]+', Number.Integer), |
|
550 (r'"(\\\\|\\"|[^"])*"', String), |
|
551 (r'\s+', Text), |
|
552 ] |
|
553 } |