pygments.rb-jruby 0.5.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (473) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +6 -0
  3. data/CHANGELOG.md +71 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE +17 -0
  6. data/README.md +118 -0
  7. data/Rakefile +66 -0
  8. data/bench.rb +22 -0
  9. data/cache-lexers.rb +8 -0
  10. data/lexers +0 -0
  11. data/lib/pygments.rb +8 -0
  12. data/lib/pygments/lexer.rb +148 -0
  13. data/lib/pygments/mentos.py +351 -0
  14. data/lib/pygments/popen.rb +404 -0
  15. data/lib/pygments/version.rb +3 -0
  16. data/pygments.rb.gemspec +24 -0
  17. data/test/test_data.c +2581 -0
  18. data/test/test_data.py +514 -0
  19. data/test/test_data_generated +2582 -0
  20. data/test/test_pygments.rb +287 -0
  21. data/vendor/custom_lexers/github.py +565 -0
  22. data/vendor/pygments-main/AUTHORS +153 -0
  23. data/vendor/pygments-main/CHANGES +889 -0
  24. data/vendor/pygments-main/LICENSE +25 -0
  25. data/vendor/pygments-main/MANIFEST.in +6 -0
  26. data/vendor/pygments-main/Makefile +59 -0
  27. data/vendor/pygments-main/REVISION +1 -0
  28. data/vendor/pygments-main/TODO +15 -0
  29. data/vendor/pygments-main/docs/generate.py +472 -0
  30. data/vendor/pygments-main/docs/pygmentize.1 +94 -0
  31. data/vendor/pygments-main/docs/src/api.txt +270 -0
  32. data/vendor/pygments-main/docs/src/authors.txt +5 -0
  33. data/vendor/pygments-main/docs/src/changelog.txt +5 -0
  34. data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
  35. data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
  36. data/vendor/pygments-main/docs/src/filters.txt +42 -0
  37. data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
  38. data/vendor/pygments-main/docs/src/formatters.txt +48 -0
  39. data/vendor/pygments-main/docs/src/index.txt +69 -0
  40. data/vendor/pygments-main/docs/src/installation.txt +71 -0
  41. data/vendor/pygments-main/docs/src/integrate.txt +48 -0
  42. data/vendor/pygments-main/docs/src/java.txt +70 -0
  43. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +603 -0
  44. data/vendor/pygments-main/docs/src/lexers.txt +67 -0
  45. data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
  46. data/vendor/pygments-main/docs/src/plugins.txt +93 -0
  47. data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
  48. data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
  49. data/vendor/pygments-main/docs/src/styles.txt +143 -0
  50. data/vendor/pygments-main/docs/src/tokens.txt +349 -0
  51. data/vendor/pygments-main/docs/src/unicode.txt +49 -0
  52. data/vendor/pygments-main/external/autopygmentize +64 -0
  53. data/vendor/pygments-main/external/lasso-builtins-generator-9.lasso +144 -0
  54. data/vendor/pygments-main/external/markdown-processor.py +67 -0
  55. data/vendor/pygments-main/external/moin-parser.py +112 -0
  56. data/vendor/pygments-main/external/pygments.bashcomp +38 -0
  57. data/vendor/pygments-main/external/rst-directive-old.py +77 -0
  58. data/vendor/pygments-main/external/rst-directive.py +83 -0
  59. data/vendor/pygments-main/ez_setup.py +276 -0
  60. data/vendor/pygments-main/pygmentize +7 -0
  61. data/vendor/pygments-main/pygments/__init__.py +91 -0
  62. data/vendor/pygments-main/pygments/cmdline.py +441 -0
  63. data/vendor/pygments-main/pygments/console.py +74 -0
  64. data/vendor/pygments-main/pygments/filter.py +74 -0
  65. data/vendor/pygments-main/pygments/filters/__init__.py +356 -0
  66. data/vendor/pygments-main/pygments/formatter.py +95 -0
  67. data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
  68. data/vendor/pygments-main/pygments/formatters/_mapping.py +92 -0
  69. data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
  70. data/vendor/pygments-main/pygments/formatters/html.py +821 -0
  71. data/vendor/pygments-main/pygments/formatters/img.py +553 -0
  72. data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
  73. data/vendor/pygments-main/pygments/formatters/other.py +115 -0
  74. data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
  75. data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
  76. data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
  77. data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
  78. data/vendor/pygments-main/pygments/lexer.py +765 -0
  79. data/vendor/pygments-main/pygments/lexers/__init__.py +240 -0
  80. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
  81. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
  82. data/vendor/pygments-main/pygments/lexers/_lassobuiltins.py +5172 -0
  83. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
  84. data/vendor/pygments-main/pygments/lexers/_mapping.py +354 -0
  85. data/vendor/pygments-main/pygments/lexers/_openedgebuiltins.py +562 -0
  86. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
  87. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +233 -0
  88. data/vendor/pygments-main/pygments/lexers/_robotframeworklexer.py +557 -0
  89. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +40 -0
  90. data/vendor/pygments-main/pygments/lexers/_sourcemodbuiltins.py +1072 -0
  91. data/vendor/pygments-main/pygments/lexers/_stan_builtins.py +360 -0
  92. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +13 -0
  93. data/vendor/pygments-main/pygments/lexers/agile.py +2290 -0
  94. data/vendor/pygments-main/pygments/lexers/asm.py +398 -0
  95. data/vendor/pygments-main/pygments/lexers/compiled.py +3723 -0
  96. data/vendor/pygments-main/pygments/lexers/dalvik.py +104 -0
  97. data/vendor/pygments-main/pygments/lexers/dotnet.py +671 -0
  98. data/vendor/pygments-main/pygments/lexers/foxpro.py +428 -0
  99. data/vendor/pygments-main/pygments/lexers/functional.py +2731 -0
  100. data/vendor/pygments-main/pygments/lexers/github.py +565 -0
  101. data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
  102. data/vendor/pygments-main/pygments/lexers/jvm.py +1112 -0
  103. data/vendor/pygments-main/pygments/lexers/math.py +1918 -0
  104. data/vendor/pygments-main/pygments/lexers/other.py +3778 -0
  105. data/vendor/pygments-main/pygments/lexers/parsers.py +778 -0
  106. data/vendor/pygments-main/pygments/lexers/shell.py +424 -0
  107. data/vendor/pygments-main/pygments/lexers/special.py +100 -0
  108. data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
  109. data/vendor/pygments-main/pygments/lexers/templates.py +1742 -0
  110. data/vendor/pygments-main/pygments/lexers/text.py +1893 -0
  111. data/vendor/pygments-main/pygments/lexers/web.py +4045 -0
  112. data/vendor/pygments-main/pygments/modeline.py +40 -0
  113. data/vendor/pygments-main/pygments/plugin.py +74 -0
  114. data/vendor/pygments-main/pygments/scanner.py +104 -0
  115. data/vendor/pygments-main/pygments/style.py +117 -0
  116. data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
  117. data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
  118. data/vendor/pygments-main/pygments/styles/borland.py +51 -0
  119. data/vendor/pygments-main/pygments/styles/bw.py +49 -0
  120. data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
  121. data/vendor/pygments-main/pygments/styles/default.py +73 -0
  122. data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
  123. data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
  124. data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
  125. data/vendor/pygments-main/pygments/styles/manni.py +75 -0
  126. data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
  127. data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
  128. data/vendor/pygments-main/pygments/styles/native.py +65 -0
  129. data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
  130. data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
  131. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  132. data/vendor/pygments-main/pygments/styles/tango.py +141 -0
  133. data/vendor/pygments-main/pygments/styles/trac.py +63 -0
  134. data/vendor/pygments-main/pygments/styles/vim.py +63 -0
  135. data/vendor/pygments-main/pygments/styles/vs.py +38 -0
  136. data/vendor/pygments-main/pygments/token.py +195 -0
  137. data/vendor/pygments-main/pygments/unistring.py +140 -0
  138. data/vendor/pygments-main/pygments/util.py +277 -0
  139. data/vendor/pygments-main/scripts/check_sources.py +242 -0
  140. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +32 -0
  141. data/vendor/pygments-main/scripts/epydoc.css +280 -0
  142. data/vendor/pygments-main/scripts/find_codetags.py +205 -0
  143. data/vendor/pygments-main/scripts/find_error.py +170 -0
  144. data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
  145. data/vendor/pygments-main/scripts/pylintrc +301 -0
  146. data/vendor/pygments-main/scripts/reindent.py +291 -0
  147. data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
  148. data/vendor/pygments-main/setup.cfg +7 -0
  149. data/vendor/pygments-main/setup.py +90 -0
  150. data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
  151. data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
  152. data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
  153. data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
  154. data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
  155. data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
  156. data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
  157. data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
  158. data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
  159. data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
  160. data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
  161. data/vendor/pygments-main/tests/examplefiles/BOM.js +1 -0
  162. data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
  163. data/vendor/pygments-main/tests/examplefiles/Config.in.cache +1973 -0
  164. data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
  165. data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
  166. data/vendor/pygments-main/tests/examplefiles/Deflate.fs +578 -0
  167. data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
  168. data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
  169. data/vendor/pygments-main/tests/examplefiles/Get-CommandDefinitionHtml.ps1 +66 -0
  170. data/vendor/pygments-main/tests/examplefiles/IPDispatchC.nc +104 -0
  171. data/vendor/pygments-main/tests/examplefiles/IPDispatchP.nc +671 -0
  172. data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
  173. data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
  174. data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
  175. data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
  176. data/vendor/pygments-main/tests/examplefiles/RoleQ.pm6 +23 -0
  177. data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
  178. data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
  179. data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
  180. data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
  181. data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
  182. data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
  183. data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
  184. data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
  185. data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
  186. data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
  187. data/vendor/pygments-main/tests/examplefiles/autoit_submit.au3 +25 -0
  188. data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
  189. data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
  190. data/vendor/pygments-main/tests/examplefiles/bigtest.nsi +308 -0
  191. data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
  192. data/vendor/pygments-main/tests/examplefiles/ca65_example +284 -0
  193. data/vendor/pygments-main/tests/examplefiles/cbmbas_example +9 -0
  194. data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
  195. data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
  196. data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
  197. data/vendor/pygments-main/tests/examplefiles/classes.dylan +125 -0
  198. data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
  199. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  200. data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
  201. data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
  202. data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
  203. data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
  204. data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
  205. data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
  206. data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
  207. data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
  208. data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
  209. data/vendor/pygments-main/tests/examplefiles/example.Rd +78 -0
  210. data/vendor/pygments-main/tests/examplefiles/example.bug +54 -0
  211. data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
  212. data/vendor/pygments-main/tests/examplefiles/example.ceylon +52 -0
  213. data/vendor/pygments-main/tests/examplefiles/example.clay +33 -0
  214. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  215. data/vendor/pygments-main/tests/examplefiles/example.cob +3556 -0
  216. data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
  217. data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
  218. data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
  219. data/vendor/pygments-main/tests/examplefiles/example.hx +142 -0
  220. data/vendor/pygments-main/tests/examplefiles/example.jag +48 -0
  221. data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
  222. data/vendor/pygments-main/tests/examplefiles/example.lagda +19 -0
  223. data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
  224. data/vendor/pygments-main/tests/examplefiles/example.monkey +152 -0
  225. data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
  226. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  227. data/vendor/pygments-main/tests/examplefiles/example.msc +43 -0
  228. data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
  229. data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
  230. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  231. data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
  232. data/vendor/pygments-main/tests/examplefiles/example.prg +161 -0
  233. data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
  234. data/vendor/pygments-main/tests/examplefiles/example.reg +19 -0
  235. data/vendor/pygments-main/tests/examplefiles/example.rexx +50 -0
  236. data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
  237. data/vendor/pygments-main/tests/examplefiles/example.rkt +95 -0
  238. data/vendor/pygments-main/tests/examplefiles/example.rpf +4 -0
  239. data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
  240. data/vendor/pygments-main/tests/examplefiles/example.shell-session +45 -0
  241. data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
  242. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  243. data/vendor/pygments-main/tests/examplefiles/example.stan +108 -0
  244. data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
  245. data/vendor/pygments-main/tests/examplefiles/example.ts +28 -0
  246. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  247. data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
  248. data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
  249. data/vendor/pygments-main/tests/examplefiles/example.xtend +34 -0
  250. data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
  251. data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
  252. data/vendor/pygments-main/tests/examplefiles/example2.msc +79 -0
  253. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  254. data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
  255. data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
  256. data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
  257. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  258. data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
  259. data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
  260. data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
  261. data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
  262. data/vendor/pygments-main/tests/examplefiles/garcia-wachs.kk +133 -0
  263. data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
  264. data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
  265. data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
  266. data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
  267. data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
  268. data/vendor/pygments-main/tests/examplefiles/grammar-test.p6 +22 -0
  269. data/vendor/pygments-main/tests/examplefiles/hello.smali +40 -0
  270. data/vendor/pygments-main/tests/examplefiles/hello.sp +9 -0
  271. data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
  272. data/vendor/pygments-main/tests/examplefiles/http_request_example +15 -0
  273. data/vendor/pygments-main/tests/examplefiles/http_response_example +29 -0
  274. data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
  275. data/vendor/pygments-main/tests/examplefiles/inet_pton6.dg +71 -0
  276. data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
  277. data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
  278. data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
  279. data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
  280. data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
  281. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  282. data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
  283. data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
  284. data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
  285. data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
  286. data/vendor/pygments-main/tests/examplefiles/json.lasso +301 -0
  287. data/vendor/pygments-main/tests/examplefiles/json.lasso9 +213 -0
  288. data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
  289. data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
  290. data/vendor/pygments-main/tests/examplefiles/livescript-demo.ls +41 -0
  291. data/vendor/pygments-main/tests/examplefiles/logos_example.xm +28 -0
  292. data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
  293. data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
  294. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  295. data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
  296. data/vendor/pygments-main/tests/examplefiles/matlab_sample +30 -0
  297. data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
  298. data/vendor/pygments-main/tests/examplefiles/metagrammar.treetop +455 -0
  299. data/vendor/pygments-main/tests/examplefiles/mg_sample.pro +73 -0
  300. data/vendor/pygments-main/tests/examplefiles/minehunt.qml +112 -0
  301. data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
  302. data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
  303. data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
  304. data/vendor/pygments-main/tests/examplefiles/nanomsg.intr +95 -0
  305. data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
  306. data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
  307. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
  308. data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
  309. data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
  310. data/vendor/pygments-main/tests/examplefiles/objc_example.m +32 -0
  311. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
  312. data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
  313. data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
  314. data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
  315. data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
  316. data/vendor/pygments-main/tests/examplefiles/phpMyAdmin.spec +163 -0
  317. data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
  318. data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
  319. data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
  320. data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
  321. data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
  322. data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
  323. data/vendor/pygments-main/tests/examplefiles/py3tb_test.py3tb +4 -0
  324. data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
  325. data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
  326. data/vendor/pygments-main/tests/examplefiles/pytb_test3.pytb +4 -0
  327. data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
  328. data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
  329. data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
  330. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
  331. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
  332. data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
  333. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  334. data/vendor/pygments-main/tests/examplefiles/robotframework.txt +39 -0
  335. data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
  336. data/vendor/pygments-main/tests/examplefiles/rust_example.rs +233 -0
  337. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  338. data/vendor/pygments-main/tests/examplefiles/session.dylan-console +9 -0
  339. data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
  340. data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
  341. data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
  342. data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
  343. data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
  344. data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
  345. data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
  346. data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
  347. data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
  348. data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
  349. data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
  350. data/vendor/pygments-main/tests/examplefiles/swig_java.swg +1329 -0
  351. data/vendor/pygments-main/tests/examplefiles/swig_std_vector.i +225 -0
  352. data/vendor/pygments-main/tests/examplefiles/test.R +153 -0
  353. data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
  354. data/vendor/pygments-main/tests/examplefiles/test.agda +102 -0
  355. data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
  356. data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
  357. data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
  358. data/vendor/pygments-main/tests/examplefiles/test.bb +95 -0
  359. data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
  360. data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
  361. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  362. data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
  363. data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
  364. data/vendor/pygments-main/tests/examplefiles/test.cu +36 -0
  365. data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
  366. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  367. data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
  368. data/vendor/pygments-main/tests/examplefiles/test.ebnf +31 -0
  369. data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
  370. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  371. data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
  372. data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
  373. data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
  374. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  375. data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
  376. data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
  377. data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
  378. data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
  379. data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
  380. data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
  381. data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
  382. data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
  383. data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
  384. data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
  385. data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
  386. data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
  387. data/vendor/pygments-main/tests/examplefiles/test.opa +10 -0
  388. data/vendor/pygments-main/tests/examplefiles/test.p6 +252 -0
  389. data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
  390. data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
  391. data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
  392. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  393. data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
  394. data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
  395. data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
  396. data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
  397. data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
  398. data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
  399. data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
  400. data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
  401. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  402. data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
  403. data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
  404. data/vendor/pygments-main/tests/examplefiles/test2.pypylog +120 -0
  405. data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
  406. data/vendor/pygments-main/tests/examplefiles/type.lisp +1218 -0
  407. data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
  408. data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
  409. data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
  410. data/vendor/pygments-main/tests/examplefiles/unix-io.lid +37 -0
  411. data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
  412. data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
  413. data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
  414. data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
  415. data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
  416. data/vendor/pygments-main/tests/old_run.py +138 -0
  417. data/vendor/pygments-main/tests/run.py +49 -0
  418. data/vendor/pygments-main/tests/support.py +15 -0
  419. data/vendor/pygments-main/tests/support/tags +36 -0
  420. data/vendor/pygments-main/tests/test_basic_api.py +295 -0
  421. data/vendor/pygments-main/tests/test_clexer.py +31 -0
  422. data/vendor/pygments-main/tests/test_cmdline.py +105 -0
  423. data/vendor/pygments-main/tests/test_examplefiles.py +99 -0
  424. data/vendor/pygments-main/tests/test_html_formatter.py +178 -0
  425. data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
  426. data/vendor/pygments-main/tests/test_lexers_other.py +68 -0
  427. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  428. data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
  429. data/vendor/pygments-main/tests/test_token.py +46 -0
  430. data/vendor/pygments-main/tests/test_using_api.py +40 -0
  431. data/vendor/pygments-main/tests/test_util.py +135 -0
  432. data/vendor/simplejson/.gitignore +10 -0
  433. data/vendor/simplejson/.travis.yml +5 -0
  434. data/vendor/simplejson/CHANGES.txt +291 -0
  435. data/vendor/simplejson/LICENSE.txt +19 -0
  436. data/vendor/simplejson/MANIFEST.in +5 -0
  437. data/vendor/simplejson/README.rst +19 -0
  438. data/vendor/simplejson/conf.py +179 -0
  439. data/vendor/simplejson/index.rst +628 -0
  440. data/vendor/simplejson/scripts/make_docs.py +18 -0
  441. data/vendor/simplejson/setup.py +104 -0
  442. data/vendor/simplejson/simplejson/__init__.py +510 -0
  443. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  444. data/vendor/simplejson/simplejson/decoder.py +425 -0
  445. data/vendor/simplejson/simplejson/encoder.py +567 -0
  446. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  447. data/vendor/simplejson/simplejson/scanner.py +77 -0
  448. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  449. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  450. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  451. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  452. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  453. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  454. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  455. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  456. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  457. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  458. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  459. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  460. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  461. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  462. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  463. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  464. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  465. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  466. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  467. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  468. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  469. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  470. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  471. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  472. data/vendor/simplejson/simplejson/tool.py +39 -0
  473. metadata +557 -0
@@ -0,0 +1,19 @@
1
+ module toplevel(clock,reset);
2
+ input clock;
3
+ input reset;
4
+
5
+ reg flop1;
6
+ reg flop2;
7
+
8
+ always @ (posedge reset or posedge clock)
9
+ if (reset)
10
+ begin
11
+ flop1 <= 0;
12
+ flop2 <= 1;
13
+ end
14
+ else
15
+ begin
16
+ flop1 <= flop2;
17
+ flop2 <= flop1;
18
+ end
19
+ endmodule
@@ -0,0 +1,6 @@
1
+ // Scilab
2
+ //
3
+ disp(%pi);
4
+
5
+ assert_checkequal(2+2,4);
6
+
@@ -0,0 +1,1213 @@
1
+ (***********************************************************************)
2
+ (* *)
3
+ (* Objective Caml *)
4
+ (* *)
5
+ (* Pierre Weis, projet Cristal, INRIA Rocquencourt *)
6
+ (* *)
7
+ (* Copyright 1996 Institut National de Recherche en Informatique et *)
8
+ (* en Automatique. All rights reserved. This file is distributed *)
9
+ (* under the terms of the GNU Library General Public License, with *)
10
+ (* the special exception on linking described in file ../LICENSE. *)
11
+ (* *)
12
+ (***********************************************************************)
13
+
14
+ (* $Id: format.ml,v 1.65 2005/09/26 10:13:08 weis Exp $ *)
15
+
16
+ (**************************************************************
17
+
18
+ Data structures definitions.
19
+
20
+ **************************************************************)
21
+
22
+ type size;;
23
+
24
+ external size_of_int : int -> size = "%identity";;
25
+ external int_of_size : size -> int = "%identity";;
26
+
27
+ (* Tokens are one of the following : *)
28
+
29
+ type pp_token =
30
+ | Pp_text of string (* normal text *)
31
+ | Pp_break of int * int (* complete break *)
32
+ | Pp_tbreak of int * int (* go to next tabulation *)
33
+ | Pp_stab (* set a tabulation *)
34
+ | Pp_begin of int * block_type (* beginning of a block *)
35
+ | Pp_end (* end of a block *)
36
+ | Pp_tbegin of tblock (* beginning of a tabulation block *)
37
+ | Pp_tend (* end of a tabulation block *)
38
+ | Pp_newline (* to force a newline inside a block *)
39
+ | Pp_if_newline (* to do something only if this very
40
+ line has been broken *)
41
+ | Pp_open_tag of string (* opening a tag name *)
42
+ | Pp_close_tag (* closing the most recently opened tag *)
43
+
44
+ and tag = string
45
+
46
+ and block_type =
47
+ | Pp_hbox (* Horizontal block no line breaking *)
48
+ | Pp_vbox (* Vertical block each break leads to a new line *)
49
+ | Pp_hvbox (* Horizontal-vertical block: same as vbox, except if this block
50
+ is small enough to fit on a single line *)
51
+ | Pp_hovbox (* Horizontal or Vertical block: breaks lead to new line
52
+ only when necessary to print the content of the block *)
53
+ | Pp_box (* Horizontal or Indent block: breaks lead to new line
54
+ only when necessary to print the content of the block, or
55
+ when it leads to a new indentation of the current line *)
56
+ | Pp_fits (* Internal usage: when a block fits on a single line *)
57
+
58
+ and tblock = Pp_tbox of int list ref (* Tabulation box *)
59
+ ;;
60
+
61
+ (* The Queue:
62
+ contains all formatting elements.
63
+ elements are tuples (size, token, length), where
64
+ size is set when the size of the block is known
65
+ len is the declared length of the token. *)
66
+ type pp_queue_elem = {
67
+ mutable elem_size : size; token : pp_token; length : int
68
+ };;
69
+
70
+ (* Scan stack:
71
+ each element is (left_total, queue element) where left_total
72
+ is the value of pp_left_total when the element has been enqueued. *)
73
+ type pp_scan_elem = Scan_elem of int * pp_queue_elem;;
74
+
75
+ (* Formatting stack:
76
+ used to break the lines while printing tokens.
77
+ The formatting stack contains the description of
78
+ the currently active blocks. *)
79
+ type pp_format_elem = Format_elem of block_type * int;;
80
+
81
+ (* General purpose queues, used in the formatter. *)
82
+ type 'a queue_elem = | Nil | Cons of 'a queue_cell
83
+ and 'a queue_cell = {mutable head : 'a; mutable tail : 'a queue_elem};;
84
+
85
+ type 'a queue = {
86
+ mutable insert : 'a queue_elem;
87
+ mutable body : 'a queue_elem
88
+ };;
89
+
90
+ (* The formatter specific tag handling functions. *)
91
+ type formatter_tag_functions = {
92
+ mark_open_tag : tag -> string;
93
+ mark_close_tag : tag -> string;
94
+ print_open_tag : tag -> unit;
95
+ print_close_tag : tag -> unit;
96
+
97
+ };;
98
+
99
+ (* A formatter with all its machinery. *)
100
+ type formatter = {
101
+ mutable pp_scan_stack : pp_scan_elem list;
102
+ mutable pp_format_stack : pp_format_elem list;
103
+ mutable pp_tbox_stack : tblock list;
104
+ mutable pp_tag_stack : tag list;
105
+ mutable pp_mark_stack : tag list;
106
+ (* Global variables: default initialization is
107
+ set_margin 78
108
+ set_min_space_left 0. *)
109
+ (* Value of right margin. *)
110
+ mutable pp_margin : int;
111
+ (* Minimal space left before margin, when opening a block. *)
112
+ mutable pp_min_space_left : int;
113
+ (* Maximum value of indentation:
114
+ no blocks can be opened further. *)
115
+ mutable pp_max_indent : int;
116
+ (* Space remaining on the current line. *)
117
+ mutable pp_space_left : int;
118
+ (* Current value of indentation. *)
119
+ mutable pp_current_indent : int;
120
+ (* True when the line has been broken by the pretty-printer. *)
121
+ mutable pp_is_new_line : bool;
122
+ (* Total width of tokens already printed. *)
123
+ mutable pp_left_total : int;
124
+ (* Total width of tokens ever put in queue. *)
125
+ mutable pp_right_total : int;
126
+ (* Current number of opened blocks. *)
127
+ mutable pp_curr_depth : int;
128
+ (* Maximum number of blocks which can be simultaneously opened. *)
129
+ mutable pp_max_boxes : int;
130
+ (* Ellipsis string. *)
131
+ mutable pp_ellipsis : string;
132
+ (* Output function. *)
133
+ mutable pp_output_function : string -> int -> int -> unit;
134
+ (* Flushing function. *)
135
+ mutable pp_flush_function : unit -> unit;
136
+ (* Output of new lines. *)
137
+ mutable pp_output_newline : unit -> unit;
138
+ (* Output of indentation spaces. *)
139
+ mutable pp_output_spaces : int -> unit;
140
+ (* Are tags printed ? *)
141
+ mutable pp_print_tags : bool;
142
+ (* Are tags marked ? *)
143
+ mutable pp_mark_tags : bool;
144
+ (* Find opening and closing markers of tags. *)
145
+ mutable pp_mark_open_tag : tag -> string;
146
+ mutable pp_mark_close_tag : tag -> string;
147
+ mutable pp_print_open_tag : tag -> unit;
148
+ mutable pp_print_close_tag : tag -> unit;
149
+ (* The pretty-printer queue. *)
150
+ mutable pp_queue : pp_queue_elem queue
151
+ };;
152
+
153
+ (**************************************************************
154
+
155
+ Auxilliaries and basic functions.
156
+
157
+ **************************************************************)
158
+
159
+
160
+ (* Queues auxilliaries. *)
161
+ let make_queue () = {insert = Nil; body = Nil};;
162
+
163
+ let clear_queue q = q.insert <- Nil; q.body <- Nil;;
164
+
165
+ let add_queue x q =
166
+ let c = Cons {head = x; tail = Nil} in
167
+ match q with
168
+ | {insert = Cons cell} -> q.insert <- c; cell.tail <- c
169
+ (* Invariant: when insert is Nil body should be Nil. *)
170
+ | _ -> q.insert <- c; q.body <- c;;
171
+
172
+ exception Empty_queue;;
173
+
174
+ let peek_queue = function
175
+ | {body = Cons {head = x}} -> x
176
+ | _ -> raise Empty_queue;;
177
+
178
+ let take_queue = function
179
+ | {body = Cons {head = x; tail = tl}} as q ->
180
+ q.body <- tl;
181
+ if tl = Nil then q.insert <- Nil; (* Maintain the invariant. *)
182
+ x
183
+ | _ -> raise Empty_queue;;
184
+
185
+ (* Enter a token in the pretty-printer queue. *)
186
+ let pp_enqueue state ({length = len} as token) =
187
+ state.pp_right_total <- state.pp_right_total + len;
188
+ add_queue token state.pp_queue;;
189
+
190
+ let pp_clear_queue state =
191
+ state.pp_left_total <- 1; state.pp_right_total <- 1;
192
+ clear_queue state.pp_queue;;
193
+
194
+ (* Pp_infinity: large value for default tokens size.
195
+
196
+ Pp_infinity is documented as being greater than 1e10; to avoid
197
+ confusion about the word ``greater'', we choose pp_infinity greater
198
+ than 1e10 + 1; for correct handling of tests in the algorithm,
199
+ pp_infinity must be even one more than 1e10 + 1; let's stand on the
200
+ safe side by choosing 1.e10+10.
201
+
202
+ Pp_infinity could probably be 1073741823 that is 2^30 - 1, that is
203
+ the minimal upper bound for integers; now that max_int is defined,
204
+ this limit could also be defined as max_int - 1.
205
+
206
+ However, before setting pp_infinity to something around max_int, we
207
+ must carefully double-check all the integer arithmetic operations
208
+ that involve pp_infinity, since any overflow would wreck havoc the
209
+ pretty-printing algorithm's invariants. Given that this arithmetic
210
+ correctness check is difficult and error prone and given that 1e10
211
+ + 1 is in practice large enough, there is no need to attempt to set
212
+ pp_infinity to the theoretically maximum limit. Is it not worth the
213
+ burden ! *)
214
+
215
+ let pp_infinity = 1000000010;;
216
+
217
+ (* Output functions for the formatter. *)
218
+ let pp_output_string state s = state.pp_output_function s 0 (String.length s)
219
+ and pp_output_newline state = state.pp_output_newline ();;
220
+
221
+ let pp_display_blanks state n = state.pp_output_spaces n;;
222
+
223
+ (* To format a break, indenting a new line. *)
224
+ let break_new_line state offset width =
225
+ pp_output_newline state;
226
+ state.pp_is_new_line <- true;
227
+ let indent = state.pp_margin - width + offset in
228
+ (* Don't indent more than pp_max_indent. *)
229
+ let real_indent = min state.pp_max_indent indent in
230
+ state.pp_current_indent <- real_indent;
231
+ state.pp_space_left <- state.pp_margin - state.pp_current_indent;
232
+ pp_display_blanks state state.pp_current_indent;;
233
+
234
+ (* To force a line break inside a block: no offset is added. *)
235
+ let break_line state width = break_new_line state 0 width;;
236
+
237
+ (* To format a break that fits on the current line. *)
238
+ let break_same_line state width =
239
+ state.pp_space_left <- state.pp_space_left - width;
240
+ pp_display_blanks state width;;
241
+
242
+ (* To indent no more than pp_max_indent, if one tries to open a block
243
+ beyond pp_max_indent, then the block is rejected on the left
244
+ by simulating a break. *)
245
+ let pp_force_break_line state =
246
+ match state.pp_format_stack with
247
+ | Format_elem (bl_ty, width) :: _ ->
248
+ if width > state.pp_space_left then
249
+ (match bl_ty with
250
+ | Pp_fits -> () | Pp_hbox -> () | _ -> break_line state width)
251
+ | _ -> pp_output_newline state;;
252
+
253
+ (* To skip a token, if the previous line has been broken. *)
254
+ let pp_skip_token state =
255
+ (* When calling pp_skip_token the queue cannot be empty. *)
256
+ match take_queue state.pp_queue with
257
+ {elem_size = size; length = len} ->
258
+ state.pp_left_total <- state.pp_left_total - len;
259
+ state.pp_space_left <- state.pp_space_left + int_of_size size;;
260
+
261
+ (**************************************************************
262
+
263
+ The main pretting printing functions.
264
+
265
+ **************************************************************)
266
+
267
+ (* To format a token. *)
268
+ let format_pp_token state size = function
269
+
270
+ | Pp_text s ->
271
+ state.pp_space_left <- state.pp_space_left - size;
272
+ pp_output_string state s;
273
+ state.pp_is_new_line <- false
274
+
275
+ | Pp_begin (off, ty) ->
276
+ let insertion_point = state.pp_margin - state.pp_space_left in
277
+ if insertion_point > state.pp_max_indent then
278
+ (* can't open a block right there. *)
279
+ begin pp_force_break_line state end;
280
+ let offset = state.pp_space_left - off in
281
+ let bl_type =
282
+ begin match ty with
283
+ | Pp_vbox -> Pp_vbox
284
+ | _ -> if size > state.pp_space_left then ty else Pp_fits
285
+ end in
286
+ state.pp_format_stack <-
287
+ Format_elem (bl_type, offset) :: state.pp_format_stack
288
+
289
+ | Pp_end ->
290
+ begin match state.pp_format_stack with
291
+ | x :: (y :: l as ls) -> state.pp_format_stack <- ls
292
+ | _ -> () (* No more block to close. *)
293
+ end
294
+
295
+ | Pp_tbegin (Pp_tbox _ as tbox) ->
296
+ state.pp_tbox_stack <- tbox :: state.pp_tbox_stack
297
+
298
+ | Pp_tend ->
299
+ begin match state.pp_tbox_stack with
300
+ | x :: ls -> state.pp_tbox_stack <- ls
301
+ | _ -> () (* No more tabulation block to close. *)
302
+ end
303
+
304
+ | Pp_stab ->
305
+ begin match state.pp_tbox_stack with
306
+ | Pp_tbox tabs :: _ ->
307
+ let rec add_tab n = function
308
+ | [] -> [n]
309
+ | x :: l as ls -> if n < x then n :: ls else x :: add_tab n l in
310
+ tabs := add_tab (state.pp_margin - state.pp_space_left) !tabs
311
+ | _ -> () (* No opened tabulation block. *)
312
+ end
313
+
314
+ | Pp_tbreak (n, off) ->
315
+ let insertion_point = state.pp_margin - state.pp_space_left in
316
+ begin match state.pp_tbox_stack with
317
+ | Pp_tbox tabs :: _ ->
318
+ let rec find n = function
319
+ | x :: l -> if x >= n then x else find n l
320
+ | [] -> raise Not_found in
321
+ let tab =
322
+ match !tabs with
323
+ | x :: l ->
324
+ begin try find insertion_point !tabs with Not_found -> x end
325
+ | _ -> insertion_point in
326
+ let offset = tab - insertion_point in
327
+ if offset >= 0 then break_same_line state (offset + n) else
328
+ break_new_line state (tab + off) state.pp_margin
329
+ | _ -> () (* No opened tabulation block. *)
330
+ end
331
+
332
+ | Pp_newline ->
333
+ begin match state.pp_format_stack with
334
+ | Format_elem (_, width) :: _ -> break_line state width
335
+ | _ -> pp_output_newline state
336
+ end
337
+
338
+ | Pp_if_newline ->
339
+ if state.pp_current_indent != state.pp_margin - state.pp_space_left
340
+ then pp_skip_token state
341
+
342
+ | Pp_break (n, off) ->
343
+ begin match state.pp_format_stack with
344
+ | Format_elem (ty, width) :: _ ->
345
+ begin match ty with
346
+ | Pp_hovbox ->
347
+ if size > state.pp_space_left
348
+ then break_new_line state off width
349
+ else break_same_line state n
350
+ | Pp_box ->
351
+ (* Have the line just been broken here ? *)
352
+ if state.pp_is_new_line then break_same_line state n else
353
+ if size > state.pp_space_left
354
+ then break_new_line state off width else
355
+ (* break the line here leads to new indentation ? *)
356
+ if state.pp_current_indent > state.pp_margin - width + off
357
+ then break_new_line state off width
358
+ else break_same_line state n
359
+ | Pp_hvbox -> break_new_line state off width
360
+ | Pp_fits -> break_same_line state n
361
+ | Pp_vbox -> break_new_line state off width
362
+ | Pp_hbox -> break_same_line state n
363
+ end
364
+ | _ -> () (* No opened block. *)
365
+ end
366
+
367
+ | Pp_open_tag tag_name ->
368
+ let marker = state.pp_mark_open_tag tag_name in
369
+ pp_output_string state marker;
370
+ state.pp_mark_stack <- tag_name :: state.pp_mark_stack
371
+
372
+ | Pp_close_tag ->
373
+ begin match state.pp_mark_stack with
374
+ | tag_name :: tags ->
375
+ let marker = state.pp_mark_close_tag tag_name in
376
+ pp_output_string state marker;
377
+ state.pp_mark_stack <- tags
378
+ | _ -> () (* No more tag to close. *)
379
+ end;;
380
+
381
+ (* Print if token size is known or printing is delayed.
382
+ Size is known when not negative.
383
+ Printing is delayed when the text waiting in the queue requires
384
+ more room to format than exists on the current line. *)
385
+ let rec advance_left state =
386
+ try
387
+ match peek_queue state.pp_queue with
388
+ {elem_size = size; token = tok; length = len} ->
389
+ let size = int_of_size size in
390
+ if not
391
+ (size < 0 &&
392
+ (state.pp_right_total - state.pp_left_total < state.pp_space_left))
393
+ then begin
394
+ ignore(take_queue state.pp_queue);
395
+ format_pp_token state (if size < 0 then pp_infinity else size) tok;
396
+ state.pp_left_total <- len + state.pp_left_total;
397
+ advance_left state
398
+ end
399
+ with Empty_queue -> ();;
400
+
401
+ let enqueue_advance state tok = pp_enqueue state tok; advance_left state;;
402
+
403
+ (* To enqueue a string : try to advance. *)
404
+ let make_queue_elem size tok len =
405
+ {elem_size = size; token = tok; length = len};;
406
+
407
+ let enqueue_string_as state size s =
408
+ let len = int_of_size size in
409
+ enqueue_advance state (make_queue_elem size (Pp_text s) len);;
410
+
411
+ let enqueue_string state s =
412
+ let len = String.length s in
413
+ enqueue_string_as state (size_of_int len) s;;
414
+
415
+ (* Routines for scan stack
416
+ determine sizes of blocks. *)
417
+
418
+ (* The scan_stack is never empty. *)
419
+ let scan_stack_bottom =
420
+ let q_elem = make_queue_elem (size_of_int (-1)) (Pp_text "") 0 in
421
+ [Scan_elem (-1, q_elem)];;
422
+
423
+ (* Set size of blocks on scan stack:
424
+ if ty = true then size of break is set else size of block is set;
425
+ in each case pp_scan_stack is popped. *)
426
+ let clear_scan_stack state = state.pp_scan_stack <- scan_stack_bottom;;
427
+
428
+ (* Pattern matching on scan stack is exhaustive,
429
+ since scan_stack is never empty.
430
+ Pattern matching on token in scan stack is also exhaustive,
431
+ since scan_push is used on breaks and opening of boxes. *)
432
+ let set_size state ty =
433
+ match state.pp_scan_stack with
434
+ | Scan_elem
435
+ (left_tot,
436
+ ({elem_size = size; token = tok} as queue_elem)) :: t ->
437
+ let size = int_of_size size in
438
+ (* test if scan stack contains any data that is not obsolete. *)
439
+ if left_tot < state.pp_left_total then clear_scan_stack state else
440
+ begin match tok with
441
+ | Pp_break (_, _) | Pp_tbreak (_, _) ->
442
+ if ty then
443
+ begin
444
+ queue_elem.elem_size <- size_of_int (state.pp_right_total + size);
445
+ state.pp_scan_stack <- t
446
+ end
447
+ | Pp_begin (_, _) ->
448
+ if not ty then
449
+ begin
450
+ queue_elem.elem_size <- size_of_int (state.pp_right_total + size);
451
+ state.pp_scan_stack <- t
452
+ end
453
+ | _ -> () (* scan_push is only used for breaks and boxes. *)
454
+ end
455
+ | _ -> () (* scan_stack is never empty. *);;
456
+
457
+ (* Push a token on scan stack. If b is true set_size is called. *)
458
+ let scan_push state b tok =
459
+ pp_enqueue state tok;
460
+ if b then set_size state true;
461
+ state.pp_scan_stack <-
462
+ Scan_elem (state.pp_right_total, tok) :: state.pp_scan_stack;;
463
+
464
+ (* To open a new block :
465
+ the user may set the depth bound pp_max_boxes
466
+ any text nested deeper is printed as the ellipsis string. *)
467
+ let pp_open_box_gen state indent br_ty =
468
+ state.pp_curr_depth <- state.pp_curr_depth + 1;
469
+ if state.pp_curr_depth < state.pp_max_boxes then
470
+ let elem =
471
+ make_queue_elem
472
+ (size_of_int (- state.pp_right_total))
473
+ (Pp_begin (indent, br_ty))
474
+ 0 in
475
+ scan_push state false elem else
476
+ if state.pp_curr_depth = state.pp_max_boxes
477
+ then enqueue_string state state.pp_ellipsis;;
478
+
479
+ (* The box which is always opened. *)
480
+ let pp_open_sys_box state = pp_open_box_gen state 0 Pp_hovbox;;
481
+
482
+ (* Close a block, setting sizes of its subblocks. *)
483
+ let pp_close_box state () =
484
+ if state.pp_curr_depth > 1 then
485
+ begin
486
+ if state.pp_curr_depth < state.pp_max_boxes then
487
+ begin
488
+ pp_enqueue state
489
+ {elem_size = size_of_int 0; token = Pp_end; length = 0};
490
+ set_size state true; set_size state false
491
+ end;
492
+ state.pp_curr_depth <- state.pp_curr_depth - 1;
493
+ end;;
494
+
495
+ (* Open a tag, pushing it on the tag stack. *)
496
+ let pp_open_tag state tag_name =
497
+ if state.pp_print_tags then begin
498
+ state.pp_tag_stack <- tag_name :: state.pp_tag_stack;
499
+ state.pp_print_open_tag tag_name end;
500
+ if state.pp_mark_tags then
501
+ pp_enqueue state
502
+ {elem_size = size_of_int 0; token = Pp_open_tag tag_name; length = 0};;
503
+
504
+ (* Close a tag, popping it from the tag stack. *)
505
+ let pp_close_tag state () =
506
+ if state.pp_mark_tags then
507
+ pp_enqueue state
508
+ {elem_size = size_of_int 0; token = Pp_close_tag; length = 0};
509
+ if state.pp_print_tags then
510
+ begin match state.pp_tag_stack with
511
+ | tag_name :: tags ->
512
+ state.pp_print_close_tag tag_name;
513
+ state.pp_tag_stack <- tags
514
+ | _ -> () (* No more tag to close. *)
515
+ end;;
516
+
517
+ let pp_set_print_tags state b = state.pp_print_tags <- b;;
518
+ let pp_set_mark_tags state b = state.pp_mark_tags <- b;;
519
+ let pp_get_print_tags state () = state.pp_print_tags;;
520
+ let pp_get_mark_tags state () = state.pp_mark_tags;;
521
+ let pp_set_tags state b = pp_set_print_tags state b; pp_set_mark_tags state b;;
522
+
523
+ let pp_get_formatter_tag_functions state () = {
524
+ mark_open_tag = state.pp_mark_open_tag;
525
+ mark_close_tag = state.pp_mark_close_tag;
526
+ print_open_tag = state.pp_print_open_tag;
527
+ print_close_tag = state.pp_print_close_tag;
528
+ };;
529
+
530
+ let pp_set_formatter_tag_functions state {
531
+ mark_open_tag = mot;
532
+ mark_close_tag = mct;
533
+ print_open_tag = pot;
534
+ print_close_tag = pct;
535
+ } =
536
+ state.pp_mark_open_tag <- mot;
537
+ state.pp_mark_close_tag <- mct;
538
+ state.pp_print_open_tag <- pot;
539
+ state.pp_print_close_tag <- pct;;
540
+
541
+ (* Initialize pretty-printer. *)
542
+ let pp_rinit state =
543
+ pp_clear_queue state;
544
+ clear_scan_stack state;
545
+ state.pp_format_stack <- [];
546
+ state.pp_tbox_stack <- [];
547
+ state.pp_tag_stack <- [];
548
+ state.pp_mark_stack <- [];
549
+ state.pp_current_indent <- 0;
550
+ state.pp_curr_depth <- 0;
551
+ state.pp_space_left <- state.pp_margin;
552
+ pp_open_sys_box state;;
553
+
554
+ (* Flushing pretty-printer queue. *)
555
+ let pp_flush_queue state b =
556
+ while state.pp_curr_depth > 1 do
557
+ pp_close_box state ()
558
+ done;
559
+ state.pp_right_total <- pp_infinity;
560
+ advance_left state;
561
+ if b then pp_output_newline state;
562
+ pp_rinit state;;
563
+
564
+ (**************************************************************
565
+
566
+ Procedures to format objects, and use boxes
567
+
568
+ **************************************************************)
569
+
570
+ (* To format a string. *)
571
+ let pp_print_as_size state size s =
572
+ if state.pp_curr_depth < state.pp_max_boxes
573
+ then enqueue_string_as state size s;;
574
+
575
+ let pp_print_as state isize s =
576
+ pp_print_as_size state (size_of_int isize) s;;
577
+
578
+ let pp_print_string state s =
579
+ pp_print_as state (String.length s) s;;
580
+
581
+ (* To format an integer. *)
582
+ let pp_print_int state i = pp_print_string state (string_of_int i);;
583
+
584
+ (* To format a float. *)
585
+ let pp_print_float state f = pp_print_string state (string_of_float f);;
586
+
587
+ (* To format a boolean. *)
588
+ let pp_print_bool state b = pp_print_string state (string_of_bool b);;
589
+
590
+ (* To format a char. *)
591
+ let pp_print_char state c =
592
+ let s = String.create 1 in
593
+ s.[0] <- c;
594
+ pp_print_as state 1 s;;
595
+
596
+ (* Opening boxes. *)
597
+ let pp_open_hbox state () = pp_open_box_gen state 0 Pp_hbox
598
+ and pp_open_vbox state indent = pp_open_box_gen state indent Pp_vbox
599
+
600
+ and pp_open_hvbox state indent = pp_open_box_gen state indent Pp_hvbox
601
+ and pp_open_hovbox state indent = pp_open_box_gen state indent Pp_hovbox
602
+ and pp_open_box state indent = pp_open_box_gen state indent Pp_box;;
603
+
604
+ (* Print a new line after printing all queued text
605
+ (same for print_flush but without a newline). *)
606
+ let pp_print_newline state () =
607
+ pp_flush_queue state true; state.pp_flush_function ()
608
+ and pp_print_flush state () =
609
+ pp_flush_queue state false; state.pp_flush_function ();;
610
+
611
+ (* To get a newline when one does not want to close the current block. *)
612
+ let pp_force_newline state () =
613
+ if state.pp_curr_depth < state.pp_max_boxes then
614
+ enqueue_advance state (make_queue_elem (size_of_int 0) Pp_newline 0);;
615
+
616
+ (* To format something if the line has just been broken. *)
617
+ let pp_print_if_newline state () =
618
+ if state.pp_curr_depth < state.pp_max_boxes then
619
+ enqueue_advance state (make_queue_elem (size_of_int 0) Pp_if_newline 0);;
620
+
621
+ (* Breaks: indicate where a block may be broken.
622
+ If line is broken then offset is added to the indentation of the current
623
+ block else (the value of) width blanks are printed.
624
+ To do (?) : add a maximum width and offset value. *)
625
+ let pp_print_break state width offset =
626
+ if state.pp_curr_depth < state.pp_max_boxes then
627
+ let elem =
628
+ make_queue_elem
629
+ (size_of_int (- state.pp_right_total))
630
+ (Pp_break (width, offset))
631
+ width in
632
+ scan_push state true elem;;
633
+
634
+ let pp_print_space state () = pp_print_break state 1 0
635
+ and pp_print_cut state () = pp_print_break state 0 0;;
636
+
637
+ (* Tabulation boxes. *)
638
+ let pp_open_tbox state () =
639
+ state.pp_curr_depth <- state.pp_curr_depth + 1;
640
+ if state.pp_curr_depth < state.pp_max_boxes then
641
+ let elem =
642
+ make_queue_elem (size_of_int 0) (Pp_tbegin (Pp_tbox (ref []))) 0 in
643
+ enqueue_advance state elem;;
644
+
645
+ (* Close a tabulation block. *)
646
+ let pp_close_tbox state () =
647
+ if state.pp_curr_depth > 1 then begin
648
+ if state.pp_curr_depth < state.pp_max_boxes then
649
+ let elem = make_queue_elem (size_of_int 0) Pp_tend 0 in
650
+ enqueue_advance state elem;
651
+ state.pp_curr_depth <- state.pp_curr_depth - 1 end;;
652
+
653
+ (* Print a tabulation break. *)
654
+ let pp_print_tbreak state width offset =
655
+ if state.pp_curr_depth < state.pp_max_boxes then
656
+ let elem =
657
+ make_queue_elem
658
+ (size_of_int (- state.pp_right_total))
659
+ (Pp_tbreak (width, offset))
660
+ width in
661
+ scan_push state true elem;;
662
+
663
+ let pp_print_tab state () = pp_print_tbreak state 0 0;;
664
+
665
+ let pp_set_tab state () =
666
+ if state.pp_curr_depth < state.pp_max_boxes then
667
+ let elem =
668
+ make_queue_elem (size_of_int 0) Pp_stab 0 in
669
+ enqueue_advance state elem;;
670
+
671
+ (**************************************************************
672
+
673
+ Procedures to control the pretty-printers
674
+
675
+ **************************************************************)
676
+
677
+ (* Fit max_boxes. *)
678
+ let pp_set_max_boxes state n = if n > 1 then state.pp_max_boxes <- n;;
679
+
680
+ (* To know the current maximum number of boxes allowed. *)
681
+ let pp_get_max_boxes state () = state.pp_max_boxes;;
682
+
683
+ let pp_over_max_boxes state () = state.pp_curr_depth = state.pp_max_boxes;;
684
+
685
+ (* Ellipsis. *)
686
+ let pp_set_ellipsis_text state s = state.pp_ellipsis <- s
687
+ and pp_get_ellipsis_text state () = state.pp_ellipsis;;
688
+
689
+ (* To set the margin of pretty-printer. *)
690
+ let pp_limit n =
691
+ if n < pp_infinity then n else pred pp_infinity;;
692
+
693
+ let pp_set_min_space_left state n =
694
+ if n >= 1 then
695
+ let n = pp_limit n in
696
+ state.pp_min_space_left <- n;
697
+ state.pp_max_indent <- state.pp_margin - state.pp_min_space_left;
698
+ pp_rinit state;;
699
+
700
+ (* Initially, we have :
701
+ pp_max_indent = pp_margin - pp_min_space_left, and
702
+ pp_space_left = pp_margin. *)
703
+ let pp_set_max_indent state n =
704
+ pp_set_min_space_left state (state.pp_margin - n);;
705
+ let pp_get_max_indent state () = state.pp_max_indent;;
706
+
707
+ let pp_set_margin state n =
708
+ if n >= 1 then
709
+ let n = pp_limit n in
710
+ state.pp_margin <- n;
711
+ let new_max_indent =
712
+ (* Try to maintain max_indent to its actual value. *)
713
+ if state.pp_max_indent <= state.pp_margin
714
+ then state.pp_max_indent else
715
+ (* If possible maintain pp_min_space_left to its actual value,
716
+ if this leads to a too small max_indent, take half of the
717
+ new margin, if it is greater than 1. *)
718
+ max (max (state.pp_margin - state.pp_min_space_left)
719
+ (state.pp_margin / 2)) 1 in
720
+ (* Rebuild invariants. *)
721
+ pp_set_max_indent state new_max_indent;;
722
+
723
+ let pp_get_margin state () = state.pp_margin;;
724
+
725
+ let pp_set_formatter_output_functions state f g =
726
+ state.pp_output_function <- f; state.pp_flush_function <- g;;
727
+ let pp_get_formatter_output_functions state () =
728
+ (state.pp_output_function, state.pp_flush_function);;
729
+
730
+ let pp_set_all_formatter_output_functions state
731
+ ~out:f ~flush:g ~newline:h ~spaces:i =
732
+ pp_set_formatter_output_functions state f g;
733
+ state.pp_output_newline <- (function () -> h ());
734
+ state.pp_output_spaces <- (function n -> i n);;
735
+ let pp_get_all_formatter_output_functions state () =
736
+ (state.pp_output_function, state.pp_flush_function,
737
+ state.pp_output_newline, state.pp_output_spaces);;
738
+
739
+ let pp_set_formatter_out_channel state os =
740
+ state.pp_output_function <- output os;
741
+ state.pp_flush_function <- (fun () -> flush os);;
742
+
743
+ (**************************************************************
744
+
745
+ Creation of specific formatters
746
+
747
+ **************************************************************)
748
+
749
+ let default_pp_mark_open_tag s = "<" ^ s ^ ">";;
750
+ let default_pp_mark_close_tag s = "</" ^ s ^ ">";;
751
+
752
+ let default_pp_print_open_tag s = ();;
753
+ let default_pp_print_close_tag = default_pp_print_open_tag;;
754
+
755
+ let pp_make_formatter f g h i =
756
+ (* The initial state of the formatter contains a dummy box. *)
757
+ let pp_q = make_queue () in
758
+ let sys_tok =
759
+ make_queue_elem (size_of_int (-1)) (Pp_begin (0, Pp_hovbox)) 0 in
760
+ add_queue sys_tok pp_q;
761
+ let sys_scan_stack =
762
+ (Scan_elem (1, sys_tok)) :: scan_stack_bottom in
763
+ {pp_scan_stack = sys_scan_stack;
764
+ pp_format_stack = [];
765
+ pp_tbox_stack = [];
766
+ pp_tag_stack = [];
767
+ pp_mark_stack = [];
768
+ pp_margin = 78;
769
+ pp_min_space_left = 10;
770
+ pp_max_indent = 78 - 10;
771
+ pp_space_left = 78;
772
+ pp_current_indent = 0;
773
+ pp_is_new_line = true;
774
+ pp_left_total = 1;
775
+ pp_right_total = 1;
776
+ pp_curr_depth = 1;
777
+ pp_max_boxes = max_int;
778
+ pp_ellipsis = ".";
779
+ pp_output_function = f;
780
+ pp_flush_function = g;
781
+ pp_output_newline = h;
782
+ pp_output_spaces = i;
783
+ pp_print_tags = false;
784
+ pp_mark_tags = false;
785
+ pp_mark_open_tag = default_pp_mark_open_tag;
786
+ pp_mark_close_tag = default_pp_mark_close_tag;
787
+ pp_print_open_tag = default_pp_print_open_tag;
788
+ pp_print_close_tag = default_pp_print_close_tag;
789
+ pp_queue = pp_q
790
+ };;
791
+
792
+ (* Default function to output spaces. *)
793
+ let blank_line = String.make 80 ' ';;
794
+ let rec display_blanks state n =
795
+ if n > 0 then
796
+ if n <= 80 then state.pp_output_function blank_line 0 n else
797
+ begin
798
+ state.pp_output_function blank_line 0 80;
799
+ display_blanks state (n - 80)
800
+ end;;
801
+
802
+ (* Default function to output new lines. *)
803
+ let display_newline state () = state.pp_output_function "\n" 0 1;;
804
+
805
+ let make_formatter f g =
806
+ let ff = pp_make_formatter f g ignore ignore in
807
+ ff.pp_output_newline <- display_newline ff;
808
+ ff.pp_output_spaces <- display_blanks ff;
809
+ ff;;
810
+
811
+ let formatter_of_out_channel oc =
812
+ make_formatter (output oc) (fun () -> flush oc);;
813
+
814
+ let formatter_of_buffer b =
815
+ make_formatter (Buffer.add_substring b) ignore;;
816
+
817
+ let stdbuf = Buffer.create 512;;
818
+
819
+ let str_formatter = formatter_of_buffer stdbuf;;
820
+ let std_formatter = formatter_of_out_channel stdout;;
821
+ let err_formatter = formatter_of_out_channel stderr;;
822
+
823
+ let flush_str_formatter () =
824
+ pp_flush_queue str_formatter false;
825
+ let s = Buffer.contents stdbuf in
826
+ Buffer.reset stdbuf;
827
+ s;;
828
+
829
+ (**************************************************************
830
+
831
+ Basic functions on the standard formatter
832
+
833
+ **************************************************************)
834
+
835
+ let open_hbox = pp_open_hbox std_formatter
836
+ and open_vbox = pp_open_vbox std_formatter
837
+ and open_hvbox = pp_open_hvbox std_formatter
838
+ and open_hovbox = pp_open_hovbox std_formatter
839
+ and open_box = pp_open_box std_formatter
840
+ and close_box = pp_close_box std_formatter
841
+ and open_tag = pp_open_tag std_formatter
842
+ and close_tag = pp_close_tag std_formatter
843
+ and print_as = pp_print_as std_formatter
844
+ and print_string = pp_print_string std_formatter
845
+ and print_int = pp_print_int std_formatter
846
+ and print_float = pp_print_float std_formatter
847
+ and print_char = pp_print_char std_formatter
848
+ and print_bool = pp_print_bool std_formatter
849
+ and print_break = pp_print_break std_formatter
850
+ and print_cut = pp_print_cut std_formatter
851
+ and print_space = pp_print_space std_formatter
852
+ and force_newline = pp_force_newline std_formatter
853
+ and print_flush = pp_print_flush std_formatter
854
+ and print_newline = pp_print_newline std_formatter
855
+ and print_if_newline = pp_print_if_newline std_formatter
856
+
857
+ and open_tbox = pp_open_tbox std_formatter
858
+ and close_tbox = pp_close_tbox std_formatter
859
+ and print_tbreak = pp_print_tbreak std_formatter
860
+
861
+ and set_tab = pp_set_tab std_formatter
862
+ and print_tab = pp_print_tab std_formatter
863
+
864
+ and set_margin = pp_set_margin std_formatter
865
+ and get_margin = pp_get_margin std_formatter
866
+
867
+ and set_max_indent = pp_set_max_indent std_formatter
868
+ and get_max_indent = pp_get_max_indent std_formatter
869
+
870
+ and set_max_boxes = pp_set_max_boxes std_formatter
871
+ and get_max_boxes = pp_get_max_boxes std_formatter
872
+ and over_max_boxes = pp_over_max_boxes std_formatter
873
+
874
+ and set_ellipsis_text = pp_set_ellipsis_text std_formatter
875
+ and get_ellipsis_text = pp_get_ellipsis_text std_formatter
876
+
877
+ and set_formatter_out_channel =
878
+ pp_set_formatter_out_channel std_formatter
879
+
880
+ and set_formatter_output_functions =
881
+ pp_set_formatter_output_functions std_formatter
882
+ and get_formatter_output_functions =
883
+ pp_get_formatter_output_functions std_formatter
884
+
885
+ and set_all_formatter_output_functions =
886
+ pp_set_all_formatter_output_functions std_formatter
887
+ and get_all_formatter_output_functions =
888
+ pp_get_all_formatter_output_functions std_formatter
889
+
890
+ and set_formatter_tag_functions =
891
+ pp_set_formatter_tag_functions std_formatter
892
+ and get_formatter_tag_functions =
893
+ pp_get_formatter_tag_functions std_formatter
894
+ and set_print_tags =
895
+ pp_set_print_tags std_formatter
896
+ and get_print_tags =
897
+ pp_get_print_tags std_formatter
898
+ and set_mark_tags =
899
+ pp_set_mark_tags std_formatter
900
+ and get_mark_tags =
901
+ pp_get_mark_tags std_formatter
902
+ and set_tags =
903
+ pp_set_tags std_formatter
904
+ ;;
905
+
906
+
907
+ (**************************************************************
908
+
909
+ Printf implementation.
910
+
911
+ **************************************************************)
912
+
913
+ (* Error messages when processing formats. *)
914
+
915
+ (* Trailer: giving up at character number ... *)
916
+ let giving_up mess fmt i =
917
+ "fprintf: " ^ mess ^ " ``" ^ fmt ^ "'', \
918
+ giving up at character number " ^ string_of_int i ^
919
+ (if i < String.length fmt
920
+ then " (" ^ String.make 1 fmt.[i] ^ ")."
921
+ else String.make 1 '.');;
922
+
923
+ (* When an invalid format deserves a special error explanation. *)
924
+ let format_invalid_arg mess fmt i = invalid_arg (giving_up mess fmt i);;
925
+
926
+ (* Standard invalid format. *)
927
+ let invalid_format fmt i = format_invalid_arg "bad format" fmt i;;
928
+
929
+ (* Cannot find a valid integer into that format. *)
930
+ let invalid_integer fmt i =
931
+ invalid_arg (giving_up "bad integer specification" fmt i);;
932
+
933
+ (* Finding an integer out of a sub-string of the format. *)
934
+ let format_int_of_string fmt i s =
935
+ let sz =
936
+ try int_of_string s with
937
+ | Failure s -> invalid_integer fmt i in
938
+ size_of_int sz;;
939
+
940
+ (* Getting strings out of buffers. *)
941
+ let get_buffer_out b =
942
+ let s = Buffer.contents b in
943
+ Buffer.reset b;
944
+ s;;
945
+
946
+ (* [ppf] is supposed to be a pretty-printer that outputs in buffer [b]:
947
+ to extract contents of [ppf] as a string we flush [ppf] and get the string
948
+ out of [b]. *)
949
+ let string_out b ppf =
950
+ pp_flush_queue ppf false;
951
+ get_buffer_out b;;
952
+
953
+ (* Applies [printer] to a formatter that outputs on a fresh buffer,
954
+ then returns the resulting material. *)
955
+ let exstring printer arg =
956
+ let b = Buffer.create 512 in
957
+ let ppf = formatter_of_buffer b in
958
+ printer ppf arg;
959
+ string_out b ppf;;
960
+
961
+ (* To turn out a character accumulator into the proper string result. *)
962
+ let implode_rev s0 = function
963
+ | [] -> s0
964
+ | l -> String.concat "" (List.rev (s0 :: l));;
965
+
966
+ external format_to_string : ('a, 'b, 'c, 'd) format4 -> string = "%identity";;
967
+
968
+ (* [fprintf_out] is the printf-like function generator: given the
969
+ - [str] flag that tells if we are printing into a string,
970
+ - the [out] function that has to be called at the end of formatting,
971
+ it generates a [fprintf] function that takes as arguments a [ppf]
972
+ formatter and a printing format to print the rest of arguments
973
+ according to the format.
974
+ Regular [fprintf]-like functions of this module are obtained via partial
975
+ applications of [fprintf_out]. *)
976
+ let mkprintf str get_out =
977
+ let rec kprintf k fmt =
978
+ let fmt = format_to_string fmt in
979
+ let len = String.length fmt in
980
+
981
+ let kpr fmt v =
982
+ let ppf = get_out fmt in
983
+ let print_as = ref None in
984
+ let pp_print_as_char c =
985
+ match !print_as with
986
+ | None -> pp_print_char ppf c
987
+ | Some size ->
988
+ pp_print_as_size ppf size (String.make 1 c);
989
+ print_as := None
990
+ and pp_print_as_string s =
991
+ match !print_as with
992
+ | None -> pp_print_string ppf s
993
+ | Some size ->
994
+ pp_print_as_size ppf size s;
995
+ print_as := None in
996
+
997
+ let rec doprn n i =
998
+ if i >= len then Obj.magic (k ppf) else
999
+ match fmt.[i] with
1000
+ | '%' ->
1001
+ Printf.scan_format fmt v n i cont_s cont_a cont_t cont_f cont_m
1002
+ | '@' ->
1003
+ let i = succ i in
1004
+ if i >= len then invalid_format fmt i else
1005
+ begin match fmt.[i] with
1006
+ | '[' ->
1007
+ do_pp_open_box ppf n (succ i)
1008
+ | ']' ->
1009
+ pp_close_box ppf ();
1010
+ doprn n (succ i)
1011
+ | '{' ->
1012
+ do_pp_open_tag ppf n (succ i)
1013
+ | '}' ->
1014
+ pp_close_tag ppf ();
1015
+ doprn n (succ i)
1016
+ | ' ' ->
1017
+ pp_print_space ppf ();
1018
+ doprn n (succ i)
1019
+ | ',' ->
1020
+ pp_print_cut ppf ();
1021
+ doprn n (succ i)
1022
+ | '?' ->
1023
+ pp_print_flush ppf ();
1024
+ doprn n (succ i)
1025
+ | '.' ->
1026
+ pp_print_newline ppf ();
1027
+ doprn n (succ i)
1028
+ | '\n' ->
1029
+ pp_force_newline ppf ();
1030
+ doprn n (succ i)
1031
+ | ';' ->
1032
+ do_pp_break ppf n (succ i)
1033
+ | '<' ->
1034
+ let got_size size n i =
1035
+ print_as := Some size;
1036
+ doprn n (skip_gt i) in
1037
+ get_int n (succ i) got_size
1038
+ | '@' as c ->
1039
+ pp_print_as_char c;
1040
+ doprn n (succ i)
1041
+ | c -> invalid_format fmt i
1042
+ end
1043
+ | c ->
1044
+ pp_print_as_char c;
1045
+ doprn n (succ i)
1046
+
1047
+ and cont_s n s i =
1048
+ pp_print_as_string s; doprn n i
1049
+ and cont_a n printer arg i =
1050
+ if str then
1051
+ pp_print_as_string ((Obj.magic printer : unit -> _ -> string) () arg)
1052
+ else
1053
+ printer ppf arg;
1054
+ doprn n i
1055
+ and cont_t n printer i =
1056
+ if str then
1057
+ pp_print_as_string ((Obj.magic printer : unit -> string) ())
1058
+ else
1059
+ printer ppf;
1060
+ doprn n i
1061
+ and cont_f n i =
1062
+ pp_print_flush ppf (); doprn n i
1063
+
1064
+ and cont_m n sfmt i =
1065
+ kprintf (Obj.magic (fun _ -> doprn n i)) sfmt
1066
+
1067
+ and get_int n i c =
1068
+ if i >= len then invalid_integer fmt i else
1069
+ match fmt.[i] with
1070
+ | ' ' -> get_int n (succ i) c
1071
+ | '%' ->
1072
+ let cont_s n s i = c (format_int_of_string fmt i s) n i
1073
+ and cont_a n printer arg i = invalid_integer fmt i
1074
+ and cont_t n printer i = invalid_integer fmt i
1075
+ and cont_f n i = invalid_integer fmt i
1076
+ and cont_m n sfmt i = invalid_integer fmt i in
1077
+ Printf.scan_format fmt v n i cont_s cont_a cont_t cont_f cont_m
1078
+ | _ ->
1079
+ let rec get j =
1080
+ if j >= len then invalid_integer fmt j else
1081
+ match fmt.[j] with
1082
+ | '0' .. '9' | '-' -> get (succ j)
1083
+ | _ ->
1084
+ let size =
1085
+ if j = i then size_of_int 0 else
1086
+ format_int_of_string fmt j (String.sub fmt i (j - i)) in
1087
+ c size n j in
1088
+ get i
1089
+
1090
+ and skip_gt i =
1091
+ if i >= len then invalid_format fmt i else
1092
+ match fmt.[i] with
1093
+ | ' ' -> skip_gt (succ i)
1094
+ | '>' -> succ i
1095
+ | _ -> invalid_format fmt i
1096
+
1097
+ and get_box_kind i =
1098
+ if i >= len then Pp_box, i else
1099
+ match fmt.[i] with
1100
+ | 'h' ->
1101
+ let i = succ i in
1102
+ if i >= len then Pp_hbox, i else
1103
+ begin match fmt.[i] with
1104
+ | 'o' ->
1105
+ let i = succ i in
1106
+ if i >= len then format_invalid_arg "bad box format" fmt i else
1107
+ begin match fmt.[i] with
1108
+ | 'v' -> Pp_hovbox, succ i
1109
+ | c ->
1110
+ format_invalid_arg
1111
+ ("bad box name ho" ^ String.make 1 c) fmt i end
1112
+ | 'v' -> Pp_hvbox, succ i
1113
+ | c -> Pp_hbox, i
1114
+ end
1115
+ | 'b' -> Pp_box, succ i
1116
+ | 'v' -> Pp_vbox, succ i
1117
+ | _ -> Pp_box, i
1118
+
1119
+ and get_tag_name n i c =
1120
+ let rec get accu n i j =
1121
+ if j >= len
1122
+ then c (implode_rev (String.sub fmt i (j - i)) accu) n j else
1123
+ match fmt.[j] with
1124
+ | '>' -> c (implode_rev (String.sub fmt i (j - i)) accu) n j
1125
+ | '%' ->
1126
+ let s0 = String.sub fmt i (j - i) in
1127
+ let cont_s n s i = get (s :: s0 :: accu) n i i
1128
+ and cont_a n printer arg i =
1129
+ let s =
1130
+ if str
1131
+ then (Obj.magic printer : unit -> _ -> string) () arg
1132
+ else exstring printer arg in
1133
+ get (s :: s0 :: accu) n i i
1134
+ and cont_t n printer i =
1135
+ let s =
1136
+ if str
1137
+ then (Obj.magic printer : unit -> string) ()
1138
+ else exstring (fun ppf () -> printer ppf) () in
1139
+ get (s :: s0 :: accu) n i i
1140
+ and cont_f n i =
1141
+ format_invalid_arg "bad tag name specification" fmt i
1142
+ and cont_m n sfmt i =
1143
+ format_invalid_arg "bad tag name specification" fmt i in
1144
+ Printf.scan_format fmt v n j cont_s cont_a cont_t cont_f cont_m
1145
+ | c -> get accu n i (succ j) in
1146
+ get [] n i i
1147
+
1148
+ and do_pp_break ppf n i =
1149
+ if i >= len then begin pp_print_space ppf (); doprn n i end else
1150
+ match fmt.[i] with
1151
+ | '<' ->
1152
+ let rec got_nspaces nspaces n i =
1153
+ get_int n i (got_offset nspaces)
1154
+ and got_offset nspaces offset n i =
1155
+ pp_print_break ppf (int_of_size nspaces) (int_of_size offset);
1156
+ doprn n (skip_gt i) in
1157
+ get_int n (succ i) got_nspaces
1158
+ | c -> pp_print_space ppf (); doprn n i
1159
+
1160
+ and do_pp_open_box ppf n i =
1161
+ if i >= len then begin pp_open_box_gen ppf 0 Pp_box; doprn n i end else
1162
+ match fmt.[i] with
1163
+ | '<' ->
1164
+ let kind, i = get_box_kind (succ i) in
1165
+ let got_size size n i =
1166
+ pp_open_box_gen ppf (int_of_size size) kind;
1167
+ doprn n (skip_gt i) in
1168
+ get_int n i got_size
1169
+ | c -> pp_open_box_gen ppf 0 Pp_box; doprn n i
1170
+
1171
+ and do_pp_open_tag ppf n i =
1172
+ if i >= len then begin pp_open_tag ppf ""; doprn n i end else
1173
+ match fmt.[i] with
1174
+ | '<' ->
1175
+ let got_name tag_name n i =
1176
+ pp_open_tag ppf tag_name;
1177
+ doprn n (skip_gt i) in
1178
+ get_tag_name n (succ i) got_name
1179
+ | c -> pp_open_tag ppf ""; doprn n i in
1180
+
1181
+ doprn (Printf.index_of_int 0) 0 in
1182
+
1183
+ Printf.kapr kpr fmt in
1184
+
1185
+ kprintf;;
1186
+
1187
+ (**************************************************************
1188
+
1189
+ Defining [fprintf] and various flavors of [fprintf].
1190
+
1191
+ **************************************************************)
1192
+
1193
+ let kfprintf k ppf = mkprintf false (fun _ -> ppf) k;;
1194
+
1195
+ let fprintf ppf = kfprintf ignore ppf;;
1196
+ let printf fmt = fprintf std_formatter fmt;;
1197
+ let eprintf fmt = fprintf err_formatter fmt;;
1198
+
1199
+ let kbprintf k b =
1200
+ mkprintf false (fun _ -> formatter_of_buffer b) k;;
1201
+
1202
+ let bprintf b = kbprintf ignore b;;
1203
+
1204
+ let ksprintf k =
1205
+ let b = Buffer.create 512 in
1206
+ let k ppf = k (string_out b ppf) in
1207
+ mkprintf true (fun _ -> formatter_of_buffer b) k;;
1208
+
1209
+ let kprintf = ksprintf;;
1210
+
1211
+ let sprintf fmt = ksprintf (fun s -> s) fmt;;
1212
+
1213
+ at_exit print_flush;;