pygments.rb 1.1.1 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (383) hide show
  1. checksums.yaml +5 -5
  2. data/.github/dependabot.yml +13 -0
  3. data/.github/workflows/ci.yml +28 -0
  4. data/.github/workflows/release.yml +24 -0
  5. data/.gitignore +5 -5
  6. data/CHANGELOG.adoc +123 -0
  7. data/Gemfile +3 -1
  8. data/LICENSE +1 -1
  9. data/README.adoc +161 -0
  10. data/Rakefile +13 -19
  11. data/bench.rb +8 -7
  12. data/cache-lexers.rb +3 -2
  13. data/lexers +0 -0
  14. data/lib/pygments.rb +10 -11
  15. data/lib/pygments/lexer.rb +5 -5
  16. data/lib/pygments/mentos.py +23 -66
  17. data/lib/pygments/popen.rb +155 -204
  18. data/lib/pygments/version.rb +2 -2
  19. data/pygments.rb.gemspec +11 -9
  20. data/test/test_pygments.rb +54 -87
  21. data/vendor/pygments-main/{AUTHORS → Pygments-2.7.3.dist-info/AUTHORS} +23 -3
  22. data/vendor/pygments-main/Pygments-2.7.3.dist-info/INSTALLER +1 -0
  23. data/vendor/pygments-main/{LICENSE → Pygments-2.7.3.dist-info/LICENSE} +1 -1
  24. data/vendor/pygments-main/Pygments-2.7.3.dist-info/METADATA +49 -0
  25. data/vendor/pygments-main/Pygments-2.7.3.dist-info/RECORD +482 -0
  26. data/vendor/pygments-main/Pygments-2.7.3.dist-info/REQUESTED +0 -0
  27. data/vendor/pygments-main/Pygments-2.7.3.dist-info/WHEEL +5 -0
  28. data/vendor/pygments-main/Pygments-2.7.3.dist-info/entry_points.txt +3 -0
  29. data/vendor/pygments-main/Pygments-2.7.3.dist-info/top_level.txt +1 -0
  30. data/vendor/pygments-main/bin/pygmentize +8 -0
  31. data/vendor/pygments-main/pygments/__init__.py +6 -11
  32. data/vendor/pygments-main/pygments/__main__.py +18 -0
  33. data/vendor/pygments-main/pygments/cmdline.py +94 -41
  34. data/vendor/pygments-main/pygments/console.py +6 -9
  35. data/vendor/pygments-main/pygments/filter.py +4 -6
  36. data/vendor/pygments-main/pygments/filters/__init__.py +609 -21
  37. data/vendor/pygments-main/pygments/formatter.py +4 -4
  38. data/vendor/pygments-main/pygments/formatters/__init__.py +42 -6
  39. data/vendor/pygments-main/pygments/formatters/_mapping.py +1 -3
  40. data/vendor/pygments-main/pygments/formatters/bbcode.py +1 -1
  41. data/vendor/pygments-main/pygments/formatters/html.py +223 -135
  42. data/vendor/pygments-main/pygments/formatters/img.py +102 -38
  43. data/vendor/pygments-main/pygments/formatters/irc.py +39 -39
  44. data/vendor/pygments-main/pygments/formatters/latex.py +56 -26
  45. data/vendor/pygments-main/pygments/formatters/other.py +12 -8
  46. data/vendor/pygments-main/pygments/formatters/rtf.py +29 -29
  47. data/vendor/pygments-main/pygments/formatters/svg.py +38 -4
  48. data/vendor/pygments-main/pygments/formatters/terminal.py +25 -31
  49. data/vendor/pygments-main/pygments/formatters/terminal256.py +22 -12
  50. data/vendor/pygments-main/pygments/lexer.py +41 -39
  51. data/vendor/pygments-main/pygments/lexers/__init__.py +62 -15
  52. data/vendor/pygments-main/pygments/lexers/_asy_builtins.py +5 -5
  53. data/vendor/pygments-main/pygments/lexers/_cl_builtins.py +15 -15
  54. data/vendor/pygments-main/pygments/lexers/_cocoa_builtins.py +11 -12
  55. data/vendor/pygments-main/pygments/lexers/_csound_builtins.py +1717 -1338
  56. data/vendor/pygments-main/pygments/lexers/_lasso_builtins.py +8 -1
  57. data/vendor/pygments-main/pygments/lexers/_lua_builtins.py +2 -4
  58. data/vendor/pygments-main/pygments/lexers/_mapping.py +79 -33
  59. data/vendor/pygments-main/pygments/lexers/_mql_builtins.py +2 -2
  60. data/vendor/pygments-main/pygments/lexers/_mysql_builtins.py +1282 -0
  61. data/vendor/pygments-main/pygments/lexers/_openedge_builtins.py +1 -1
  62. data/vendor/pygments-main/pygments/lexers/_php_builtins.py +17 -20
  63. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +73 -16
  64. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +2 -2
  65. data/vendor/pygments-main/pygments/lexers/_sourcemod_builtins.py +1 -3
  66. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +151 -125
  67. data/vendor/pygments-main/pygments/lexers/_stata_builtins.py +6 -4
  68. data/vendor/pygments-main/pygments/lexers/_tsql_builtins.py +1 -1
  69. data/vendor/pygments-main/pygments/lexers/_usd_builtins.py +113 -0
  70. data/vendor/pygments-main/pygments/lexers/_vbscript_builtins.py +280 -0
  71. data/vendor/pygments-main/pygments/lexers/_vim_builtins.py +1 -1
  72. data/vendor/pygments-main/pygments/lexers/actionscript.py +8 -3
  73. data/vendor/pygments-main/pygments/lexers/agile.py +1 -1
  74. data/vendor/pygments-main/pygments/lexers/algebra.py +20 -1
  75. data/vendor/pygments-main/pygments/lexers/ambient.py +1 -1
  76. data/vendor/pygments-main/pygments/lexers/ampl.py +3 -3
  77. data/vendor/pygments-main/pygments/lexers/apl.py +15 -15
  78. data/vendor/pygments-main/pygments/lexers/archetype.py +3 -3
  79. data/vendor/pygments-main/pygments/lexers/arrow.py +117 -0
  80. data/vendor/pygments-main/pygments/lexers/asm.py +445 -70
  81. data/vendor/pygments-main/pygments/lexers/automation.py +3 -3
  82. data/vendor/pygments-main/pygments/lexers/bare.py +104 -0
  83. data/vendor/pygments-main/pygments/lexers/basic.py +166 -4
  84. data/vendor/pygments-main/pygments/lexers/bibtex.py +13 -9
  85. data/vendor/pygments-main/pygments/lexers/boa.py +102 -0
  86. data/vendor/pygments-main/pygments/lexers/business.py +69 -36
  87. data/vendor/pygments-main/pygments/lexers/c_cpp.py +137 -45
  88. data/vendor/pygments-main/pygments/lexers/c_like.py +68 -43
  89. data/vendor/pygments-main/pygments/lexers/capnproto.py +20 -21
  90. data/vendor/pygments-main/pygments/lexers/chapel.py +25 -14
  91. data/vendor/pygments-main/pygments/lexers/clean.py +135 -244
  92. data/vendor/pygments-main/pygments/lexers/compiled.py +1 -1
  93. data/vendor/pygments-main/pygments/lexers/configs.py +188 -37
  94. data/vendor/pygments-main/pygments/lexers/console.py +1 -1
  95. data/vendor/pygments-main/pygments/lexers/crystal.py +31 -23
  96. data/vendor/pygments-main/pygments/lexers/csound.py +288 -187
  97. data/vendor/pygments-main/pygments/lexers/css.py +18 -16
  98. data/vendor/pygments-main/pygments/lexers/d.py +10 -5
  99. data/vendor/pygments-main/pygments/lexers/dalvik.py +1 -1
  100. data/vendor/pygments-main/pygments/lexers/data.py +240 -97
  101. data/vendor/pygments-main/pygments/lexers/devicetree.py +109 -0
  102. data/vendor/pygments-main/pygments/lexers/diff.py +4 -4
  103. data/vendor/pygments-main/pygments/lexers/dotnet.py +40 -24
  104. data/vendor/pygments-main/pygments/lexers/dsls.py +147 -65
  105. data/vendor/pygments-main/pygments/lexers/dylan.py +16 -18
  106. data/vendor/pygments-main/pygments/lexers/ecl.py +16 -2
  107. data/vendor/pygments-main/pygments/lexers/eiffel.py +1 -1
  108. data/vendor/pygments-main/pygments/lexers/elm.py +5 -5
  109. data/vendor/pygments-main/pygments/lexers/email.py +151 -0
  110. data/vendor/pygments-main/pygments/lexers/erlang.py +29 -32
  111. data/vendor/pygments-main/pygments/lexers/esoteric.py +54 -25
  112. data/vendor/pygments-main/pygments/lexers/ezhil.py +24 -15
  113. data/vendor/pygments-main/pygments/lexers/factor.py +1 -1
  114. data/vendor/pygments-main/pygments/lexers/fantom.py +1 -1
  115. data/vendor/pygments-main/pygments/lexers/felix.py +1 -1
  116. data/vendor/pygments-main/pygments/lexers/floscript.py +83 -0
  117. data/vendor/pygments-main/pygments/lexers/forth.py +41 -40
  118. data/vendor/pygments-main/pygments/lexers/fortran.py +5 -4
  119. data/vendor/pygments-main/pygments/lexers/foxpro.py +2 -2
  120. data/vendor/pygments-main/pygments/lexers/freefem.py +898 -0
  121. data/vendor/pygments-main/pygments/lexers/functional.py +1 -1
  122. data/vendor/pygments-main/pygments/lexers/gdscript.py +346 -0
  123. data/vendor/pygments-main/pygments/lexers/go.py +1 -1
  124. data/vendor/pygments-main/pygments/lexers/grammar_notation.py +63 -6
  125. data/vendor/pygments-main/pygments/lexers/graph.py +14 -9
  126. data/vendor/pygments-main/pygments/lexers/graphics.py +272 -25
  127. data/vendor/pygments-main/pygments/lexers/haskell.py +52 -22
  128. data/vendor/pygments-main/pygments/lexers/haxe.py +6 -6
  129. data/vendor/pygments-main/pygments/lexers/hdl.py +176 -86
  130. data/vendor/pygments-main/pygments/lexers/hexdump.py +18 -12
  131. data/vendor/pygments-main/pygments/lexers/html.py +31 -19
  132. data/vendor/pygments-main/pygments/lexers/idl.py +20 -9
  133. data/vendor/pygments-main/pygments/lexers/igor.py +244 -112
  134. data/vendor/pygments-main/pygments/lexers/inferno.py +2 -2
  135. data/vendor/pygments-main/pygments/lexers/installers.py +1 -1
  136. data/vendor/pygments-main/pygments/lexers/int_fiction.py +40 -15
  137. data/vendor/pygments-main/pygments/lexers/iolang.py +2 -2
  138. data/vendor/pygments-main/pygments/lexers/j.py +3 -3
  139. data/vendor/pygments-main/pygments/lexers/javascript.py +100 -66
  140. data/vendor/pygments-main/pygments/lexers/julia.py +46 -48
  141. data/vendor/pygments-main/pygments/lexers/jvm.py +265 -165
  142. data/vendor/pygments-main/pygments/lexers/lisp.py +882 -804
  143. data/vendor/pygments-main/pygments/lexers/make.py +10 -6
  144. data/vendor/pygments-main/pygments/lexers/markup.py +213 -43
  145. data/vendor/pygments-main/pygments/lexers/math.py +1 -1
  146. data/vendor/pygments-main/pygments/lexers/matlab.py +98 -41
  147. data/vendor/pygments-main/pygments/lexers/mime.py +226 -0
  148. data/vendor/pygments-main/pygments/lexers/ml.py +198 -9
  149. data/vendor/pygments-main/pygments/lexers/modeling.py +26 -18
  150. data/vendor/pygments-main/pygments/lexers/modula2.py +25 -6
  151. data/vendor/pygments-main/pygments/lexers/monte.py +4 -3
  152. data/vendor/pygments-main/pygments/lexers/mosel.py +448 -0
  153. data/vendor/pygments-main/pygments/lexers/ncl.py +85 -244
  154. data/vendor/pygments-main/pygments/lexers/nimrod.py +4 -4
  155. data/vendor/pygments-main/pygments/lexers/nit.py +1 -1
  156. data/vendor/pygments-main/pygments/lexers/nix.py +1 -1
  157. data/vendor/pygments-main/pygments/lexers/oberon.py +17 -1
  158. data/vendor/pygments-main/pygments/lexers/objective.py +16 -16
  159. data/vendor/pygments-main/pygments/lexers/ooc.py +1 -1
  160. data/vendor/pygments-main/pygments/lexers/other.py +1 -1
  161. data/vendor/pygments-main/pygments/lexers/parasail.py +1 -1
  162. data/vendor/pygments-main/pygments/lexers/parsers.py +23 -58
  163. data/vendor/pygments-main/pygments/lexers/pascal.py +23 -23
  164. data/vendor/pygments-main/pygments/lexers/pawn.py +30 -24
  165. data/vendor/pygments-main/pygments/lexers/perl.py +276 -160
  166. data/vendor/pygments-main/pygments/lexers/php.py +64 -10
  167. data/vendor/pygments-main/pygments/lexers/pointless.py +71 -0
  168. data/vendor/pygments-main/pygments/lexers/pony.py +94 -0
  169. data/vendor/pygments-main/pygments/lexers/praat.py +38 -30
  170. data/vendor/pygments-main/pygments/lexers/prolog.py +36 -36
  171. data/vendor/pygments-main/pygments/lexers/promql.py +183 -0
  172. data/vendor/pygments-main/pygments/lexers/python.py +439 -226
  173. data/vendor/pygments-main/pygments/lexers/qvt.py +6 -6
  174. data/vendor/pygments-main/pygments/lexers/r.py +13 -275
  175. data/vendor/pygments-main/pygments/lexers/rdf.py +232 -39
  176. data/vendor/pygments-main/pygments/lexers/rebol.py +8 -8
  177. data/vendor/pygments-main/pygments/lexers/resource.py +2 -2
  178. data/vendor/pygments-main/pygments/lexers/ride.py +139 -0
  179. data/vendor/pygments-main/pygments/lexers/rnc.py +1 -1
  180. data/vendor/pygments-main/pygments/lexers/roboconf.py +1 -1
  181. data/vendor/pygments-main/pygments/lexers/robotframework.py +23 -31
  182. data/vendor/pygments-main/pygments/lexers/ruby.py +22 -24
  183. data/vendor/pygments-main/pygments/lexers/rust.py +86 -71
  184. data/vendor/pygments-main/pygments/lexers/sas.py +7 -7
  185. data/vendor/pygments-main/pygments/lexers/scdoc.py +83 -0
  186. data/vendor/pygments-main/pygments/lexers/scripting.py +75 -13
  187. data/vendor/pygments-main/pygments/lexers/sgf.py +61 -0
  188. data/vendor/pygments-main/pygments/lexers/shell.py +175 -51
  189. data/vendor/pygments-main/pygments/lexers/sieve.py +69 -0
  190. data/vendor/pygments-main/pygments/lexers/slash.py +185 -0
  191. data/vendor/pygments-main/pygments/lexers/smalltalk.py +2 -2
  192. data/vendor/pygments-main/pygments/lexers/smv.py +30 -26
  193. data/vendor/pygments-main/pygments/lexers/snobol.py +1 -1
  194. data/vendor/pygments-main/pygments/lexers/solidity.py +92 -0
  195. data/vendor/pygments-main/pygments/lexers/special.py +5 -3
  196. data/vendor/pygments-main/pygments/lexers/sql.py +333 -177
  197. data/vendor/pygments-main/pygments/lexers/stata.py +107 -42
  198. data/vendor/pygments-main/pygments/lexers/supercollider.py +6 -1
  199. data/vendor/pygments-main/pygments/lexers/tcl.py +1 -1
  200. data/vendor/pygments-main/pygments/lexers/templates.py +144 -132
  201. data/vendor/pygments-main/pygments/lexers/teraterm.py +335 -0
  202. data/vendor/pygments-main/pygments/lexers/testing.py +6 -6
  203. data/vendor/pygments-main/pygments/lexers/text.py +2 -1
  204. data/vendor/pygments-main/pygments/lexers/textedit.py +4 -4
  205. data/vendor/pygments-main/pygments/lexers/textfmts.py +146 -13
  206. data/vendor/pygments-main/pygments/lexers/theorem.py +69 -53
  207. data/vendor/pygments-main/pygments/lexers/tnt.py +263 -0
  208. data/vendor/pygments-main/pygments/lexers/trafficscript.py +1 -1
  209. data/vendor/pygments-main/pygments/lexers/typoscript.py +8 -14
  210. data/vendor/pygments-main/pygments/lexers/unicon.py +412 -0
  211. data/vendor/pygments-main/pygments/lexers/urbi.py +14 -1
  212. data/vendor/pygments-main/pygments/lexers/usd.py +90 -0
  213. data/vendor/pygments-main/pygments/lexers/varnish.py +5 -5
  214. data/vendor/pygments-main/pygments/lexers/verification.py +15 -12
  215. data/vendor/pygments-main/pygments/lexers/web.py +1 -1
  216. data/vendor/pygments-main/pygments/lexers/webidl.py +299 -0
  217. data/vendor/pygments-main/pygments/lexers/webmisc.py +50 -38
  218. data/vendor/pygments-main/pygments/lexers/whiley.py +11 -12
  219. data/vendor/pygments-main/pygments/lexers/x10.py +1 -1
  220. data/vendor/pygments-main/pygments/lexers/xorg.py +37 -0
  221. data/vendor/pygments-main/pygments/lexers/yang.py +104 -0
  222. data/vendor/pygments-main/pygments/lexers/zig.py +124 -0
  223. data/vendor/pygments-main/pygments/modeline.py +6 -5
  224. data/vendor/pygments-main/pygments/plugin.py +14 -18
  225. data/vendor/pygments-main/pygments/regexopt.py +1 -1
  226. data/vendor/pygments-main/pygments/scanner.py +2 -2
  227. data/vendor/pygments-main/pygments/sphinxext.py +2 -4
  228. data/vendor/pygments-main/pygments/style.py +61 -24
  229. data/vendor/pygments-main/pygments/styles/__init__.py +13 -5
  230. data/vendor/pygments-main/pygments/styles/abap.py +29 -0
  231. data/vendor/pygments-main/pygments/styles/algol.py +1 -1
  232. data/vendor/pygments-main/pygments/styles/algol_nu.py +1 -1
  233. data/vendor/pygments-main/pygments/styles/arduino.py +2 -2
  234. data/vendor/pygments-main/pygments/styles/autumn.py +1 -1
  235. data/vendor/pygments-main/pygments/styles/borland.py +1 -1
  236. data/vendor/pygments-main/pygments/styles/bw.py +1 -1
  237. data/vendor/pygments-main/pygments/styles/colorful.py +1 -1
  238. data/vendor/pygments-main/pygments/styles/default.py +1 -1
  239. data/vendor/pygments-main/pygments/styles/emacs.py +1 -1
  240. data/vendor/pygments-main/pygments/styles/friendly.py +1 -1
  241. data/vendor/pygments-main/pygments/styles/fruity.py +1 -1
  242. data/vendor/pygments-main/pygments/styles/igor.py +1 -1
  243. data/vendor/pygments-main/pygments/styles/inkpot.py +67 -0
  244. data/vendor/pygments-main/pygments/styles/lovelace.py +1 -1
  245. data/vendor/pygments-main/pygments/styles/manni.py +1 -1
  246. data/vendor/pygments-main/pygments/styles/monokai.py +4 -3
  247. data/vendor/pygments-main/pygments/styles/murphy.py +1 -1
  248. data/vendor/pygments-main/pygments/styles/native.py +1 -1
  249. data/vendor/pygments-main/pygments/styles/paraiso_dark.py +1 -1
  250. data/vendor/pygments-main/pygments/styles/paraiso_light.py +1 -1
  251. data/vendor/pygments-main/pygments/styles/pastie.py +1 -1
  252. data/vendor/pygments-main/pygments/styles/perldoc.py +1 -1
  253. data/vendor/pygments-main/pygments/styles/rainbow_dash.py +89 -0
  254. data/vendor/pygments-main/pygments/styles/rrt.py +1 -1
  255. data/vendor/pygments-main/pygments/styles/sas.py +3 -0
  256. data/vendor/pygments-main/pygments/styles/solarized.py +134 -0
  257. data/vendor/pygments-main/pygments/styles/stata_dark.py +41 -0
  258. data/vendor/pygments-main/pygments/styles/stata_light.py +39 -0
  259. data/vendor/pygments-main/pygments/styles/tango.py +1 -1
  260. data/vendor/pygments-main/pygments/styles/trac.py +1 -1
  261. data/vendor/pygments-main/pygments/styles/vim.py +1 -1
  262. data/vendor/pygments-main/pygments/styles/vs.py +1 -1
  263. data/vendor/pygments-main/pygments/styles/xcode.py +1 -1
  264. data/vendor/pygments-main/pygments/token.py +1 -1
  265. data/vendor/pygments-main/pygments/unistring.py +47 -108
  266. data/vendor/pygments-main/pygments/util.py +19 -95
  267. metadata +72 -138
  268. data/CHANGELOG.md +0 -94
  269. data/README.md +0 -121
  270. data/circle.yml +0 -20
  271. data/test/test_data.c +0 -2581
  272. data/test/test_data.py +0 -514
  273. data/test/test_data_generated +0 -2582
  274. data/vendor/custom_lexers/github.py +0 -565
  275. data/vendor/pygments-main/CHANGES +0 -1163
  276. data/vendor/pygments-main/MANIFEST.in +0 -6
  277. data/vendor/pygments-main/Makefile +0 -65
  278. data/vendor/pygments-main/README.rst +0 -39
  279. data/vendor/pygments-main/REVISION +0 -1
  280. data/vendor/pygments-main/TODO +0 -12
  281. data/vendor/pygments-main/doc/Makefile +0 -153
  282. data/vendor/pygments-main/doc/_static/favicon.ico +0 -0
  283. data/vendor/pygments-main/doc/_static/logo_new.png +0 -0
  284. data/vendor/pygments-main/doc/_static/logo_only.png +0 -0
  285. data/vendor/pygments-main/doc/_templates/docssidebar.html +0 -3
  286. data/vendor/pygments-main/doc/_templates/indexsidebar.html +0 -25
  287. data/vendor/pygments-main/doc/_themes/pygments14/layout.html +0 -98
  288. data/vendor/pygments-main/doc/_themes/pygments14/static/bodybg.png +0 -0
  289. data/vendor/pygments-main/doc/_themes/pygments14/static/docbg.png +0 -0
  290. data/vendor/pygments-main/doc/_themes/pygments14/static/listitem.png +0 -0
  291. data/vendor/pygments-main/doc/_themes/pygments14/static/logo.png +0 -0
  292. data/vendor/pygments-main/doc/_themes/pygments14/static/pocoo.png +0 -0
  293. data/vendor/pygments-main/doc/_themes/pygments14/static/pygments14.css_t +0 -401
  294. data/vendor/pygments-main/doc/_themes/pygments14/theme.conf +0 -15
  295. data/vendor/pygments-main/doc/conf.py +0 -241
  296. data/vendor/pygments-main/doc/docs/api.rst +0 -331
  297. data/vendor/pygments-main/doc/docs/authors.rst +0 -4
  298. data/vendor/pygments-main/doc/docs/changelog.rst +0 -1
  299. data/vendor/pygments-main/doc/docs/cmdline.rst +0 -149
  300. data/vendor/pygments-main/doc/docs/filterdevelopment.rst +0 -71
  301. data/vendor/pygments-main/doc/docs/filters.rst +0 -41
  302. data/vendor/pygments-main/doc/docs/formatterdevelopment.rst +0 -169
  303. data/vendor/pygments-main/doc/docs/formatters.rst +0 -48
  304. data/vendor/pygments-main/doc/docs/index.rst +0 -66
  305. data/vendor/pygments-main/doc/docs/integrate.rst +0 -40
  306. data/vendor/pygments-main/doc/docs/java.rst +0 -70
  307. data/vendor/pygments-main/doc/docs/lexerdevelopment.rst +0 -689
  308. data/vendor/pygments-main/doc/docs/lexers.rst +0 -69
  309. data/vendor/pygments-main/doc/docs/moinmoin.rst +0 -39
  310. data/vendor/pygments-main/doc/docs/plugins.rst +0 -93
  311. data/vendor/pygments-main/doc/docs/quickstart.rst +0 -205
  312. data/vendor/pygments-main/doc/docs/rstdirective.rst +0 -22
  313. data/vendor/pygments-main/doc/docs/styles.rst +0 -201
  314. data/vendor/pygments-main/doc/docs/tokens.rst +0 -372
  315. data/vendor/pygments-main/doc/docs/unicode.rst +0 -58
  316. data/vendor/pygments-main/doc/download.rst +0 -41
  317. data/vendor/pygments-main/doc/faq.rst +0 -139
  318. data/vendor/pygments-main/doc/index.rst +0 -54
  319. data/vendor/pygments-main/doc/languages.rst +0 -154
  320. data/vendor/pygments-main/doc/make.bat +0 -190
  321. data/vendor/pygments-main/doc/pygmentize.1 +0 -94
  322. data/vendor/pygments-main/external/autopygmentize +0 -84
  323. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +0 -162
  324. data/vendor/pygments-main/external/markdown-processor.py +0 -67
  325. data/vendor/pygments-main/external/moin-parser.py +0 -112
  326. data/vendor/pygments-main/external/pygments.bashcomp +0 -38
  327. data/vendor/pygments-main/external/rst-directive.py +0 -82
  328. data/vendor/pygments-main/pygmentize +0 -8
  329. data/vendor/pygments-main/pygments/lexers/github.py +0 -565
  330. data/vendor/pygments-main/pygments/styles/stata.py +0 -37
  331. data/vendor/pygments-main/requirements.txt +0 -5
  332. data/vendor/pygments-main/scripts/check_sources.py +0 -211
  333. data/vendor/pygments-main/scripts/debug_lexer.py +0 -246
  334. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +0 -33
  335. data/vendor/pygments-main/scripts/epydoc.css +0 -280
  336. data/vendor/pygments-main/scripts/find_error.py +0 -1
  337. data/vendor/pygments-main/scripts/get_vimkw.py +0 -74
  338. data/vendor/pygments-main/scripts/pylintrc +0 -301
  339. data/vendor/pygments-main/scripts/vim2pygments.py +0 -935
  340. data/vendor/pygments-main/setup.cfg +0 -10
  341. data/vendor/pygments-main/setup.py +0 -77
  342. data/vendor/pygments-main/tox.ini +0 -7
  343. data/vendor/simplejson/.gitignore +0 -10
  344. data/vendor/simplejson/.travis.yml +0 -5
  345. data/vendor/simplejson/CHANGES.txt +0 -291
  346. data/vendor/simplejson/LICENSE.txt +0 -19
  347. data/vendor/simplejson/MANIFEST.in +0 -5
  348. data/vendor/simplejson/README.rst +0 -19
  349. data/vendor/simplejson/conf.py +0 -179
  350. data/vendor/simplejson/index.rst +0 -628
  351. data/vendor/simplejson/scripts/make_docs.py +0 -18
  352. data/vendor/simplejson/setup.py +0 -104
  353. data/vendor/simplejson/simplejson/__init__.py +0 -510
  354. data/vendor/simplejson/simplejson/_speedups.c +0 -2745
  355. data/vendor/simplejson/simplejson/decoder.py +0 -425
  356. data/vendor/simplejson/simplejson/encoder.py +0 -567
  357. data/vendor/simplejson/simplejson/ordered_dict.py +0 -119
  358. data/vendor/simplejson/simplejson/scanner.py +0 -77
  359. data/vendor/simplejson/simplejson/tests/__init__.py +0 -67
  360. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +0 -55
  361. data/vendor/simplejson/simplejson/tests/test_check_circular.py +0 -30
  362. data/vendor/simplejson/simplejson/tests/test_decimal.py +0 -66
  363. data/vendor/simplejson/simplejson/tests/test_decode.py +0 -83
  364. data/vendor/simplejson/simplejson/tests/test_default.py +0 -9
  365. data/vendor/simplejson/simplejson/tests/test_dump.py +0 -67
  366. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +0 -46
  367. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +0 -32
  368. data/vendor/simplejson/simplejson/tests/test_errors.py +0 -34
  369. data/vendor/simplejson/simplejson/tests/test_fail.py +0 -91
  370. data/vendor/simplejson/simplejson/tests/test_float.py +0 -19
  371. data/vendor/simplejson/simplejson/tests/test_indent.py +0 -86
  372. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +0 -20
  373. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +0 -121
  374. data/vendor/simplejson/simplejson/tests/test_pass1.py +0 -76
  375. data/vendor/simplejson/simplejson/tests/test_pass2.py +0 -14
  376. data/vendor/simplejson/simplejson/tests/test_pass3.py +0 -20
  377. data/vendor/simplejson/simplejson/tests/test_recursion.py +0 -67
  378. data/vendor/simplejson/simplejson/tests/test_scanstring.py +0 -117
  379. data/vendor/simplejson/simplejson/tests/test_separators.py +0 -42
  380. data/vendor/simplejson/simplejson/tests/test_speedups.py +0 -20
  381. data/vendor/simplejson/simplejson/tests/test_tuple.py +0 -49
  382. data/vendor/simplejson/simplejson/tests/test_unicode.py +0 -109
  383. data/vendor/simplejson/simplejson/tool.py +0 -39
@@ -1,66 +0,0 @@
1
- Pygments documentation
2
- ======================
3
-
4
- **Starting with Pygments**
5
-
6
- .. toctree::
7
- :maxdepth: 1
8
-
9
- ../download
10
- quickstart
11
- cmdline
12
-
13
- **Builtin components**
14
-
15
- .. toctree::
16
- :maxdepth: 1
17
-
18
- lexers
19
- filters
20
- formatters
21
- styles
22
-
23
- **Reference**
24
-
25
- .. toctree::
26
- :maxdepth: 1
27
-
28
- unicode
29
- tokens
30
- api
31
-
32
- **Hacking for Pygments**
33
-
34
- .. toctree::
35
- :maxdepth: 1
36
-
37
- lexerdevelopment
38
- formatterdevelopment
39
- filterdevelopment
40
- plugins
41
-
42
- **Hints and tricks**
43
-
44
- .. toctree::
45
- :maxdepth: 1
46
-
47
- rstdirective
48
- moinmoin
49
- java
50
- integrate
51
-
52
- **About Pygments**
53
-
54
- .. toctree::
55
- :maxdepth: 1
56
-
57
- changelog
58
- authors
59
-
60
-
61
- If you find bugs or have suggestions for the documentation, please look
62
- :ref:`here <contribute>` for info on how to contact the team.
63
-
64
- .. XXX You can download an offline version of this documentation from the
65
- :doc:`download page </download>`.
66
-
@@ -1,40 +0,0 @@
1
- .. -*- mode: rst -*-
2
-
3
- ===================================
4
- Using Pygments in various scenarios
5
- ===================================
6
-
7
- Markdown
8
- --------
9
-
10
- Since Pygments 0.9, the distribution ships Markdown_ preprocessor sample code
11
- that uses Pygments to render source code in
12
- :file:`external/markdown-processor.py`. You can copy and adapt it to your
13
- liking.
14
-
15
- .. _Markdown: http://www.freewisdom.org/projects/python-markdown/
16
-
17
- TextMate
18
- --------
19
-
20
- Antonio Cangiano has created a Pygments bundle for TextMate that allows to
21
- colorize code via a simple menu option. It can be found here_.
22
-
23
- .. _here: http://antoniocangiano.com/2008/10/28/pygments-textmate-bundle/
24
-
25
- Bash completion
26
- ---------------
27
-
28
- The source distribution contains a file ``external/pygments.bashcomp`` that
29
- sets up completion for the ``pygmentize`` command in bash.
30
-
31
- Wrappers for other languages
32
- ----------------------------
33
-
34
- These libraries provide Pygments highlighting for users of other languages
35
- than Python:
36
-
37
- * `pygments.rb <https://github.com/tmm1/pygments.rb>`_, a pygments wrapper for Ruby
38
- * `Clygments <https://github.com/bfontaine/clygments>`_, a pygments wrapper for
39
- Clojure
40
- * `PHPygments <https://github.com/capynet/PHPygments>`_, a pygments wrapper for PHP
@@ -1,70 +0,0 @@
1
- =====================
2
- Use Pygments in Java
3
- =====================
4
-
5
- Thanks to `Jython <http://www.jython.org>`_ it is possible to use Pygments in
6
- Java.
7
-
8
- This page is a simple tutorial to get an idea of how this works. You can
9
- then look at the `Jython documentation <http://www.jython.org/docs/>`_ for more
10
- advanced uses.
11
-
12
- Since version 1.5, Pygments is deployed on `Maven Central
13
- <http://repo1.maven.org/maven2/org/pygments/pygments/>`_ as a JAR, as is Jython
14
- which makes it a lot easier to create a Java project.
15
-
16
- Here is an example of a `Maven <http://www.maven.org>`_ ``pom.xml`` file for a
17
- project running Pygments:
18
-
19
- .. sourcecode:: xml
20
-
21
- <?xml version="1.0" encoding="UTF-8"?>
22
-
23
- <project xmlns="http://maven.apache.org/POM/4.0.0"
24
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
25
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
26
- http://maven.apache.org/maven-v4_0_0.xsd">
27
- <modelVersion>4.0.0</modelVersion>
28
- <groupId>example</groupId>
29
- <artifactId>example</artifactId>
30
- <version>1.0-SNAPSHOT</version>
31
- <dependencies>
32
- <dependency>
33
- <groupId>org.python</groupId>
34
- <artifactId>jython-standalone</artifactId>
35
- <version>2.5.3</version>
36
- </dependency>
37
- <dependency>
38
- <groupId>org.pygments</groupId>
39
- <artifactId>pygments</artifactId>
40
- <version>1.5</version>
41
- <scope>runtime</scope>
42
- </dependency>
43
- </dependencies>
44
- </project>
45
-
46
- The following Java example:
47
-
48
- .. sourcecode:: java
49
-
50
- PythonInterpreter interpreter = new PythonInterpreter();
51
-
52
- // Set a variable with the content you want to work with
53
- interpreter.set("code", code);
54
-
55
- // Simple use Pygments as you would in Python
56
- interpreter.exec("from pygments import highlight\n"
57
- + "from pygments.lexers import PythonLexer\n"
58
- + "from pygments.formatters import HtmlFormatter\n"
59
- + "\nresult = highlight(code, PythonLexer(), HtmlFormatter())");
60
-
61
- // Get the result that has been set in a variable
62
- System.out.println(interpreter.get("result", String.class));
63
-
64
- will print something like:
65
-
66
- .. sourcecode:: html
67
-
68
- <div class="highlight">
69
- <pre><span class="k">print</span> <span class="s">&quot;Hello World&quot;</span></pre>
70
- </div>
@@ -1,689 +0,0 @@
1
- .. -*- mode: rst -*-
2
-
3
- .. highlight:: python
4
-
5
- ====================
6
- Write your own lexer
7
- ====================
8
-
9
- If a lexer for your favorite language is missing in the Pygments package, you
10
- can easily write your own and extend Pygments.
11
-
12
- All you need can be found inside the :mod:`pygments.lexer` module. As you can
13
- read in the :doc:`API documentation <api>`, a lexer is a class that is
14
- initialized with some keyword arguments (the lexer options) and that provides a
15
- :meth:`.get_tokens_unprocessed()` method which is given a string or unicode
16
- object with the data to lex.
17
-
18
- The :meth:`.get_tokens_unprocessed()` method must return an iterator or iterable
19
- containing tuples in the form ``(index, token, value)``. Normally you don't
20
- need to do this since there are base lexers that do most of the work and that
21
- you can subclass.
22
-
23
-
24
- RegexLexer
25
- ==========
26
-
27
- The lexer base class used by almost all of Pygments' lexers is the
28
- :class:`RegexLexer`. This class allows you to define lexing rules in terms of
29
- *regular expressions* for different *states*.
30
-
31
- States are groups of regular expressions that are matched against the input
32
- string at the *current position*. If one of these expressions matches, a
33
- corresponding action is performed (such as yielding a token with a specific
34
- type, or changing state), the current position is set to where the last match
35
- ended and the matching process continues with the first regex of the current
36
- state.
37
-
38
- Lexer states are kept on a stack: each time a new state is entered, the new
39
- state is pushed onto the stack. The most basic lexers (like the `DiffLexer`)
40
- just need one state.
41
-
42
- Each state is defined as a list of tuples in the form (`regex`, `action`,
43
- `new_state`) where the last item is optional. In the most basic form, `action`
44
- is a token type (like `Name.Builtin`). That means: When `regex` matches, emit a
45
- token with the match text and type `tokentype` and push `new_state` on the state
46
- stack. If the new state is ``'#pop'``, the topmost state is popped from the
47
- stack instead. To pop more than one state, use ``'#pop:2'`` and so on.
48
- ``'#push'`` is a synonym for pushing the current state on the stack.
49
-
50
- The following example shows the `DiffLexer` from the builtin lexers. Note that
51
- it contains some additional attributes `name`, `aliases` and `filenames` which
52
- aren't required for a lexer. They are used by the builtin lexer lookup
53
- functions. ::
54
-
55
- from pygments.lexer import RegexLexer
56
- from pygments.token import *
57
-
58
- class DiffLexer(RegexLexer):
59
- name = 'Diff'
60
- aliases = ['diff']
61
- filenames = ['*.diff']
62
-
63
- tokens = {
64
- 'root': [
65
- (r' .*\n', Text),
66
- (r'\+.*\n', Generic.Inserted),
67
- (r'-.*\n', Generic.Deleted),
68
- (r'@.*\n', Generic.Subheading),
69
- (r'Index.*\n', Generic.Heading),
70
- (r'=.*\n', Generic.Heading),
71
- (r'.*\n', Text),
72
- ]
73
- }
74
-
75
- As you can see this lexer only uses one state. When the lexer starts scanning
76
- the text, it first checks if the current character is a space. If this is true
77
- it scans everything until newline and returns the data as a `Text` token (which
78
- is the "no special highlighting" token).
79
-
80
- If this rule doesn't match, it checks if the current char is a plus sign. And
81
- so on.
82
-
83
- If no rule matches at the current position, the current char is emitted as an
84
- `Error` token that indicates a lexing error, and the position is increased by
85
- one.
86
-
87
-
88
- Adding and testing a new lexer
89
- ==============================
90
-
91
- Using a lexer that is not part of Pygments can be done via the Python API. You
92
- can import and instantiate the lexer, and pass it to :func:`pygments.highlight`.
93
-
94
- To prepare your new lexer for inclusion in the Pygments distribution, so that it
95
- will be found when passing filenames or lexer aliases from the command line, you
96
- have to perform the following steps.
97
-
98
- First, change to the current directory containing the Pygments source code. You
99
- will need to have either an unpacked source tarball, or (preferably) a copy
100
- cloned from BitBucket.
101
-
102
- .. code-block:: console
103
-
104
- $ cd .../pygments-main
105
-
106
- Select a matching module under ``pygments/lexers``, or create a new module for
107
- your lexer class.
108
-
109
- Next, make sure the lexer is known from outside of the module. All modules in
110
- the ``pygments.lexers`` package specify ``__all__``. For example,
111
- ``esoteric.py`` sets::
112
-
113
- __all__ = ['BrainfuckLexer', 'BefungeLexer', ...]
114
-
115
- Add the name of your lexer class to this list (or create the list if your lexer
116
- is the only class in the module).
117
-
118
- Finally the lexer can be made publicly known by rebuilding the lexer mapping:
119
-
120
- .. code-block:: console
121
-
122
- $ make mapfiles
123
-
124
- To test the new lexer, store an example file with the proper extension in
125
- ``tests/examplefiles``. For example, to test your ``DiffLexer``, add a
126
- ``tests/examplefiles/example.diff`` containing a sample diff output.
127
-
128
- Now you can use pygmentize to render your example to HTML:
129
-
130
- .. code-block:: console
131
-
132
- $ ./pygmentize -O full -f html -o /tmp/example.html tests/examplefiles/example.diff
133
-
134
- Note that this explicitly calls the ``pygmentize`` in the current directory
135
- by preceding it with ``./``. This ensures your modifications are used.
136
- Otherwise a possibly already installed, unmodified version without your new
137
- lexer would have been called from the system search path (``$PATH``).
138
-
139
- To view the result, open ``/tmp/example.html`` in your browser.
140
-
141
- Once the example renders as expected, you should run the complete test suite:
142
-
143
- .. code-block:: console
144
-
145
- $ make test
146
-
147
- It also tests that your lexer fulfills the lexer API and certain invariants,
148
- such as that the concatenation of all token text is the same as the input text.
149
-
150
-
151
- Regex Flags
152
- ===========
153
-
154
- You can either define regex flags locally in the regex (``r'(?x)foo bar'``) or
155
- globally by adding a `flags` attribute to your lexer class. If no attribute is
156
- defined, it defaults to `re.MULTILINE`. For more information about regular
157
- expression flags see the page about `regular expressions`_ in the Python
158
- documentation.
159
-
160
- .. _regular expressions: http://docs.python.org/library/re.html#regular-expression-syntax
161
-
162
-
163
- Scanning multiple tokens at once
164
- ================================
165
-
166
- So far, the `action` element in the rule tuple of regex, action and state has
167
- been a single token type. Now we look at the first of several other possible
168
- values.
169
-
170
- Here is a more complex lexer that highlights INI files. INI files consist of
171
- sections, comments and ``key = value`` pairs::
172
-
173
- from pygments.lexer import RegexLexer, bygroups
174
- from pygments.token import *
175
-
176
- class IniLexer(RegexLexer):
177
- name = 'INI'
178
- aliases = ['ini', 'cfg']
179
- filenames = ['*.ini', '*.cfg']
180
-
181
- tokens = {
182
- 'root': [
183
- (r'\s+', Text),
184
- (r';.*?$', Comment),
185
- (r'\[.*?\]$', Keyword),
186
- (r'(.*?)(\s*)(=)(\s*)(.*?)$',
187
- bygroups(Name.Attribute, Text, Operator, Text, String))
188
- ]
189
- }
190
-
191
- The lexer first looks for whitespace, comments and section names. Later it
192
- looks for a line that looks like a key, value pair, separated by an ``'='``
193
- sign, and optional whitespace.
194
-
195
- The `bygroups` helper yields each capturing group in the regex with a different
196
- token type. First the `Name.Attribute` token, then a `Text` token for the
197
- optional whitespace, after that a `Operator` token for the equals sign. Then a
198
- `Text` token for the whitespace again. The rest of the line is returned as
199
- `String`.
200
-
201
- Note that for this to work, every part of the match must be inside a capturing
202
- group (a ``(...)``), and there must not be any nested capturing groups. If you
203
- nevertheless need a group, use a non-capturing group defined using this syntax:
204
- ``(?:some|words|here)`` (note the ``?:`` after the beginning parenthesis).
205
-
206
- If you find yourself needing a capturing group inside the regex which shouldn't
207
- be part of the output but is used in the regular expressions for backreferencing
208
- (eg: ``r'(<(foo|bar)>)(.*?)(</\2>)'``), you can pass `None` to the bygroups
209
- function and that group will be skipped in the output.
210
-
211
-
212
- Changing states
213
- ===============
214
-
215
- Many lexers need multiple states to work as expected. For example, some
216
- languages allow multiline comments to be nested. Since this is a recursive
217
- pattern it's impossible to lex just using regular expressions.
218
-
219
- Here is a lexer that recognizes C++ style comments (multi-line with ``/* */``
220
- and single-line with ``//`` until end of line)::
221
-
222
- from pygments.lexer import RegexLexer
223
- from pygments.token import *
224
-
225
- class CppCommentLexer(RegexLexer):
226
- name = 'Example Lexer with states'
227
-
228
- tokens = {
229
- 'root': [
230
- (r'[^/]+', Text),
231
- (r'/\*', Comment.Multiline, 'comment'),
232
- (r'//.*?$', Comment.Singleline),
233
- (r'/', Text)
234
- ],
235
- 'comment': [
236
- (r'[^*/]', Comment.Multiline),
237
- (r'/\*', Comment.Multiline, '#push'),
238
- (r'\*/', Comment.Multiline, '#pop'),
239
- (r'[*/]', Comment.Multiline)
240
- ]
241
- }
242
-
243
- This lexer starts lexing in the ``'root'`` state. It tries to match as much as
244
- possible until it finds a slash (``'/'``). If the next character after the slash
245
- is an asterisk (``'*'``) the `RegexLexer` sends those two characters to the
246
- output stream marked as `Comment.Multiline` and continues lexing with the rules
247
- defined in the ``'comment'`` state.
248
-
249
- If there wasn't an asterisk after the slash, the `RegexLexer` checks if it's a
250
- Singleline comment (i.e. followed by a second slash). If this also wasn't the
251
- case it must be a single slash, which is not a comment starter (the separate
252
- regex for a single slash must also be given, else the slash would be marked as
253
- an error token).
254
-
255
- Inside the ``'comment'`` state, we do the same thing again. Scan until the
256
- lexer finds a star or slash. If it's the opening of a multiline comment, push
257
- the ``'comment'`` state on the stack and continue scanning, again in the
258
- ``'comment'`` state. Else, check if it's the end of the multiline comment. If
259
- yes, pop one state from the stack.
260
-
261
- Note: If you pop from an empty stack you'll get an `IndexError`. (There is an
262
- easy way to prevent this from happening: don't ``'#pop'`` in the root state).
263
-
264
- If the `RegexLexer` encounters a newline that is flagged as an error token, the
265
- stack is emptied and the lexer continues scanning in the ``'root'`` state. This
266
- can help producing error-tolerant highlighting for erroneous input, e.g. when a
267
- single-line string is not closed.
268
-
269
-
270
- Advanced state tricks
271
- =====================
272
-
273
- There are a few more things you can do with states:
274
-
275
- - You can push multiple states onto the stack if you give a tuple instead of a
276
- simple string as the third item in a rule tuple. For example, if you want to
277
- match a comment containing a directive, something like:
278
-
279
- .. code-block:: text
280
-
281
- /* <processing directive> rest of comment */
282
-
283
- you can use this rule::
284
-
285
- tokens = {
286
- 'root': [
287
- (r'/\* <', Comment, ('comment', 'directive')),
288
- ...
289
- ],
290
- 'directive': [
291
- (r'[^>]*', Comment.Directive),
292
- (r'>', Comment, '#pop'),
293
- ],
294
- 'comment': [
295
- (r'[^*]+', Comment),
296
- (r'\*/', Comment, '#pop'),
297
- (r'\*', Comment),
298
- ]
299
- }
300
-
301
- When this encounters the above sample, first ``'comment'`` and ``'directive'``
302
- are pushed onto the stack, then the lexer continues in the directive state
303
- until it finds the closing ``>``, then it continues in the comment state until
304
- the closing ``*/``. Then, both states are popped from the stack again and
305
- lexing continues in the root state.
306
-
307
- .. versionadded:: 0.9
308
- The tuple can contain the special ``'#push'`` and ``'#pop'`` (but not
309
- ``'#pop:n'``) directives.
310
-
311
-
312
- - You can include the rules of a state in the definition of another. This is
313
- done by using `include` from `pygments.lexer`::
314
-
315
- from pygments.lexer import RegexLexer, bygroups, include
316
- from pygments.token import *
317
-
318
- class ExampleLexer(RegexLexer):
319
- tokens = {
320
- 'comments': [
321
- (r'/\*.*?\*/', Comment),
322
- (r'//.*?\n', Comment),
323
- ],
324
- 'root': [
325
- include('comments'),
326
- (r'(function )(\w+)( {)',
327
- bygroups(Keyword, Name, Keyword), 'function'),
328
- (r'.', Text),
329
- ],
330
- 'function': [
331
- (r'[^}/]+', Text),
332
- include('comments'),
333
- (r'/', Text),
334
- (r'\}', Keyword, '#pop'),
335
- ]
336
- }
337
-
338
- This is a hypothetical lexer for a language that consist of functions and
339
- comments. Because comments can occur at toplevel and in functions, we need
340
- rules for comments in both states. As you can see, the `include` helper saves
341
- repeating rules that occur more than once (in this example, the state
342
- ``'comment'`` will never be entered by the lexer, as it's only there to be
343
- included in ``'root'`` and ``'function'``).
344
-
345
- - Sometimes, you may want to "combine" a state from existing ones. This is
346
- possible with the `combined` helper from `pygments.lexer`.
347
-
348
- If you, instead of a new state, write ``combined('state1', 'state2')`` as the
349
- third item of a rule tuple, a new anonymous state will be formed from state1
350
- and state2 and if the rule matches, the lexer will enter this state.
351
-
352
- This is not used very often, but can be helpful in some cases, such as the
353
- `PythonLexer`'s string literal processing.
354
-
355
- - If you want your lexer to start lexing in a different state you can modify the
356
- stack by overriding the `get_tokens_unprocessed()` method::
357
-
358
- from pygments.lexer import RegexLexer
359
-
360
- class ExampleLexer(RegexLexer):
361
- tokens = {...}
362
-
363
- def get_tokens_unprocessed(self, text, stack=('root', 'otherstate')):
364
- for item in RegexLexer.get_tokens_unprocessed(text, stack):
365
- yield item
366
-
367
- Some lexers like the `PhpLexer` use this to make the leading ``<?php``
368
- preprocessor comments optional. Note that you can crash the lexer easily by
369
- putting values into the stack that don't exist in the token map. Also
370
- removing ``'root'`` from the stack can result in strange errors!
371
-
372
- - In some lexers, a state should be popped if anything is encountered that isn't
373
- matched by a rule in the state. You could use an empty regex at the end of
374
- the state list, but Pygments provides a more obvious way of spelling that:
375
- ``default('#pop')`` is equivalent to ``('', Text, '#pop')``.
376
-
377
- .. versionadded:: 2.0
378
-
379
-
380
- Subclassing lexers derived from RegexLexer
381
- ==========================================
382
-
383
- .. versionadded:: 1.6
384
-
385
- Sometimes multiple languages are very similar, but should still be lexed by
386
- different lexer classes.
387
-
388
- When subclassing a lexer derived from RegexLexer, the ``tokens`` dictionaries
389
- defined in the parent and child class are merged. For example::
390
-
391
- from pygments.lexer import RegexLexer, inherit
392
- from pygments.token import *
393
-
394
- class BaseLexer(RegexLexer):
395
- tokens = {
396
- 'root': [
397
- ('[a-z]+', Name),
398
- (r'/\*', Comment, 'comment'),
399
- ('"', String, 'string'),
400
- ('\s+', Text),
401
- ],
402
- 'string': [
403
- ('[^"]+', String),
404
- ('"', String, '#pop'),
405
- ],
406
- 'comment': [
407
- ...
408
- ],
409
- }
410
-
411
- class DerivedLexer(BaseLexer):
412
- tokens = {
413
- 'root': [
414
- ('[0-9]+', Number),
415
- inherit,
416
- ],
417
- 'string': [
418
- (r'[^"\\]+', String),
419
- (r'\\.', String.Escape),
420
- ('"', String, '#pop'),
421
- ],
422
- }
423
-
424
- The `BaseLexer` defines two states, lexing names and strings. The
425
- `DerivedLexer` defines its own tokens dictionary, which extends the definitions
426
- of the base lexer:
427
-
428
- * The "root" state has an additional rule and then the special object `inherit`,
429
- which tells Pygments to insert the token definitions of the parent class at
430
- that point.
431
-
432
- * The "string" state is replaced entirely, since there is not `inherit` rule.
433
-
434
- * The "comment" state is inherited entirely.
435
-
436
-
437
- Using multiple lexers
438
- =====================
439
-
440
- Using multiple lexers for the same input can be tricky. One of the easiest
441
- combination techniques is shown here: You can replace the action entry in a rule
442
- tuple with a lexer class. The matched text will then be lexed with that lexer,
443
- and the resulting tokens will be yielded.
444
-
445
- For example, look at this stripped-down HTML lexer::
446
-
447
- from pygments.lexer import RegexLexer, bygroups, using
448
- from pygments.token import *
449
- from pygments.lexers.javascript import JavascriptLexer
450
-
451
- class HtmlLexer(RegexLexer):
452
- name = 'HTML'
453
- aliases = ['html']
454
- filenames = ['*.html', '*.htm']
455
-
456
- flags = re.IGNORECASE | re.DOTALL
457
- tokens = {
458
- 'root': [
459
- ('[^<&]+', Text),
460
- ('&.*?;', Name.Entity),
461
- (r'<\s*script\s*', Name.Tag, ('script-content', 'tag')),
462
- (r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
463
- (r'<\s*/\s*[a-zA-Z0-9:]+\s*>', Name.Tag),
464
- ],
465
- 'script-content': [
466
- (r'(.+?)(<\s*/\s*script\s*>)',
467
- bygroups(using(JavascriptLexer), Name.Tag),
468
- '#pop'),
469
- ]
470
- }
471
-
472
- Here the content of a ``<script>`` tag is passed to a newly created instance of
473
- a `JavascriptLexer` and not processed by the `HtmlLexer`. This is done using
474
- the `using` helper that takes the other lexer class as its parameter.
475
-
476
- Note the combination of `bygroups` and `using`. This makes sure that the
477
- content up to the ``</script>`` end tag is processed by the `JavascriptLexer`,
478
- while the end tag is yielded as a normal token with the `Name.Tag` type.
479
-
480
- Also note the ``(r'<\s*script\s*', Name.Tag, ('script-content', 'tag'))`` rule.
481
- Here, two states are pushed onto the state stack, ``'script-content'`` and
482
- ``'tag'``. That means that first ``'tag'`` is processed, which will lex
483
- attributes and the closing ``>``, then the ``'tag'`` state is popped and the
484
- next state on top of the stack will be ``'script-content'``.
485
-
486
- Since you cannot refer to the class currently being defined, use `this`
487
- (imported from `pygments.lexer`) to refer to the current lexer class, i.e.
488
- ``using(this)``. This construct may seem unnecessary, but this is often the
489
- most obvious way of lexing arbitrary syntax between fixed delimiters without
490
- introducing deeply nested states.
491
-
492
- The `using()` helper has a special keyword argument, `state`, which works as
493
- follows: if given, the lexer to use initially is not in the ``"root"`` state,
494
- but in the state given by this argument. This does not work with advanced
495
- `RegexLexer` subclasses such as `ExtendedRegexLexer` (see below).
496
-
497
- Any other keywords arguments passed to `using()` are added to the keyword
498
- arguments used to create the lexer.
499
-
500
-
501
- Delegating Lexer
502
- ================
503
-
504
- Another approach for nested lexers is the `DelegatingLexer` which is for example
505
- used for the template engine lexers. It takes two lexers as arguments on
506
- initialisation: a `root_lexer` and a `language_lexer`.
507
-
508
- The input is processed as follows: First, the whole text is lexed with the
509
- `language_lexer`. All tokens yielded with the special type of ``Other`` are
510
- then concatenated and given to the `root_lexer`. The language tokens of the
511
- `language_lexer` are then inserted into the `root_lexer`'s token stream at the
512
- appropriate positions. ::
513
-
514
- from pygments.lexer import DelegatingLexer
515
- from pygments.lexers.web import HtmlLexer, PhpLexer
516
-
517
- class HtmlPhpLexer(DelegatingLexer):
518
- def __init__(self, **options):
519
- super(HtmlPhpLexer, self).__init__(HtmlLexer, PhpLexer, **options)
520
-
521
- This procedure ensures that e.g. HTML with template tags in it is highlighted
522
- correctly even if the template tags are put into HTML tags or attributes.
523
-
524
- If you want to change the needle token ``Other`` to something else, you can give
525
- the lexer another token type as the third parameter::
526
-
527
- DelegatingLexer.__init__(MyLexer, OtherLexer, Text, **options)
528
-
529
-
530
- Callbacks
531
- =========
532
-
533
- Sometimes the grammar of a language is so complex that a lexer would be unable
534
- to process it just by using regular expressions and stacks.
535
-
536
- For this, the `RegexLexer` allows callbacks to be given in rule tuples, instead
537
- of token types (`bygroups` and `using` are nothing else but preimplemented
538
- callbacks). The callback must be a function taking two arguments:
539
-
540
- * the lexer itself
541
- * the match object for the last matched rule
542
-
543
- The callback must then return an iterable of (or simply yield) ``(index,
544
- tokentype, value)`` tuples, which are then just passed through by
545
- `get_tokens_unprocessed()`. The ``index`` here is the position of the token in
546
- the input string, ``tokentype`` is the normal token type (like `Name.Builtin`),
547
- and ``value`` the associated part of the input string.
548
-
549
- You can see an example here::
550
-
551
- from pygments.lexer import RegexLexer
552
- from pygments.token import Generic
553
-
554
- class HypotheticLexer(RegexLexer):
555
-
556
- def headline_callback(lexer, match):
557
- equal_signs = match.group(1)
558
- text = match.group(2)
559
- yield match.start(), Generic.Headline, equal_signs + text + equal_signs
560
-
561
- tokens = {
562
- 'root': [
563
- (r'(=+)(.*?)(\1)', headline_callback)
564
- ]
565
- }
566
-
567
- If the regex for the `headline_callback` matches, the function is called with
568
- the match object. Note that after the callback is done, processing continues
569
- normally, that is, after the end of the previous match. The callback has no
570
- possibility to influence the position.
571
-
572
- There are not really any simple examples for lexer callbacks, but you can see
573
- them in action e.g. in the `SMLLexer` class in `ml.py`_.
574
-
575
- .. _ml.py: http://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/ml.py
576
-
577
-
578
- The ExtendedRegexLexer class
579
- ============================
580
-
581
- The `RegexLexer`, even with callbacks, unfortunately isn't powerful enough for
582
- the funky syntax rules of languages such as Ruby.
583
-
584
- But fear not; even then you don't have to abandon the regular expression
585
- approach: Pygments has a subclass of `RegexLexer`, the `ExtendedRegexLexer`.
586
- All features known from RegexLexers are available here too, and the tokens are
587
- specified in exactly the same way, *except* for one detail:
588
-
589
- The `get_tokens_unprocessed()` method holds its internal state data not as local
590
- variables, but in an instance of the `pygments.lexer.LexerContext` class, and
591
- that instance is passed to callbacks as a third argument. This means that you
592
- can modify the lexer state in callbacks.
593
-
594
- The `LexerContext` class has the following members:
595
-
596
- * `text` -- the input text
597
- * `pos` -- the current starting position that is used for matching regexes
598
- * `stack` -- a list containing the state stack
599
- * `end` -- the maximum position to which regexes are matched, this defaults to
600
- the length of `text`
601
-
602
- Additionally, the `get_tokens_unprocessed()` method can be given a
603
- `LexerContext` instead of a string and will then process this context instead of
604
- creating a new one for the string argument.
605
-
606
- Note that because you can set the current position to anything in the callback,
607
- it won't be automatically be set by the caller after the callback is finished.
608
- For example, this is how the hypothetical lexer above would be written with the
609
- `ExtendedRegexLexer`::
610
-
611
- from pygments.lexer import ExtendedRegexLexer
612
- from pygments.token import Generic
613
-
614
- class ExHypotheticLexer(ExtendedRegexLexer):
615
-
616
- def headline_callback(lexer, match, ctx):
617
- equal_signs = match.group(1)
618
- text = match.group(2)
619
- yield match.start(), Generic.Headline, equal_signs + text + equal_signs
620
- ctx.pos = match.end()
621
-
622
- tokens = {
623
- 'root': [
624
- (r'(=+)(.*?)(\1)', headline_callback)
625
- ]
626
- }
627
-
628
- This might sound confusing (and it can really be). But it is needed, and for an
629
- example look at the Ruby lexer in `ruby.py`_.
630
-
631
- .. _ruby.py: https://bitbucket.org/birkenfeld/pygments-main/src/tip/pygments/lexers/ruby.py
632
-
633
-
634
- Handling Lists of Keywords
635
- ==========================
636
-
637
- For a relatively short list (hundreds) you can construct an optimized regular
638
- expression directly using ``words()`` (longer lists, see next section). This
639
- function handles a few things for you automatically, including escaping
640
- metacharacters and Python's first-match rather than longest-match in
641
- alternations. Feel free to put the lists themselves in
642
- ``pygments/lexers/_$lang_builtins.py`` (see examples there), and generated by
643
- code if possible.
644
-
645
- An example of using ``words()`` is something like::
646
-
647
- from pygments.lexer import RegexLexer, words, Name
648
-
649
- class MyLexer(RegexLexer):
650
-
651
- tokens = {
652
- 'root': [
653
- (words(('else', 'elseif'), suffix=r'\b'), Name.Builtin),
654
- (r'\w+', Name),
655
- ],
656
- }
657
-
658
- As you can see, you can add ``prefix`` and ``suffix`` parts to the constructed
659
- regex.
660
-
661
-
662
- Modifying Token Streams
663
- =======================
664
-
665
- Some languages ship a lot of builtin functions (for example PHP). The total
666
- amount of those functions differs from system to system because not everybody
667
- has every extension installed. In the case of PHP there are over 3000 builtin
668
- functions. That's an incredibly huge amount of functions, much more than you
669
- want to put into a regular expression.
670
-
671
- But because only `Name` tokens can be function names this is solvable by
672
- overriding the ``get_tokens_unprocessed()`` method. The following lexer
673
- subclasses the `PythonLexer` so that it highlights some additional names as
674
- pseudo keywords::
675
-
676
- from pygments.lexers.python import PythonLexer
677
- from pygments.token import Name, Keyword
678
-
679
- class MyPythonLexer(PythonLexer):
680
- EXTRA_KEYWORDS = set(('foo', 'bar', 'foobar', 'barfoo', 'spam', 'eggs'))
681
-
682
- def get_tokens_unprocessed(self, text):
683
- for index, token, value in PythonLexer.get_tokens_unprocessed(self, text):
684
- if token is Name and value in self.EXTRA_KEYWORDS:
685
- yield index, Keyword.Pseudo, value
686
- else:
687
- yield index, token, value
688
-
689
- The `PhpLexer` and `LuaLexer` use this method to resolve builtin functions.