ThirdParty/Pygments/pygments/lexers/graphics.py

changeset 6651
e8f3b5568b21
parent 5713
6762afd9f963
equal deleted inserted replaced
6650:1dd52aa8897c 6651:e8f3b5568b21
13 this, default 13 this, default
14 from pygments.token import Text, Comment, Operator, Keyword, Name, \ 14 from pygments.token import Text, Comment, Operator, Keyword, Name, \
15 Number, Punctuation, String 15 Number, Punctuation, String
16 16
17 __all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer', 17 __all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer',
18 'PovrayLexer'] 18 'PovrayLexer', 'HLSLShaderLexer']
19 19
20 20
21 class GLShaderLexer(RegexLexer): 21 class GLShaderLexer(RegexLexer):
22 """ 22 """
23 GLSL (OpenGL Shader) lexer. 23 GLSL (OpenGL Shader) lexer.
44 (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), 45 (r'0[xX][0-9a-fA-F]*', Number.Hex),
46 (r'0[0-7]*', Number.Oct), 46 (r'0[0-7]*', Number.Oct),
47 (r'[1-9][0-9]*', Number.Integer), 47 (r'[1-9][0-9]*', Number.Integer),
48 (words(( 48 (words((
49 'attribute', 'const', 'uniform', 'varying', 'centroid', 'break', 49 # Storage qualifiers
50 'continue', 'do', 'for', 'while', 'if', 'else', 'in', 'out', 50 'attribute', 'const', 'uniform', 'varying',
51 'inout', 'float', 'int', 'void', 'bool', 'true', 'false', 51 'buffer', 'shared', 'in', 'out',
52 'invariant', 'discard', 'return', 'mat2', 'mat3' 'mat4', 52 # Layout qualifiers
53 'mat2x2', 'mat3x2', 'mat4x2', 'mat2x3', 'mat3x3', 'mat4x3', 53 'layout',
54 'mat2x4', 'mat3x4', 'mat4x4', 'vec2', 'vec3', 'vec4', 54 # Interpolation qualifiers
55 'ivec2', 'ivec3', 'ivec4', 'bvec2', 'bvec3', 'bvec4', 55 'flat', 'smooth', 'noperspective',
56 'sampler1D', 'sampler2D', 'sampler3D' 'samplerCube', 56 # Auxiliary qualifiers
57 'sampler1DShadow', 'sampler2DShadow', 'struct'), 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'),
58 prefix=r'\b', suffix=r'\b'), 72 prefix=r'\b', suffix=r'\b'),
59 Keyword), 73 Keyword),
60 (words(( 74 (words((
61 'asm', 'class', 'union', 'enum', 'typedef', 'template', 'this', 75 # Boolean values
62 'packed', 'goto', 'switch', 'default', 'inline', 'noinline', 76 'true', 'false'),
63 'volatile', 'public', 'static', 'extern', 'external', 'interface', 77 prefix=r'\b', suffix=r'\b'),
64 'long', 'short', 'double', 'half', 'fixed', 'unsigned', 'lowp', 78 Keyword.Constant),
65 'mediump', 'highp', 'precision', 'input', 'output', 79 (words((
66 'hvec2', 'hvec3', 'hvec4', 'dvec2', 'dvec3', 'dvec4', 80 # Miscellaneous types
67 'fvec2', 'fvec3', 'fvec4', 'sampler2DRect', 'sampler3DRect', 81 'void', 'atomic_uint',
68 'sampler2DRectShadow', 'sizeof', 'cast', 'namespace', 'using'), 82 # Floating-point scalars and vectors
69 prefix=r'\b', suffix=r'\b'), 83 'float', 'vec2', 'vec3', 'vec4',
70 Keyword), # future use 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),
71 (r'[a-zA-Z_]\w*', Name), 145 (r'[a-zA-Z_]\w*', Name),
72 (r'\.', Punctuation), 146 (r'\.', Punctuation),
73 (r'\s+', Text), 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
74 ], 302 ],
75 } 303 }
76 304
77 305
78 class PostScriptLexer(RegexLexer): 306 class PostScriptLexer(RegexLexer):
231 # Perhaps useless 459 # Perhaps useless
232 (r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|' 460 (r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|'
233 r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|' 461 r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|'
234 r'picture|position|real|revolution|slice|splitface|ticksgridT|' 462 r'picture|position|real|revolution|slice|splitface|ticksgridT|'
235 r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type), 463 r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type),
236 ('[a-zA-Z_]\w*:(?!:)', Name.Label), 464 (r'[a-zA-Z_]\w*:(?!:)', Name.Label),
237 ('[a-zA-Z_]\w*', Name), 465 (r'[a-zA-Z_]\w*', Name),
238 ], 466 ],
239 'root': [ 467 'root': [
240 include('whitespace'), 468 include('whitespace'),
241 # functions 469 # functions
242 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments 470 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments
332 'she$ll', 'sy$stem', 'up$date'), 560 'she$ll', 'sy$stem', 'up$date'),
333 Keyword, 'genericargs'), 561 Keyword, 'genericargs'),
334 (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump', 562 (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
335 'she$ll', 'test$'), 563 'she$ll', 'test$'),
336 Keyword, 'noargs'), 564 Keyword, 'noargs'),
337 ('([a-zA-Z_]\w*)(\s*)(=)', 565 (r'([a-zA-Z_]\w*)(\s*)(=)',
338 bygroups(Name.Variable, Text, Operator), 'genericargs'), 566 bygroups(Name.Variable, Text, Operator), 'genericargs'),
339 ('([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)', 567 (r'([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)',
340 bygroups(Name.Function, Text, Operator), 'genericargs'), 568 bygroups(Name.Function, Text, Operator), 'genericargs'),
341 (r'@[a-zA-Z_]\w*', Name.Constant), # macros 569 (r'@[a-zA-Z_]\w*', Name.Constant), # macros
342 (r';', Keyword), 570 (r';', Keyword),
343 ], 571 ],
344 'comment': [ 572 'comment': [
380 (r"'", String, 'sqstring'), 608 (r"'", String, 'sqstring'),
381 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), 609 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float),
382 (r'(\d+\.\d*|\.\d+)', Number.Float), 610 (r'(\d+\.\d*|\.\d+)', Number.Float),
383 (r'-?\d+', Number.Integer), 611 (r'-?\d+', Number.Integer),
384 ('[,.~!%^&*+=|?:<>/-]', Operator), 612 ('[,.~!%^&*+=|?:<>/-]', Operator),
385 ('[{}()\[\]]', Punctuation), 613 (r'[{}()\[\]]', Punctuation),
386 (r'(eq|ne)\b', Operator.Word), 614 (r'(eq|ne)\b', Operator.Word),
387 (r'([a-zA-Z_]\w*)(\s*)(\()', 615 (r'([a-zA-Z_]\w*)(\s*)(\()',
388 bygroups(Name.Function, Text, Punctuation)), 616 bygroups(Name.Function, Text, Punctuation)),
389 (r'[a-zA-Z_]\w*', Name), 617 (r'[a-zA-Z_]\w*', Name),
390 (r'@[a-zA-Z_]\w*', Name.Constant), # macros 618 (r'@[a-zA-Z_]\w*', Name.Constant), # macros

eric ide

mercurial