Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.11/site-packages/pygments/lexers/graphics.py: 85%

Shortcuts on this page

r m x   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

81 statements  

1""" 

2 pygments.lexers.graphics 

3 ~~~~~~~~~~~~~~~~~~~~~~~~ 

4 

5 Lexers for computer graphics and plotting related languages. 

6 

7 :copyright: Copyright 2006-2025 by the Pygments team, see AUTHORS. 

8 :license: BSD, see LICENSE for details. 

9""" 

10 

11from pygments.lexer import RegexLexer, words, include, bygroups, using, \ 

12 this, default 

13from pygments.token import Text, Comment, Operator, Keyword, Name, \ 

14 Number, Punctuation, String, Whitespace 

15 

16__all__ = ['GLShaderLexer', 'PostScriptLexer', 'AsymptoteLexer', 'GnuplotLexer', 

17 'PovrayLexer', 'HLSLShaderLexer'] 

18 

19 

20class GLShaderLexer(RegexLexer): 

21 """ 

22 GLSL (OpenGL Shader) lexer. 

23 """ 

24 name = 'GLSL' 

25 aliases = ['glsl'] 

26 filenames = ['*.vert', '*.frag', '*.geo'] 

27 mimetypes = ['text/x-glslsrc'] 

28 url = 'https://www.khronos.org/api/opengl' 

29 version_added = '1.1' 

30 

31 tokens = { 

32 'root': [ 

33 (r'#(?:.*\\\n)*.*$', Comment.Preproc), 

34 (r'//.*$', Comment.Single), 

35 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 

36 (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?', 

37 Operator), 

38 (r'[?:]', Operator), # quick hack for ternary 

39 (r'\bdefined\b', Operator), 

40 (r'[;{}(),\[\]]', Punctuation), 

41 # FIXME when e is present, no decimal point needed 

42 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float), 

43 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float), 

44 (r'0[xX][0-9a-fA-F]*', Number.Hex), 

45 (r'0[0-7]*', Number.Oct), 

46 (r'[1-9][0-9]*', Number.Integer), 

47 (words(( 

48 # Storage qualifiers 

49 'attribute', 'const', 'uniform', 'varying', 

50 'buffer', 'shared', 'in', 'out', 

51 # Layout qualifiers 

52 'layout', 

53 # Interpolation qualifiers 

54 'flat', 'smooth', 'noperspective', 

55 # Auxiliary qualifiers 

56 'centroid', 'sample', 'patch', 

57 # Parameter qualifiers. Some double as Storage qualifiers 

58 'inout', 

59 # Precision qualifiers 

60 'lowp', 'mediump', 'highp', 'precision', 

61 # Invariance qualifiers 

62 'invariant', 

63 # Precise qualifiers 

64 'precise', 

65 # Memory qualifiers 

66 'coherent', 'volatile', 'restrict', 'readonly', 'writeonly', 

67 # Statements 

68 'break', 'continue', 'do', 'for', 'while', 'switch', 

69 'case', 'default', 'if', 'else', 'subroutine', 

70 'discard', 'return', 'struct'), 

71 prefix=r'\b', suffix=r'\b'), 

72 Keyword), 

73 (words(( 

74 # Boolean values 

75 'true', 'false'), 

76 prefix=r'\b', suffix=r'\b'), 

77 Keyword.Constant), 

78 (words(( 

79 # Miscellaneous types 

80 'void', 'atomic_uint', 

81 # Floating-point scalars and vectors 

82 'float', 'vec2', 'vec3', 'vec4', 

83 'double', 'dvec2', 'dvec3', 'dvec4', 

84 # Integer scalars and vectors 

85 'int', 'ivec2', 'ivec3', 'ivec4', 

86 'uint', 'uvec2', 'uvec3', 'uvec4', 

87 # Boolean scalars and vectors 

88 'bool', 'bvec2', 'bvec3', 'bvec4', 

89 # Matrices 

90 'mat2', 'mat3', 'mat4', 'dmat2', 'dmat3', 'dmat4', 

91 'mat2x2', 'mat2x3', 'mat2x4', 'dmat2x2', 'dmat2x3', 'dmat2x4', 

92 'mat3x2', 'mat3x3', 'mat3x4', 'dmat3x2', 'dmat3x3', 

93 'dmat3x4', 'mat4x2', 'mat4x3', 'mat4x4', 'dmat4x2', 'dmat4x3', 'dmat4x4', 

94 # Floating-point samplers 

95 'sampler1D', 'sampler2D', 'sampler3D', 'samplerCube', 

96 'sampler1DArray', 'sampler2DArray', 'samplerCubeArray', 

97 'sampler2DRect', 'samplerBuffer', 

98 'sampler2DMS', 'sampler2DMSArray', 

99 # Shadow samplers 

100 'sampler1DShadow', 'sampler2DShadow', 'samplerCubeShadow', 

101 'sampler1DArrayShadow', 'sampler2DArrayShadow', 

102 'samplerCubeArrayShadow', 'sampler2DRectShadow', 

103 # Signed integer samplers 

104 'isampler1D', 'isampler2D', 'isampler3D', 'isamplerCube', 

105 'isampler1DArray', 'isampler2DArray', 'isamplerCubeArray', 

106 'isampler2DRect', 'isamplerBuffer', 

107 'isampler2DMS', 'isampler2DMSArray', 

108 # Unsigned integer samplers 

109 'usampler1D', 'usampler2D', 'usampler3D', 'usamplerCube', 

110 'usampler1DArray', 'usampler2DArray', 'usamplerCubeArray', 

111 'usampler2DRect', 'usamplerBuffer', 

112 'usampler2DMS', 'usampler2DMSArray', 

113 # Floating-point image types 

114 'image1D', 'image2D', 'image3D', 'imageCube', 

115 'image1DArray', 'image2DArray', 'imageCubeArray', 

116 'image2DRect', 'imageBuffer', 

117 'image2DMS', 'image2DMSArray', 

118 # Signed integer image types 

119 'iimage1D', 'iimage2D', 'iimage3D', 'iimageCube', 

120 'iimage1DArray', 'iimage2DArray', 'iimageCubeArray', 

121 'iimage2DRect', 'iimageBuffer', 

122 'iimage2DMS', 'iimage2DMSArray', 

123 # Unsigned integer image types 

124 'uimage1D', 'uimage2D', 'uimage3D', 'uimageCube', 

125 'uimage1DArray', 'uimage2DArray', 'uimageCubeArray', 

126 'uimage2DRect', 'uimageBuffer', 

127 'uimage2DMS', 'uimage2DMSArray'), 

128 prefix=r'\b', suffix=r'\b'), 

129 Keyword.Type), 

130 (words(( 

131 # Reserved for future use. 

132 'common', 'partition', 'active', 'asm', 'class', 

133 'union', 'enum', 'typedef', 'template', 'this', 

134 'resource', 'goto', 'inline', 'noinline', 'public', 

135 'static', 'extern', 'external', 'interface', 'long', 

136 'short', 'half', 'fixed', 'unsigned', 'superp', 'input', 

137 'output', 'hvec2', 'hvec3', 'hvec4', 'fvec2', 'fvec3', 

138 'fvec4', 'sampler3DRect', 'filter', 'sizeof', 'cast', 

139 'namespace', 'using'), 

140 prefix=r'\b', suffix=r'\b'), 

141 Keyword.Reserved), 

142 # All names beginning with "gl_" are reserved. 

143 (r'gl_\w*', Name.Builtin), 

144 (r'[a-zA-Z_]\w*', Name), 

145 (r'\.', Punctuation), 

146 (r'\s+', Whitespace), 

147 ], 

148 } 

149 

150 

151class HLSLShaderLexer(RegexLexer): 

152 """ 

153 HLSL (Microsoft Direct3D Shader) lexer. 

154 """ 

155 name = 'HLSL' 

156 aliases = ['hlsl'] 

157 filenames = ['*.hlsl', '*.hlsli'] 

158 mimetypes = ['text/x-hlsl'] 

159 url = 'https://learn.microsoft.com/en-us/windows/win32/direct3dhlsl/dx-graphics-hlsl' 

160 version_added = '2.3' 

161 

162 tokens = { 

163 'root': [ 

164 (r'#(?:.*\\\n)*.*$', Comment.Preproc), 

165 (r'//.*$', Comment.Single), 

166 (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline), 

167 (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?', 

168 Operator), 

169 (r'[?:]', Operator), # quick hack for ternary 

170 (r'\bdefined\b', Operator), 

171 (r'[;{}(),.\[\]]', Punctuation), 

172 # FIXME when e is present, no decimal point needed 

173 (r'[+-]?\d*\.\d+([eE][-+]?\d+)?f?', Number.Float), 

174 (r'[+-]?\d+\.\d*([eE][-+]?\d+)?f?', Number.Float), 

175 (r'0[xX][0-9a-fA-F]*', Number.Hex), 

176 (r'0[0-7]*', Number.Oct), 

177 (r'[1-9][0-9]*', Number.Integer), 

178 (r'"', String, 'string'), 

179 (words(( 

180 'asm','asm_fragment','break','case','cbuffer','centroid','class', 

181 'column_major','compile','compile_fragment','const','continue', 

182 'default','discard','do','else','export','extern','for','fxgroup', 

183 'globallycoherent','groupshared','if','in','inline','inout', 

184 'interface','line','lineadj','linear','namespace','nointerpolation', 

185 'noperspective','NULL','out','packoffset','pass','pixelfragment', 

186 'point','precise','return','register','row_major','sample', 

187 'sampler','shared','stateblock','stateblock_state','static', 

188 'struct','switch','tbuffer','technique','technique10', 

189 'technique11','texture','typedef','triangle','triangleadj', 

190 'uniform','vertexfragment','volatile','while'), 

191 prefix=r'\b', suffix=r'\b'), 

192 Keyword), 

193 (words(('true','false'), prefix=r'\b', suffix=r'\b'), 

194 Keyword.Constant), 

195 (words(( 

196 'auto','catch','char','const_cast','delete','dynamic_cast','enum', 

197 'explicit','friend','goto','long','mutable','new','operator', 

198 'private','protected','public','reinterpret_cast','short','signed', 

199 'sizeof','static_cast','template','this','throw','try','typename', 

200 'union','unsigned','using','virtual'), 

201 prefix=r'\b', suffix=r'\b'), 

202 Keyword.Reserved), 

203 (words(( 

204 'dword','matrix','snorm','string','unorm','unsigned','void','vector', 

205 'BlendState','Buffer','ByteAddressBuffer','ComputeShader', 

206 'DepthStencilState','DepthStencilView','DomainShader', 

207 'GeometryShader','HullShader','InputPatch','LineStream', 

208 'OutputPatch','PixelShader','PointStream','RasterizerState', 

209 'RenderTargetView','RasterizerOrderedBuffer', 

210 'RasterizerOrderedByteAddressBuffer', 

211 'RasterizerOrderedStructuredBuffer','RasterizerOrderedTexture1D', 

212 'RasterizerOrderedTexture1DArray','RasterizerOrderedTexture2D', 

213 'RasterizerOrderedTexture2DArray','RasterizerOrderedTexture3D', 

214 'RWBuffer','RWByteAddressBuffer','RWStructuredBuffer', 

215 'RWTexture1D','RWTexture1DArray','RWTexture2D','RWTexture2DArray', 

216 'RWTexture3D','SamplerState','SamplerComparisonState', 

217 'StructuredBuffer','Texture1D','Texture1DArray','Texture2D', 

218 'Texture2DArray','Texture2DMS','Texture2DMSArray','Texture3D', 

219 'TextureCube','TextureCubeArray','TriangleStream','VertexShader'), 

220 prefix=r'\b', suffix=r'\b'), 

221 Keyword.Type), 

222 (words(( 

223 'bool','double','float','int','half','min16float','min10float', 

224 'min16int','min12int','min16uint','uint'), 

225 prefix=r'\b', suffix=r'([1-4](x[1-4])?)?\b'), 

226 Keyword.Type), # vector and matrix types 

227 (words(( 

228 'abort','abs','acos','all','AllMemoryBarrier', 

229 'AllMemoryBarrierWithGroupSync','any','AppendStructuredBuffer', 

230 'asdouble','asfloat','asin','asint','asuint','asuint','atan', 

231 'atan2','ceil','CheckAccessFullyMapped','clamp','clip', 

232 'CompileShader','ConsumeStructuredBuffer','cos','cosh','countbits', 

233 'cross','D3DCOLORtoUBYTE4','ddx','ddx_coarse','ddx_fine','ddy', 

234 'ddy_coarse','ddy_fine','degrees','determinant', 

235 'DeviceMemoryBarrier','DeviceMemoryBarrierWithGroupSync','distance', 

236 'dot','dst','errorf','EvaluateAttributeAtCentroid', 

237 'EvaluateAttributeAtSample','EvaluateAttributeSnapped','exp', 

238 'exp2','f16tof32','f32tof16','faceforward','firstbithigh', 

239 'firstbitlow','floor','fma','fmod','frac','frexp','fwidth', 

240 'GetRenderTargetSampleCount','GetRenderTargetSamplePosition', 

241 'GlobalOrderedCountIncrement','GroupMemoryBarrier', 

242 'GroupMemoryBarrierWithGroupSync','InterlockedAdd','InterlockedAnd', 

243 'InterlockedCompareExchange','InterlockedCompareStore', 

244 'InterlockedExchange','InterlockedMax','InterlockedMin', 

245 'InterlockedOr','InterlockedXor','isfinite','isinf','isnan', 

246 'ldexp','length','lerp','lit','log','log10','log2','mad','max', 

247 'min','modf','msad4','mul','noise','normalize','pow','printf', 

248 'Process2DQuadTessFactorsAvg','Process2DQuadTessFactorsMax', 

249 'Process2DQuadTessFactorsMin','ProcessIsolineTessFactors', 

250 'ProcessQuadTessFactorsAvg','ProcessQuadTessFactorsMax', 

251 'ProcessQuadTessFactorsMin','ProcessTriTessFactorsAvg', 

252 'ProcessTriTessFactorsMax','ProcessTriTessFactorsMin', 

253 'QuadReadLaneAt','QuadSwapX','QuadSwapY','radians','rcp', 

254 'reflect','refract','reversebits','round','rsqrt','saturate', 

255 'sign','sin','sincos','sinh','smoothstep','sqrt','step','tan', 

256 'tanh','tex1D','tex1D','tex1Dbias','tex1Dgrad','tex1Dlod', 

257 'tex1Dproj','tex2D','tex2D','tex2Dbias','tex2Dgrad','tex2Dlod', 

258 'tex2Dproj','tex3D','tex3D','tex3Dbias','tex3Dgrad','tex3Dlod', 

259 'tex3Dproj','texCUBE','texCUBE','texCUBEbias','texCUBEgrad', 

260 'texCUBElod','texCUBEproj','transpose','trunc','WaveAllBitAnd', 

261 'WaveAllMax','WaveAllMin','WaveAllBitOr','WaveAllBitXor', 

262 'WaveAllEqual','WaveAllProduct','WaveAllSum','WaveAllTrue', 

263 'WaveAnyTrue','WaveBallot','WaveGetLaneCount','WaveGetLaneIndex', 

264 'WaveGetOrderedIndex','WaveIsHelperLane','WaveOnce', 

265 'WavePrefixProduct','WavePrefixSum','WaveReadFirstLane', 

266 'WaveReadLaneAt'), 

267 prefix=r'\b', suffix=r'\b'), 

268 Name.Builtin), # built-in functions 

269 (words(( 

270 'SV_ClipDistance','SV_ClipDistance0','SV_ClipDistance1', 

271 'SV_Culldistance','SV_CullDistance0','SV_CullDistance1', 

272 'SV_Coverage','SV_Depth','SV_DepthGreaterEqual', 

273 'SV_DepthLessEqual','SV_DispatchThreadID','SV_DomainLocation', 

274 'SV_GroupID','SV_GroupIndex','SV_GroupThreadID','SV_GSInstanceID', 

275 'SV_InnerCoverage','SV_InsideTessFactor','SV_InstanceID', 

276 'SV_IsFrontFace','SV_OutputControlPointID','SV_Position', 

277 'SV_PrimitiveID','SV_RenderTargetArrayIndex','SV_SampleIndex', 

278 'SV_StencilRef','SV_TessFactor','SV_VertexID', 

279 'SV_ViewportArrayIndex'), 

280 prefix=r'\b', suffix=r'\b'), 

281 Name.Decorator), # system-value semantics 

282 (r'\bSV_Target[0-7]?\b', Name.Decorator), 

283 (words(( 

284 'allow_uav_condition','branch','call','domain','earlydepthstencil', 

285 'fastopt','flatten','forcecase','instance','loop','maxtessfactor', 

286 'numthreads','outputcontrolpoints','outputtopology','partitioning', 

287 'patchconstantfunc','unroll'), 

288 prefix=r'\b', suffix=r'\b'), 

289 Name.Decorator), # attributes 

290 (r'[a-zA-Z_]\w*', Name), 

291 (r'\\$', Comment.Preproc), # backslash at end of line -- usually macro continuation 

292 (r'\s+', Whitespace), 

293 ], 

294 'string': [ 

295 (r'"', String, '#pop'), 

296 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|' 

297 r'u[a-fA-F0-9]{4}|U[a-fA-F0-9]{8}|[0-7]{1,3})', String.Escape), 

298 (r'[^\\"\n]+', String), # all other characters 

299 (r'\\\n', String), # line continuation 

300 (r'\\', String), # stray backslash 

301 ], 

302 } 

303 

304 

305class PostScriptLexer(RegexLexer): 

306 """ 

307 Lexer for PostScript files. 

308 """ 

309 name = 'PostScript' 

310 url = 'https://en.wikipedia.org/wiki/PostScript' 

311 aliases = ['postscript', 'postscr'] 

312 filenames = ['*.ps', '*.eps'] 

313 mimetypes = ['application/postscript'] 

314 version_added = '1.4' 

315 

316 delimiter = r'()<>\[\]{}/%\s' 

317 delimiter_end = rf'(?=[{delimiter}])' 

318 

319 valid_name_chars = rf'[^{delimiter}]' 

320 valid_name = rf"{valid_name_chars}+{delimiter_end}" 

321 

322 tokens = { 

323 'root': [ 

324 # All comment types 

325 (r'^%!.+$', Comment.Preproc), 

326 (r'%%.*$', Comment.Special), 

327 (r'(^%.*\n){2,}', Comment.Multiline), 

328 (r'%.*$', Comment.Single), 

329 

330 # String literals are awkward; enter separate state. 

331 (r'\(', String, 'stringliteral'), 

332 

333 (r'[{}<>\[\]]', Punctuation), 

334 

335 # Numbers 

336 (r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex), 

337 # Slight abuse: use Oct to signify any explicit base system 

338 (r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)' 

339 r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct), 

340 (r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?' 

341 + delimiter_end, Number.Float), 

342 (r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer), 

343 

344 # References 

345 (rf'\/{valid_name}', Name.Variable), 

346 

347 # Names 

348 (valid_name, Name.Function), # Anything else is executed 

349 

350 # These keywords taken from 

351 # <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf> 

352 # Is there an authoritative list anywhere that doesn't involve 

353 # trawling documentation? 

354 

355 (r'(false|true)' + delimiter_end, Keyword.Constant), 

356 

357 # Conditionals / flow control 

358 (r'(eq|ne|g[et]|l[et]|and|or|not|if(?:else)?|for(?:all)?)' 

359 + delimiter_end, Keyword.Reserved), 

360 

361 (words(( 

362 'abs', 'add', 'aload', 'arc', 'arcn', 'array', 'atan', 'begin', 

363 'bind', 'ceiling', 'charpath', 'clip', 'closepath', 'concat', 

364 'concatmatrix', 'copy', 'cos', 'currentlinewidth', 'currentmatrix', 

365 'currentpoint', 'curveto', 'cvi', 'cvs', 'def', 'defaultmatrix', 

366 'dict', 'dictstackoverflow', 'div', 'dtransform', 'dup', 'end', 

367 'exch', 'exec', 'exit', 'exp', 'fill', 'findfont', 'floor', 'get', 

368 'getinterval', 'grestore', 'gsave', 'gt', 'identmatrix', 'idiv', 

369 'idtransform', 'index', 'invertmatrix', 'itransform', 'length', 

370 'lineto', 'ln', 'load', 'log', 'loop', 'matrix', 'mod', 'moveto', 

371 'mul', 'neg', 'newpath', 'pathforall', 'pathbbox', 'pop', 'print', 

372 'pstack', 'put', 'quit', 'rand', 'rangecheck', 'rcurveto', 'repeat', 

373 'restore', 'rlineto', 'rmoveto', 'roll', 'rotate', 'round', 'run', 

374 'save', 'scale', 'scalefont', 'setdash', 'setfont', 'setgray', 

375 'setlinecap', 'setlinejoin', 'setlinewidth', 'setmatrix', 

376 'setrgbcolor', 'shfill', 'show', 'showpage', 'sin', 'sqrt', 

377 'stack', 'stringwidth', 'stroke', 'strokepath', 'sub', 'syntaxerror', 

378 'transform', 'translate', 'truncate', 'typecheck', 'undefined', 

379 'undefinedfilename', 'undefinedresult'), suffix=delimiter_end), 

380 Name.Builtin), 

381 

382 (r'\s+', Whitespace), 

383 ], 

384 

385 'stringliteral': [ 

386 (r'[^()\\]+', String), 

387 (r'\\', String.Escape, 'escape'), 

388 (r'\(', String, '#push'), 

389 (r'\)', String, '#pop'), 

390 ], 

391 

392 'escape': [ 

393 (r'[0-8]{3}|n|r|t|b|f|\\|\(|\)', String.Escape, '#pop'), 

394 default('#pop'), 

395 ], 

396 } 

397 

398 

399class AsymptoteLexer(RegexLexer): 

400 """ 

401 For Asymptote source code. 

402 """ 

403 name = 'Asymptote' 

404 url = 'http://asymptote.sf.net/' 

405 aliases = ['asymptote', 'asy'] 

406 filenames = ['*.asy'] 

407 mimetypes = ['text/x-asymptote'] 

408 version_added = '1.2' 

409 

410 #: optional Comment or Whitespace 

411 _ws = r'(?:\s|//.*?\n|/\*.*?\*/)+' 

412 

413 tokens = { 

414 'whitespace': [ 

415 (r'\n', Whitespace), 

416 (r'\s+', Whitespace), 

417 (r'(\\)(\n)', bygroups(Text, Whitespace)), # line continuation 

418 (r'//(\n|(.|\n)*?[^\\]\n)', Comment), 

419 (r'/(\\\n)?\*(.|\n)*?\*(\\\n)?/', Comment), 

420 ], 

421 'statements': [ 

422 # simple string (TeX friendly) 

423 (r'"(\\\\|\\[^\\]|[^"\\])*"', String), 

424 # C style string (with character escapes) 

425 (r"'", String, 'string'), 

426 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float), 

427 (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float), 

428 (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex), 

429 (r'0[0-7]+[Ll]?', Number.Oct), 

430 (r'\d+[Ll]?', Number.Integer), 

431 (r'[~!%^&*+=|?:<>/-]', Operator), 

432 (r'[()\[\],.]', Punctuation), 

433 (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)), 

434 (r'(and|controls|tension|atleast|curl|if|else|while|for|do|' 

435 r'return|break|continue|struct|typedef|new|access|import|' 

436 r'unravel|from|include|quote|static|public|private|restricted|' 

437 r'this|explicit|true|false|null|cycle|newframe|operator)\b', Keyword), 

438 # Since an asy-type-name can be also an asy-function-name, 

439 # in the following we test if the string " [a-zA-Z]" follows 

440 # the Keyword.Type. 

441 # Of course it is not perfect ! 

442 (r'(Braid|FitResult|Label|Legend|TreeNode|abscissa|arc|arrowhead|' 

443 r'binarytree|binarytreeNode|block|bool|bool3|bounds|bqe|circle|' 

444 r'conic|coord|coordsys|cputime|ellipse|file|filltype|frame|grid3|' 

445 r'guide|horner|hsv|hyperbola|indexedTransform|int|inversion|key|' 

446 r'light|line|linefit|marginT|marker|mass|object|pair|parabola|path|' 

447 r'path3|pen|picture|point|position|projection|real|revolution|' 

448 r'scaleT|scientific|segment|side|slice|splitface|string|surface|' 

449 r'tensionSpecifier|ticklocate|ticksgridT|tickvalues|transform|' 

450 r'transformation|tree|triangle|trilinear|triple|vector|' 

451 r'vertex|void)(?=\s+[a-zA-Z])', Keyword.Type), 

452 # Now the asy-type-name which are not asy-function-name 

453 # except yours ! 

454 # Perhaps useless 

455 (r'(Braid|FitResult|TreeNode|abscissa|arrowhead|block|bool|bool3|' 

456 r'bounds|coord|frame|guide|horner|int|linefit|marginT|pair|pen|' 

457 r'picture|position|real|revolution|slice|splitface|ticksgridT|' 

458 r'tickvalues|tree|triple|vertex|void)\b', Keyword.Type), 

459 (r'[a-zA-Z_]\w*:(?!:)', Name.Label), 

460 (r'[a-zA-Z_]\w*', Name), 

461 ], 

462 'root': [ 

463 include('whitespace'), 

464 # functions 

465 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments 

466 r'([a-zA-Z_]\w*)' # method name 

467 r'(\s*\([^;]*?\))' # signature 

468 r'(' + _ws + r')(\{)', 

469 bygroups(using(this), Name.Function, using(this), using(this), 

470 Punctuation), 

471 'function'), 

472 # function declarations 

473 (r'((?:[\w*\s])+?(?:\s|\*))' # return arguments 

474 r'([a-zA-Z_]\w*)' # method name 

475 r'(\s*\([^;]*?\))' # signature 

476 r'(' + _ws + r')(;)', 

477 bygroups(using(this), Name.Function, using(this), using(this), 

478 Punctuation)), 

479 default('statement'), 

480 ], 

481 'statement': [ 

482 include('whitespace'), 

483 include('statements'), 

484 ('[{}]', Punctuation), 

485 (';', Punctuation, '#pop'), 

486 ], 

487 'function': [ 

488 include('whitespace'), 

489 include('statements'), 

490 (';', Punctuation), 

491 (r'\{', Punctuation, '#push'), 

492 (r'\}', Punctuation, '#pop'), 

493 ], 

494 'string': [ 

495 (r"'", String, '#pop'), 

496 (r'\\([\\abfnrtv"\'?]|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 

497 (r'\n', String), 

498 (r"[^\\'\n]+", String), # all other characters 

499 (r'\\\n', String), 

500 (r'\\n', String), # line continuation 

501 (r'\\', String), # stray backslash 

502 ], 

503 } 

504 

505 def get_tokens_unprocessed(self, text): 

506 from pygments.lexers._asy_builtins import ASYFUNCNAME, ASYVARNAME 

507 for index, token, value in \ 

508 RegexLexer.get_tokens_unprocessed(self, text): 

509 if token is Name and value in ASYFUNCNAME: 

510 token = Name.Function 

511 elif token is Name and value in ASYVARNAME: 

512 token = Name.Variable 

513 yield index, token, value 

514 

515 

516def _shortened(word): 

517 dpos = word.find('$') 

518 return '|'.join(word[:dpos] + word[dpos+1:i] + r'\b' 

519 for i in range(len(word), dpos, -1)) 

520 

521 

522def _shortened_many(*words): 

523 return '|'.join(map(_shortened, words)) 

524 

525 

526class GnuplotLexer(RegexLexer): 

527 """ 

528 For Gnuplot plotting scripts. 

529 """ 

530 

531 name = 'Gnuplot' 

532 url = 'http://gnuplot.info/' 

533 aliases = ['gnuplot'] 

534 filenames = ['*.plot', '*.plt'] 

535 mimetypes = ['text/x-gnuplot'] 

536 version_added = '0.11' 

537 

538 tokens = { 

539 'root': [ 

540 include('whitespace'), 

541 (_shortened('bi$nd'), Keyword, 'bind'), 

542 (_shortened_many('ex$it', 'q$uit'), Keyword, 'quit'), 

543 (_shortened('f$it'), Keyword, 'fit'), 

544 (r'(if)(\s*)(\()', bygroups(Keyword, Text, Punctuation), 'if'), 

545 (r'else\b', Keyword), 

546 (_shortened('pa$use'), Keyword, 'pause'), 

547 (_shortened_many('p$lot', 'rep$lot', 'sp$lot'), Keyword, 'plot'), 

548 (_shortened('sa$ve'), Keyword, 'save'), 

549 (_shortened('se$t'), Keyword, ('genericargs', 'optionarg')), 

550 (_shortened_many('sh$ow', 'uns$et'), 

551 Keyword, ('noargs', 'optionarg')), 

552 (_shortened_many('low$er', 'ra$ise', 'ca$ll', 'cd$', 'cl$ear', 

553 'h$elp', '\\?$', 'hi$story', 'l$oad', 'pr$int', 

554 'pwd$', 're$read', 'res$et', 'scr$eendump', 

555 'she$ll', 'sy$stem', 'up$date'), 

556 Keyword, 'genericargs'), 

557 (_shortened_many('pwd$', 're$read', 'res$et', 'scr$eendump', 

558 'she$ll', 'test$'), 

559 Keyword, 'noargs'), 

560 (r'([a-zA-Z_]\w*)(\s*)(=)', 

561 bygroups(Name.Variable, Whitespace, Operator), 'genericargs'), 

562 (r'([a-zA-Z_]\w*)(\s*)(\()(.*?)(\))(\s*)(=)', 

563 bygroups(Name.Function, Whitespace, Punctuation, 

564 Text, Punctuation, Whitespace, Operator), 'genericargs'), 

565 (r'@[a-zA-Z_]\w*', Name.Constant), # macros 

566 (r';', Keyword), 

567 ], 

568 'comment': [ 

569 (r'[^\\\n]+', Comment), 

570 (r'\\\n', Comment), 

571 (r'\\', Comment), 

572 # don't add the newline to the Comment token 

573 default('#pop'), 

574 ], 

575 'whitespace': [ 

576 ('#', Comment, 'comment'), 

577 (r'[ \t\v\f]+', Whitespace), 

578 ], 

579 'noargs': [ 

580 include('whitespace'), 

581 # semicolon and newline end the argument list 

582 (r';', Punctuation, '#pop'), 

583 (r'\n', Whitespace, '#pop'), 

584 ], 

585 'dqstring': [ 

586 (r'"', String, '#pop'), 

587 (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape), 

588 (r'[^\\"\n]+', String), # all other characters 

589 (r'\\\n', String), # line continuation 

590 (r'\\', String), # stray backslash 

591 (r'\n', Whitespace, '#pop'), # newline ends the string too 

592 ], 

593 'sqstring': [ 

594 (r"''", String), # escaped single quote 

595 (r"'", String, '#pop'), 

596 (r"[^\\'\n]+", String), # all other characters 

597 (r'\\\n', String), # line continuation 

598 (r'\\', String), # normal backslash 

599 (r'\n', Whitespace, '#pop'), # newline ends the string too 

600 ], 

601 'genericargs': [ 

602 include('noargs'), 

603 (r'"', String, 'dqstring'), 

604 (r"'", String, 'sqstring'), 

605 (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+', Number.Float), 

606 (r'(\d+\.\d*|\.\d+)', Number.Float), 

607 (r'-?\d+', Number.Integer), 

608 ('[,.~!%^&*+=|?:<>/-]', Operator), 

609 (r'[{}()\[\]]', Punctuation), 

610 (r'(eq|ne)\b', Operator.Word), 

611 (r'([a-zA-Z_]\w*)(\s*)(\()', 

612 bygroups(Name.Function, Text, Punctuation)), 

613 (r'[a-zA-Z_]\w*', Name), 

614 (r'@[a-zA-Z_]\w*', Name.Constant), # macros 

615 (r'(\\)(\n)', bygroups(Text, Whitespace)), 

616 ], 

617 'optionarg': [ 

618 include('whitespace'), 

619 (_shortened_many( 

620 "a$ll", "an$gles", "ar$row", "au$toscale", "b$ars", "bor$der", 

621 "box$width", "cl$abel", "c$lip", "cn$trparam", "co$ntour", "da$ta", 

622 "data$file", "dg$rid3d", "du$mmy", "enc$oding", "dec$imalsign", 

623 "fit$", "font$path", "fo$rmat", "fu$nction", "fu$nctions", "g$rid", 

624 "hid$den3d", "his$torysize", "is$osamples", "k$ey", "keyt$itle", 

625 "la$bel", "li$nestyle", "ls$", "loa$dpath", "loc$ale", "log$scale", 

626 "mac$ros", "map$ping", "map$ping3d", "mar$gin", "lmar$gin", 

627 "rmar$gin", "tmar$gin", "bmar$gin", "mo$use", "multi$plot", 

628 "mxt$ics", "nomxt$ics", "mx2t$ics", "nomx2t$ics", "myt$ics", 

629 "nomyt$ics", "my2t$ics", "nomy2t$ics", "mzt$ics", "nomzt$ics", 

630 "mcbt$ics", "nomcbt$ics", "of$fsets", "or$igin", "o$utput", 

631 "pa$rametric", "pm$3d", "pal$ette", "colorb$ox", "p$lot", 

632 "poi$ntsize", "pol$ar", "pr$int", "obj$ect", "sa$mples", "si$ze", 

633 "st$yle", "su$rface", "table$", "t$erminal", "termo$ptions", "ti$cs", 

634 "ticsc$ale", "ticsl$evel", "timef$mt", "tim$estamp", "tit$le", 

635 "v$ariables", "ve$rsion", "vi$ew", "xyp$lane", "xda$ta", "x2da$ta", 

636 "yda$ta", "y2da$ta", "zda$ta", "cbda$ta", "xl$abel", "x2l$abel", 

637 "yl$abel", "y2l$abel", "zl$abel", "cbl$abel", "xti$cs", "noxti$cs", 

638 "x2ti$cs", "nox2ti$cs", "yti$cs", "noyti$cs", "y2ti$cs", "noy2ti$cs", 

639 "zti$cs", "nozti$cs", "cbti$cs", "nocbti$cs", "xdti$cs", "noxdti$cs", 

640 "x2dti$cs", "nox2dti$cs", "ydti$cs", "noydti$cs", "y2dti$cs", 

641 "noy2dti$cs", "zdti$cs", "nozdti$cs", "cbdti$cs", "nocbdti$cs", 

642 "xmti$cs", "noxmti$cs", "x2mti$cs", "nox2mti$cs", "ymti$cs", 

643 "noymti$cs", "y2mti$cs", "noy2mti$cs", "zmti$cs", "nozmti$cs", 

644 "cbmti$cs", "nocbmti$cs", "xr$ange", "x2r$ange", "yr$ange", 

645 "y2r$ange", "zr$ange", "cbr$ange", "rr$ange", "tr$ange", "ur$ange", 

646 "vr$ange", "xzeroa$xis", "x2zeroa$xis", "yzeroa$xis", "y2zeroa$xis", 

647 "zzeroa$xis", "zeroa$xis", "z$ero"), Name.Builtin, '#pop'), 

648 ], 

649 'bind': [ 

650 ('!', Keyword, '#pop'), 

651 (_shortened('all$windows'), Name.Builtin), 

652 include('genericargs'), 

653 ], 

654 'quit': [ 

655 (r'gnuplot\b', Keyword), 

656 include('noargs'), 

657 ], 

658 'fit': [ 

659 (r'via\b', Name.Builtin), 

660 include('plot'), 

661 ], 

662 'if': [ 

663 (r'\)', Punctuation, '#pop'), 

664 include('genericargs'), 

665 ], 

666 'pause': [ 

667 (r'(mouse|any|button1|button2|button3)\b', Name.Builtin), 

668 (_shortened('key$press'), Name.Builtin), 

669 include('genericargs'), 

670 ], 

671 'plot': [ 

672 (_shortened_many('ax$es', 'axi$s', 'bin$ary', 'ev$ery', 'i$ndex', 

673 'mat$rix', 's$mooth', 'thru$', 't$itle', 

674 'not$itle', 'u$sing', 'w$ith'), 

675 Name.Builtin), 

676 include('genericargs'), 

677 ], 

678 'save': [ 

679 (_shortened_many('f$unctions', 's$et', 't$erminal', 'v$ariables'), 

680 Name.Builtin), 

681 include('genericargs'), 

682 ], 

683 } 

684 

685 

686class PovrayLexer(RegexLexer): 

687 """ 

688 For Persistence of Vision Raytracer files. 

689 """ 

690 name = 'POVRay' 

691 url = 'http://www.povray.org/' 

692 aliases = ['pov'] 

693 filenames = ['*.pov', '*.inc'] 

694 mimetypes = ['text/x-povray'] 

695 version_added = '0.11' 

696 

697 tokens = { 

698 'root': [ 

699 (r'/\*[\w\W]*?\*/', Comment.Multiline), 

700 (r'//.*$', Comment.Single), 

701 (r'(?s)"(?:\\.|[^"\\])+"', String.Double), 

702 (words(( 

703 'break', 'case', 'debug', 'declare', 'default', 'define', 'else', 

704 'elseif', 'end', 'error', 'fclose', 'fopen', 'for', 'if', 'ifdef', 

705 'ifndef', 'include', 'local', 'macro', 'range', 'read', 'render', 

706 'statistics', 'switch', 'undef', 'version', 'warning', 'while', 

707 'write'), prefix=r'#', suffix=r'\b'), 

708 Comment.Preproc), 

709 (words(( 

710 'aa_level', 'aa_threshold', 'abs', 'acos', 'acosh', 'adaptive', 'adc_bailout', 

711 'agate', 'agate_turb', 'all', 'alpha', 'ambient', 'ambient_light', 'angle', 

712 'aperture', 'arc_angle', 'area_light', 'asc', 'asin', 'asinh', 'assumed_gamma', 

713 'atan', 'atan2', 'atanh', 'atmosphere', 'atmospheric_attenuation', 

714 'attenuating', 'average', 'background', 'black_hole', 'blue', 'blur_samples', 

715 'bounded_by', 'box_mapping', 'bozo', 'break', 'brick', 'brick_size', 

716 'brightness', 'brilliance', 'bumps', 'bumpy1', 'bumpy2', 'bumpy3', 'bump_map', 

717 'bump_size', 'case', 'caustics', 'ceil', 'checker', 'chr', 'clipped_by', 'clock', 

718 'color', 'color_map', 'colour', 'colour_map', 'component', 'composite', 'concat', 

719 'confidence', 'conic_sweep', 'constant', 'control0', 'control1', 'cos', 'cosh', 

720 'count', 'crackle', 'crand', 'cube', 'cubic_spline', 'cylindrical_mapping', 

721 'debug', 'declare', 'default', 'degrees', 'dents', 'diffuse', 'direction', 

722 'distance', 'distance_maximum', 'div', 'dust', 'dust_type', 'eccentricity', 

723 'else', 'emitting', 'end', 'error', 'error_bound', 'exp', 'exponent', 

724 'fade_distance', 'fade_power', 'falloff', 'falloff_angle', 'false', 

725 'file_exists', 'filter', 'finish', 'fisheye', 'flatness', 'flip', 'floor', 

726 'focal_point', 'fog', 'fog_alt', 'fog_offset', 'fog_type', 'frequency', 'gif', 

727 'global_settings', 'glowing', 'gradient', 'granite', 'gray_threshold', 

728 'green', 'halo', 'hexagon', 'hf_gray_16', 'hierarchy', 'hollow', 'hypercomplex', 

729 'if', 'ifdef', 'iff', 'image_map', 'incidence', 'include', 'int', 'interpolate', 

730 'inverse', 'ior', 'irid', 'irid_wavelength', 'jitter', 'lambda', 'leopard', 

731 'linear', 'linear_spline', 'linear_sweep', 'location', 'log', 'looks_like', 

732 'look_at', 'low_error_factor', 'mandel', 'map_type', 'marble', 'material_map', 

733 'matrix', 'max', 'max_intersections', 'max_iteration', 'max_trace_level', 

734 'max_value', 'metallic', 'min', 'minimum_reuse', 'mod', 'mortar', 

735 'nearest_count', 'no', 'normal', 'normal_map', 'no_shadow', 'number_of_waves', 

736 'octaves', 'off', 'offset', 'omega', 'omnimax', 'on', 'once', 'onion', 'open', 

737 'orthographic', 'panoramic', 'pattern1', 'pattern2', 'pattern3', 

738 'perspective', 'pgm', 'phase', 'phong', 'phong_size', 'pi', 'pigment', 

739 'pigment_map', 'planar_mapping', 'png', 'point_at', 'pot', 'pow', 'ppm', 

740 'precision', 'pwr', 'quadratic_spline', 'quaternion', 'quick_color', 

741 'quick_colour', 'quilted', 'radial', 'radians', 'radiosity', 'radius', 'rainbow', 

742 'ramp_wave', 'rand', 'range', 'reciprocal', 'recursion_limit', 'red', 

743 'reflection', 'refraction', 'render', 'repeat', 'rgb', 'rgbf', 'rgbft', 'rgbt', 

744 'right', 'ripples', 'rotate', 'roughness', 'samples', 'scale', 'scallop_wave', 

745 'scattering', 'seed', 'shadowless', 'sin', 'sine_wave', 'sinh', 'sky', 'sky_sphere', 

746 'slice', 'slope_map', 'smooth', 'specular', 'spherical_mapping', 'spiral', 

747 'spiral1', 'spiral2', 'spotlight', 'spotted', 'sqr', 'sqrt', 'statistics', 'str', 

748 'strcmp', 'strength', 'strlen', 'strlwr', 'strupr', 'sturm', 'substr', 'switch', 'sys', 

749 't', 'tan', 'tanh', 'test_camera_1', 'test_camera_2', 'test_camera_3', 

750 'test_camera_4', 'texture', 'texture_map', 'tga', 'thickness', 'threshold', 

751 'tightness', 'tile2', 'tiles', 'track', 'transform', 'translate', 'transmit', 

752 'triangle_wave', 'true', 'ttf', 'turbulence', 'turb_depth', 'type', 

753 'ultra_wide_angle', 'up', 'use_color', 'use_colour', 'use_index', 'u_steps', 

754 'val', 'variance', 'vaxis_rotate', 'vcross', 'vdot', 'version', 'vlength', 

755 'vnormalize', 'volume_object', 'volume_rendered', 'vol_with_light', 

756 'vrotate', 'v_steps', 'warning', 'warp', 'water_level', 'waves', 'while', 'width', 

757 'wood', 'wrinkles', 'yes'), prefix=r'\b', suffix=r'\b'), 

758 Keyword), 

759 (words(( 

760 'bicubic_patch', 'blob', 'box', 'camera', 'cone', 'cubic', 'cylinder', 'difference', 

761 'disc', 'height_field', 'intersection', 'julia_fractal', 'lathe', 

762 'light_source', 'merge', 'mesh', 'object', 'plane', 'poly', 'polygon', 'prism', 

763 'quadric', 'quartic', 'smooth_triangle', 'sor', 'sphere', 'superellipsoid', 

764 'text', 'torus', 'triangle', 'union'), suffix=r'\b'), 

765 Name.Builtin), 

766 (r'\b(x|y|z|u|v)\b', Name.Builtin.Pseudo), 

767 (r'[a-zA-Z_]\w*', Name), 

768 (r'[0-9]*\.[0-9]+', Number.Float), 

769 (r'[0-9]+', Number.Integer), 

770 (r'[\[\](){}<>;,]', Punctuation), 

771 (r'[-+*/=.|&]|<=|>=|!=', Operator), 

772 (r'"(\\\\|\\[^\\]|[^"\\])*"', String), 

773 (r'\s+', Whitespace), 

774 ] 

775 } 

776 

777 def analyse_text(text): 

778 """POVRAY is similar to JSON/C, but the combination of camera and 

779 light_source is probably not very likely elsewhere. HLSL or GLSL 

780 are similar (GLSL even has #version), but they miss #declare, and 

781 light_source/camera are not keywords anywhere else -- it's fair 

782 to assume though that any POVRAY scene must have a camera and 

783 lightsource.""" 

784 result = 0 

785 if '#version' in text: 

786 result += 0.05 

787 if '#declare' in text: 

788 result += 0.05 

789 if 'camera' in text: 

790 result += 0.05 

791 if 'light_source' in text: 

792 result += 0.1 

793 

794 return result