eric6/ThirdParty/Pygments/pygments/lexers/graphics.py

changeset 6942
2602857055c5
parent 6651
e8f3b5568b21
child 7547
21b0534faebc
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
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-2017 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', 'HLSLShaderLexer']
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 # Storage qualifiers
50 'attribute', 'const', 'uniform', 'varying',
51 'buffer', 'shared', 'in', 'out',
52 # Layout qualifiers
53 'layout',
54 # Interpolation qualifiers
55 'flat', 'smooth', 'noperspective',
56 # Auxiliary qualifiers
57 'centroid', 'sample', 'patch',
58 # Parameter qualifiers. Some double as Storage qualifiers
59 'inout',
60 # Precision qualifiers
61 'lowp', 'mediump', 'highp', 'precision',
62 # Invariance qualifiers
63 'invariant',
64 # Precise qualifiers
65 'precise',
66 # Memory qualifiers
67 'coherent', 'volatile', 'restrict', 'readonly', 'writeonly',
68 # Statements
69 'break', 'continue', 'do', 'for', 'while', 'switch',
70 'case', 'default', 'if', 'else', 'subroutine',
71 'discard', 'return', 'struct'),
72 prefix=r'\b', suffix=r'\b'),
73 Keyword),
74 (words((
75 # Boolean values
76 'true', 'false'),
77 prefix=r'\b', suffix=r'\b'),
78 Keyword.Constant),
79 (words((
80 # Miscellaneous types
81 'void', 'atomic_uint',
82 # Floating-point scalars and vectors
83 'float', 'vec2', 'vec3', 'vec4',
84 'double', 'dvec2', 'dvec3', 'dvec4',
85 # Integer scalars and vectors
86 'int', 'ivec2', 'ivec3', 'ivec4',
87 'uint', 'uvec2', 'uvec3', 'uvec4',
88 # Boolean scalars and vectors
89 'bool', 'bvec2', 'bvec3', 'bvec4',
90 # Matrices
91 'mat2', 'mat3', 'mat4', 'dmat2', 'dmat3', 'dmat4',
92 'mat2x2', 'mat2x3', 'mat2x4', 'dmat2x2', 'dmat2x3', 'dmat2x4',
93 'mat3x2', 'mat3x3', 'mat3x4', 'dmat3x2', 'dmat3x3',
94 'dmat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat4x2', 'dmat4x3', 'dmat4x4',
95 # Floating-point samplers
96 'sampler1D', 'sampler2D', 'sampler3D', 'samplerCube',
97 'sampler1DArray', 'sampler2DArray', 'samplerCubeArray',
98 'sampler2DRect', 'samplerBuffer',
99 'sampler2DMS', 'sampler2DMSArray',
100 # Shadow samplers
101 'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow',
102 'sampler1DArrayShadow', 'sampler2DArrayShadow',
103 'samplerCubeArrayShadow', 'sampler2DRectShadow',
104 # Signed integer samplers
105 'isampler1D', 'isampler2D', 'isampler3D', 'isamplerCube',
106 'isampler1DArray', 'isampler2DArray', 'isamplerCubeArray',
107 'isampler2DRect', 'isamplerBuffer',
108 'isampler2DMS', 'isampler2DMSArray',
109 # Unsigned integer samplers
110 'usampler1D', 'usampler2D', 'usampler3D', 'usamplerCube',
111 'usampler1DArray', 'usampler2DArray', 'usamplerCubeArray',
112 'usampler2DRect', 'usamplerBuffer',
113 'usampler2DMS', 'usampler2DMSArray',
114 # Floating-point image types
115 'image1D', 'image2D', 'image3D', 'imageCube',
116 'image1DArray', 'image2DArray', 'imageCubeArray',
117 'image2DRect', 'imageBuffer',
118 'image2DMS', 'image2DMSArray',
119 # Signed integer image types
120 'iimage1D', 'iimage2D', 'iimage3D', 'iimageCube',
121 'iimage1DArray', 'iimage2DArray', 'iimageCubeArray',
122 'iimage2DRect', 'iimageBuffer',
123 'iimage2DMS', 'iimage2DMSArray',
124 # Unsigned integer image types
125 'uimage1D', 'uimage2D', 'uimage3D', 'uimageCube',
126 'uimage1DArray', 'uimage2DArray', 'uimageCubeArray',
127 'uimage2DRect', 'uimageBuffer',
128 'uimage2DMS', 'uimage2DMSArray'),
129 prefix=r'\b', suffix=r'\b'),
130 Keyword.Type),
131 (words((
132 # Reserved for future use.
133 'common', 'partition', 'active', 'asm', 'class',
134 'union', 'enum', 'typedef', 'template', 'this',
135 'resource', 'goto', 'inline', 'noinline', 'public',
136 'static', 'extern', 'external', 'interface', 'long',
137 'short', 'half', 'fixed', 'unsigned', 'superp', 'input',
138 'output', 'hvec2', 'hvec3', 'hvec4', 'fvec2', 'fvec3',
139 'fvec4', 'sampler3DRect', 'filter', 'sizeof', 'cast',
140 'namespace', 'using'),
141 prefix=r'\b', suffix=r'\b'),
142 Keyword.Reserved),
143 # All names beginning with "gl_" are reserved.
144 (r'gl_\w*', Name.Builtin),
145 (r'[a-zA-Z_]\w*', Name),
146 (r'\.', Punctuation),
147 (r'\s+', Text),
148 ],
149 }
150
151
152 class HLSLShaderLexer(RegexLexer):
153 """
154 HLSL (Microsoft Direct3D Shader) lexer.
155
156 .. versionadded:: 2.3
157 """
158 name = 'HLSL'
159 aliases = ['hlsl']
160 filenames = ['*.hlsl', '*.hlsli']
161 mimetypes = ['text/x-hlsl']
162
163 tokens = {
164 'root': [
165 (r'^#.*', Comment.Preproc),
166 (r'//.*', Comment.Single),
167 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
168 (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
169 Operator),
170 (r'[?:]', Operator), # quick hack for ternary
171 (r'\bdefined\b', Operator),
172 (r'[;{}(),.\[\]]', Punctuation),
173 # FIXME when e is present, no decimal point needed
174 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?f?', Number.Float),
175 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?f?', Number.Float),
176 (r'0[xX][0-9a-fA-F]*', Number.Hex),
177 (r'0[0-7]*', Number.Oct),
178 (r'[1-9][0-9]*', Number.Integer),
179 (r'"', String, 'string'),
180 (words((
181 'asm','asm_fragment','break','case','cbuffer','centroid','class',
182 'column_major','compile','compile_fragment','const','continue',
183 'default','discard','do','else','export','extern','for','fxgroup',
184 'globallycoherent','groupshared','if','in','inline','inout',
185 'interface','line','lineadj','linear','namespace','nointerpolation',
186 'noperspective','NULL','out','packoffset','pass','pixelfragment',
187 'point','precise','return','register','row_major','sample',
188 'sampler','shared','stateblock','stateblock_state','static',
189 'struct','switch','tbuffer','technique','technique10',
190 'technique11','texture','typedef','triangle','triangleadj',
191 'uniform','vertexfragment','volatile','while'),
192 prefix=r'\b', suffix=r'\b'),
193 Keyword),
194 (words(('true','false'), prefix=r'\b', suffix=r'\b'),
195 Keyword.Constant),
196 (words((
197 'auto','catch','char','const_cast','delete','dynamic_cast','enum',
198 'explicit','friend','goto','long','mutable','new','operator',
199 'private','protected','public','reinterpret_cast','short','signed',
200 'sizeof','static_cast','template','this','throw','try','typename',
201 'union','unsigned','using','virtual'),
202 prefix=r'\b', suffix=r'\b'),
203 Keyword.Reserved),
204 (words((
205 'dword','matrix','snorm','string','unorm','unsigned','void','vector',
206 'BlendState','Buffer','ByteAddressBuffer','ComputeShader',
207 'DepthStencilState','DepthStencilView','DomainShader',
208 'GeometryShader','HullShader','InputPatch','LineStream',
209 'OutputPatch','PixelShader','PointStream','RasterizerState',
210 'RenderTargetView','RasterizerOrderedBuffer',
211 'RasterizerOrderedByteAddressBuffer',
212 'RasterizerOrderedStructuredBuffer','RasterizerOrderedTexture1D',
213 'RasterizerOrderedTexture1DArray','RasterizerOrderedTexture2D',
214 'RasterizerOrderedTexture2DArray','RasterizerOrderedTexture3D',
215 'RWBuffer','RWByteAddressBuffer','RWStructuredBuffer',
216 'RWTexture1D','RWTexture1DArray','RWTexture2D','RWTexture2DArray',
217 'RWTexture3D','SamplerState','SamplerComparisonState',
218 'StructuredBuffer','Texture1D','Texture1DArray','Texture2D',
219 'Texture2DArray','Texture2DMS','Texture2DMSArray','Texture3D',
220 'TextureCube','TextureCubeArray','TriangleStream','VertexShader'),
221 prefix=r'\b', suffix=r'\b'),
222 Keyword.Type),
223 (words((
224 'bool','double','float','int','half','min16float','min10float',
225 'min16int','min12int','min16uint','uint'),
226 prefix=r'\b', suffix=r'([1-4](x[1-4])?)?\b'),
227 Keyword.Type), # vector and matrix types
228 (words((
229 'abort','abs','acos','all','AllMemoryBarrier',
230 'AllMemoryBarrierWithGroupSync','any','AppendStructuredBuffer',
231 'asdouble','asfloat','asin','asint','asuint','asuint','atan',
232 'atan2','ceil','CheckAccessFullyMapped','clamp','clip',
233 'CompileShader','ConsumeStructuredBuffer','cos','cosh','countbits',
234 'cross','D3DCOLORtoUBYTE4','ddx','ddx_coarse','ddx_fine','ddy',
235 'ddy_coarse','ddy_fine','degrees','determinant',
236 'DeviceMemoryBarrier','DeviceMemoryBarrierWithGroupSync','distance',
237 'dot','dst','errorf','EvaluateAttributeAtCentroid',
238 'EvaluateAttributeAtSample','EvaluateAttributeSnapped','exp',
239 'exp2','f16tof32','f32tof16','faceforward','firstbithigh',
240 'firstbitlow','floor','fma','fmod','frac','frexp','fwidth',
241 'GetRenderTargetSampleCount','GetRenderTargetSamplePosition',
242 'GlobalOrderedCountIncrement','GroupMemoryBarrier',
243 'GroupMemoryBarrierWithGroupSync','InterlockedAdd','InterlockedAnd',
244 'InterlockedCompareExchange','InterlockedCompareStore',
245 'InterlockedExchange','InterlockedMax','InterlockedMin',
246 'InterlockedOr','InterlockedXor','isfinite','isinf','isnan',
247 'ldexp','length','lerp','lit','log','log10','log2','mad','max',
248 'min','modf','msad4','mul','noise','normalize','pow','printf',
249 'Process2DQuadTessFactorsAvg','Process2DQuadTessFactorsMax',
250 'Process2DQuadTessFactorsMin','ProcessIsolineTessFactors',
251 'ProcessQuadTessFactorsAvg','ProcessQuadTessFactorsMax',
252 'ProcessQuadTessFactorsMin','ProcessTriTessFactorsAvg',
253 'ProcessTriTessFactorsMax','ProcessTriTessFactorsMin',
254 'QuadReadLaneAt','QuadSwapX','QuadSwapY','radians','rcp',
255 'reflect','refract','reversebits','round','rsqrt','saturate',
256 'sign','sin','sincos','sinh','smoothstep','sqrt','step','tan',
257 'tanh','tex1D','tex1D','tex1Dbias','tex1Dgrad','tex1Dlod',
258 'tex1Dproj','tex2D','tex2D','tex2Dbias','tex2Dgrad','tex2Dlod',
259 'tex2Dproj','tex3D','tex3D','tex3Dbias','tex3Dgrad','tex3Dlod',
260 'tex3Dproj','texCUBE','texCUBE','texCUBEbias','texCUBEgrad',
261 'texCUBElod','texCUBEproj','transpose','trunc','WaveAllBitAnd',
262 'WaveAllMax','WaveAllMin','WaveAllBitOr','WaveAllBitXor',
263 'WaveAllEqual','WaveAllProduct','WaveAllSum','WaveAllTrue',
264 'WaveAnyTrue','WaveBallot','WaveGetLaneCount','WaveGetLaneIndex',
265 'WaveGetOrderedIndex','WaveIsHelperLane','WaveOnce',
266 'WavePrefixProduct','WavePrefixSum','WaveReadFirstLane',
267 'WaveReadLaneAt'),
268 prefix=r'\b', suffix=r'\b'),
269 Name.Builtin), # built-in functions
270 (words((
271 'SV_ClipDistance','SV_ClipDistance0','SV_ClipDistance1',
272 'SV_Culldistance','SV_CullDistance0','SV_CullDistance1',
273 'SV_Coverage','SV_Depth','SV_DepthGreaterEqual',
274 'SV_DepthLessEqual','SV_DispatchThreadID','SV_DomainLocation',
275 'SV_GroupID','SV_GroupIndex','SV_GroupThreadID','SV_GSInstanceID',
276 'SV_InnerCoverage','SV_InsideTessFactor','SV_InstanceID',
277 'SV_IsFrontFace','SV_OutputControlPointID','SV_Position',
278 'SV_PrimitiveID','SV_RenderTargetArrayIndex','SV_SampleIndex',
279 'SV_StencilRef','SV_TessFactor','SV_VertexID',
280 'SV_ViewportArrayIndex'),
281 prefix=r'\b', suffix=r'\b'),
282 Name.Decorator), # system-value semantics
283 (r'\bSV_Target[0-7]?\b', Name.Decorator),
284 (words((
285 'allow_uav_condition','branch','call','domain','earlydepthstencil',
286 'fastopt','flatten','forcecase','instance','loop','maxtessfactor',
287 'numthreads','outputcontrolpoints','outputtopology','partitioning',
288 'patchconstantfunc','unroll'),
289 prefix=r'\b', suffix=r'\b'),
290 Name.Decorator), # attributes
291 (r'[a-zA-Z_]\w*', Name),
292 (r'\\$', Comment.Preproc), # backslash at end of line -- usually macro continuation
293 (r'\s+', Text),
294 ],
295 'string': [
296 (r'"', String, '#pop'),
297 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|'
298 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape),
299 (r'[^\\"\n]+', String), # all other characters
300 (r'\\\n', String), # line continuation
301 (r'\\', String), # stray backslash
302 ],
303 }
304
305
306 class PostScriptLexer(RegexLexer):
307 """
308 Lexer for PostScript files.
309
310 The PostScript Language Reference published by Adobe at
311 <http://partners.adobe.com/public/developer/en/ps/PLRM.pdf>
312 is the authority for this.
313
314 .. versionadded:: 1.4
315 """
316 name = 'PostScript'
317 aliases = ['postscript', 'postscr']
318 filenames = ['*.ps', '*.eps']
319 mimetypes = ['application/postscript']
320
321 delimiter = r'()<>\[\]{}/%\s'
322 delimiter_end = r'(?=[%s])' % delimiter
323
324 valid_name_chars = r'[^%s]' % delimiter
325 valid_name = r"%s+%s" % (valid_name_chars, delimiter_end)
326
327 tokens = {
328 'root': [
329 # All comment types
330 (r'^%!.+\n', Comment.Preproc),
331 (r'%%.*\n', Comment.Special),
332 (r'(^%.*\n){2,}', Comment.Multiline),
333 (r'%.*\n', Comment.Single),
334
335 # String literals are awkward; enter separate state.
336 (r'\(', String, 'stringliteral'),
337
338 (r'[{}<>\[\]]', Punctuation),
339
340 # Numbers
341 (r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex),
342 # Slight abuse: use Oct to signify any explicit base system
343 (r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)'
344 r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct),
345 (r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?'
346 + delimiter_end, Number.Float),
347 (r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer),
348
349 # References
350 (r'\/%s' % valid_name, Name.Variable),
351
352 # Names
353 (valid_name, Name.Function), # Anything else is executed
354
355 # These keywords taken from
356 # <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf>
357 # Is there an authoritative list anywhere that doesn't involve
358 # trawling documentation?
359
360 (r'(false|true)' + delimiter_end, Keyword.Constant),
361
362 # Conditionals / flow control
363 (r'(eq|ne|g[et]|l[et]|and|or|not|if(?:else)?|for(?:all)?)'
364 + delimiter_end, Keyword.Reserved),
365
366 (words((
367 'abs', 'add', 'aload', 'arc', 'arcn', 'array', 'atan', 'begin',
368 'bind', 'ceiling', 'charpath', 'clip', 'closepath', 'concat',
369 'concatmatrix', 'copy', 'cos', 'currentlinewidth', 'currentmatrix',
370 'currentpoint', 'curveto', 'cvi', 'cvs', 'def', 'defaultmatrix',
371 'dict', 'dictstackoverflow', 'div', 'dtransform', 'dup', 'end',
372 'exch', 'exec', 'exit', 'exp', 'fill', 'findfont', 'floor', 'get',
373 'getinterval', 'grestore', 'gsave', 'gt', 'identmatrix', 'idiv',
374 'idtransform', 'index', 'invertmatrix', 'itransform', 'length',
375 'lineto', 'ln', 'load', 'log', 'loop', 'matrix', 'mod', 'moveto',
376 'mul', 'neg', 'newpath', 'pathforall', 'pathbbox', 'pop', 'print',
377 'pstack', 'put', 'quit', 'rand', 'rangecheck', 'rcurveto', 'repeat',
378 'restore', 'rlineto', 'rmoveto', 'roll', 'rotate', 'round', 'run',
379 'save', 'scale', 'scalefont', 'setdash', 'setfont', 'setgray',
380 'setlinecap', 'setlinejoin', 'setlinewidth', 'setmatrix',
381 'setrgbcolor', 'shfill', 'show', 'showpage', 'sin', 'sqrt',
382 'stack', 'stringwidth', 'stroke', 'strokepath', 'sub', 'syntaxerror',
383 'transform', 'translate', 'truncate', 'typecheck', 'undefined',
384 'undefinedfilename', 'undefinedresult'), suffix=delimiter_end),
385 Name.Builtin),
386
387 (r'\s+', Text),
388 ],
389
390 'stringliteral': [
391 (r'[^()\\]+', String),
392 (r'\\', String.Escape, 'escape'),
393 (r'\(', String, '#push'),
394 (r'\)', String, '#pop'),
395 ],
396
397 'escape': [
398 (r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', String.Escape, '#pop'),
399 default('#pop'),
400 ],
401 }
402
403
404 class AsymptoteLexer(RegexLexer):
405 """
406 For `Asymptote <http://asymptote.sf.net/>`_ source code.
407
408 .. versionadded:: 1.2
409 """
410 name = 'Asymptote'
411 aliases = ['asy', 'asymptote']
412 filenames = ['*.asy']
413 mimetypes = ['text/x-asymptote']
414
415 #: optional Comment or Whitespace
416 _ws = r'(?:\s|//.*?\n|/\*.*?\*/)+'
417
418 tokens = {
419 'whitespace': [
420 (r'\n', Text),
421 (r'\s+', Text),
422 (r'\\\n', Text), # line continuation
423 (r'//(\n|(.|\n)*?[^\\]\n)', Comment),
424 (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment),
425 ],
426 'statements': [
427 # simple string (TeX friendly)
428 (r'"(\\\\|\\"|[^"])*"', String),
429 # C style string (with character escapes)
430 (r"'", String, 'string'),
431 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
432 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
433 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
434 (r'0[0-7]+[Ll]?', Number.Oct),
435 (r'\d+[Ll]?', Number.Integer),
436 (r'[~!%^&*+=|?:<>/-]', Operator),
437 (r'[()\[\],.]', Punctuation),
438 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
439 (r'(and|controls|tension|atleast|curl|if|else|while|for|do|'
440 r'return|break|continue|struct|typedef|new|access|import|'
441 r'unravel|from|include|quote|static|public|private|restricted|'
442 r'this|explicit|true|false|null|cycle|newframe|operator)\b', Keyword),
443 # Since an asy-type-name can be also an asy-function-name,
444 # in the following we test if the string " [a-zA-Z]" follows
445 # the Keyword.Type.
446 # Of course it is not perfect !
447 (r'(Braid|FitResult|Label|Legend|TreeNode|abscissa|arc|arrowhead|'
448 r'binarytree|binarytreeNode|block|bool|bool3|bounds|bqe|circle|'
449 r'conic|coord|coordsys|cputime|ellipse|file|filltype|frame|grid3|'
450 r'guide|horner|hsv|hyperbola|indexedTransform|int|inversion|key|'
451 r'light|line|linefit|marginT|marker|mass|object|pair|parabola|path|'
452 r'path3|pen|picture|point|position|projection|real|revolution|'
453 r'scaleT|scientific|segment|side|slice|splitface|string|surface|'
454 r'tensionSpecifier|ticklocate|ticksgridT|tickvalues|transform|'
455 r'transformation|tree|triangle|trilinear|triple|vector|'
456 r'vertex|void)(?=\s+[a-zA-Z])', Keyword.Type),
457 # Now the asy-type-name which are not asy-function-name
458 # except yours !
459 # Perhaps useless
460 (r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|'
461 r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|'
462 r'picture|position|real|revolution|slice|splitface|ticksgridT|'
463 r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type),
464 (r'[a-zA-Z_]\w*:(?!:)', Name.Label),
465 (r'[a-zA-Z_]\w*', Name),
466 ],
467 'root': [
468 include('whitespace'),
469 # functions
470 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments
471 r'([a-zA-Z_]\w*)' # method name
472 r'(\s*\([^;]*?\))' # signature
473 r'(' + _ws + r')(\{)',
474 bygroups(using(this), Name.Function, using(this), using(this),
475 Punctuation),
476 'function'),
477 # function declarations
478 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments
479 r'([a-zA-Z_]\w*)' # method name
480 r'(\s*\([^;]*?\))' # signature
481 r'(' + _ws + r')(;)',
482 bygroups(using(this), Name.Function, using(this), using(this),
483 Punctuation)),
484 default('statement'),
485 ],
486 'statement': [
487 include('whitespace'),
488 include('statements'),
489 ('[{}]', Punctuation),
490 (';', Punctuation, '#pop'),
491 ],
492 'function': [
493 include('whitespace'),
494 include('statements'),
495 (';', Punctuation),
496 (r'\{', Punctuation, '#push'),
497 (r'\}', Punctuation, '#pop'),
498 ],
499 'string': [
500 (r"'", String, '#pop'),
501 (r'\\([\\abfnrtv"\'?]|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
502 (r'\n', String),
503 (r"[^\\'\n]+", String), # all other characters
504 (r'\\\n', String),
505 (r'\\n', String), # line continuation
506 (r'\\', String), # stray backslash
507 ],
508 }
509
510 def get_tokens_unprocessed(self, text):
511 from pygments.lexers._asy_builtins import ASYFUNCNAME, ASYVARNAME
512 for index, token, value in \
513 RegexLexer.get_tokens_unprocessed(self, text):
514 if token is Name and value in ASYFUNCNAME:
515 token = Name.Function
516 elif token is Name and value in ASYVARNAME:
517 token = Name.Variable
518 yield index, token, value
519
520
521 def _shortened(word):
522 dpos = word.find('$')
523 return '|'.join(word[:dpos] + word[dpos+1:i] + r'\b'
524 for i in range(len(word), dpos, -1))
525
526
527 def _shortened_many(*words):
528 return '|'.join(map(_shortened, words))
529
530
531 class GnuplotLexer(RegexLexer):
532 """
533 For `Gnuplot <http://gnuplot.info/>`_ plotting scripts.
534
535 .. versionadded:: 0.11
536 """
537
538 name = 'Gnuplot'
539 aliases = ['gnuplot']
540 filenames = ['*.plot', '*.plt']
541 mimetypes = ['text/x-gnuplot']
542
543 tokens = {
544 'root': [
545 include('whitespace'),
546 (_shortened('bi$nd'), Keyword, 'bind'),
547 (_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'),
548 (_shortened('f$it'), Keyword, 'fit'),
549 (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'),
550 (r'else\b', Keyword),
551 (_shortened('pa$use'), Keyword, 'pause'),
552 (_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'),
553 (_shortened('sa$ve'), Keyword, 'save'),
554 (_shortened('se$t'), Keyword, ('genericargs', 'optionarg')),
555 (_shortened_many('sh$ow', 'uns$et'),
556 Keyword, ('noargs', 'optionarg')),
557 (_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear',
558 'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int',
559 'pwd$', 're$read', 'res$et', 'scr$eendump',
560 'she$ll', 'sy$stem', 'up$date'),
561 Keyword, 'genericargs'),
562 (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
563 'she$ll', 'test$'),
564 Keyword, 'noargs'),
565 (r'([a-zA-Z_]\w*)(\s*)(=)',
566 bygroups(Name.Variable, Text, Operator), 'genericargs'),
567 (r'([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)',
568 bygroups(Name.Function, Text, Operator), 'genericargs'),
569 (r'@[a-zA-Z_]\w*', Name.Constant), # macros
570 (r';', Keyword),
571 ],
572 'comment': [
573 (r'[^\\\n]', Comment),
574 (r'\\\n', Comment),
575 (r'\\', Comment),
576 # don't add the newline to the Comment token
577 default('#pop'),
578 ],
579 'whitespace': [
580 ('#', Comment, 'comment'),
581 (r'[ \t\v\f]+', Text),
582 ],
583 'noargs': [
584 include('whitespace'),
585 # semicolon and newline end the argument list
586 (r';', Punctuation, '#pop'),
587 (r'\n', Text, '#pop'),
588 ],
589 'dqstring': [
590 (r'"', String, '#pop'),
591 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
592 (r'[^\\"\n]+', String), # all other characters
593 (r'\\\n', String), # line continuation
594 (r'\\', String), # stray backslash
595 (r'\n', String, '#pop'), # newline ends the string too
596 ],
597 'sqstring': [
598 (r"''", String), # escaped single quote
599 (r"'", String, '#pop'),
600 (r"[^\\'\n]+", String), # all other characters
601 (r'\\\n', String), # line continuation
602 (r'\\', String), # normal backslash
603 (r'\n', String, '#pop'), # newline ends the string too
604 ],
605 'genericargs': [
606 include('noargs'),
607 (r'"', String, 'dqstring'),
608 (r"'", String, 'sqstring'),
609 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
610 (r'(\d+\.\d*|\.\d+)', Number.Float),
611 (r'-?\d+', Number.Integer),
612 ('[,.~!%^&*+=|?:<>/-]', Operator),
613 (r'[{}()\[\]]', Punctuation),
614 (r'(eq|ne)\b', Operator.Word),
615 (r'([a-zA-Z_]\w*)(\s*)(\()',
616 bygroups(Name.Function, Text, Punctuation)),
617 (r'[a-zA-Z_]\w*', Name),
618 (r'@[a-zA-Z_]\w*', Name.Constant), # macros
619 (r'\\\n', Text),
620 ],
621 'optionarg': [
622 include('whitespace'),
623 (_shortened_many(
624 "a$ll", "an$gles", "ar$row", "au$toscale", "b$ars", "bor$der",
625 "box$width", "cl$abel", "c$lip", "cn$trparam", "co$ntour", "da$ta",
626 "data$file", "dg$rid3d", "du$mmy", "enc$oding", "dec$imalsign",
627 "fit$", "font$path", "fo$rmat", "fu$nction", "fu$nctions", "g$rid",
628 "hid$den3d", "his$torysize", "is$osamples", "k$ey", "keyt$itle",
629 "la$bel", "li$nestyle", "ls$", "loa$dpath", "loc$ale", "log$scale",
630 "mac$ros", "map$ping", "map$ping3d", "mar$gin", "lmar$gin",
631 "rmar$gin", "tmar$gin", "bmar$gin", "mo$use", "multi$plot",
632 "mxt$ics", "nomxt$ics", "mx2t$ics", "nomx2t$ics", "myt$ics",
633 "nomyt$ics", "my2t$ics", "nomy2t$ics", "mzt$ics", "nomzt$ics",
634 "mcbt$ics", "nomcbt$ics", "of$fsets", "or$igin", "o$utput",
635 "pa$rametric", "pm$3d", "pal$ette", "colorb$ox", "p$lot",
636 "poi$ntsize", "pol$ar", "pr$int", "obj$ect", "sa$mples", "si$ze",
637 "st$yle", "su$rface", "table$", "t$erminal", "termo$ptions", "ti$cs",
638 "ticsc$ale", "ticsl$evel", "timef$mt", "tim$estamp", "tit$le",
639 "v$ariables", "ve$rsion", "vi$ew", "xyp$lane", "xda$ta", "x2da$ta",
640 "yda$ta", "y2da$ta", "zda$ta", "cbda$ta", "xl$abel", "x2l$abel",
641 "yl$abel", "y2l$abel", "zl$abel", "cbl$abel", "xti$cs", "noxti$cs",
642 "x2ti$cs", "nox2ti$cs", "yti$cs", "noyti$cs", "y2ti$cs", "noy2ti$cs",
643 "zti$cs", "nozti$cs", "cbti$cs", "nocbti$cs", "xdti$cs", "noxdti$cs",
644 "x2dti$cs", "nox2dti$cs", "ydti$cs", "noydti$cs", "y2dti$cs",
645 "noy2dti$cs", "zdti$cs", "nozdti$cs", "cbdti$cs", "nocbdti$cs",
646 "xmti$cs", "noxmti$cs", "x2mti$cs", "nox2mti$cs", "ymti$cs",
647 "noymti$cs", "y2mti$cs", "noy2mti$cs", "zmti$cs", "nozmti$cs",
648 "cbmti$cs", "nocbmti$cs", "xr$ange", "x2r$ange", "yr$ange",
649 "y2r$ange", "zr$ange", "cbr$ange", "rr$ange", "tr$ange", "ur$ange",
650 "vr$ange", "xzeroa$xis", "x2zeroa$xis", "yzeroa$xis", "y2zeroa$xis",
651 "zzeroa$xis", "zeroa$xis", "z$ero"), Name.Builtin, '#pop'),
652 ],
653 'bind': [
654 ('!', Keyword, '#pop'),
655 (_shortened('all$windows'), Name.Builtin),
656 include('genericargs'),
657 ],
658 'quit': [
659 (r'gnuplot\b', Keyword),
660 include('noargs'),
661 ],
662 'fit': [
663 (r'via\b', Name.Builtin),
664 include('plot'),
665 ],
666 'if': [
667 (r'\)', Punctuation, '#pop'),
668 include('genericargs'),
669 ],
670 'pause': [
671 (r'(mouse|any|button1|button2|button3)\b', Name.Builtin),
672 (_shortened('key$press'), Name.Builtin),
673 include('genericargs'),
674 ],
675 'plot': [
676 (_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex',
677 'mat$rix', 's$mooth', 'thru$', 't$itle',
678 'not$itle', 'u$sing', 'w$ith'),
679 Name.Builtin),
680 include('genericargs'),
681 ],
682 'save': [
683 (_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'),
684 Name.Builtin),
685 include('genericargs'),
686 ],
687 }
688
689
690 class PovrayLexer(RegexLexer):
691 """
692 For `Persistence of Vision Raytracer <http://www.povray.org/>`_ files.
693
694 .. versionadded:: 0.11
695 """
696 name = 'POVRay'
697 aliases = ['pov']
698 filenames = ['*.pov', '*.inc']
699 mimetypes = ['text/x-povray']
700
701 tokens = {
702 'root': [
703 (r'/\*[\w\W]*?\*/', Comment.Multiline),
704 (r'//.*\n', Comment.Single),
705 (r'(?s)"(?:\\.|[^"\\])+"', String.Double),
706 (words((
707 'break', 'case', 'debug', 'declare', 'default', 'define', 'else',
708 'elseif', 'end', 'error', 'fclose', 'fopen', 'for', 'if', 'ifdef',
709 'ifndef', 'include', 'local', 'macro', 'range', 'read', 'render',
710 'statistics', 'switch', 'undef', 'version', 'warning', 'while',
711 'write'), prefix=r'#', suffix=r'\b'),
712 Comment.Preproc),
713 (words((
714 'aa_level', 'aa_threshold', 'abs', 'acos', 'acosh', 'adaptive', 'adc_bailout',
715 'agate', 'agate_turb', 'all', 'alpha', 'ambient', 'ambient_light', 'angle',
716 'aperture', 'arc_angle', 'area_light', 'asc', 'asin', 'asinh', 'assumed_gamma',
717 'atan', 'atan2', 'atanh', 'atmosphere', 'atmospheric_attenuation',
718 'attenuating', 'average', 'background', 'black_hole', 'blue', 'blur_samples',
719 'bounded_by', 'box_mapping', 'bozo', 'break', 'brick', 'brick_size',
720 'brightness', 'brilliance', 'bumps', 'bumpy1', 'bumpy2', 'bumpy3', 'bump_map',
721 'bump_size', 'case', 'caustics', 'ceil', 'checker', 'chr', 'clipped_by', 'clock',
722 'color', 'color_map', 'colour', 'colour_map', 'component', 'composite', 'concat',
723 'confidence', 'conic_sweep', 'constant', 'control0', 'control1', 'cos', 'cosh',
724 'count', 'crackle', 'crand', 'cube', 'cubic_spline', 'cylindrical_mapping',
725 'debug', 'declare', 'default', 'degrees', 'dents', 'diffuse', 'direction',
726 'distance', 'distance_maximum', 'div', 'dust', 'dust_type', 'eccentricity',
727 'else', 'emitting', 'end', 'error', 'error_bound', 'exp', 'exponent',
728 'fade_distance', 'fade_power', 'falloff', 'falloff_angle', 'false',
729 'file_exists', 'filter', 'finish', 'fisheye', 'flatness', 'flip', 'floor',
730 'focal_point', 'fog', 'fog_alt', 'fog_offset', 'fog_type', 'frequency', 'gif',
731 'global_settings', 'glowing', 'gradient', 'granite', 'gray_threshold',
732 'green', 'halo', 'hexagon', 'hf_gray_16', 'hierarchy', 'hollow', 'hypercomplex',
733 'if', 'ifdef', 'iff', 'image_map', 'incidence', 'include', 'int', 'interpolate',
734 'inverse', 'ior', 'irid', 'irid_wavelength', 'jitter', 'lambda', 'leopard',
735 'linear', 'linear_spline', 'linear_sweep', 'location', 'log', 'looks_like',
736 'look_at', 'low_error_factor', 'mandel', 'map_type', 'marble', 'material_map',
737 'matrix', 'max', 'max_intersections', 'max_iteration', 'max_trace_level',
738 'max_value', 'metallic', 'min', 'minimum_reuse', 'mod', 'mortar',
739 'nearest_count', 'no', 'normal', 'normal_map', 'no_shadow', 'number_of_waves',
740 'octaves', 'off', 'offset', 'omega', 'omnimax', 'on', 'once', 'onion', 'open',
741 'orthographic', 'panoramic', 'pattern1', 'pattern2', 'pattern3',
742 'perspective', 'pgm', 'phase', 'phong', 'phong_size', 'pi', 'pigment',
743 'pigment_map', 'planar_mapping', 'png', 'point_at', 'pot', 'pow', 'ppm',
744 'precision', 'pwr', 'quadratic_spline', 'quaternion', 'quick_color',
745 'quick_colour', 'quilted', 'radial', 'radians', 'radiosity', 'radius', 'rainbow',
746 'ramp_wave', 'rand', 'range', 'reciprocal', 'recursion_limit', 'red',
747 'reflection', 'refraction', 'render', 'repeat', 'rgb', 'rgbf', 'rgbft', 'rgbt',
748 'right', 'ripples', 'rotate', 'roughness', 'samples', 'scale', 'scallop_wave',
749 'scattering', 'seed', 'shadowless', 'sin', 'sine_wave', 'sinh', 'sky', 'sky_sphere',
750 'slice', 'slope_map', 'smooth', 'specular', 'spherical_mapping', 'spiral',
751 'spiral1', 'spiral2', 'spotlight', 'spotted', 'sqr', 'sqrt', 'statistics', 'str',
752 'strcmp', 'strength', 'strlen', 'strlwr', 'strupr', 'sturm', 'substr', 'switch', 'sys',
753 't', 'tan', 'tanh', 'test_camera_1', 'test_camera_2', 'test_camera_3',
754 'test_camera_4', 'texture', 'texture_map', 'tga', 'thickness', 'threshold',
755 'tightness', 'tile2', 'tiles', 'track', 'transform', 'translate', 'transmit',
756 'triangle_wave', 'true', 'ttf', 'turbulence', 'turb_depth', 'type',
757 'ultra_wide_angle', 'up', 'use_color', 'use_colour', 'use_index', 'u_steps',
758 'val', 'variance', 'vaxis_rotate', 'vcross', 'vdot', 'version', 'vlength',
759 'vnormalize', 'volume_object', 'volume_rendered', 'vol_with_light',
760 'vrotate', 'v_steps', 'warning', 'warp', 'water_level', 'waves', 'while', 'width',
761 'wood', 'wrinkles', 'yes'), prefix=r'\b', suffix=r'\b'),
762 Keyword),
763 (words((
764 'bicubic_patch', 'blob', 'box', 'camera', 'cone', 'cubic', 'cylinder', 'difference',
765 'disc', 'height_field', 'intersection', 'julia_fractal', 'lathe',
766 'light_source', 'merge', 'mesh', 'object', 'plane', 'poly', 'polygon', 'prism',
767 'quadric', 'quartic', 'smooth_triangle', 'sor', 'sphere', 'superellipsoid',
768 'text', 'torus', 'triangle', 'union'), suffix=r'\b'),
769 Name.Builtin),
770 # TODO: <=, etc
771 (r'[\[\](){}<>;,]', Punctuation),
772 (r'[-+*/=]', Operator),
773 (r'\b(x|y|z|u|v)\b', Name.Builtin.Pseudo),
774 (r'[a-zA-Z_]\w*', Name),
775 (r'[0-9]+\.[0-9]*', Number.Float),
776 (r'\.[0-9]+', Number.Float),
777 (r'[0-9]+', Number.Integer),
778 (r'"(\\\\|\\"|[^"])*"', String),
779 (r'\s+', Text),
780 ]
781 }

eric ide

mercurial