ThirdParty/Pygments/pygments/lexers/graphics.py

changeset 6651
e8f3b5568b21
parent 5713
6762afd9f963
--- a/ThirdParty/Pygments/pygments/lexers/graphics.py	Sat Jan 12 12:11:42 2019 +0100
+++ b/ThirdParty/Pygments/pygments/lexers/graphics.py	Sat Jan 12 12:40:14 2019 +0100
@@ -15,7 +15,7 @@
     Number, Punctuation, String
 
 __all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer',
-           'PovrayLexer']
+           'PovrayLexer', 'HLSLShaderLexer']
 
 
 class GLShaderLexer(RegexLexer):
@@ -46,28 +46,102 @@
             (r'0[0-7]*', Number.Oct),
             (r'[1-9][0-9]*', Number.Integer),
             (words((
-                'attribute', 'const', 'uniform', 'varying', 'centroid', 'break',
-                'continue', 'do', 'for', 'while', 'if', 'else', 'in', 'out',
-                'inout', 'float', 'int', 'void', 'bool', 'true', 'false',
-                'invariant', 'discard', 'return', 'mat2', 'mat3' 'mat4',
-                'mat2x2', 'mat3x2', 'mat4x2', 'mat2x3', 'mat3x3', 'mat4x3',
-                'mat2x4', 'mat3x4', 'mat4x4', 'vec2', 'vec3', 'vec4',
-                'ivec2', 'ivec3', 'ivec4', 'bvec2', 'bvec3', 'bvec4',
-                'sampler1D', 'sampler2D', 'sampler3D' 'samplerCube',
-                'sampler1DShadow', 'sampler2DShadow', 'struct'),
+                # Storage qualifiers
+                'attribute', 'const', 'uniform', 'varying',
+                'buffer', 'shared', 'in', 'out',
+                # Layout qualifiers
+                'layout',
+                # Interpolation qualifiers
+                'flat', 'smooth', 'noperspective',
+                # Auxiliary qualifiers
+                'centroid', 'sample', 'patch',
+                # Parameter qualifiers. Some double as Storage qualifiers
+                'inout',
+                # Precision qualifiers
+                'lowp', 'mediump', 'highp', 'precision',
+                # Invariance qualifiers
+                'invariant',
+                # Precise qualifiers
+                'precise',
+                # Memory qualifiers
+                'coherent', 'volatile', 'restrict', 'readonly', 'writeonly',
+                # Statements
+                'break', 'continue', 'do', 'for', 'while', 'switch',
+                'case', 'default', 'if', 'else', 'subroutine',
+                'discard', 'return', 'struct'),
                 prefix=r'\b', suffix=r'\b'),
              Keyword),
             (words((
-                'asm', 'class', 'union', 'enum', 'typedef', 'template', 'this',
-                'packed', 'goto', 'switch', 'default', 'inline', 'noinline',
-                'volatile', 'public', 'static', 'extern', 'external', 'interface',
-                'long', 'short', 'double', 'half', 'fixed', 'unsigned', 'lowp',
-                'mediump', 'highp', 'precision', 'input', 'output',
-                'hvec2', 'hvec3', 'hvec4', 'dvec2', 'dvec3', 'dvec4',
-                'fvec2', 'fvec3', 'fvec4', 'sampler2DRect', 'sampler3DRect',
-                'sampler2DRectShadow', 'sizeof', 'cast', 'namespace', 'using'),
+                # Boolean values
+                'true', 'false'),
                 prefix=r'\b', suffix=r'\b'),
-             Keyword),  # future use
+             Keyword.Constant),
+            (words((
+                # Miscellaneous types
+                'void', 'atomic_uint',
+                # Floating-point scalars and vectors
+                'float', 'vec2', 'vec3', 'vec4',
+                'double', 'dvec2', 'dvec3', 'dvec4',
+                # Integer scalars and vectors
+                'int', 'ivec2', 'ivec3', 'ivec4',
+                'uint', 'uvec2', 'uvec3', 'uvec4',
+                # Boolean scalars and vectors
+                'bool', 'bvec2', 'bvec3', 'bvec4',
+                # Matrices
+                'mat2', 'mat3', 'mat4', 'dmat2', 'dmat3', 'dmat4',
+                'mat2x2', 'mat2x3', 'mat2x4', 'dmat2x2', 'dmat2x3', 'dmat2x4',
+                'mat3x2', 'mat3x3', 'mat3x4', 'dmat3x2', 'dmat3x3',
+                'dmat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat4x2', 'dmat4x3', 'dmat4x4',
+                # Floating-point samplers
+                'sampler1D', 'sampler2D', 'sampler3D', 'samplerCube',
+                'sampler1DArray', 'sampler2DArray', 'samplerCubeArray',
+                'sampler2DRect', 'samplerBuffer',
+                'sampler2DMS', 'sampler2DMSArray',
+                # Shadow samplers
+                'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow',
+                'sampler1DArrayShadow', 'sampler2DArrayShadow',
+                'samplerCubeArrayShadow', 'sampler2DRectShadow',
+                # Signed integer samplers
+                'isampler1D', 'isampler2D', 'isampler3D', 'isamplerCube',
+                'isampler1DArray', 'isampler2DArray', 'isamplerCubeArray',
+                'isampler2DRect', 'isamplerBuffer',
+                'isampler2DMS', 'isampler2DMSArray',
+                # Unsigned integer samplers
+                'usampler1D', 'usampler2D', 'usampler3D', 'usamplerCube',
+                'usampler1DArray', 'usampler2DArray', 'usamplerCubeArray',
+                'usampler2DRect', 'usamplerBuffer',
+                'usampler2DMS', 'usampler2DMSArray',
+                # Floating-point image types
+                'image1D', 'image2D', 'image3D', 'imageCube',
+                'image1DArray', 'image2DArray', 'imageCubeArray',
+                'image2DRect', 'imageBuffer',
+                'image2DMS', 'image2DMSArray',
+                # Signed integer image types
+                'iimage1D', 'iimage2D', 'iimage3D', 'iimageCube',
+                'iimage1DArray', 'iimage2DArray', 'iimageCubeArray',
+                'iimage2DRect', 'iimageBuffer',
+                'iimage2DMS', 'iimage2DMSArray',
+                # Unsigned integer image types
+                'uimage1D', 'uimage2D', 'uimage3D', 'uimageCube',
+                'uimage1DArray', 'uimage2DArray', 'uimageCubeArray',
+                'uimage2DRect', 'uimageBuffer',
+                'uimage2DMS', 'uimage2DMSArray'),
+                prefix=r'\b', suffix=r'\b'),
+             Keyword.Type),
+            (words((
+                # Reserved for future use.
+                'common', 'partition', 'active', 'asm', 'class',
+                'union', 'enum', 'typedef', 'template', 'this',
+                'resource', 'goto', 'inline', 'noinline', 'public',
+                'static', 'extern', 'external', 'interface', 'long',
+                'short', 'half', 'fixed', 'unsigned', 'superp', 'input',
+                'output', 'hvec2', 'hvec3', 'hvec4', 'fvec2', 'fvec3',
+                'fvec4', 'sampler3DRect', 'filter', 'sizeof', 'cast',
+                'namespace', 'using'),
+                prefix=r'\b', suffix=r'\b'),
+             Keyword.Reserved),
+            # All names beginning with "gl_" are reserved.
+            (r'gl_\w*', Name.Builtin),
             (r'[a-zA-Z_]\w*', Name),
             (r'\.', Punctuation),
             (r'\s+', Text),
@@ -75,6 +149,160 @@
     }
 
 
+class HLSLShaderLexer(RegexLexer):
+    """
+    HLSL (Microsoft Direct3D Shader) lexer.
+
+    .. versionadded:: 2.3
+    """
+    name = 'HLSL'
+    aliases = ['hlsl']
+    filenames = ['*.hlsl', '*.hlsli']
+    mimetypes = ['text/x-hlsl']
+
+    tokens = {
+        'root': [
+            (r'^#.*', Comment.Preproc),
+            (r'//.*', Comment.Single),
+            (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
+            (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
+             Operator),
+            (r'[?:]', Operator),  # quick hack for ternary
+            (r'\bdefined\b', Operator),
+            (r'[;{}(),.\[\]]', Punctuation),
+            # FIXME when e is present, no decimal point needed
+            (r'[+-]?\d*\.\d+([eE][-+]?\d+)?f?', Number.Float),
+            (r'[+-]?\d+\.\d*([eE][-+]?\d+)?f?', Number.Float),
+            (r'0[xX][0-9a-fA-F]*', Number.Hex),
+            (r'0[0-7]*', Number.Oct),
+            (r'[1-9][0-9]*', Number.Integer),
+            (r'"', String, 'string'),
+            (words((
+                'asm','asm_fragment','break','case','cbuffer','centroid','class',
+                'column_major','compile','compile_fragment','const','continue',
+                'default','discard','do','else','export','extern','for','fxgroup',
+                'globallycoherent','groupshared','if','in','inline','inout',
+                'interface','line','lineadj','linear','namespace','nointerpolation',
+                'noperspective','NULL','out','packoffset','pass','pixelfragment',
+                'point','precise','return','register','row_major','sample',
+                'sampler','shared','stateblock','stateblock_state','static',
+                'struct','switch','tbuffer','technique','technique10',
+                'technique11','texture','typedef','triangle','triangleadj',
+                'uniform','vertexfragment','volatile','while'),
+                prefix=r'\b', suffix=r'\b'),
+             Keyword),
+            (words(('true','false'), prefix=r'\b', suffix=r'\b'),
+             Keyword.Constant),
+            (words((
+                'auto','catch','char','const_cast','delete','dynamic_cast','enum',
+                'explicit','friend','goto','long','mutable','new','operator',
+                'private','protected','public','reinterpret_cast','short','signed',
+                'sizeof','static_cast','template','this','throw','try','typename',
+                'union','unsigned','using','virtual'),
+                prefix=r'\b', suffix=r'\b'),
+             Keyword.Reserved),
+            (words((
+                'dword','matrix','snorm','string','unorm','unsigned','void','vector',
+                'BlendState','Buffer','ByteAddressBuffer','ComputeShader',
+                'DepthStencilState','DepthStencilView','DomainShader',
+                'GeometryShader','HullShader','InputPatch','LineStream',
+                'OutputPatch','PixelShader','PointStream','RasterizerState',
+                'RenderTargetView','RasterizerOrderedBuffer',
+                'RasterizerOrderedByteAddressBuffer',
+                'RasterizerOrderedStructuredBuffer','RasterizerOrderedTexture1D',
+                'RasterizerOrderedTexture1DArray','RasterizerOrderedTexture2D',
+                'RasterizerOrderedTexture2DArray','RasterizerOrderedTexture3D',
+                'RWBuffer','RWByteAddressBuffer','RWStructuredBuffer',
+                'RWTexture1D','RWTexture1DArray','RWTexture2D','RWTexture2DArray',
+                'RWTexture3D','SamplerState','SamplerComparisonState',
+                'StructuredBuffer','Texture1D','Texture1DArray','Texture2D',
+                'Texture2DArray','Texture2DMS','Texture2DMSArray','Texture3D',
+                'TextureCube','TextureCubeArray','TriangleStream','VertexShader'),
+                prefix=r'\b', suffix=r'\b'),
+             Keyword.Type),
+            (words((
+                'bool','double','float','int','half','min16float','min10float',
+                'min16int','min12int','min16uint','uint'),
+                prefix=r'\b', suffix=r'([1-4](x[1-4])?)?\b'),
+             Keyword.Type),     # vector and matrix types
+            (words((
+                'abort','abs','acos','all','AllMemoryBarrier',
+                'AllMemoryBarrierWithGroupSync','any','AppendStructuredBuffer',
+                'asdouble','asfloat','asin','asint','asuint','asuint','atan',
+                'atan2','ceil','CheckAccessFullyMapped','clamp','clip',
+                'CompileShader','ConsumeStructuredBuffer','cos','cosh','countbits',
+                'cross','D3DCOLORtoUBYTE4','ddx','ddx_coarse','ddx_fine','ddy',
+                'ddy_coarse','ddy_fine','degrees','determinant',
+                'DeviceMemoryBarrier','DeviceMemoryBarrierWithGroupSync','distance',
+                'dot','dst','errorf','EvaluateAttributeAtCentroid',
+                'EvaluateAttributeAtSample','EvaluateAttributeSnapped','exp',
+                'exp2','f16tof32','f32tof16','faceforward','firstbithigh',
+                'firstbitlow','floor','fma','fmod','frac','frexp','fwidth',
+                'GetRenderTargetSampleCount','GetRenderTargetSamplePosition',
+                'GlobalOrderedCountIncrement','GroupMemoryBarrier',
+                'GroupMemoryBarrierWithGroupSync','InterlockedAdd','InterlockedAnd',
+                'InterlockedCompareExchange','InterlockedCompareStore',
+                'InterlockedExchange','InterlockedMax','InterlockedMin',
+                'InterlockedOr','InterlockedXor','isfinite','isinf','isnan',
+                'ldexp','length','lerp','lit','log','log10','log2','mad','max',
+                'min','modf','msad4','mul','noise','normalize','pow','printf',
+                'Process2DQuadTessFactorsAvg','Process2DQuadTessFactorsMax',
+                'Process2DQuadTessFactorsMin','ProcessIsolineTessFactors',
+                'ProcessQuadTessFactorsAvg','ProcessQuadTessFactorsMax',
+                'ProcessQuadTessFactorsMin','ProcessTriTessFactorsAvg',
+                'ProcessTriTessFactorsMax','ProcessTriTessFactorsMin',
+                'QuadReadLaneAt','QuadSwapX','QuadSwapY','radians','rcp',
+                'reflect','refract','reversebits','round','rsqrt','saturate',
+                'sign','sin','sincos','sinh','smoothstep','sqrt','step','tan',
+                'tanh','tex1D','tex1D','tex1Dbias','tex1Dgrad','tex1Dlod',
+                'tex1Dproj','tex2D','tex2D','tex2Dbias','tex2Dgrad','tex2Dlod',
+                'tex2Dproj','tex3D','tex3D','tex3Dbias','tex3Dgrad','tex3Dlod',
+                'tex3Dproj','texCUBE','texCUBE','texCUBEbias','texCUBEgrad',
+                'texCUBElod','texCUBEproj','transpose','trunc','WaveAllBitAnd',
+                'WaveAllMax','WaveAllMin','WaveAllBitOr','WaveAllBitXor',
+                'WaveAllEqual','WaveAllProduct','WaveAllSum','WaveAllTrue',
+                'WaveAnyTrue','WaveBallot','WaveGetLaneCount','WaveGetLaneIndex',
+                'WaveGetOrderedIndex','WaveIsHelperLane','WaveOnce',
+                'WavePrefixProduct','WavePrefixSum','WaveReadFirstLane',
+                'WaveReadLaneAt'),
+                prefix=r'\b', suffix=r'\b'),
+             Name.Builtin),     # built-in functions
+            (words((
+                'SV_ClipDistance','SV_ClipDistance0','SV_ClipDistance1',
+                'SV_Culldistance','SV_CullDistance0','SV_CullDistance1',
+                'SV_Coverage','SV_Depth','SV_DepthGreaterEqual',
+                'SV_DepthLessEqual','SV_DispatchThreadID','SV_DomainLocation',
+                'SV_GroupID','SV_GroupIndex','SV_GroupThreadID','SV_GSInstanceID',
+                'SV_InnerCoverage','SV_InsideTessFactor','SV_InstanceID',
+                'SV_IsFrontFace','SV_OutputControlPointID','SV_Position',
+                'SV_PrimitiveID','SV_RenderTargetArrayIndex','SV_SampleIndex',
+                'SV_StencilRef','SV_TessFactor','SV_VertexID',
+                'SV_ViewportArrayIndex'),
+                prefix=r'\b', suffix=r'\b'),
+             Name.Decorator),   # system-value semantics
+            (r'\bSV_Target[0-7]?\b', Name.Decorator),
+            (words((
+                'allow_uav_condition','branch','call','domain','earlydepthstencil',
+                'fastopt','flatten','forcecase','instance','loop','maxtessfactor',
+                'numthreads','outputcontrolpoints','outputtopology','partitioning',
+                'patchconstantfunc','unroll'),
+                prefix=r'\b', suffix=r'\b'),
+             Name.Decorator),   # attributes
+            (r'[a-zA-Z_]\w*', Name),
+            (r'\\$', Comment.Preproc),  # backslash at end of line -- usually macro continuation
+            (r'\s+', Text),
+        ],
+        'string': [
+            (r'"', String, '#pop'),
+            (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|'
+             r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape),
+            (r'[^\\"\n]+', String),  # all other characters
+            (r'\\\n', String),  # line continuation
+            (r'\\', String),  # stray backslash
+        ],
+    }
+
+
 class PostScriptLexer(RegexLexer):
     """
     Lexer for PostScript files.
@@ -233,8 +461,8 @@
              r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|'
              r'picture|position|real|revolution|slice|splitface|ticksgridT|'
              r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type),
-            ('[a-zA-Z_]\w*:(?!:)', Name.Label),
-            ('[a-zA-Z_]\w*', Name),
+            (r'[a-zA-Z_]\w*:(?!:)', Name.Label),
+            (r'[a-zA-Z_]\w*', Name),
         ],
         'root': [
             include('whitespace'),
@@ -334,9 +562,9 @@
             (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump',
                              'she$ll', 'test$'),
              Keyword, 'noargs'),
-            ('([a-zA-Z_]\w*)(\s*)(=)',
+            (r'([a-zA-Z_]\w*)(\s*)(=)',
              bygroups(Name.Variable, Text, Operator), 'genericargs'),
-            ('([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)',
+            (r'([a-zA-Z_]\w*)(\s*\(.*?\)\s*)(=)',
              bygroups(Name.Function, Text, Operator), 'genericargs'),
             (r'@[a-zA-Z_]\w*', Name.Constant),  # macros
             (r';', Keyword),
@@ -382,7 +610,7 @@
             (r'(\d+\.\d*|\.\d+)', Number.Float),
             (r'-?\d+', Number.Integer),
             ('[,.~!%^&*+=|?:<>/-]', Operator),
-            ('[{}()\[\]]', Punctuation),
+            (r'[{}()\[\]]', Punctuation),
             (r'(eq|ne)\b', Operator.Word),
             (r'([a-zA-Z_]\w*)(\s*)(\()',
              bygroups(Name.Function, Text, Punctuation)),

eric ide

mercurial