diff options
author | Georg Brandl <georg@python.org> | 2010-08-22 12:22:25 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2010-08-22 12:22:25 +0200 |
commit | 090f2376b50111e9b71f65b105bf9ace953f42ab (patch) | |
tree | 647037c962a4597e0f0212a1f8a075a57cf3a543 | |
parent | 738b4c9c5da596ff428565651e603cad4cf7906a (diff) | |
download | pygments-090f2376b50111e9b71f65b105bf9ace953f42ab.tar.gz |
Add PostScript lexer (#486).
-rw-r--r-- | AUTHORS | 1 | ||||
-rw-r--r-- | CHANGES | 3 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 1 | ||||
-rw-r--r-- | pygments/lexers/other.py | 94 | ||||
-rw-r--r-- | tests/examplefiles/cells.ps | 515 |
5 files changed, 612 insertions, 2 deletions
@@ -25,6 +25,7 @@ Other contributors, listed alphabetically, are: * Owen Durni -- haXe lexer * Nick Efford -- Python 3 lexer * Artem Egorkine -- terminal256 formatter +* James H. Fisher -- PostScript lexer * Laurent Gautier -- R/S lexer * Krzysiek Goj -- Scala lexer * Matt Good -- Genshi, Cheetah lexers @@ -10,9 +10,10 @@ Version 1.4 - Lexers added: * Factor (#520) + * PostScript (#486) + * Verilog (#491) * BlitzMax Basic (#478) * Ioke (#465) - * Verilog (#491) * Java properties, split out of the INI lexer (#445) - Performance improvements in the HTML formatter (#523). diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index ef1a942e..667c47d8 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -146,6 +146,7 @@ LEXERS = { 'OocLexer': ('pygments.lexers.compiled', 'Ooc', ('ooc',), ('*.ooc',), ('text/x-ooc',)), 'PerlLexer': ('pygments.lexers.agile', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm'), ('text/x-perl', 'application/x-perl')), 'PhpLexer': ('pygments.lexers.web', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]'), ('text/x-php',)), + 'PostScriptLexer': ('pygments.lexers.other', 'PostScript', ('postscript',), ('*.ps', '*.eps'), ('application/postscript',)), 'PovrayLexer': ('pygments.lexers.other', 'POVRay', ('pov',), ('*.pov', '*.inc'), ('text/x-povray',)), 'PrologLexer': ('pygments.lexers.compiled', 'Prolog', ('prolog',), ('*.prolog', '*.pro', '*.pl'), ('text/x-prolog',)), 'PropertiesLexer': ('pygments.lexers.text', 'Properties', ('properties',), ('*.properties',), ('text/x-java-properties',)), diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index 98014254..286dc68a 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -24,7 +24,7 @@ __all__ = ['SqlLexer', 'MySqlLexer', 'SqliteConsoleLexer', 'BrainfuckLexer', 'MOOCodeLexer', 'SmalltalkLexer', 'TcshLexer', 'LogtalkLexer', 'GnuplotLexer', 'PovrayLexer', 'AppleScriptLexer', 'BashSessionLexer', 'ModelicaLexer', 'RebolLexer', 'ABAPLexer', - 'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer'] + 'NewspeakLexer', 'GherkinLexer', 'AsymptoteLexer', 'PostScriptLexer'] line_re = re.compile('.*?\n') @@ -2312,3 +2312,95 @@ class AsymptoteLexer(RegexLexer): elif token is Name and value in ASYVARNAME: token = Name.Variable yield index, token, value + + +class PostScriptLexer(RegexLexer): + """ + Lexer for PostScript files. + + The PostScript Language Reference published by Adobe at + <http://partners.adobe.com/public/developer/en/ps/PLRM.pdf> + is the authority for this. + + *New in Pygments 1.4.* + """ + name = 'PostScript' + aliases = ['postscript'] + filenames = ['*.ps', '*.eps'] + mimetypes = ['application/postscript'] + + delimiter = r'\(\)\<\>\[\]\{\}\/\%\s' + delimiter_end = r'(?=[%s])' % delimiter + + valid_name_chars = r'[^%s]' % delimiter + valid_name = r"%s+%s" % (valid_name_chars, delimiter_end) + + tokens = { + 'root': [ + # All comment types + (r'^%!.+\n', Comment.Preproc), + (r'%%.*\n', Comment.Special), + (r'(^%.*\n){2,}', Comment.Multiline), + (r'%.*\n', Comment.Single), + + # String literals are awkward; enter separate state. + (r'\(', String, 'stringliteral'), + + (r'[\{\}(\<\<)(\>\>)\[\]]', Punctuation), + + # Numbers + (r'<[0-9A-Fa-f]+>' + delimiter_end, Number.Hex), + # Slight abuse: use Oct to signify any explicit base system + (r'[0-9]+\#(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)' + r'((e|E)[0-9]+)?' + delimiter_end, Number.Oct), + (r'(\-|\+)?([0-9]+\.?|[0-9]*\.[0-9]+|[0-9]+\.[0-9]*)((e|E)[0-9]+)?' + + delimiter_end, Number.Float), + (r'(\-|\+)?[0-9]+' + delimiter_end, Number.Integer), + + # References + (r'\/%s' % valid_name, Name.Variable), + + # Names + (valid_name, Name.Function), # Anything else is executed + + # These keywords taken from + # <http://www.math.ubc.ca/~cass/graphics/manual/pdf/a1.pdf> + # Is there an authoritative list anywhere that doesn't involve + # trawling documentation? + + (r'(false|true)' + delimiter_end, Keyword.Constant), + + # Conditionals / flow control + (r'(eq|ne|ge|gt|le|lt|and|or|not|if|ifelse|for|forall)' + + delimiter_end, Keyword.Reserved), + + ('(abs|add|aload|arc|arcn|array|atan|begin|bind|ceiling|charpath|' + 'clip|closepath|concat|concatmatrix|copy|cos|currentlinewidth|' + 'currentmatrix|currentpoint|curveto|cvi|cvs|def|defaultmatrix|' + 'dict|dictstackoverflow|div|dtransform|dup|end|exch|exec|exit|exp|' + 'fill|findfont|floor|get|getinterval|grestore|gsave|gt|' + 'identmatrix|idiv|idtransform|index|invertmatrix|itransform|' + 'length|lineto|ln|load|log|loop|matrix|mod|moveto|mul|neg|newpath|' + 'pathforall|pathbbox||pop|print|pstack|put|quit|rand|rangecheck|' + 'rcurveto|repeat|restore|rlineto|rmoveto|roll|rotate|round|run|' + 'save|scale|scalefont|setdash|setfont|setgray|setlinecap|' + 'setlinejoin|setlinewidth|setmatrix|setrgbcolor|shfill|show|' + 'showpage|sin|sqrt|stack|stringwidth|stroke|strokepath|sub|' + 'syntaxerror|transform|translate|truncate|typecheck|undefined|' + 'undefinedfilename|undefinedresult)' + delimiter_end, + Name.Builtin), + + (r'\s+', Text), + ], + + 'stringliteral': [ + (r'[^\(\)\\]+', String), + (r'\\', String.Escape, 'escape'), + (r'\(', String, '#push'), + (r'\)', String, '#pop'), + ], + + 'escape': [ + (r'([0-8]{3}|n|r|t|b|f|\\|\(|\)|)', String.Escape, '#pop'), + ], + } diff --git a/tests/examplefiles/cells.ps b/tests/examplefiles/cells.ps new file mode 100644 index 00000000..d5bc325f --- /dev/null +++ b/tests/examplefiles/cells.ps @@ -0,0 +1,515 @@ +%!PS-Adobe-2.0 +%%Creator: PS_Write.F +%%Title: cells.ps +%%Pages: 1 +%%Document-Fonts: Times-Roman +%%CreationDate: 09/29/99 +%%BoundingBox: 36 36 576 756 +%%EndComments +%%BeginProlog +%%EndProlog +/inch {72 mul} def +/Palatino-Roman findfont +1.00 inch scalefont +setfont + 0.0000 0.0000 0.0000 setrgbcolor +%%Page: 1 1 +save + 0.7000 0.7000 0.7000 setrgbcolor + newpath + 497 294 moveto + 500 297 lineto + 503 300 lineto + 506 303 lineto + 510 307 lineto + 513 310 lineto + 516 313 lineto + 519 316 lineto + 522 319 lineto + 526 323 lineto + 529 326 lineto + 532 329 lineto + 535 332 lineto + 538 335 lineto + 541 338 lineto + 545 342 lineto + 548 345 lineto + 551 348 lineto + 554 351 lineto + 557 354 lineto + 561 358 lineto + 0.7000 0.7000 0.7000 setrgbcolor + stroke + newpath + 51 358 moveto + 65 385 lineto + 84 408 lineto + 109 425 lineto + 138 433 lineto + 168 436 lineto + 198 435 lineto + 226 436 lineto + 252 442 lineto + 279 451 lineto + 306 463 lineto + 335 472 lineto + 365 475 lineto + 394 470 lineto + 421 455 lineto + 444 436 lineto + 465 414 lineto + 485 395 lineto + 508 380 lineto + 533 369 lineto + 561 358 lineto + 0.7000 0.7000 0.7000 setrgbcolor + stroke + newpath + 115 294 moveto + 112 297 lineto + 109 300 lineto + 106 303 lineto + 102 307 lineto + 99 310 lineto + 96 313 lineto + 93 316 lineto + 90 319 lineto + 86 323 lineto + 83 326 lineto + 80 329 lineto + 77 332 lineto + 74 335 lineto + 71 338 lineto + 67 342 lineto + 64 345 lineto + 61 348 lineto + 58 351 lineto + 55 354 lineto + 51 358 lineto + 0.7000 0.7000 0.7000 setrgbcolor + stroke + newpath + 115 294 moveto + 131 308 lineto + 147 321 lineto + 165 333 lineto + 183 344 lineto + 203 352 lineto + 223 360 lineto + 243 366 lineto + 264 370 lineto + 285 372 lineto + 306 373 lineto + 327 372 lineto + 348 370 lineto + 369 366 lineto + 389 360 lineto + 409 352 lineto + 429 344 lineto + 447 333 lineto + 465 321 lineto + 481 308 lineto + 497 294 lineto + 0.7000 0.7000 0.7000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 171 337 moveto + 164 348 lineto + 158 360 lineto + 151 371 lineto + 145 383 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 145 383 moveto + 126 372 lineto + 109 359 lineto + 95 343 lineto + 83 326 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 83 326 moveto + 91 318 lineto + 99 310 lineto + 107 302 lineto + 115 294 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 115 294 moveto + 128 306 lineto + 142 317 lineto + 156 327 lineto + 171 337 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 236 364 moveto + 234 373 lineto + 231 382 lineto + 229 391 lineto + 226 400 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 226 400 moveto + 206 397 lineto + 185 394 lineto + 165 390 lineto + 145 383 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 145 383 moveto + 151 371 lineto + 158 360 lineto + 164 348 lineto + 171 337 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 171 337 moveto + 187 345 lineto + 203 352 lineto + 219 359 lineto + 236 364 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 306 373 moveto + 306 384 lineto + 306 396 lineto + 306 407 lineto + 306 418 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 418 moveto + 286 413 lineto + 266 408 lineto + 246 403 lineto + 226 400 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 226 400 moveto + 229 391 lineto + 231 382 lineto + 234 373 lineto + 236 364 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 236 364 moveto + 253 368 lineto + 271 371 lineto + 288 372 lineto + 306 373 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 376 364 moveto + 379 377 lineto + 383 389 lineto + 386 402 lineto + 390 415 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 390 415 moveto + 369 421 lineto + 348 423 lineto + 327 422 lineto + 306 418 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 418 moveto + 306 407 lineto + 306 396 lineto + 306 384 lineto + 306 373 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 373 moveto + 324 372 lineto + 341 371 lineto + 359 368 lineto + 376 364 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 441 337 moveto + 446 345 lineto + 450 353 lineto + 455 361 lineto + 460 369 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 460 369 moveto + 443 381 lineto + 427 394 lineto + 409 406 lineto + 390 415 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 390 415 moveto + 386 402 lineto + 383 389 lineto + 379 377 lineto + 376 364 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 376 364 moveto + 393 359 lineto + 409 352 lineto + 425 345 lineto + 441 337 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 497 294 moveto + 505 302 lineto + 513 310 lineto + 521 318 lineto + 529 326 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 529 326 moveto + 511 336 lineto + 493 347 lineto + 476 357 lineto + 460 369 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 460 369 moveto + 455 361 lineto + 450 353 lineto + 446 345 lineto + 441 337 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 441 337 moveto + 456 327 lineto + 470 317 lineto + 484 306 lineto + 497 294 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 145 383 moveto + 138 394 lineto + 131 405 lineto + 125 417 lineto + 118 428 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 118 428 moveto + 96 417 lineto + 77 401 lineto + 63 380 lineto + 51 358 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 51 358 moveto + 59 350 lineto + 67 342 lineto + 75 334 lineto + 83 326 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 83 326 moveto + 95 343 lineto + 109 359 lineto + 126 372 lineto + 145 383 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 226 400 moveto + 224 409 lineto + 222 418 lineto + 219 427 lineto + 217 436 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 217 436 moveto + 193 435 lineto + 168 436 lineto + 143 434 lineto + 118 428 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 118 428 moveto + 125 417 lineto + 131 405 lineto + 138 394 lineto + 145 383 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 145 383 moveto + 165 390 lineto + 185 394 lineto + 206 397 lineto + 226 400 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 306 418 moveto + 306 429 lineto + 306 441 lineto + 306 452 lineto + 306 463 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 463 moveto + 283 453 lineto + 261 444 lineto + 239 438 lineto + 217 436 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 217 436 moveto + 219 427 lineto + 222 418 lineto + 224 409 lineto + 226 400 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 226 400 moveto + 246 403 lineto + 266 408 lineto + 286 413 lineto + 306 418 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 390 415 moveto + 393 428 lineto + 396 440 lineto + 400 453 lineto + 403 466 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 403 466 moveto + 380 474 lineto + 355 475 lineto + 330 471 lineto + 306 463 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 463 moveto + 306 452 lineto + 306 441 lineto + 306 429 lineto + 306 418 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 306 418 moveto + 327 422 lineto + 348 423 lineto + 369 421 lineto + 390 415 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 460 369 moveto + 464 377 lineto + 469 385 lineto + 474 393 lineto + 478 401 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 478 401 moveto + 461 418 lineto + 444 436 lineto + 425 452 lineto + 403 466 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 403 466 moveto + 400 453 lineto + 396 440 lineto + 393 428 lineto + 390 415 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 390 415 moveto + 409 406 lineto + 427 394 lineto + 443 381 lineto + 460 369 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + 0.0000 0.0000 0.4000 setrgbcolor + newpath + 529 326 moveto + 537 334 lineto + 545 342 lineto + 553 350 lineto + 561 358 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 561 358 moveto + 537 367 lineto + 516 376 lineto + 496 387 lineto + 478 401 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 478 401 moveto + 474 393 lineto + 469 385 lineto + 464 377 lineto + 460 369 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke + newpath + 460 369 moveto + 476 357 lineto + 493 347 lineto + 511 336 lineto + 529 326 lineto + 0.0000 0.0000 0.4000 setrgbcolor + stroke +restore +showpage +%%Trailer +%%Pages: 1 +%%EOF |