graphics.py 25 KB

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