gitlab-pygments.rb 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (399) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +2 -0
  3. data/README.md +91 -0
  4. data/Rakefile +78 -0
  5. data/bench.rb +22 -0
  6. data/cache-lexers.rb +8 -0
  7. data/lexers +0 -0
  8. data/lib/pygments/lexer.rb +148 -0
  9. data/lib/pygments/mentos.py +344 -0
  10. data/lib/pygments/popen.rb +389 -0
  11. data/lib/pygments/version.rb +3 -0
  12. data/lib/pygments.rb +8 -0
  13. data/pygments.rb.gemspec +24 -0
  14. data/test/test_data.c +2581 -0
  15. data/test/test_data.py +514 -0
  16. data/test/test_data_generated +2582 -0
  17. data/test/test_pygments.rb +276 -0
  18. data/vendor/custom_formatters/gitlab.py +171 -0
  19. data/vendor/custom_lexers/github.py +362 -0
  20. data/vendor/pygments-main/AUTHORS +115 -0
  21. data/vendor/pygments-main/CHANGES +762 -0
  22. data/vendor/pygments-main/LICENSE +25 -0
  23. data/vendor/pygments-main/MANIFEST.in +6 -0
  24. data/vendor/pygments-main/Makefile +59 -0
  25. data/vendor/pygments-main/REVISION +1 -0
  26. data/vendor/pygments-main/TODO +15 -0
  27. data/vendor/pygments-main/docs/generate.py +472 -0
  28. data/vendor/pygments-main/docs/pygmentize.1 +94 -0
  29. data/vendor/pygments-main/docs/src/api.txt +270 -0
  30. data/vendor/pygments-main/docs/src/authors.txt +5 -0
  31. data/vendor/pygments-main/docs/src/changelog.txt +5 -0
  32. data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
  33. data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
  34. data/vendor/pygments-main/docs/src/filters.txt +42 -0
  35. data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
  36. data/vendor/pygments-main/docs/src/formatters.txt +48 -0
  37. data/vendor/pygments-main/docs/src/index.txt +69 -0
  38. data/vendor/pygments-main/docs/src/installation.txt +71 -0
  39. data/vendor/pygments-main/docs/src/integrate.txt +43 -0
  40. data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
  41. data/vendor/pygments-main/docs/src/lexers.txt +67 -0
  42. data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
  43. data/vendor/pygments-main/docs/src/plugins.txt +93 -0
  44. data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
  45. data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
  46. data/vendor/pygments-main/docs/src/styles.txt +143 -0
  47. data/vendor/pygments-main/docs/src/tokens.txt +349 -0
  48. data/vendor/pygments-main/docs/src/unicode.txt +49 -0
  49. data/vendor/pygments-main/external/markdown-processor.py +67 -0
  50. data/vendor/pygments-main/external/moin-parser.py +112 -0
  51. data/vendor/pygments-main/external/pygments.bashcomp +38 -0
  52. data/vendor/pygments-main/external/rst-directive-old.py +77 -0
  53. data/vendor/pygments-main/external/rst-directive.py +83 -0
  54. data/vendor/pygments-main/ez_setup.py +276 -0
  55. data/vendor/pygments-main/pygmentize +7 -0
  56. data/vendor/pygments-main/pygments/__init__.py +91 -0
  57. data/vendor/pygments-main/pygments/cmdline.py +433 -0
  58. data/vendor/pygments-main/pygments/console.py +74 -0
  59. data/vendor/pygments-main/pygments/filter.py +74 -0
  60. data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
  61. data/vendor/pygments-main/pygments/formatter.py +92 -0
  62. data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
  63. data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
  64. data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
  65. data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
  66. data/vendor/pygments-main/pygments/formatters/html.py +750 -0
  67. data/vendor/pygments-main/pygments/formatters/img.py +553 -0
  68. data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
  69. data/vendor/pygments-main/pygments/formatters/other.py +117 -0
  70. data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
  71. data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
  72. data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
  73. data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
  74. data/vendor/pygments-main/pygments/lexer.py +697 -0
  75. data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
  76. data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
  77. data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
  78. data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
  79. data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
  80. data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
  81. data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
  82. data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
  83. data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
  84. data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
  85. data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
  86. data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
  87. data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
  88. data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
  89. data/vendor/pygments-main/pygments/lexers/github.py +362 -0
  90. data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
  91. data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
  92. data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
  93. data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
  94. data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
  95. data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
  96. data/vendor/pygments-main/pygments/lexers/special.py +100 -0
  97. data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
  98. data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
  99. data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
  100. data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
  101. data/vendor/pygments-main/pygments/plugin.py +74 -0
  102. data/vendor/pygments-main/pygments/scanner.py +104 -0
  103. data/vendor/pygments-main/pygments/style.py +117 -0
  104. data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
  105. data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
  106. data/vendor/pygments-main/pygments/styles/borland.py +51 -0
  107. data/vendor/pygments-main/pygments/styles/bw.py +49 -0
  108. data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
  109. data/vendor/pygments-main/pygments/styles/default.py +73 -0
  110. data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
  111. data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
  112. data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
  113. data/vendor/pygments-main/pygments/styles/manni.py +75 -0
  114. data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
  115. data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
  116. data/vendor/pygments-main/pygments/styles/native.py +65 -0
  117. data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
  118. data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
  119. data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
  120. data/vendor/pygments-main/pygments/styles/tango.py +141 -0
  121. data/vendor/pygments-main/pygments/styles/trac.py +63 -0
  122. data/vendor/pygments-main/pygments/styles/vim.py +63 -0
  123. data/vendor/pygments-main/pygments/styles/vs.py +38 -0
  124. data/vendor/pygments-main/pygments/token.py +195 -0
  125. data/vendor/pygments-main/pygments/unistring.py +130 -0
  126. data/vendor/pygments-main/pygments/util.py +232 -0
  127. data/vendor/pygments-main/scripts/check_sources.py +242 -0
  128. data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
  129. data/vendor/pygments-main/scripts/epydoc.css +280 -0
  130. data/vendor/pygments-main/scripts/find_codetags.py +205 -0
  131. data/vendor/pygments-main/scripts/find_error.py +171 -0
  132. data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
  133. data/vendor/pygments-main/scripts/pylintrc +301 -0
  134. data/vendor/pygments-main/scripts/reindent.py +291 -0
  135. data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
  136. data/vendor/pygments-main/setup.cfg +6 -0
  137. data/vendor/pygments-main/setup.py +88 -0
  138. data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
  139. data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
  140. data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
  141. data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
  142. data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
  143. data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
  144. data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
  145. data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
  146. data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
  147. data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
  148. data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
  149. data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
  150. data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
  151. data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
  152. data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
  153. data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
  154. data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
  155. data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
  156. data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
  157. data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
  158. data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
  159. data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
  160. data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
  161. data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
  162. data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
  163. data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
  164. data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
  165. data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
  166. data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
  167. data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
  168. data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
  169. data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
  170. data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
  171. data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
  172. data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
  173. data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
  174. data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
  175. data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
  176. data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
  177. data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
  178. data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
  179. data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
  180. data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
  181. data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
  182. data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
  183. data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
  184. data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
  185. data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
  186. data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
  187. data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
  188. data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
  189. data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
  190. data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
  191. data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
  192. data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
  193. data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
  194. data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
  195. data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
  196. data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
  197. data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
  198. data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
  199. data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
  200. data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
  201. data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
  202. data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
  203. data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
  204. data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
  205. data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
  206. data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
  207. data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
  208. data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
  209. data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
  210. data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
  211. data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
  212. data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
  213. data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
  214. data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
  215. data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
  216. data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
  217. data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
  218. data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
  219. data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
  220. data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
  221. data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
  222. data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
  223. data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
  224. data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
  225. data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
  226. data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
  227. data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
  228. data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
  229. data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
  230. data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
  231. data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
  232. data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
  233. data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
  234. data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
  235. data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
  236. data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
  237. data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
  238. data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
  239. data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
  240. data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
  241. data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
  242. data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
  243. data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
  244. data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
  245. data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
  246. data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
  247. data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
  248. data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
  249. data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
  250. data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
  251. data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
  252. data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
  253. data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
  254. data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
  255. data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
  256. data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
  257. data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
  258. data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
  259. data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
  260. data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
  261. data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
  262. data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
  263. data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
  264. data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
  265. data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
  266. data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
  267. data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
  268. data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
  269. data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
  270. data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
  271. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
  272. data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
  273. data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
  274. data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
  275. data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
  276. data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
  277. data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
  278. data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
  279. data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
  280. data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
  281. data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
  282. data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
  283. data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
  284. data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
  285. data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
  286. data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
  287. data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
  288. data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
  289. data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
  290. data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
  291. data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
  292. data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
  293. data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
  294. data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
  295. data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
  296. data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
  297. data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
  298. data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
  299. data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
  300. data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
  301. data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
  302. data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
  303. data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
  304. data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
  305. data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
  306. data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
  307. data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
  308. data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
  309. data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
  310. data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
  311. data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
  312. data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
  313. data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
  314. data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
  315. data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
  316. data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
  317. data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
  318. data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
  319. data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
  320. data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
  321. data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
  322. data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
  323. data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
  324. data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
  325. data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
  326. data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
  327. data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
  328. data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
  329. data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
  330. data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
  331. data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
  332. data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
  333. data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
  334. data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
  335. data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
  336. data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
  337. data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
  338. data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
  339. data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
  340. data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
  341. data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
  342. data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
  343. data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
  344. data/vendor/pygments-main/tests/old_run.py +138 -0
  345. data/vendor/pygments-main/tests/run.py +48 -0
  346. data/vendor/pygments-main/tests/support.py +15 -0
  347. data/vendor/pygments-main/tests/test_basic_api.py +294 -0
  348. data/vendor/pygments-main/tests/test_clexer.py +31 -0
  349. data/vendor/pygments-main/tests/test_cmdline.py +105 -0
  350. data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
  351. data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
  352. data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
  353. data/vendor/pygments-main/tests/test_perllexer.py +137 -0
  354. data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
  355. data/vendor/pygments-main/tests/test_token.py +46 -0
  356. data/vendor/pygments-main/tests/test_using_api.py +40 -0
  357. data/vendor/pygments-main/tests/test_util.py +116 -0
  358. data/vendor/simplejson/.gitignore +10 -0
  359. data/vendor/simplejson/.travis.yml +5 -0
  360. data/vendor/simplejson/CHANGES.txt +291 -0
  361. data/vendor/simplejson/LICENSE.txt +19 -0
  362. data/vendor/simplejson/MANIFEST.in +5 -0
  363. data/vendor/simplejson/README.rst +19 -0
  364. data/vendor/simplejson/conf.py +179 -0
  365. data/vendor/simplejson/index.rst +628 -0
  366. data/vendor/simplejson/scripts/make_docs.py +18 -0
  367. data/vendor/simplejson/setup.py +104 -0
  368. data/vendor/simplejson/simplejson/__init__.py +510 -0
  369. data/vendor/simplejson/simplejson/_speedups.c +2745 -0
  370. data/vendor/simplejson/simplejson/decoder.py +425 -0
  371. data/vendor/simplejson/simplejson/encoder.py +567 -0
  372. data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
  373. data/vendor/simplejson/simplejson/scanner.py +77 -0
  374. data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
  375. data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
  376. data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
  377. data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
  378. data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
  379. data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
  380. data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
  381. data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
  382. data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
  383. data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
  384. data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
  385. data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
  386. data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
  387. data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
  388. data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
  389. data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
  390. data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
  391. data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
  392. data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
  393. data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
  394. data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
  395. data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
  396. data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
  397. data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
  398. data/vendor/simplejson/simplejson/tool.py +39 -0
  399. metadata +492 -0
@@ -0,0 +1,360 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.lexers.asm
4
+ ~~~~~~~~~~~~~~~~~~~
5
+
6
+ Lexers for assembly languages.
7
+
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+
14
+ from pygments.lexer import RegexLexer, include, bygroups, using, DelegatingLexer
15
+ from pygments.lexers.compiled import DLexer, CppLexer, CLexer
16
+ from pygments.token import Text, Name, Number, String, Comment, Punctuation, \
17
+ Other, Keyword, Operator
18
+
19
+ __all__ = ['GasLexer', 'ObjdumpLexer','DObjdumpLexer', 'CppObjdumpLexer',
20
+ 'CObjdumpLexer', 'LlvmLexer', 'NasmLexer']
21
+
22
+
23
+ class GasLexer(RegexLexer):
24
+ """
25
+ For Gas (AT&T) assembly code.
26
+ """
27
+ name = 'GAS'
28
+ aliases = ['gas']
29
+ filenames = ['*.s', '*.S']
30
+ mimetypes = ['text/x-gas']
31
+
32
+ #: optional Comment or Whitespace
33
+ string = r'"(\\"|[^"])*"'
34
+ char = r'[a-zA-Z$._0-9@-]'
35
+ identifier = r'(?:[a-zA-Z$_]' + char + '*|\.' + char + '+)'
36
+ number = r'(?:0[xX][a-zA-Z0-9]+|\d+)'
37
+
38
+ tokens = {
39
+ 'root': [
40
+ include('whitespace'),
41
+ (identifier + ':', Name.Label),
42
+ (r'\.' + identifier, Name.Attribute, 'directive-args'),
43
+ (r'lock|rep(n?z)?|data\d+', Name.Attribute),
44
+ (identifier, Name.Function, 'instruction-args'),
45
+ (r'[\r\n]+', Text)
46
+ ],
47
+ 'directive-args': [
48
+ (identifier, Name.Constant),
49
+ (string, String),
50
+ ('@' + identifier, Name.Attribute),
51
+ (number, Number.Integer),
52
+ (r'[\r\n]+', Text, '#pop'),
53
+
54
+ (r'#.*?$', Comment, '#pop'),
55
+
56
+ include('punctuation'),
57
+ include('whitespace')
58
+ ],
59
+ 'instruction-args': [
60
+ # For objdump-disassembled code, shouldn't occur in
61
+ # actual assembler input
62
+ ('([a-z0-9]+)( )(<)('+identifier+')(>)',
63
+ bygroups(Number.Hex, Text, Punctuation, Name.Constant,
64
+ Punctuation)),
65
+ ('([a-z0-9]+)( )(<)('+identifier+')([-+])('+number+')(>)',
66
+ bygroups(Number.Hex, Text, Punctuation, Name.Constant,
67
+ Punctuation, Number.Integer, Punctuation)),
68
+
69
+ # Address constants
70
+ (identifier, Name.Constant),
71
+ (number, Number.Integer),
72
+ # Registers
73
+ ('%' + identifier, Name.Variable),
74
+ # Numeric constants
75
+ ('$'+number, Number.Integer),
76
+ (r"$'(.|\\')'", String.Char),
77
+ (r'[\r\n]+', Text, '#pop'),
78
+ (r'#.*?$', Comment, '#pop'),
79
+ include('punctuation'),
80
+ include('whitespace')
81
+ ],
82
+ 'whitespace': [
83
+ (r'\n', Text),
84
+ (r'\s+', Text),
85
+ (r'#.*?\n', Comment)
86
+ ],
87
+ 'punctuation': [
88
+ (r'[-*,.():]+', Punctuation)
89
+ ]
90
+ }
91
+
92
+ def analyse_text(text):
93
+ if re.match(r'^\.(text|data|section)', text, re.M):
94
+ return True
95
+ elif re.match(r'^\.\w+', text, re.M):
96
+ return 0.1
97
+
98
+
99
+ class ObjdumpLexer(RegexLexer):
100
+ """
101
+ For the output of 'objdump -dr'
102
+ """
103
+ name = 'objdump'
104
+ aliases = ['objdump']
105
+ filenames = ['*.objdump']
106
+ mimetypes = ['text/x-objdump']
107
+
108
+ hex = r'[0-9A-Za-z]'
109
+
110
+ tokens = {
111
+ 'root': [
112
+ # File name & format:
113
+ ('(.*?)(:)( +file format )(.*?)$',
114
+ bygroups(Name.Label, Punctuation, Text, String)),
115
+ # Section header
116
+ ('(Disassembly of section )(.*?)(:)$',
117
+ bygroups(Text, Name.Label, Punctuation)),
118
+ # Function labels
119
+ # (With offset)
120
+ ('('+hex+'+)( )(<)(.*?)([-+])(0[xX][A-Za-z0-9]+)(>:)$',
121
+ bygroups(Number.Hex, Text, Punctuation, Name.Function,
122
+ Punctuation, Number.Hex, Punctuation)),
123
+ # (Without offset)
124
+ ('('+hex+'+)( )(<)(.*?)(>:)$',
125
+ bygroups(Number.Hex, Text, Punctuation, Name.Function,
126
+ Punctuation)),
127
+ # Code line with disassembled instructions
128
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *\t)([a-zA-Z].*?)$',
129
+ bygroups(Text, Name.Label, Text, Number.Hex, Text,
130
+ using(GasLexer))),
131
+ # Code line with ascii
132
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)( *)(.*?)$',
133
+ bygroups(Text, Name.Label, Text, Number.Hex, Text, String)),
134
+ # Continued code line, only raw opcodes without disassembled
135
+ # instruction
136
+ ('( *)('+hex+r'+:)(\t)((?:'+hex+hex+' )+)$',
137
+ bygroups(Text, Name.Label, Text, Number.Hex)),
138
+ # Skipped a few bytes
139
+ (r'\t\.\.\.$', Text),
140
+ # Relocation line
141
+ # (With offset)
142
+ (r'(\t\t\t)('+hex+r'+:)( )([^\t]+)(\t)(.*?)([-+])(0x' + hex + '+)$',
143
+ bygroups(Text, Name.Label, Text, Name.Property, Text,
144
+ Name.Constant, Punctuation, Number.Hex)),
145
+ # (Without offset)
146
+ (r'(\t\t\t)('+hex+r'+:)( )([^\t]+)(\t)(.*?)$',
147
+ bygroups(Text, Name.Label, Text, Name.Property, Text,
148
+ Name.Constant)),
149
+ (r'[^\n]+\n', Other)
150
+ ]
151
+ }
152
+
153
+
154
+ class DObjdumpLexer(DelegatingLexer):
155
+ """
156
+ For the output of 'objdump -Sr on compiled D files'
157
+ """
158
+ name = 'd-objdump'
159
+ aliases = ['d-objdump']
160
+ filenames = ['*.d-objdump']
161
+ mimetypes = ['text/x-d-objdump']
162
+
163
+ def __init__(self, **options):
164
+ super(DObjdumpLexer, self).__init__(DLexer, ObjdumpLexer, **options)
165
+
166
+
167
+ class CppObjdumpLexer(DelegatingLexer):
168
+ """
169
+ For the output of 'objdump -Sr on compiled C++ files'
170
+ """
171
+ name = 'cpp-objdump'
172
+ aliases = ['cpp-objdump', 'c++-objdumb', 'cxx-objdump']
173
+ filenames = ['*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump']
174
+ mimetypes = ['text/x-cpp-objdump']
175
+
176
+ def __init__(self, **options):
177
+ super(CppObjdumpLexer, self).__init__(CppLexer, ObjdumpLexer, **options)
178
+
179
+
180
+ class CObjdumpLexer(DelegatingLexer):
181
+ """
182
+ For the output of 'objdump -Sr on compiled C files'
183
+ """
184
+ name = 'c-objdump'
185
+ aliases = ['c-objdump']
186
+ filenames = ['*.c-objdump']
187
+ mimetypes = ['text/x-c-objdump']
188
+
189
+ def __init__(self, **options):
190
+ super(CObjdumpLexer, self).__init__(CLexer, ObjdumpLexer, **options)
191
+
192
+
193
+ class LlvmLexer(RegexLexer):
194
+ """
195
+ For LLVM assembly code.
196
+ """
197
+ name = 'LLVM'
198
+ aliases = ['llvm']
199
+ filenames = ['*.ll']
200
+ mimetypes = ['text/x-llvm']
201
+
202
+ #: optional Comment or Whitespace
203
+ string = r'"[^"]*?"'
204
+ identifier = r'([-a-zA-Z$._][-a-zA-Z$._0-9]*|' + string + ')'
205
+
206
+ tokens = {
207
+ 'root': [
208
+ include('whitespace'),
209
+
210
+ # Before keywords, because keywords are valid label names :(...
211
+ (r'^\s*' + identifier + '\s*:', Name.Label),
212
+
213
+ include('keyword'),
214
+
215
+ (r'%' + identifier, Name.Variable),#Name.Identifier.Local),
216
+ (r'@' + identifier, Name.Variable.Global),#Name.Identifier.Global),
217
+ (r'%\d+', Name.Variable.Anonymous),#Name.Identifier.Anonymous),
218
+ (r'@\d+', Name.Variable.Global),#Name.Identifier.Anonymous),
219
+ (r'!' + identifier, Name.Variable),
220
+ (r'!\d+', Name.Variable.Anonymous),
221
+ (r'c?' + string, String),
222
+
223
+ (r'0[xX][a-fA-F0-9]+', Number),
224
+ (r'-?\d+(?:[.]\d+)?(?:[eE][-+]?\d+(?:[.]\d+)?)?', Number),
225
+
226
+ (r'[=<>{}\[\]()*.,!]|x\b', Punctuation)
227
+ ],
228
+ 'whitespace': [
229
+ (r'(\n|\s)+', Text),
230
+ (r';.*?\n', Comment)
231
+ ],
232
+ 'keyword': [
233
+ # Regular keywords
234
+ (r'(begin|end'
235
+ r'|true|false'
236
+ r'|declare|define'
237
+ r'|global|constant'
238
+
239
+ r'|private|linker_private|internal|available_externally|linkonce'
240
+ r'|linkonce_odr|weak|weak_odr|appending|dllimport|dllexport'
241
+ r'|common|default|hidden|protected|extern_weak|external'
242
+ r'|thread_local|zeroinitializer|undef|null|to|tail|target|triple'
243
+ r'|deplibs|datalayout|volatile|nuw|nsw|exact|inbounds|align'
244
+ r'|addrspace|section|alias|module|asm|sideeffect|gc|dbg'
245
+
246
+ r'|ccc|fastcc|coldcc|x86_stdcallcc|x86_fastcallcc|arm_apcscc'
247
+ r'|arm_aapcscc|arm_aapcs_vfpcc'
248
+
249
+ r'|cc|c'
250
+
251
+ r'|signext|zeroext|inreg|sret|nounwind|noreturn|noalias|nocapture'
252
+ r'|byval|nest|readnone|readonly'
253
+
254
+ r'|inlinehint|noinline|alwaysinline|optsize|ssp|sspreq|noredzone'
255
+ r'|noimplicitfloat|naked'
256
+
257
+ r'|type|opaque'
258
+
259
+ r'|eq|ne|slt|sgt|sle'
260
+ r'|sge|ult|ugt|ule|uge'
261
+ r'|oeq|one|olt|ogt|ole'
262
+ r'|oge|ord|uno|ueq|une'
263
+ r'|x'
264
+
265
+ # instructions
266
+ r'|add|fadd|sub|fsub|mul|fmul|udiv|sdiv|fdiv|urem|srem|frem|shl'
267
+ r'|lshr|ashr|and|or|xor|icmp|fcmp'
268
+
269
+ r'|phi|call|trunc|zext|sext|fptrunc|fpext|uitofp|sitofp|fptoui'
270
+ r'fptosi|inttoptr|ptrtoint|bitcast|select|va_arg|ret|br|switch'
271
+ r'|invoke|unwind|unreachable'
272
+
273
+ r'|malloc|alloca|free|load|store|getelementptr'
274
+
275
+ r'|extractelement|insertelement|shufflevector|getresult'
276
+ r'|extractvalue|insertvalue'
277
+
278
+ r')\b', Keyword),
279
+
280
+ # Types
281
+ (r'void|float|double|x86_fp80|fp128|ppc_fp128|label|metadata',
282
+ Keyword.Type),
283
+
284
+ # Integer types
285
+ (r'i[1-9]\d*', Keyword)
286
+ ]
287
+ }
288
+
289
+
290
+ class NasmLexer(RegexLexer):
291
+ """
292
+ For Nasm (Intel) assembly code.
293
+ """
294
+ name = 'NASM'
295
+ aliases = ['nasm']
296
+ filenames = ['*.asm', '*.ASM']
297
+ mimetypes = ['text/x-nasm']
298
+
299
+ identifier = r'[a-zA-Z$._?][a-zA-Z0-9$._?#@~]*'
300
+ hexn = r'(?:0[xX][0-9a-fA-F]+|$0[0-9a-fA-F]*|[0-9]+[0-9a-fA-F]*h)'
301
+ octn = r'[0-7]+q'
302
+ binn = r'[01]+b'
303
+ decn = r'[0-9]+'
304
+ floatn = decn + r'\.e?' + decn
305
+ string = r'"(\\"|[^"\n])*"|' + r"'(\\'|[^'\n])*'|" + r"`(\\`|[^`\n])*`"
306
+ declkw = r'(?:res|d)[bwdqt]|times'
307
+ register = (r'r[0-9][0-5]?[bwd]|'
308
+ r'[a-d][lh]|[er]?[a-d]x|[er]?[sb]p|[er]?[sd]i|[c-gs]s|st[0-7]|'
309
+ r'mm[0-7]|cr[0-4]|dr[0-367]|tr[3-7]')
310
+ wordop = r'seg|wrt|strict'
311
+ type = r'byte|[dq]?word'
312
+ directives = (r'BITS|USE16|USE32|SECTION|SEGMENT|ABSOLUTE|EXTERN|GLOBAL|'
313
+ r'ORG|ALIGN|STRUC|ENDSTRUC|COMMON|CPU|GROUP|UPPERCASE|IMPORT|'
314
+ r'EXPORT|LIBRARY|MODULE')
315
+
316
+ flags = re.IGNORECASE | re.MULTILINE
317
+ tokens = {
318
+ 'root': [
319
+ include('whitespace'),
320
+ (r'^\s*%', Comment.Preproc, 'preproc'),
321
+ (identifier + ':', Name.Label),
322
+ (r'(%s)(\s+)(equ)' % identifier,
323
+ bygroups(Name.Constant, Keyword.Declaration, Keyword.Declaration),
324
+ 'instruction-args'),
325
+ (directives, Keyword, 'instruction-args'),
326
+ (declkw, Keyword.Declaration, 'instruction-args'),
327
+ (identifier, Name.Function, 'instruction-args'),
328
+ (r'[\r\n]+', Text)
329
+ ],
330
+ 'instruction-args': [
331
+ (string, String),
332
+ (hexn, Number.Hex),
333
+ (octn, Number.Oct),
334
+ (binn, Number),
335
+ (floatn, Number.Float),
336
+ (decn, Number.Integer),
337
+ include('punctuation'),
338
+ (register, Name.Builtin),
339
+ (identifier, Name.Variable),
340
+ (r'[\r\n]+', Text, '#pop'),
341
+ include('whitespace')
342
+ ],
343
+ 'preproc': [
344
+ (r'[^;\n]+', Comment.Preproc),
345
+ (r';.*?\n', Comment.Single, '#pop'),
346
+ (r'\n', Comment.Preproc, '#pop'),
347
+ ],
348
+ 'whitespace': [
349
+ (r'\n', Text),
350
+ (r'[ \t]+', Text),
351
+ (r';.*', Comment.Single)
352
+ ],
353
+ 'punctuation': [
354
+ (r'[,():\[\]]+', Punctuation),
355
+ (r'[&|^<>+*/%~-]+', Operator),
356
+ (r'[$]+', Keyword.Constant),
357
+ (wordop, Operator.Word),
358
+ (type, Keyword.Type)
359
+ ],
360
+ }
@@ -0,0 +1,2891 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ pygments.lexers.compiled
4
+ ~~~~~~~~~~~~~~~~~~~~~~~~
5
+
6
+ Lexers for compiled languages.
7
+
8
+ :copyright: Copyright 2006-2012 by the Pygments team, see AUTHORS.
9
+ :license: BSD, see LICENSE for details.
10
+ """
11
+
12
+ import re
13
+ from string import Template
14
+
15
+ from pygments.lexer import Lexer, RegexLexer, include, bygroups, using, \
16
+ this, combined
17
+ from pygments.util import get_bool_opt, get_list_opt
18
+ from pygments.token import Text, Comment, Operator, Keyword, Name, String, \
19
+ Number, Punctuation, Error, Literal
20
+ from pygments.scanner import Scanner
21
+
22
+ # backwards compatibility
23
+ from pygments.lexers.functional import OcamlLexer
24
+ from pygments.lexers.jvm import JavaLexer, ScalaLexer
25
+
26
+ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer',
27
+ 'DylanLexer', 'ObjectiveCLexer', 'FortranLexer', 'GLShaderLexer',
28
+ 'PrologLexer', 'CythonLexer', 'ValaLexer', 'OocLexer', 'GoLexer',
29
+ 'FelixLexer', 'AdaLexer', 'Modula2Lexer', 'BlitzMaxLexer',
30
+ 'NimrodLexer', 'FantomLexer']
31
+
32
+
33
+ class CLexer(RegexLexer):
34
+ """
35
+ For C source code with preprocessor directives.
36
+ """
37
+ name = 'C'
38
+ aliases = ['c']
39
+ filenames = ['*.c', '*.h', '*.idc']
40
+ mimetypes = ['text/x-chdr', 'text/x-csrc']
41
+
42
+ #: optional Comment or Whitespace
43
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
44
+
45
+ tokens = {
46
+ 'whitespace': [
47
+ # preprocessor directives: without whitespace
48
+ ('^#if\s+0', Comment.Preproc, 'if0'),
49
+ ('^#', Comment.Preproc, 'macro'),
50
+ # or with whitespace
51
+ ('^(' + _ws + r')(#if\s+0)',
52
+ bygroups(using(this), Comment.Preproc), 'if0'),
53
+ ('^(' + _ws + ')(#)',
54
+ bygroups(using(this), Comment.Preproc), 'macro'),
55
+ (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))',
56
+ bygroups(Text, Name.Label)),
57
+ (r'\n', Text),
58
+ (r'\s+', Text),
59
+ (r'\\\n', Text), # line continuation
60
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
61
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
62
+ ],
63
+ 'statements': [
64
+ (r'L?"', String, 'string'),
65
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
66
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
67
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
68
+ (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
69
+ (r'0[0-7]+[LlUu]*', Number.Oct),
70
+ (r'\d+[LlUu]*', Number.Integer),
71
+ (r'\*/', Error),
72
+ (r'[~!%^&*+=|?:<>/-]', Operator),
73
+ (r'[()\[\],.]', Punctuation),
74
+ (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
75
+ (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
76
+ r'for|goto|if|register|restricted|return|sizeof|static|struct|'
77
+ r'switch|typedef|union|volatile|virtual|while)\b', Keyword),
78
+ (r'(int|long|float|short|double|char|unsigned|signed|void)\b',
79
+ Keyword.Type),
80
+ (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved),
81
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
82
+ r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
83
+ (r'(true|false|NULL)\b', Name.Builtin),
84
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
85
+ ],
86
+ 'root': [
87
+ include('whitespace'),
88
+ # functions
89
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
90
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
91
+ r'(\s*\([^;]*?\))' # signature
92
+ r'(' + _ws + r')({)',
93
+ bygroups(using(this), Name.Function, using(this), using(this),
94
+ Punctuation),
95
+ 'function'),
96
+ # function declarations
97
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
98
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
99
+ r'(\s*\([^;]*?\))' # signature
100
+ r'(' + _ws + r')(;)',
101
+ bygroups(using(this), Name.Function, using(this), using(this),
102
+ Punctuation)),
103
+ ('', Text, 'statement'),
104
+ ],
105
+ 'statement' : [
106
+ include('whitespace'),
107
+ include('statements'),
108
+ ('[{}]', Punctuation),
109
+ (';', Punctuation, '#pop'),
110
+ ],
111
+ 'function': [
112
+ include('whitespace'),
113
+ include('statements'),
114
+ (';', Punctuation),
115
+ ('{', Punctuation, '#push'),
116
+ ('}', Punctuation, '#pop'),
117
+ ],
118
+ 'string': [
119
+ (r'"', String, '#pop'),
120
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
121
+ (r'[^\\"\n]+', String), # all other characters
122
+ (r'\\\n', String), # line continuation
123
+ (r'\\', String), # stray backslash
124
+ ],
125
+ 'macro': [
126
+ (r'[^/\n]+', Comment.Preproc),
127
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
128
+ (r'//.*?\n', Comment.Single, '#pop'),
129
+ (r'/', Comment.Preproc),
130
+ (r'(?<=\\)\n', Comment.Preproc),
131
+ (r'\n', Comment.Preproc, '#pop'),
132
+ ],
133
+ 'if0': [
134
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
135
+ (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
136
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
137
+ (r'.*?\n', Comment),
138
+ ]
139
+ }
140
+
141
+ stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t',
142
+ 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list',
143
+ 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t',
144
+ 'wctrans_t', 'wint_t', 'wctype_t']
145
+ c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
146
+ 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
147
+ 'int_least16_t', 'int_least32_t', 'int_least64_t',
148
+ 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
149
+ 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
150
+ 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
151
+ 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t']
152
+
153
+ def __init__(self, **options):
154
+ self.stdlibhighlighting = get_bool_opt(options,
155
+ 'stdlibhighlighting', True)
156
+ self.c99highlighting = get_bool_opt(options,
157
+ 'c99highlighting', True)
158
+ RegexLexer.__init__(self, **options)
159
+
160
+ def get_tokens_unprocessed(self, text):
161
+ for index, token, value in \
162
+ RegexLexer.get_tokens_unprocessed(self, text):
163
+ if token is Name:
164
+ if self.stdlibhighlighting and value in self.stdlib_types:
165
+ token = Keyword.Type
166
+ elif self.c99highlighting and value in self.c99_types:
167
+ token = Keyword.Type
168
+ yield index, token, value
169
+
170
+ class CppLexer(RegexLexer):
171
+ """
172
+ For C++ source code with preprocessor directives.
173
+ """
174
+ name = 'C++'
175
+ aliases = ['cpp', 'c++']
176
+ filenames = ['*.cpp', '*.hpp', '*.c++', '*.h++',
177
+ '*.cc', '*.hh', '*.cxx', '*.hxx']
178
+ mimetypes = ['text/x-c++hdr', 'text/x-c++src']
179
+
180
+ #: optional Comment or Whitespace
181
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
182
+
183
+ tokens = {
184
+ 'root': [
185
+ # preprocessor directives: without whitespace
186
+ ('^#if\s+0', Comment.Preproc, 'if0'),
187
+ ('^#', Comment.Preproc, 'macro'),
188
+ # or with whitespace
189
+ ('^(' + _ws + r')(#if\s+0)',
190
+ bygroups(using(this), Comment.Preproc), 'if0'),
191
+ ('^(' + _ws + ')(#)',
192
+ bygroups(using(this), Comment.Preproc), 'macro'),
193
+ (r'\n', Text),
194
+ (r'\s+', Text),
195
+ (r'\\\n', Text), # line continuation
196
+ (r'/(\\\n)?/(\n|(.|\n)*?[^\\]\n)', Comment.Single),
197
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
198
+ (r'[{}]', Punctuation),
199
+ (r'L?"', String, 'string'),
200
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
201
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
202
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
203
+ (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
204
+ (r'0[0-7]+[LlUu]*', Number.Oct),
205
+ (r'\d+[LlUu]*', Number.Integer),
206
+ (r'\*/', Error),
207
+ (r'[~!%^&*+=|?:<>/-]', Operator),
208
+ (r'[()\[\],.;]', Punctuation),
209
+ (r'(asm|auto|break|case|catch|const|const_cast|continue|'
210
+ r'default|delete|do|dynamic_cast|else|enum|explicit|export|'
211
+ r'extern|for|friend|goto|if|mutable|namespace|new|operator|'
212
+ r'private|protected|public|register|reinterpret_cast|return|'
213
+ r'restrict|sizeof|static|static_cast|struct|switch|template|'
214
+ r'this|throw|throws|try|typedef|typeid|typename|union|using|'
215
+ r'volatile|virtual|while)\b', Keyword),
216
+ (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
217
+ (r'(bool|int|long|float|short|double|char|unsigned|signed|'
218
+ r'void|wchar_t)\b', Keyword.Type),
219
+ (r'(_{0,2}inline|naked|thread)\b', Keyword.Reserved),
220
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
221
+ r'declspec|finally|int64|try|leave|wchar_t|w64|virtual_inheritance|'
222
+ r'uuidof|unaligned|super|single_inheritance|raise|noop|'
223
+ r'multiple_inheritance|m128i|m128d|m128|m64|interface|'
224
+ r'identifier|forceinline|event|assume)\b', Keyword.Reserved),
225
+ # Offload C++ extensions, http://offload.codeplay.com/
226
+ (r'(__offload|__blockingoffload|__outer)\b', Keyword.Pseudo),
227
+ (r'(true|false)\b', Keyword.Constant),
228
+ (r'NULL\b', Name.Builtin),
229
+ ('[a-zA-Z_][a-zA-Z0-9_]*:(?!:)', Name.Label),
230
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
231
+ ],
232
+ 'classname': [
233
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'),
234
+ # template specification
235
+ (r'\s*(?=>)', Text, '#pop'),
236
+ ],
237
+ 'string': [
238
+ (r'"', String, '#pop'),
239
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
240
+ (r'[^\\"\n]+', String), # all other characters
241
+ (r'\\\n', String), # line continuation
242
+ (r'\\', String), # stray backslash
243
+ ],
244
+ 'macro': [
245
+ (r'[^/\n]+', Comment.Preproc),
246
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
247
+ (r'//.*?\n', Comment.Single, '#pop'),
248
+ (r'/', Comment.Preproc),
249
+ (r'(?<=\\)\n', Comment.Preproc),
250
+ (r'\n', Comment.Preproc, '#pop'),
251
+ ],
252
+ 'if0': [
253
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
254
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
255
+ (r'.*?\n', Comment),
256
+ ]
257
+ }
258
+
259
+
260
+ class ECLexer(RegexLexer):
261
+ """
262
+ For eC source code with preprocessor directives.
263
+
264
+ *New in Pygments 1.5.*
265
+ """
266
+ name = 'eC'
267
+ aliases = ['ec']
268
+ filenames = ['*.ec', '*.eh']
269
+ mimetypes = ['text/x-echdr', 'text/x-ecsrc']
270
+
271
+ #: optional Comment or Whitespace
272
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
273
+
274
+ tokens = {
275
+ 'whitespace': [
276
+ # preprocessor directives: without whitespace
277
+ ('^#if\s+0', Comment.Preproc, 'if0'),
278
+ ('^#', Comment.Preproc, 'macro'),
279
+ # or with whitespace
280
+ ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'),
281
+ ('^' + _ws + '#', Comment.Preproc, 'macro'),
282
+ (r'^(\s*)([a-zA-Z_][a-zA-Z0-9_]*:(?!:))', bygroups(Text, Name.Label)),
283
+ (r'\n', Text),
284
+ (r'\s+', Text),
285
+ (r'\\\n', Text), # line continuation
286
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
287
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
288
+ ],
289
+ 'statements': [
290
+ (r'L?"', String, 'string'),
291
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
292
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[LlUu]*', Number.Float),
293
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
294
+ (r'0x[0-9a-fA-F]+[LlUu]*', Number.Hex),
295
+ (r'0[0-7]+[LlUu]*', Number.Oct),
296
+ (r'\d+[LlUu]*', Number.Integer),
297
+ (r'\*/', Error),
298
+ (r'[~!%^&*+=|?:<>/-]', Operator),
299
+ (r'[()\[\],.]', Punctuation),
300
+ (r'\b(case)(.+?)(:)', bygroups(Keyword, using(this), Text)),
301
+ (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
302
+ r'for|goto|if|register|restricted|return|sizeof|static|struct|'
303
+ r'switch|typedef|union|volatile|virtual|while|class|private|public|'
304
+ r'property|import|delete|new|new0|renew|renew0|define|get|set|remote|dllexport|dllimport|stdcall|'
305
+ r'subclass|__on_register_module|namespace|using|typed_object|any_object|incref|register|watch|'
306
+ r'stopwatching|firewatchers|watchable|class_designer|class_fixed|class_no_expansion|isset|'
307
+ r'class_default_property|property_category|class_data|class_property|virtual|thisclass|'
308
+ r'dbtable|dbindex|database_open|dbfield)\b', Keyword),
309
+ (r'(int|long|float|short|double|char|unsigned|signed|void)\b',
310
+ Keyword.Type),
311
+ (r'(uint|uint16|uint32|uint64|bool|byte|unichar|int64)\b',
312
+ Keyword.Type),
313
+ (r'(class)(\s+)', bygroups(Keyword, Text), 'classname'),
314
+ (r'(_{0,2}inline|naked|restrict|thread|typename)\b', Keyword.Reserved),
315
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
316
+ r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
317
+ (r'(true|false|null|value|this|NULL)\b', Name.Builtin),
318
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
319
+ ],
320
+ 'root': [
321
+ include('whitespace'),
322
+ # functions
323
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
324
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
325
+ r'(\s*\([^;]*?\))' # signature
326
+ r'(' + _ws + r')({)',
327
+ bygroups(using(this), Name.Function, using(this), using(this),
328
+ Punctuation),
329
+ 'function'),
330
+ # function declarations
331
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
332
+ r'([a-zA-Z_][a-zA-Z0-9_]*)' # method name
333
+ r'(\s*\([^;]*?\))' # signature
334
+ r'(' + _ws + r')(;)',
335
+ bygroups(using(this), Name.Function, using(this), using(this),
336
+ Punctuation)),
337
+ ('', Text, 'statement'),
338
+ ],
339
+ 'classname': [
340
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop'),
341
+ # template specification
342
+ (r'\s*(?=>)', Text, '#pop'),
343
+ ],
344
+ 'statement' : [
345
+ include('whitespace'),
346
+ include('statements'),
347
+ ('[{}]', Punctuation),
348
+ (';', Punctuation, '#pop'),
349
+ ],
350
+ 'function': [
351
+ include('whitespace'),
352
+ include('statements'),
353
+ (';', Punctuation),
354
+ ('{', Punctuation, '#push'),
355
+ ('}', Punctuation, '#pop'),
356
+ ],
357
+ 'string': [
358
+ (r'"', String, '#pop'),
359
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
360
+ (r'[^\\"\n]+', String), # all other characters
361
+ (r'\\\n', String), # line continuation
362
+ (r'\\', String), # stray backslash
363
+ ],
364
+ 'macro': [
365
+ (r'[^/\n]+', Comment.Preproc),
366
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
367
+ (r'//.*?\n', Comment.Single, '#pop'),
368
+ (r'/', Comment.Preproc),
369
+ (r'(?<=\\)\n', Comment.Preproc),
370
+ (r'\n', Comment.Preproc, '#pop'),
371
+ ],
372
+ 'if0': [
373
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
374
+ (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
375
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
376
+ (r'.*?\n', Comment),
377
+ ]
378
+ }
379
+
380
+ stdlib_types = ['size_t', 'ssize_t', 'off_t', 'wchar_t', 'ptrdiff_t',
381
+ 'sig_atomic_t', 'fpos_t', 'clock_t', 'time_t', 'va_list',
382
+ 'jmp_buf', 'FILE', 'DIR', 'div_t', 'ldiv_t', 'mbstate_t',
383
+ 'wctrans_t', 'wint_t', 'wctype_t']
384
+ c99_types = ['_Bool', '_Complex', 'int8_t', 'int16_t', 'int32_t', 'int64_t',
385
+ 'uint8_t', 'uint16_t', 'uint32_t', 'uint64_t', 'int_least8_t',
386
+ 'int_least16_t', 'int_least32_t', 'int_least64_t',
387
+ 'uint_least8_t', 'uint_least16_t', 'uint_least32_t',
388
+ 'uint_least64_t', 'int_fast8_t', 'int_fast16_t', 'int_fast32_t',
389
+ 'int_fast64_t', 'uint_fast8_t', 'uint_fast16_t', 'uint_fast32_t',
390
+ 'uint_fast64_t', 'intptr_t', 'uintptr_t', 'intmax_t', 'uintmax_t']
391
+
392
+ def __init__(self, **options):
393
+ self.stdlibhighlighting = get_bool_opt(options,
394
+ 'stdlibhighlighting', True)
395
+ self.c99highlighting = get_bool_opt(options,
396
+ 'c99highlighting', True)
397
+ RegexLexer.__init__(self, **options)
398
+
399
+ def get_tokens_unprocessed(self, text):
400
+ for index, token, value in \
401
+ RegexLexer.get_tokens_unprocessed(self, text):
402
+ if token is Name:
403
+ if self.stdlibhighlighting and value in self.stdlib_types:
404
+ token = Keyword.Type
405
+ elif self.c99highlighting and value in self.c99_types:
406
+ token = Keyword.Type
407
+ yield index, token, value
408
+
409
+
410
+ class DLexer(RegexLexer):
411
+ """
412
+ For D source.
413
+
414
+ *New in Pygments 1.2.*
415
+ """
416
+ name = 'D'
417
+ filenames = ['*.d', '*.di']
418
+ aliases = ['d']
419
+ mimetypes = ['text/x-dsrc']
420
+
421
+ tokens = {
422
+ 'root': [
423
+ (r'\n', Text),
424
+ (r'\s+', Text),
425
+ #(r'\\\n', Text), # line continuations
426
+ # Comments
427
+ (r'//(.*?)\n', Comment.Single),
428
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
429
+ (r'/\+', Comment.Multiline, 'nested_comment'),
430
+ # Keywords
431
+ (r'(abstract|alias|align|asm|assert|auto|body|break|case|cast'
432
+ r'|catch|class|const|continue|debug|default|delegate|delete'
433
+ r'|deprecated|do|else|enum|export|extern|finally|final'
434
+ r'|foreach_reverse|foreach|for|function|goto|if|import|inout'
435
+ r'|interface|invariant|in|is|lazy|mixin|module|new|nothrow|out'
436
+ r'|override|package|pragma|private|protected|public|pure|ref|return'
437
+ r'|scope|static|struct|super|switch|synchronized|template|this'
438
+ r'|throw|try|typedef|typeid|typeof|union|unittest|version|volatile'
439
+ r'|while|with|__traits)\b', Keyword
440
+ ),
441
+ (r'(bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float'
442
+ r'|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong'
443
+ r'|ushort|void|wchar)\b', Keyword.Type
444
+ ),
445
+ (r'(false|true|null)\b', Keyword.Constant),
446
+ (r'macro\b', Keyword.Reserved),
447
+ (r'(string|wstring|dstring)\b', Name.Builtin),
448
+ # FloatLiteral
449
+ # -- HexFloat
450
+ (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
451
+ r'[pP][+\-]?[0-9_]+[fFL]?[i]?', Number.Float),
452
+ # -- DecimalFloat
453
+ (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
454
+ r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[fFL]?[i]?', Number.Float),
455
+ (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[fFL]?[i]?', Number.Float),
456
+ # IntegerLiteral
457
+ # -- Binary
458
+ (r'0[Bb][01_]+', Number),
459
+ # -- Octal
460
+ (r'0[0-7_]+', Number.Oct),
461
+ # -- Hexadecimal
462
+ (r'0[xX][0-9a-fA-F_]+', Number.Hex),
463
+ # -- Decimal
464
+ (r'(0|[1-9][0-9_]*)([LUu]|Lu|LU|uL|UL)?', Number.Integer),
465
+ # CharacterLiteral
466
+ (r"""'(\\['"?\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
467
+ r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|\\&\w+;|.)'""",
468
+ String.Char
469
+ ),
470
+ # StringLiteral
471
+ # -- WysiwygString
472
+ (r'r"[^"]*"[cwd]?', String),
473
+ # -- AlternateWysiwygString
474
+ (r'`[^`]*`[cwd]?', String),
475
+ # -- DoubleQuotedString
476
+ (r'"(\\\\|\\"|[^"])*"[cwd]?', String),
477
+ # -- EscapeSequence
478
+ (r"\\(['\"?\\abfnrtv]|x[0-9a-fA-F]{2}|[0-7]{1,3}"
479
+ r"|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)",
480
+ String
481
+ ),
482
+ # -- HexString
483
+ (r'x"[0-9a-fA-F_\s]*"[cwd]?', String),
484
+ # -- DelimitedString
485
+ (r'q"\[', String, 'delimited_bracket'),
486
+ (r'q"\(', String, 'delimited_parenthesis'),
487
+ (r'q"<', String, 'delimited_angle'),
488
+ (r'q"{', String, 'delimited_curly'),
489
+ (r'q"([a-zA-Z_]\w*)\n.*?\n\1"', String),
490
+ (r'q"(.).*?\1"', String),
491
+ # -- TokenString
492
+ (r'q{', String, 'token_string'),
493
+ # Tokens
494
+ (r'(~=|\^=|%=|\*=|==|!>=|!<=|!<>=|!<>|!<|!>|!=|>>>=|>>>|>>=|>>|>='
495
+ r'|<>=|<>|<<=|<<|<=|\+\+|\+=|--|-=|\|\||\|=|&&|&=|\.\.\.|\.\.|/=)'
496
+ r'|[/.&|\-+<>!()\[\]{}?,;:$=*%^~]', Punctuation
497
+ ),
498
+ # Identifier
499
+ (r'[a-zA-Z_]\w*', Name),
500
+ ],
501
+ 'nested_comment': [
502
+ (r'[^+/]+', Comment.Multiline),
503
+ (r'/\+', Comment.Multiline, '#push'),
504
+ (r'\+/', Comment.Multiline, '#pop'),
505
+ (r'[+/]', Comment.Multiline),
506
+ ],
507
+ 'token_string': [
508
+ (r'{', Punctuation, 'token_string_nest'),
509
+ (r'}', String, '#pop'),
510
+ include('root'),
511
+ ],
512
+ 'token_string_nest': [
513
+ (r'{', Punctuation, '#push'),
514
+ (r'}', Punctuation, '#pop'),
515
+ include('root'),
516
+ ],
517
+ 'delimited_bracket': [
518
+ (r'[^\[\]]+', String),
519
+ (r'\[', String, 'delimited_inside_bracket'),
520
+ (r'\]"', String, '#pop'),
521
+ ],
522
+ 'delimited_inside_bracket': [
523
+ (r'[^\[\]]+', String),
524
+ (r'\[', String, '#push'),
525
+ (r'\]', String, '#pop'),
526
+ ],
527
+ 'delimited_parenthesis': [
528
+ (r'[^\(\)]+', String),
529
+ (r'\(', String, 'delimited_inside_parenthesis'),
530
+ (r'\)"', String, '#pop'),
531
+ ],
532
+ 'delimited_inside_parenthesis': [
533
+ (r'[^\(\)]+', String),
534
+ (r'\(', String, '#push'),
535
+ (r'\)', String, '#pop'),
536
+ ],
537
+ 'delimited_angle': [
538
+ (r'[^<>]+', String),
539
+ (r'<', String, 'delimited_inside_angle'),
540
+ (r'>"', String, '#pop'),
541
+ ],
542
+ 'delimited_inside_angle': [
543
+ (r'[^<>]+', String),
544
+ (r'<', String, '#push'),
545
+ (r'>', String, '#pop'),
546
+ ],
547
+ 'delimited_curly': [
548
+ (r'[^{}]+', String),
549
+ (r'{', String, 'delimited_inside_curly'),
550
+ (r'}"', String, '#pop'),
551
+ ],
552
+ 'delimited_inside_curly': [
553
+ (r'[^{}]+', String),
554
+ (r'{', String, '#push'),
555
+ (r'}', String, '#pop'),
556
+ ],
557
+ }
558
+
559
+
560
+ class DelphiLexer(Lexer):
561
+ """
562
+ For `Delphi <http://www.borland.com/delphi/>`_ (Borland Object Pascal),
563
+ Turbo Pascal and Free Pascal source code.
564
+
565
+ Additional options accepted:
566
+
567
+ `turbopascal`
568
+ Highlight Turbo Pascal specific keywords (default: ``True``).
569
+ `delphi`
570
+ Highlight Borland Delphi specific keywords (default: ``True``).
571
+ `freepascal`
572
+ Highlight Free Pascal specific keywords (default: ``True``).
573
+ `units`
574
+ A list of units that should be considered builtin, supported are
575
+ ``System``, ``SysUtils``, ``Classes`` and ``Math``.
576
+ Default is to consider all of them builtin.
577
+ """
578
+ name = 'Delphi'
579
+ aliases = ['delphi', 'pas', 'pascal', 'objectpascal']
580
+ filenames = ['*.pas']
581
+ mimetypes = ['text/x-pascal']
582
+
583
+ TURBO_PASCAL_KEYWORDS = [
584
+ 'absolute', 'and', 'array', 'asm', 'begin', 'break', 'case',
585
+ 'const', 'constructor', 'continue', 'destructor', 'div', 'do',
586
+ 'downto', 'else', 'end', 'file', 'for', 'function', 'goto',
587
+ 'if', 'implementation', 'in', 'inherited', 'inline', 'interface',
588
+ 'label', 'mod', 'nil', 'not', 'object', 'of', 'on', 'operator',
589
+ 'or', 'packed', 'procedure', 'program', 'record', 'reintroduce',
590
+ 'repeat', 'self', 'set', 'shl', 'shr', 'string', 'then', 'to',
591
+ 'type', 'unit', 'until', 'uses', 'var', 'while', 'with', 'xor'
592
+ ]
593
+
594
+ DELPHI_KEYWORDS = [
595
+ 'as', 'class', 'except', 'exports', 'finalization', 'finally',
596
+ 'initialization', 'is', 'library', 'on', 'property', 'raise',
597
+ 'threadvar', 'try'
598
+ ]
599
+
600
+ FREE_PASCAL_KEYWORDS = [
601
+ 'dispose', 'exit', 'false', 'new', 'true'
602
+ ]
603
+
604
+ BLOCK_KEYWORDS = set([
605
+ 'begin', 'class', 'const', 'constructor', 'destructor', 'end',
606
+ 'finalization', 'function', 'implementation', 'initialization',
607
+ 'label', 'library', 'operator', 'procedure', 'program', 'property',
608
+ 'record', 'threadvar', 'type', 'unit', 'uses', 'var'
609
+ ])
610
+
611
+ FUNCTION_MODIFIERS = set([
612
+ 'alias', 'cdecl', 'export', 'inline', 'interrupt', 'nostackframe',
613
+ 'pascal', 'register', 'safecall', 'softfloat', 'stdcall',
614
+ 'varargs', 'name', 'dynamic', 'near', 'virtual', 'external',
615
+ 'override', 'assembler'
616
+ ])
617
+
618
+ # XXX: those aren't global. but currently we know no way for defining
619
+ # them just for the type context.
620
+ DIRECTIVES = set([
621
+ 'absolute', 'abstract', 'assembler', 'cppdecl', 'default', 'far',
622
+ 'far16', 'forward', 'index', 'oldfpccall', 'private', 'protected',
623
+ 'published', 'public'
624
+ ])
625
+
626
+ BUILTIN_TYPES = set([
627
+ 'ansichar', 'ansistring', 'bool', 'boolean', 'byte', 'bytebool',
628
+ 'cardinal', 'char', 'comp', 'currency', 'double', 'dword',
629
+ 'extended', 'int64', 'integer', 'iunknown', 'longbool', 'longint',
630
+ 'longword', 'pansichar', 'pansistring', 'pbool', 'pboolean',
631
+ 'pbyte', 'pbytearray', 'pcardinal', 'pchar', 'pcomp', 'pcurrency',
632
+ 'pdate', 'pdatetime', 'pdouble', 'pdword', 'pextended', 'phandle',
633
+ 'pint64', 'pinteger', 'plongint', 'plongword', 'pointer',
634
+ 'ppointer', 'pshortint', 'pshortstring', 'psingle', 'psmallint',
635
+ 'pstring', 'pvariant', 'pwidechar', 'pwidestring', 'pword',
636
+ 'pwordarray', 'pwordbool', 'real', 'real48', 'shortint',
637
+ 'shortstring', 'single', 'smallint', 'string', 'tclass', 'tdate',
638
+ 'tdatetime', 'textfile', 'thandle', 'tobject', 'ttime', 'variant',
639
+ 'widechar', 'widestring', 'word', 'wordbool'
640
+ ])
641
+
642
+ BUILTIN_UNITS = {
643
+ 'System': [
644
+ 'abs', 'acquireexceptionobject', 'addr', 'ansitoutf8',
645
+ 'append', 'arctan', 'assert', 'assigned', 'assignfile',
646
+ 'beginthread', 'blockread', 'blockwrite', 'break', 'chdir',
647
+ 'chr', 'close', 'closefile', 'comptocurrency', 'comptodouble',
648
+ 'concat', 'continue', 'copy', 'cos', 'dec', 'delete',
649
+ 'dispose', 'doubletocomp', 'endthread', 'enummodules',
650
+ 'enumresourcemodules', 'eof', 'eoln', 'erase', 'exceptaddr',
651
+ 'exceptobject', 'exclude', 'exit', 'exp', 'filepos', 'filesize',
652
+ 'fillchar', 'finalize', 'findclasshinstance', 'findhinstance',
653
+ 'findresourcehinstance', 'flush', 'frac', 'freemem',
654
+ 'get8087cw', 'getdir', 'getlasterror', 'getmem',
655
+ 'getmemorymanager', 'getmodulefilename', 'getvariantmanager',
656
+ 'halt', 'hi', 'high', 'inc', 'include', 'initialize', 'insert',
657
+ 'int', 'ioresult', 'ismemorymanagerset', 'isvariantmanagerset',
658
+ 'length', 'ln', 'lo', 'low', 'mkdir', 'move', 'new', 'odd',
659
+ 'olestrtostring', 'olestrtostrvar', 'ord', 'paramcount',
660
+ 'paramstr', 'pi', 'pos', 'pred', 'ptr', 'pucs4chars', 'random',
661
+ 'randomize', 'read', 'readln', 'reallocmem',
662
+ 'releaseexceptionobject', 'rename', 'reset', 'rewrite', 'rmdir',
663
+ 'round', 'runerror', 'seek', 'seekeof', 'seekeoln',
664
+ 'set8087cw', 'setlength', 'setlinebreakstyle',
665
+ 'setmemorymanager', 'setstring', 'settextbuf',
666
+ 'setvariantmanager', 'sin', 'sizeof', 'slice', 'sqr', 'sqrt',
667
+ 'str', 'stringofchar', 'stringtoolestr', 'stringtowidechar',
668
+ 'succ', 'swap', 'trunc', 'truncate', 'typeinfo',
669
+ 'ucs4stringtowidestring', 'unicodetoutf8', 'uniquestring',
670
+ 'upcase', 'utf8decode', 'utf8encode', 'utf8toansi',
671
+ 'utf8tounicode', 'val', 'vararrayredim', 'varclear',
672
+ 'widecharlentostring', 'widecharlentostrvar',
673
+ 'widechartostring', 'widechartostrvar',
674
+ 'widestringtoucs4string', 'write', 'writeln'
675
+ ],
676
+ 'SysUtils': [
677
+ 'abort', 'addexitproc', 'addterminateproc', 'adjustlinebreaks',
678
+ 'allocmem', 'ansicomparefilename', 'ansicomparestr',
679
+ 'ansicomparetext', 'ansidequotedstr', 'ansiextractquotedstr',
680
+ 'ansilastchar', 'ansilowercase', 'ansilowercasefilename',
681
+ 'ansipos', 'ansiquotedstr', 'ansisamestr', 'ansisametext',
682
+ 'ansistrcomp', 'ansistricomp', 'ansistrlastchar', 'ansistrlcomp',
683
+ 'ansistrlicomp', 'ansistrlower', 'ansistrpos', 'ansistrrscan',
684
+ 'ansistrscan', 'ansistrupper', 'ansiuppercase',
685
+ 'ansiuppercasefilename', 'appendstr', 'assignstr', 'beep',
686
+ 'booltostr', 'bytetocharindex', 'bytetocharlen', 'bytetype',
687
+ 'callterminateprocs', 'changefileext', 'charlength',
688
+ 'chartobyteindex', 'chartobytelen', 'comparemem', 'comparestr',
689
+ 'comparetext', 'createdir', 'createguid', 'currentyear',
690
+ 'currtostr', 'currtostrf', 'date', 'datetimetofiledate',
691
+ 'datetimetostr', 'datetimetostring', 'datetimetosystemtime',
692
+ 'datetimetotimestamp', 'datetostr', 'dayofweek', 'decodedate',
693
+ 'decodedatefully', 'decodetime', 'deletefile', 'directoryexists',
694
+ 'diskfree', 'disksize', 'disposestr', 'encodedate', 'encodetime',
695
+ 'exceptionerrormessage', 'excludetrailingbackslash',
696
+ 'excludetrailingpathdelimiter', 'expandfilename',
697
+ 'expandfilenamecase', 'expanduncfilename', 'extractfiledir',
698
+ 'extractfiledrive', 'extractfileext', 'extractfilename',
699
+ 'extractfilepath', 'extractrelativepath', 'extractshortpathname',
700
+ 'fileage', 'fileclose', 'filecreate', 'filedatetodatetime',
701
+ 'fileexists', 'filegetattr', 'filegetdate', 'fileisreadonly',
702
+ 'fileopen', 'fileread', 'filesearch', 'fileseek', 'filesetattr',
703
+ 'filesetdate', 'filesetreadonly', 'filewrite', 'finalizepackage',
704
+ 'findclose', 'findcmdlineswitch', 'findfirst', 'findnext',
705
+ 'floattocurr', 'floattodatetime', 'floattodecimal', 'floattostr',
706
+ 'floattostrf', 'floattotext', 'floattotextfmt', 'fmtloadstr',
707
+ 'fmtstr', 'forcedirectories', 'format', 'formatbuf', 'formatcurr',
708
+ 'formatdatetime', 'formatfloat', 'freeandnil', 'getcurrentdir',
709
+ 'getenvironmentvariable', 'getfileversion', 'getformatsettings',
710
+ 'getlocaleformatsettings', 'getmodulename', 'getpackagedescription',
711
+ 'getpackageinfo', 'gettime', 'guidtostring', 'incamonth',
712
+ 'includetrailingbackslash', 'includetrailingpathdelimiter',
713
+ 'incmonth', 'initializepackage', 'interlockeddecrement',
714
+ 'interlockedexchange', 'interlockedexchangeadd',
715
+ 'interlockedincrement', 'inttohex', 'inttostr', 'isdelimiter',
716
+ 'isequalguid', 'isleapyear', 'ispathdelimiter', 'isvalidident',
717
+ 'languages', 'lastdelimiter', 'loadpackage', 'loadstr',
718
+ 'lowercase', 'msecstotimestamp', 'newstr', 'nextcharindex', 'now',
719
+ 'outofmemoryerror', 'quotedstr', 'raiselastoserror',
720
+ 'raiselastwin32error', 'removedir', 'renamefile', 'replacedate',
721
+ 'replacetime', 'safeloadlibrary', 'samefilename', 'sametext',
722
+ 'setcurrentdir', 'showexception', 'sleep', 'stralloc', 'strbufsize',
723
+ 'strbytetype', 'strcat', 'strcharlength', 'strcomp', 'strcopy',
724
+ 'strdispose', 'strecopy', 'strend', 'strfmt', 'stricomp',
725
+ 'stringreplace', 'stringtoguid', 'strlcat', 'strlcomp', 'strlcopy',
726
+ 'strlen', 'strlfmt', 'strlicomp', 'strlower', 'strmove', 'strnew',
727
+ 'strnextchar', 'strpas', 'strpcopy', 'strplcopy', 'strpos',
728
+ 'strrscan', 'strscan', 'strtobool', 'strtobooldef', 'strtocurr',
729
+ 'strtocurrdef', 'strtodate', 'strtodatedef', 'strtodatetime',
730
+ 'strtodatetimedef', 'strtofloat', 'strtofloatdef', 'strtoint',
731
+ 'strtoint64', 'strtoint64def', 'strtointdef', 'strtotime',
732
+ 'strtotimedef', 'strupper', 'supports', 'syserrormessage',
733
+ 'systemtimetodatetime', 'texttofloat', 'time', 'timestamptodatetime',
734
+ 'timestamptomsecs', 'timetostr', 'trim', 'trimleft', 'trimright',
735
+ 'tryencodedate', 'tryencodetime', 'tryfloattocurr', 'tryfloattodatetime',
736
+ 'trystrtobool', 'trystrtocurr', 'trystrtodate', 'trystrtodatetime',
737
+ 'trystrtofloat', 'trystrtoint', 'trystrtoint64', 'trystrtotime',
738
+ 'unloadpackage', 'uppercase', 'widecomparestr', 'widecomparetext',
739
+ 'widefmtstr', 'wideformat', 'wideformatbuf', 'widelowercase',
740
+ 'widesamestr', 'widesametext', 'wideuppercase', 'win32check',
741
+ 'wraptext'
742
+ ],
743
+ 'Classes': [
744
+ 'activateclassgroup', 'allocatehwnd', 'bintohex', 'checksynchronize',
745
+ 'collectionsequal', 'countgenerations', 'deallocatehwnd', 'equalrect',
746
+ 'extractstrings', 'findclass', 'findglobalcomponent', 'getclass',
747
+ 'groupdescendantswith', 'hextobin', 'identtoint',
748
+ 'initinheritedcomponent', 'inttoident', 'invalidpoint',
749
+ 'isuniqueglobalcomponentname', 'linestart', 'objectbinarytotext',
750
+ 'objectresourcetotext', 'objecttexttobinary', 'objecttexttoresource',
751
+ 'pointsequal', 'readcomponentres', 'readcomponentresex',
752
+ 'readcomponentresfile', 'rect', 'registerclass', 'registerclassalias',
753
+ 'registerclasses', 'registercomponents', 'registerintegerconsts',
754
+ 'registernoicon', 'registernonactivex', 'smallpoint', 'startclassgroup',
755
+ 'teststreamformat', 'unregisterclass', 'unregisterclasses',
756
+ 'unregisterintegerconsts', 'unregistermoduleclasses',
757
+ 'writecomponentresfile'
758
+ ],
759
+ 'Math': [
760
+ 'arccos', 'arccosh', 'arccot', 'arccoth', 'arccsc', 'arccsch', 'arcsec',
761
+ 'arcsech', 'arcsin', 'arcsinh', 'arctan2', 'arctanh', 'ceil',
762
+ 'comparevalue', 'cosecant', 'cosh', 'cot', 'cotan', 'coth', 'csc',
763
+ 'csch', 'cycletodeg', 'cycletograd', 'cycletorad', 'degtocycle',
764
+ 'degtograd', 'degtorad', 'divmod', 'doubledecliningbalance',
765
+ 'ensurerange', 'floor', 'frexp', 'futurevalue', 'getexceptionmask',
766
+ 'getprecisionmode', 'getroundmode', 'gradtocycle', 'gradtodeg',
767
+ 'gradtorad', 'hypot', 'inrange', 'interestpayment', 'interestrate',
768
+ 'internalrateofreturn', 'intpower', 'isinfinite', 'isnan', 'iszero',
769
+ 'ldexp', 'lnxp1', 'log10', 'log2', 'logn', 'max', 'maxintvalue',
770
+ 'maxvalue', 'mean', 'meanandstddev', 'min', 'minintvalue', 'minvalue',
771
+ 'momentskewkurtosis', 'netpresentvalue', 'norm', 'numberofperiods',
772
+ 'payment', 'periodpayment', 'poly', 'popnstddev', 'popnvariance',
773
+ 'power', 'presentvalue', 'radtocycle', 'radtodeg', 'radtograd',
774
+ 'randg', 'randomrange', 'roundto', 'samevalue', 'sec', 'secant',
775
+ 'sech', 'setexceptionmask', 'setprecisionmode', 'setroundmode',
776
+ 'sign', 'simpleroundto', 'sincos', 'sinh', 'slndepreciation', 'stddev',
777
+ 'sum', 'sumint', 'sumofsquares', 'sumsandsquares', 'syddepreciation',
778
+ 'tan', 'tanh', 'totalvariance', 'variance'
779
+ ]
780
+ }
781
+
782
+ ASM_REGISTERS = set([
783
+ 'ah', 'al', 'ax', 'bh', 'bl', 'bp', 'bx', 'ch', 'cl', 'cr0',
784
+ 'cr1', 'cr2', 'cr3', 'cr4', 'cs', 'cx', 'dh', 'di', 'dl', 'dr0',
785
+ 'dr1', 'dr2', 'dr3', 'dr4', 'dr5', 'dr6', 'dr7', 'ds', 'dx',
786
+ 'eax', 'ebp', 'ebx', 'ecx', 'edi', 'edx', 'es', 'esi', 'esp',
787
+ 'fs', 'gs', 'mm0', 'mm1', 'mm2', 'mm3', 'mm4', 'mm5', 'mm6',
788
+ 'mm7', 'si', 'sp', 'ss', 'st0', 'st1', 'st2', 'st3', 'st4', 'st5',
789
+ 'st6', 'st7', 'xmm0', 'xmm1', 'xmm2', 'xmm3', 'xmm4', 'xmm5',
790
+ 'xmm6', 'xmm7'
791
+ ])
792
+
793
+ ASM_INSTRUCTIONS = set([
794
+ 'aaa', 'aad', 'aam', 'aas', 'adc', 'add', 'and', 'arpl', 'bound',
795
+ 'bsf', 'bsr', 'bswap', 'bt', 'btc', 'btr', 'bts', 'call', 'cbw',
796
+ 'cdq', 'clc', 'cld', 'cli', 'clts', 'cmc', 'cmova', 'cmovae',
797
+ 'cmovb', 'cmovbe', 'cmovc', 'cmovcxz', 'cmove', 'cmovg',
798
+ 'cmovge', 'cmovl', 'cmovle', 'cmovna', 'cmovnae', 'cmovnb',
799
+ 'cmovnbe', 'cmovnc', 'cmovne', 'cmovng', 'cmovnge', 'cmovnl',
800
+ 'cmovnle', 'cmovno', 'cmovnp', 'cmovns', 'cmovnz', 'cmovo',
801
+ 'cmovp', 'cmovpe', 'cmovpo', 'cmovs', 'cmovz', 'cmp', 'cmpsb',
802
+ 'cmpsd', 'cmpsw', 'cmpxchg', 'cmpxchg486', 'cmpxchg8b', 'cpuid',
803
+ 'cwd', 'cwde', 'daa', 'das', 'dec', 'div', 'emms', 'enter', 'hlt',
804
+ 'ibts', 'icebp', 'idiv', 'imul', 'in', 'inc', 'insb', 'insd',
805
+ 'insw', 'int', 'int01', 'int03', 'int1', 'int3', 'into', 'invd',
806
+ 'invlpg', 'iret', 'iretd', 'iretw', 'ja', 'jae', 'jb', 'jbe',
807
+ 'jc', 'jcxz', 'jcxz', 'je', 'jecxz', 'jg', 'jge', 'jl', 'jle',
808
+ 'jmp', 'jna', 'jnae', 'jnb', 'jnbe', 'jnc', 'jne', 'jng', 'jnge',
809
+ 'jnl', 'jnle', 'jno', 'jnp', 'jns', 'jnz', 'jo', 'jp', 'jpe',
810
+ 'jpo', 'js', 'jz', 'lahf', 'lar', 'lcall', 'lds', 'lea', 'leave',
811
+ 'les', 'lfs', 'lgdt', 'lgs', 'lidt', 'ljmp', 'lldt', 'lmsw',
812
+ 'loadall', 'loadall286', 'lock', 'lodsb', 'lodsd', 'lodsw',
813
+ 'loop', 'loope', 'loopne', 'loopnz', 'loopz', 'lsl', 'lss', 'ltr',
814
+ 'mov', 'movd', 'movq', 'movsb', 'movsd', 'movsw', 'movsx',
815
+ 'movzx', 'mul', 'neg', 'nop', 'not', 'or', 'out', 'outsb', 'outsd',
816
+ 'outsw', 'pop', 'popa', 'popad', 'popaw', 'popf', 'popfd', 'popfw',
817
+ 'push', 'pusha', 'pushad', 'pushaw', 'pushf', 'pushfd', 'pushfw',
818
+ 'rcl', 'rcr', 'rdmsr', 'rdpmc', 'rdshr', 'rdtsc', 'rep', 'repe',
819
+ 'repne', 'repnz', 'repz', 'ret', 'retf', 'retn', 'rol', 'ror',
820
+ 'rsdc', 'rsldt', 'rsm', 'sahf', 'sal', 'salc', 'sar', 'sbb',
821
+ 'scasb', 'scasd', 'scasw', 'seta', 'setae', 'setb', 'setbe',
822
+ 'setc', 'setcxz', 'sete', 'setg', 'setge', 'setl', 'setle',
823
+ 'setna', 'setnae', 'setnb', 'setnbe', 'setnc', 'setne', 'setng',
824
+ 'setnge', 'setnl', 'setnle', 'setno', 'setnp', 'setns', 'setnz',
825
+ 'seto', 'setp', 'setpe', 'setpo', 'sets', 'setz', 'sgdt', 'shl',
826
+ 'shld', 'shr', 'shrd', 'sidt', 'sldt', 'smi', 'smint', 'smintold',
827
+ 'smsw', 'stc', 'std', 'sti', 'stosb', 'stosd', 'stosw', 'str',
828
+ 'sub', 'svdc', 'svldt', 'svts', 'syscall', 'sysenter', 'sysexit',
829
+ 'sysret', 'test', 'ud1', 'ud2', 'umov', 'verr', 'verw', 'wait',
830
+ 'wbinvd', 'wrmsr', 'wrshr', 'xadd', 'xbts', 'xchg', 'xlat',
831
+ 'xlatb', 'xor'
832
+ ])
833
+
834
+ def __init__(self, **options):
835
+ Lexer.__init__(self, **options)
836
+ self.keywords = set()
837
+ if get_bool_opt(options, 'turbopascal', True):
838
+ self.keywords.update(self.TURBO_PASCAL_KEYWORDS)
839
+ if get_bool_opt(options, 'delphi', True):
840
+ self.keywords.update(self.DELPHI_KEYWORDS)
841
+ if get_bool_opt(options, 'freepascal', True):
842
+ self.keywords.update(self.FREE_PASCAL_KEYWORDS)
843
+ self.builtins = set()
844
+ for unit in get_list_opt(options, 'units', self.BUILTIN_UNITS.keys()):
845
+ self.builtins.update(self.BUILTIN_UNITS[unit])
846
+
847
+ def get_tokens_unprocessed(self, text):
848
+ scanner = Scanner(text, re.DOTALL | re.MULTILINE | re.IGNORECASE)
849
+ stack = ['initial']
850
+ in_function_block = False
851
+ in_property_block = False
852
+ was_dot = False
853
+ next_token_is_function = False
854
+ next_token_is_property = False
855
+ collect_labels = False
856
+ block_labels = set()
857
+ brace_balance = [0, 0]
858
+
859
+ while not scanner.eos:
860
+ token = Error
861
+
862
+ if stack[-1] == 'initial':
863
+ if scanner.scan(r'\s+'):
864
+ token = Text
865
+ elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
866
+ if scanner.match.startswith('$'):
867
+ token = Comment.Preproc
868
+ else:
869
+ token = Comment.Multiline
870
+ elif scanner.scan(r'//.*?$'):
871
+ token = Comment.Single
872
+ elif scanner.scan(r'[-+*\/=<>:;,.@\^]'):
873
+ token = Operator
874
+ # stop label highlighting on next ";"
875
+ if collect_labels and scanner.match == ';':
876
+ collect_labels = False
877
+ elif scanner.scan(r'[\(\)\[\]]+'):
878
+ token = Punctuation
879
+ # abort function naming ``foo = Function(...)``
880
+ next_token_is_function = False
881
+ # if we are in a function block we count the open
882
+ # braces because ootherwise it's impossible to
883
+ # determine the end of the modifier context
884
+ if in_function_block or in_property_block:
885
+ if scanner.match == '(':
886
+ brace_balance[0] += 1
887
+ elif scanner.match == ')':
888
+ brace_balance[0] -= 1
889
+ elif scanner.match == '[':
890
+ brace_balance[1] += 1
891
+ elif scanner.match == ']':
892
+ brace_balance[1] -= 1
893
+ elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
894
+ lowercase_name = scanner.match.lower()
895
+ if lowercase_name == 'result':
896
+ token = Name.Builtin.Pseudo
897
+ elif lowercase_name in self.keywords:
898
+ token = Keyword
899
+ # if we are in a special block and a
900
+ # block ending keyword occours (and the parenthesis
901
+ # is balanced) we end the current block context
902
+ if (in_function_block or in_property_block) and \
903
+ lowercase_name in self.BLOCK_KEYWORDS and \
904
+ brace_balance[0] <= 0 and \
905
+ brace_balance[1] <= 0:
906
+ in_function_block = False
907
+ in_property_block = False
908
+ brace_balance = [0, 0]
909
+ block_labels = set()
910
+ if lowercase_name in ('label', 'goto'):
911
+ collect_labels = True
912
+ elif lowercase_name == 'asm':
913
+ stack.append('asm')
914
+ elif lowercase_name == 'property':
915
+ in_property_block = True
916
+ next_token_is_property = True
917
+ elif lowercase_name in ('procedure', 'operator',
918
+ 'function', 'constructor',
919
+ 'destructor'):
920
+ in_function_block = True
921
+ next_token_is_function = True
922
+ # we are in a function block and the current name
923
+ # is in the set of registered modifiers. highlight
924
+ # it as pseudo keyword
925
+ elif in_function_block and \
926
+ lowercase_name in self.FUNCTION_MODIFIERS:
927
+ token = Keyword.Pseudo
928
+ # if we are in a property highlight some more
929
+ # modifiers
930
+ elif in_property_block and \
931
+ lowercase_name in ('read', 'write'):
932
+ token = Keyword.Pseudo
933
+ next_token_is_function = True
934
+ # if the last iteration set next_token_is_function
935
+ # to true we now want this name highlighted as
936
+ # function. so do that and reset the state
937
+ elif next_token_is_function:
938
+ # Look if the next token is a dot. If yes it's
939
+ # not a function, but a class name and the
940
+ # part after the dot a function name
941
+ if scanner.test(r'\s*\.\s*'):
942
+ token = Name.Class
943
+ # it's not a dot, our job is done
944
+ else:
945
+ token = Name.Function
946
+ next_token_is_function = False
947
+ # same for properties
948
+ elif next_token_is_property:
949
+ token = Name.Property
950
+ next_token_is_property = False
951
+ # Highlight this token as label and add it
952
+ # to the list of known labels
953
+ elif collect_labels:
954
+ token = Name.Label
955
+ block_labels.add(scanner.match.lower())
956
+ # name is in list of known labels
957
+ elif lowercase_name in block_labels:
958
+ token = Name.Label
959
+ elif lowercase_name in self.BUILTIN_TYPES:
960
+ token = Keyword.Type
961
+ elif lowercase_name in self.DIRECTIVES:
962
+ token = Keyword.Pseudo
963
+ # builtins are just builtins if the token
964
+ # before isn't a dot
965
+ elif not was_dot and lowercase_name in self.builtins:
966
+ token = Name.Builtin
967
+ else:
968
+ token = Name
969
+ elif scanner.scan(r"'"):
970
+ token = String
971
+ stack.append('string')
972
+ elif scanner.scan(r'\#(\d+|\$[0-9A-Fa-f]+)'):
973
+ token = String.Char
974
+ elif scanner.scan(r'\$[0-9A-Fa-f]+'):
975
+ token = Number.Hex
976
+ elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
977
+ token = Number.Integer
978
+ elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
979
+ token = Number.Float
980
+ else:
981
+ # if the stack depth is deeper than once, pop
982
+ if len(stack) > 1:
983
+ stack.pop()
984
+ scanner.get_char()
985
+
986
+ elif stack[-1] == 'string':
987
+ if scanner.scan(r"''"):
988
+ token = String.Escape
989
+ elif scanner.scan(r"'"):
990
+ token = String
991
+ stack.pop()
992
+ elif scanner.scan(r"[^']*"):
993
+ token = String
994
+ else:
995
+ scanner.get_char()
996
+ stack.pop()
997
+
998
+ elif stack[-1] == 'asm':
999
+ if scanner.scan(r'\s+'):
1000
+ token = Text
1001
+ elif scanner.scan(r'end'):
1002
+ token = Keyword
1003
+ stack.pop()
1004
+ elif scanner.scan(r'\{.*?\}|\(\*.*?\*\)'):
1005
+ if scanner.match.startswith('$'):
1006
+ token = Comment.Preproc
1007
+ else:
1008
+ token = Comment.Multiline
1009
+ elif scanner.scan(r'//.*?$'):
1010
+ token = Comment.Single
1011
+ elif scanner.scan(r"'"):
1012
+ token = String
1013
+ stack.append('string')
1014
+ elif scanner.scan(r'@@[A-Za-z_][A-Za-z_0-9]*'):
1015
+ token = Name.Label
1016
+ elif scanner.scan(r'[A-Za-z_][A-Za-z_0-9]*'):
1017
+ lowercase_name = scanner.match.lower()
1018
+ if lowercase_name in self.ASM_INSTRUCTIONS:
1019
+ token = Keyword
1020
+ elif lowercase_name in self.ASM_REGISTERS:
1021
+ token = Name.Builtin
1022
+ else:
1023
+ token = Name
1024
+ elif scanner.scan(r'[-+*\/=<>:;,.@\^]+'):
1025
+ token = Operator
1026
+ elif scanner.scan(r'[\(\)\[\]]+'):
1027
+ token = Punctuation
1028
+ elif scanner.scan(r'\$[0-9A-Fa-f]+'):
1029
+ token = Number.Hex
1030
+ elif scanner.scan(r'\d+(?![eE]|\.[^.])'):
1031
+ token = Number.Integer
1032
+ elif scanner.scan(r'\d+(\.\d+([eE][+-]?\d+)?|[eE][+-]?\d+)'):
1033
+ token = Number.Float
1034
+ else:
1035
+ scanner.get_char()
1036
+ stack.pop()
1037
+
1038
+ # save the dot!!!11
1039
+ if scanner.match.strip():
1040
+ was_dot = scanner.match == '.'
1041
+ yield scanner.start_pos, token, scanner.match or ''
1042
+
1043
+
1044
+ class DylanLexer(RegexLexer):
1045
+ """
1046
+ For the `Dylan <http://www.opendylan.org/>`_ language.
1047
+
1048
+ *New in Pygments 0.7.*
1049
+ """
1050
+
1051
+ name = 'Dylan'
1052
+ aliases = ['dylan']
1053
+ filenames = ['*.dylan', '*.dyl']
1054
+ mimetypes = ['text/x-dylan']
1055
+
1056
+ flags = re.DOTALL
1057
+
1058
+ tokens = {
1059
+ 'root': [
1060
+ (r'\b(subclass|abstract|block|c(on(crete|stant)|lass)|domain'
1061
+ r'|ex(c(eption|lude)|port)|f(unction(al)?)|generic|handler'
1062
+ r'|i(n(herited|line|stance|terface)|mport)|library|m(acro|ethod)'
1063
+ r'|open|primary|sealed|si(deways|ngleton)|slot'
1064
+ r'|v(ariable|irtual))\b', Name.Builtin),
1065
+ (r'<\w+>', Keyword.Type),
1066
+ (r'//.*?\n', Comment.Single),
1067
+ (r'/\*[\w\W]*?\*/', Comment.Multiline),
1068
+ (r'"', String, 'string'),
1069
+ (r"'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'", String.Char),
1070
+ (r'=>|\b(a(bove|fterwards)|b(e(gin|low)|y)|c(ase|leanup|reate)'
1071
+ r'|define|else(if)?|end|f(inally|or|rom)|i[fn]|l(et|ocal)|otherwise'
1072
+ r'|rename|s(elect|ignal)|t(hen|o)|u(n(less|til)|se)|wh(en|ile))\b',
1073
+ Keyword),
1074
+ (r'([ \t])([!\$%&\*\/:<=>\?~_^a-zA-Z0-9.+\-]*:)',
1075
+ bygroups(Text, Name.Variable)),
1076
+ (r'([ \t]*)(\S+[^:])([ \t]*)(\()([ \t]*)',
1077
+ bygroups(Text, Name.Function, Text, Punctuation, Text)),
1078
+ (r'-?[0-9.]+', Number),
1079
+ (r'[(),;]', Punctuation),
1080
+ (r'\$[a-zA-Z0-9-]+', Name.Constant),
1081
+ (r'[!$%&*/:<>=?~^.+\[\]{}-]+', Operator),
1082
+ (r'\s+', Text),
1083
+ (r'#"[a-zA-Z0-9-]+"', Keyword),
1084
+ (r'#[a-zA-Z0-9-]+', Keyword),
1085
+ (r'#(\(|\[)', Punctuation),
1086
+ (r'[a-zA-Z0-9-_]+', Name.Variable),
1087
+ ],
1088
+ 'string': [
1089
+ (r'"', String, '#pop'),
1090
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1091
+ (r'[^\\"\n]+', String), # all other characters
1092
+ (r'\\\n', String), # line continuation
1093
+ (r'\\', String), # stray backslash
1094
+ ],
1095
+ }
1096
+
1097
+
1098
+ class ObjectiveCLexer(RegexLexer):
1099
+ """
1100
+ For Objective-C source code with preprocessor directives.
1101
+ """
1102
+
1103
+ name = 'Objective-C'
1104
+ aliases = ['objective-c', 'objectivec', 'obj-c', 'objc']
1105
+ #XXX: objc has .h files too :-/
1106
+ filenames = ['*.m']
1107
+ mimetypes = ['text/x-objective-c']
1108
+
1109
+ #: optional Comment or Whitespace
1110
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
1111
+
1112
+ tokens = {
1113
+ 'whitespace': [
1114
+ # preprocessor directives: without whitespace
1115
+ ('^#if\s+0', Comment.Preproc, 'if0'),
1116
+ ('^#', Comment.Preproc, 'macro'),
1117
+ # or with whitespace
1118
+ ('^' + _ws + r'#if\s+0', Comment.Preproc, 'if0'),
1119
+ ('^' + _ws + '#', Comment.Preproc, 'macro'),
1120
+ (r'\n', Text),
1121
+ (r'\s+', Text),
1122
+ (r'\\\n', Text), # line continuation
1123
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
1124
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1125
+ ],
1126
+ 'statements': [
1127
+ (r'(L|@)?"', String, 'string'),
1128
+ (r"(L|@)?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1129
+ String.Char),
1130
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1131
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1132
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1133
+ (r'0[0-7]+[Ll]?', Number.Oct),
1134
+ (r'\d+[Ll]?', Number.Integer),
1135
+ (r'[~!%^&*+=|?:<>/-]', Operator),
1136
+ (r'[()\[\],.]', Punctuation),
1137
+ (r'(auto|break|case|const|continue|default|do|else|enum|extern|'
1138
+ r'for|goto|if|register|restricted|return|sizeof|static|struct|'
1139
+ r'switch|typedef|union|volatile|virtual|while|in|@selector|'
1140
+ r'@private|@protected|@public|@encode|'
1141
+ r'@synchronized|@try|@throw|@catch|@finally|@end|@property|'
1142
+ r'@synthesize|@dynamic)\b', Keyword),
1143
+ (r'(int|long|float|short|double|char|unsigned|signed|void|'
1144
+ r'id|BOOL|IBOutlet|IBAction|SEL)\b', Keyword.Type),
1145
+ (r'(_{0,2}inline|naked|restrict|thread|typename)\b',
1146
+ Keyword.Reserved),
1147
+ (r'__(asm|int8|based|except|int16|stdcall|cdecl|fastcall|int32|'
1148
+ r'declspec|finally|int64|try|leave)\b', Keyword.Reserved),
1149
+ (r'(TRUE|FALSE|nil|NULL)\b', Name.Builtin),
1150
+ ('[a-zA-Z$_][a-zA-Z0-9$_]*:(?!:)', Name.Label),
1151
+ ('[a-zA-Z$_][a-zA-Z0-9$_]*', Name),
1152
+ ],
1153
+ 'root': [
1154
+ include('whitespace'),
1155
+ # functions
1156
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1157
+ r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1158
+ r'(\s*\([^;]*?\))' # signature
1159
+ r'(' + _ws + r')({)',
1160
+ bygroups(using(this), Name.Function,
1161
+ using(this), Text, Punctuation),
1162
+ 'function'),
1163
+ # methods
1164
+ (r'^([-+])(\s*)' # method marker
1165
+ r'(\(.*?\))?(\s*)' # return type
1166
+ r'([a-zA-Z$_][a-zA-Z0-9$_]*:?)', # begin of method name
1167
+ bygroups(Keyword, Text, using(this),
1168
+ Text, Name.Function),
1169
+ 'method'),
1170
+ # function declarations
1171
+ (r'((?:[a-zA-Z0-9_*\s])+?(?:\s|[*]))' # return arguments
1172
+ r'([a-zA-Z$_][a-zA-Z0-9$_]*)' # method name
1173
+ r'(\s*\([^;]*?\))' # signature
1174
+ r'(' + _ws + r')(;)',
1175
+ bygroups(using(this), Name.Function,
1176
+ using(this), Text, Punctuation)),
1177
+ (r'(@interface|@implementation)(\s+)', bygroups(Keyword, Text),
1178
+ 'classname'),
1179
+ (r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
1180
+ 'forward_classname'),
1181
+ (r'(\s*)(@end)(\s*)', bygroups(Text, Keyword, Text)),
1182
+ ('', Text, 'statement'),
1183
+ ],
1184
+ 'classname' : [
1185
+ # interface definition that inherits
1186
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*:\s*)([a-zA-Z$_][a-zA-Z0-9$_]*)?',
1187
+ bygroups(Name.Class, Text, Name.Class), '#pop'),
1188
+ # interface definition for a category
1189
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*)(\([a-zA-Z$_][a-zA-Z0-9$_]*\))',
1190
+ bygroups(Name.Class, Text, Name.Label), '#pop'),
1191
+ # simple interface / implementation
1192
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)', Name.Class, '#pop')
1193
+ ],
1194
+ 'forward_classname' : [
1195
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*,\s*)',
1196
+ bygroups(Name.Class, Text), 'forward_classname'),
1197
+ ('([a-zA-Z$_][a-zA-Z0-9$_]*)(\s*;?)',
1198
+ bygroups(Name.Class, Text), '#pop')
1199
+ ],
1200
+ 'statement' : [
1201
+ include('whitespace'),
1202
+ include('statements'),
1203
+ ('[{}]', Punctuation),
1204
+ (';', Punctuation, '#pop'),
1205
+ ],
1206
+ 'function': [
1207
+ include('whitespace'),
1208
+ include('statements'),
1209
+ (';', Punctuation),
1210
+ ('{', Punctuation, '#push'),
1211
+ ('}', Punctuation, '#pop'),
1212
+ ],
1213
+ 'method': [
1214
+ include('whitespace'),
1215
+ (r'(\(.*?\))([a-zA-Z$_][a-zA-Z0-9$_]*)', bygroups(using(this),
1216
+ Name.Variable)),
1217
+ (r'[a-zA-Z$_][a-zA-Z0-9$_]*:', Name.Function),
1218
+ (';', Punctuation, '#pop'),
1219
+ ('{', Punctuation, 'function'),
1220
+ ('', Text, '#pop'),
1221
+ ],
1222
+ 'string': [
1223
+ (r'"', String, '#pop'),
1224
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1225
+ (r'[^\\"\n]+', String), # all other characters
1226
+ (r'\\\n', String), # line continuation
1227
+ (r'\\', String), # stray backslash
1228
+ ],
1229
+ 'macro': [
1230
+ (r'[^/\n]+', Comment.Preproc),
1231
+ (r'/[*](.|\n)*?[*]/', Comment.Multiline),
1232
+ (r'//.*?\n', Comment.Single, '#pop'),
1233
+ (r'/', Comment.Preproc),
1234
+ (r'(?<=\\)\n', Comment.Preproc),
1235
+ (r'\n', Comment.Preproc, '#pop'),
1236
+ ],
1237
+ 'if0': [
1238
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
1239
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
1240
+ (r'.*?\n', Comment),
1241
+ ]
1242
+ }
1243
+
1244
+ def analyse_text(text):
1245
+ if '@import' in text or '@interface' in text or \
1246
+ '@implementation' in text:
1247
+ return True
1248
+ elif '@"' in text: # strings
1249
+ return True
1250
+ elif re.match(r'\[[a-zA-Z0-9.]:', text): # message
1251
+ return True
1252
+ return False
1253
+
1254
+
1255
+ class FortranLexer(RegexLexer):
1256
+ """
1257
+ Lexer for FORTRAN 90 code.
1258
+
1259
+ *New in Pygments 0.10.*
1260
+ """
1261
+ name = 'Fortran'
1262
+ aliases = ['fortran']
1263
+ filenames = ['*.f', '*.f90', '*.F', '*.F90']
1264
+ mimetypes = ['text/x-fortran']
1265
+ flags = re.IGNORECASE
1266
+
1267
+ # Data Types: INTEGER, REAL, COMPLEX, LOGICAL, CHARACTER and DOUBLE PRECISION
1268
+ # Operators: **, *, +, -, /, <, >, <=, >=, ==, /=
1269
+ # Logical (?): NOT, AND, OR, EQV, NEQV
1270
+
1271
+ # Builtins:
1272
+ # http://gcc.gnu.org/onlinedocs/gcc-3.4.6/g77/Table-of-Intrinsic-Functions.html
1273
+
1274
+ tokens = {
1275
+ 'root': [
1276
+ (r'!.*\n', Comment),
1277
+ include('strings'),
1278
+ include('core'),
1279
+ (r'[a-z][a-z0-9_]*', Name.Variable),
1280
+ include('nums'),
1281
+ (r'[\s]+', Text),
1282
+ ],
1283
+ 'core': [
1284
+ # Statements
1285
+ (r'\b(ACCEPT|ALLOCATABLE|ALLOCATE|ARRAY|ASSIGN|ASYNCHRONOUS|'
1286
+ r'BACKSPACE|BIND|BLOCK DATA|BYTE|CALL|CASE|CLOSE|COMMON|CONTAINS|'
1287
+ r'CONTINUE|CYCLE|DATA|DEALLOCATE|DECODE|DEFERRED|DIMENSION|DO|'
1288
+ r'ELSE|ENCODE|END FILE|ENDIF|END|ENTRY|ENUMERATOR|EQUIVALENCE|'
1289
+ r'EXIT|EXTERNAL|EXTRINSIC|FINAL|FORALL|FORMAT|FUNCTION|GENERIC|'
1290
+ r'GOTO|IF|IMPLICIT|IMPORT|INCLUDE|INQUIRE|INTENT|INTERFACE|'
1291
+ r'INTRINSIC|MODULE|NAMELIST|NULLIFY|NONE|NON_INTRINSIC|'
1292
+ r'NON_OVERRIDABLE|NOPASS|OPEN|OPTIONAL|OPTIONS|PARAMETER|PASS|'
1293
+ r'PAUSE|POINTER|PRINT|PRIVATE|PROGRAM|PROTECTED|PUBLIC|PURE|READ|'
1294
+ r'RECURSIVE|RETURN|REWIND|SAVE|SELECT|SEQUENCE|STOP|SUBROUTINE|'
1295
+ r'TARGET|THEN|TYPE|USE|VALUE|VOLATILE|WHERE|WRITE|WHILE)\s*\b',
1296
+ Keyword),
1297
+
1298
+ # Data Types
1299
+ (r'\b(CHARACTER|COMPLEX|DOUBLE PRECISION|DOUBLE COMPLEX|INTEGER|'
1300
+ r'LOGICAL|REAL|C_INT|C_SHORT|C_LONG|C_LONG_LONG|C_SIGNED_CHAR|'
1301
+ r'C_SIZE_T|C_INT8_T|C_INT16_T|C_INT32_T|C_INT64_T|C_INT_LEAST8_T|'
1302
+ r'C_INT_LEAST16_T|C_INT_LEAST32_T|C_INT_LEAST64_T|C_INT_FAST8_T|'
1303
+ r'C_INT_FAST16_T|C_INT_FAST32_T|C_INT_FAST64_T|C_INTMAX_T|'
1304
+ r'C_INTPTR_T|C_FLOAT|C_DOUBLE|C_LONG_DOUBLE|C_FLOAT_COMPLEX|'
1305
+ r'C_DOUBLE_COMPLEX|C_LONG_DOUBLE_COMPLEX|C_BOOL|C_CHAR|C_PTR|'
1306
+ r'C_FUNPTR)\s*\b',
1307
+ Keyword.Type),
1308
+
1309
+ # Operators
1310
+ (r'(\*\*|\*|\+|-|\/|<|>|<=|>=|==|\/=|=)', Operator),
1311
+
1312
+ (r'(::)', Keyword.Declaration),
1313
+
1314
+ (r'[(),:&%;]', Punctuation),
1315
+
1316
+ # Intrinsics
1317
+ (r'\b(Abort|Abs|Access|AChar|ACos|AdjustL|AdjustR|AImag|AInt|Alarm|'
1318
+ r'All|Allocated|ALog|AMax|AMin|AMod|And|ANInt|Any|ASin|Associated|'
1319
+ r'ATan|BesJ|BesJN|BesY|BesYN|Bit_Size|BTest|CAbs|CCos|Ceiling|'
1320
+ r'CExp|Char|ChDir|ChMod|CLog|Cmplx|Command_Argument_Count|Complex|'
1321
+ r'Conjg|Cos|CosH|Count|CPU_Time|CShift|CSin|CSqRt|CTime|C_Funloc|'
1322
+ r'C_Loc|C_Associated|C_Null_Ptr|C_Null_Funptr|C_F_Pointer|'
1323
+ r'C_Null_Char|C_Alert|C_Backspace|C_Form_Feed|C_New_Line|'
1324
+ r'C_Carriage_Return|C_Horizontal_Tab|C_Vertical_Tab|'
1325
+ r'DAbs|DACos|DASin|DATan|Date_and_Time|DbesJ|'
1326
+ r'DbesJ|DbesJN|DbesY|DbesY|DbesYN|Dble|DCos|DCosH|DDiM|DErF|DErFC|'
1327
+ r'DExp|Digits|DiM|DInt|DLog|DLog|DMax|DMin|DMod|DNInt|Dot_Product|'
1328
+ r'DProd|DSign|DSinH|DSin|DSqRt|DTanH|DTan|DTime|EOShift|Epsilon|'
1329
+ r'ErF|ErFC|ETime|Exit|Exp|Exponent|Extends_Type_Of|FDate|FGet|'
1330
+ r'FGetC|Float|Floor|Flush|FNum|FPutC|FPut|Fraction|FSeek|FStat|'
1331
+ r'FTell|GError|GetArg|Get_Command|Get_Command_Argument|'
1332
+ r'Get_Environment_Variable|GetCWD|GetEnv|GetGId|GetLog|GetPId|'
1333
+ r'GetUId|GMTime|HostNm|Huge|IAbs|IAChar|IAnd|IArgC|IBClr|IBits|'
1334
+ r'IBSet|IChar|IDate|IDiM|IDInt|IDNInt|IEOr|IErrNo|IFix|Imag|'
1335
+ r'ImagPart|Index|Int|IOr|IRand|IsaTty|IShft|IShftC|ISign|'
1336
+ r'Iso_C_Binding|Is_Iostat_End|Is_Iostat_Eor|ITime|Kill|Kind|'
1337
+ r'LBound|Len|Len_Trim|LGe|LGt|Link|LLe|LLt|LnBlnk|Loc|Log|'
1338
+ r'Logical|Long|LShift|LStat|LTime|MatMul|Max|MaxExponent|MaxLoc|'
1339
+ r'MaxVal|MClock|Merge|Move_Alloc|Min|MinExponent|MinLoc|MinVal|'
1340
+ r'Mod|Modulo|MvBits|Nearest|New_Line|NInt|Not|Or|Pack|PError|'
1341
+ r'Precision|Present|Product|Radix|Rand|Random_Number|Random_Seed|'
1342
+ r'Range|Real|RealPart|Rename|Repeat|Reshape|RRSpacing|RShift|'
1343
+ r'Same_Type_As|Scale|Scan|Second|Selected_Int_Kind|'
1344
+ r'Selected_Real_Kind|Set_Exponent|Shape|Short|Sign|Signal|SinH|'
1345
+ r'Sin|Sleep|Sngl|Spacing|Spread|SqRt|SRand|Stat|Sum|SymLnk|'
1346
+ r'System|System_Clock|Tan|TanH|Time|Tiny|Transfer|Transpose|Trim|'
1347
+ r'TtyNam|UBound|UMask|Unlink|Unpack|Verify|XOr|ZAbs|ZCos|ZExp|'
1348
+ r'ZLog|ZSin|ZSqRt)\s*\b',
1349
+ Name.Builtin),
1350
+
1351
+ # Booleans
1352
+ (r'\.(true|false)\.', Name.Builtin),
1353
+ # Comparing Operators
1354
+ (r'\.(eq|ne|lt|le|gt|ge|not|and|or|eqv|neqv)\.', Operator.Word),
1355
+ ],
1356
+
1357
+ 'strings': [
1358
+ (r'(?s)"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
1359
+ (r"(?s)'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
1360
+ ],
1361
+
1362
+ 'nums': [
1363
+ (r'\d+(?![.Ee])', Number.Integer),
1364
+ (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
1365
+ (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
1366
+ ],
1367
+ }
1368
+
1369
+
1370
+ class GLShaderLexer(RegexLexer):
1371
+ """
1372
+ GLSL (OpenGL Shader) lexer.
1373
+
1374
+ *New in Pygments 1.1.*
1375
+ """
1376
+ name = 'GLSL'
1377
+ aliases = ['glsl']
1378
+ filenames = ['*.vert', '*.frag', '*.geo']
1379
+ mimetypes = ['text/x-glslsrc']
1380
+
1381
+ tokens = {
1382
+ 'root': [
1383
+ (r'^#.*', Comment.Preproc),
1384
+ (r'//.*', Comment.Single),
1385
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1386
+ (r'\+|-|~|!=?|\*|/|%|<<|>>|<=?|>=?|==?|&&?|\^|\|\|?',
1387
+ Operator),
1388
+ (r'[?:]', Operator), # quick hack for ternary
1389
+ (r'\bdefined\b', Operator),
1390
+ (r'[;{}(),\[\]]', Punctuation),
1391
+ #FIXME when e is present, no decimal point needed
1392
+ (r'[+-]?\d*\.\d+([eE][-+]?\d+)?', Number.Float),
1393
+ (r'[+-]?\d+\.\d*([eE][-+]?\d+)?', Number.Float),
1394
+ (r'0[xX][0-9a-fA-F]*', Number.Hex),
1395
+ (r'0[0-7]*', Number.Oct),
1396
+ (r'[1-9][0-9]*', Number.Integer),
1397
+ (r'\b(attribute|const|uniform|varying|centroid|break|continue|'
1398
+ r'do|for|while|if|else|in|out|inout|float|int|void|bool|true|'
1399
+ r'false|invariant|discard|return|mat[234]|mat[234]x[234]|'
1400
+ r'vec[234]|[ib]vec[234]|sampler[123]D|samplerCube|'
1401
+ r'sampler[12]DShadow|struct)\b', Keyword),
1402
+ (r'\b(asm|class|union|enum|typedef|template|this|packed|goto|'
1403
+ r'switch|default|inline|noinline|volatile|public|static|extern|'
1404
+ r'external|interface|long|short|double|half|fixed|unsigned|'
1405
+ r'lowp|mediump|highp|precision|input|output|hvec[234]|'
1406
+ r'[df]vec[234]|sampler[23]DRect|sampler2DRectShadow|sizeof|'
1407
+ r'cast|namespace|using)\b', Keyword), #future use
1408
+ (r'[a-zA-Z_][a-zA-Z_0-9]*', Name),
1409
+ (r'\.', Punctuation),
1410
+ (r'\s+', Text),
1411
+ ],
1412
+ }
1413
+
1414
+
1415
+ class PrologLexer(RegexLexer):
1416
+ """
1417
+ Lexer for Prolog files.
1418
+ """
1419
+ name = 'Prolog'
1420
+ aliases = ['prolog']
1421
+ filenames = ['*.prolog', '*.pro', '*.pl']
1422
+ mimetypes = ['text/x-prolog']
1423
+
1424
+ flags = re.UNICODE
1425
+
1426
+ tokens = {
1427
+ 'root': [
1428
+ (r'^#.*', Comment.Single),
1429
+ (r'/\*', Comment.Multiline, 'nested-comment'),
1430
+ (r'%.*', Comment.Single),
1431
+ (r'[0-9]+', Number),
1432
+ (r'[\[\](){}|.,;!]', Punctuation),
1433
+ (r':-|-->', Punctuation),
1434
+ (r'"(?:\\x[0-9a-fA-F]+\\|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|'
1435
+ r'\\[0-7]+\\|\\[\w\W]|[^"])*"', String.Double),
1436
+ (r"'(?:''|[^'])*'", String.Atom), # quoted atom
1437
+ # Needs to not be followed by an atom.
1438
+ #(r'=(?=\s|[a-zA-Z\[])', Operator),
1439
+ (r'(is|<|>|=<|>=|==|=:=|=|/|//|\*|\+|-)(?=\s|[a-zA-Z0-9\[])',
1440
+ Operator),
1441
+ (r'(mod|div|not)\b', Operator),
1442
+ (r'_', Keyword), # The don't-care variable
1443
+ (r'([a-z]+)(:)', bygroups(Name.Namespace, Punctuation)),
1444
+ (u'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1445
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
1446
+ u'(\\s*)(:-|-->)',
1447
+ bygroups(Name.Function, Text, Operator)), # function defn
1448
+ (u'([a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1449
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*)'
1450
+ u'(\\s*)(\\()',
1451
+ bygroups(Name.Function, Text, Punctuation)),
1452
+ (u'[a-z\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]'
1453
+ u'[a-zA-Z0-9_$\u00c0-\u1fff\u3040-\ud7ff\ue000-\uffef]*',
1454
+ String.Atom), # atom, characters
1455
+ # This one includes !
1456
+ (u'[#&*+\\-./:<=>?@\\\\^~\u00a1-\u00bf\u2010-\u303f]+',
1457
+ String.Atom), # atom, graphics
1458
+ (r'[A-Z_][A-Za-z0-9_]*', Name.Variable),
1459
+ (u'\\s+|[\u2000-\u200f\ufff0-\ufffe\uffef]', Text),
1460
+ ],
1461
+ 'nested-comment': [
1462
+ (r'\*/', Comment.Multiline, '#pop'),
1463
+ (r'/\*', Comment.Multiline, '#push'),
1464
+ (r'[^*/]+', Comment.Multiline),
1465
+ (r'[*/]', Comment.Multiline),
1466
+ ],
1467
+ }
1468
+
1469
+ def analyse_text(text):
1470
+ return ':-' in text
1471
+
1472
+
1473
+ class CythonLexer(RegexLexer):
1474
+ """
1475
+ For Pyrex and `Cython <http://cython.org>`_ source code.
1476
+
1477
+ *New in Pygments 1.1.*
1478
+ """
1479
+
1480
+ name = 'Cython'
1481
+ aliases = ['cython', 'pyx']
1482
+ filenames = ['*.pyx', '*.pxd', '*.pxi']
1483
+ mimetypes = ['text/x-cython', 'application/x-cython']
1484
+
1485
+ tokens = {
1486
+ 'root': [
1487
+ (r'\n', Text),
1488
+ (r'^(\s*)("""(?:.|\n)*?""")', bygroups(Text, String.Doc)),
1489
+ (r"^(\s*)('''(?:.|\n)*?''')", bygroups(Text, String.Doc)),
1490
+ (r'[^\S\n]+', Text),
1491
+ (r'#.*$', Comment),
1492
+ (r'[]{}:(),;[]', Punctuation),
1493
+ (r'\\\n', Text),
1494
+ (r'\\', Text),
1495
+ (r'(in|is|and|or|not)\b', Operator.Word),
1496
+ (r'(<)([a-zA-Z0-9.?]+)(>)',
1497
+ bygroups(Punctuation, Keyword.Type, Punctuation)),
1498
+ (r'!=|==|<<|>>|[-~+/*%=<>&^|.?]', Operator),
1499
+ (r'(from)(\d+)(<=)(\s+)(<)(\d+)(:)',
1500
+ bygroups(Keyword, Number.Integer, Operator, Name, Operator,
1501
+ Name, Punctuation)),
1502
+ include('keywords'),
1503
+ (r'(def|property)(\s+)', bygroups(Keyword, Text), 'funcname'),
1504
+ (r'(cp?def)(\s+)', bygroups(Keyword, Text), 'cdef'),
1505
+ (r'(class|struct)(\s+)', bygroups(Keyword, Text), 'classname'),
1506
+ (r'(from)(\s+)', bygroups(Keyword, Text), 'fromimport'),
1507
+ (r'(c?import)(\s+)', bygroups(Keyword, Text), 'import'),
1508
+ include('builtins'),
1509
+ include('backtick'),
1510
+ ('(?:[rR]|[uU][rR]|[rR][uU])"""', String, 'tdqs'),
1511
+ ("(?:[rR]|[uU][rR]|[rR][uU])'''", String, 'tsqs'),
1512
+ ('(?:[rR]|[uU][rR]|[rR][uU])"', String, 'dqs'),
1513
+ ("(?:[rR]|[uU][rR]|[rR][uU])'", String, 'sqs'),
1514
+ ('[uU]?"""', String, combined('stringescape', 'tdqs')),
1515
+ ("[uU]?'''", String, combined('stringescape', 'tsqs')),
1516
+ ('[uU]?"', String, combined('stringescape', 'dqs')),
1517
+ ("[uU]?'", String, combined('stringescape', 'sqs')),
1518
+ include('name'),
1519
+ include('numbers'),
1520
+ ],
1521
+ 'keywords': [
1522
+ (r'(assert|break|by|continue|ctypedef|del|elif|else|except\??|exec|'
1523
+ r'finally|for|gil|global|if|include|lambda|nogil|pass|print|raise|'
1524
+ r'return|try|while|yield|as|with)\b', Keyword),
1525
+ (r'(DEF|IF|ELIF|ELSE)\b', Comment.Preproc),
1526
+ ],
1527
+ 'builtins': [
1528
+ (r'(?<!\.)(__import__|abs|all|any|apply|basestring|bin|bool|buffer|'
1529
+ r'bytearray|bytes|callable|chr|classmethod|cmp|coerce|compile|'
1530
+ r'complex|delattr|dict|dir|divmod|enumerate|eval|execfile|exit|'
1531
+ r'file|filter|float|frozenset|getattr|globals|hasattr|hash|hex|id|'
1532
+ r'input|int|intern|isinstance|issubclass|iter|len|list|locals|'
1533
+ r'long|map|max|min|next|object|oct|open|ord|pow|property|range|'
1534
+ r'raw_input|reduce|reload|repr|reversed|round|set|setattr|slice|'
1535
+ r'sorted|staticmethod|str|sum|super|tuple|type|unichr|unicode|'
1536
+ r'vars|xrange|zip)\b', Name.Builtin),
1537
+ (r'(?<!\.)(self|None|Ellipsis|NotImplemented|False|True|NULL'
1538
+ r')\b', Name.Builtin.Pseudo),
1539
+ (r'(?<!\.)(ArithmeticError|AssertionError|AttributeError|'
1540
+ r'BaseException|DeprecationWarning|EOFError|EnvironmentError|'
1541
+ r'Exception|FloatingPointError|FutureWarning|GeneratorExit|IOError|'
1542
+ r'ImportError|ImportWarning|IndentationError|IndexError|KeyError|'
1543
+ r'KeyboardInterrupt|LookupError|MemoryError|NameError|'
1544
+ r'NotImplemented|NotImplementedError|OSError|OverflowError|'
1545
+ r'OverflowWarning|PendingDeprecationWarning|ReferenceError|'
1546
+ r'RuntimeError|RuntimeWarning|StandardError|StopIteration|'
1547
+ r'SyntaxError|SyntaxWarning|SystemError|SystemExit|TabError|'
1548
+ r'TypeError|UnboundLocalError|UnicodeDecodeError|'
1549
+ r'UnicodeEncodeError|UnicodeError|UnicodeTranslateError|'
1550
+ r'UnicodeWarning|UserWarning|ValueError|Warning|ZeroDivisionError'
1551
+ r')\b', Name.Exception),
1552
+ ],
1553
+ 'numbers': [
1554
+ (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
1555
+ (r'0\d+', Number.Oct),
1556
+ (r'0[xX][a-fA-F0-9]+', Number.Hex),
1557
+ (r'\d+L', Number.Integer.Long),
1558
+ (r'\d+', Number.Integer)
1559
+ ],
1560
+ 'backtick': [
1561
+ ('`.*?`', String.Backtick),
1562
+ ],
1563
+ 'name': [
1564
+ (r'@[a-zA-Z0-9_]+', Name.Decorator),
1565
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
1566
+ ],
1567
+ 'funcname': [
1568
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Function, '#pop')
1569
+ ],
1570
+ 'cdef': [
1571
+ (r'(public|readonly|extern|api|inline)\b', Keyword.Reserved),
1572
+ (r'(struct|enum|union|class)\b', Keyword),
1573
+ (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(?=[(:#=]|$)',
1574
+ bygroups(Name.Function, Text), '#pop'),
1575
+ (r'([a-zA-Z_][a-zA-Z0-9_]*)(\s*)(,)',
1576
+ bygroups(Name.Function, Text, Punctuation)),
1577
+ (r'from\b', Keyword, '#pop'),
1578
+ (r'as\b', Keyword),
1579
+ (r':', Punctuation, '#pop'),
1580
+ (r'(?=["\'])', Text, '#pop'),
1581
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Keyword.Type),
1582
+ (r'.', Text),
1583
+ ],
1584
+ 'classname': [
1585
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
1586
+ ],
1587
+ 'import': [
1588
+ (r'(\s+)(as)(\s+)', bygroups(Text, Keyword, Text)),
1589
+ (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace),
1590
+ (r'(\s*)(,)(\s*)', bygroups(Text, Operator, Text)),
1591
+ (r'', Text, '#pop') # all else: go back
1592
+ ],
1593
+ 'fromimport': [
1594
+ (r'(\s+)(c?import)\b', bygroups(Text, Keyword), '#pop'),
1595
+ (r'[a-zA-Z_.][a-zA-Z0-9_.]*', Name.Namespace),
1596
+ # ``cdef foo from "header"``, or ``for foo from 0 < i < 10``
1597
+ (r'', Text, '#pop'),
1598
+ ],
1599
+ 'stringescape': [
1600
+ (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
1601
+ r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
1602
+ ],
1603
+ 'strings': [
1604
+ (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
1605
+ '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
1606
+ (r'[^\\\'"%\n]+', String),
1607
+ # quotes, percents and backslashes must be parsed one at a time
1608
+ (r'[\'"\\]', String),
1609
+ # unhandled string formatting sign
1610
+ (r'%', String)
1611
+ # newlines are an error (use "nl" state)
1612
+ ],
1613
+ 'nl': [
1614
+ (r'\n', String)
1615
+ ],
1616
+ 'dqs': [
1617
+ (r'"', String, '#pop'),
1618
+ (r'\\\\|\\"|\\\n', String.Escape), # included here again for raw strings
1619
+ include('strings')
1620
+ ],
1621
+ 'sqs': [
1622
+ (r"'", String, '#pop'),
1623
+ (r"\\\\|\\'|\\\n", String.Escape), # included here again for raw strings
1624
+ include('strings')
1625
+ ],
1626
+ 'tdqs': [
1627
+ (r'"""', String, '#pop'),
1628
+ include('strings'),
1629
+ include('nl')
1630
+ ],
1631
+ 'tsqs': [
1632
+ (r"'''", String, '#pop'),
1633
+ include('strings'),
1634
+ include('nl')
1635
+ ],
1636
+ }
1637
+
1638
+
1639
+ class ValaLexer(RegexLexer):
1640
+ """
1641
+ For Vala source code with preprocessor directives.
1642
+
1643
+ *New in Pygments 1.1.*
1644
+ """
1645
+ name = 'Vala'
1646
+ aliases = ['vala', 'vapi']
1647
+ filenames = ['*.vala', '*.vapi']
1648
+ mimetypes = ['text/x-vala']
1649
+
1650
+ tokens = {
1651
+ 'whitespace': [
1652
+ (r'^\s*#if\s+0', Comment.Preproc, 'if0'),
1653
+ (r'\n', Text),
1654
+ (r'\s+', Text),
1655
+ (r'\\\n', Text), # line continuation
1656
+ (r'//(\n|(.|\n)*?[^\\]\n)', Comment.Single),
1657
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1658
+ ],
1659
+ 'statements': [
1660
+ (r'L?"', String, 'string'),
1661
+ (r"L?'(\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1662
+ String.Char),
1663
+ (r'(\d+\.\d*|\.\d+|\d+)[eE][+-]?\d+[lL]?', Number.Float),
1664
+ (r'(\d+\.\d*|\.\d+|\d+[fF])[fF]?', Number.Float),
1665
+ (r'0x[0-9a-fA-F]+[Ll]?', Number.Hex),
1666
+ (r'0[0-7]+[Ll]?', Number.Oct),
1667
+ (r'\d+[Ll]?', Number.Integer),
1668
+ (r'[~!%^&*+=|?:<>/-]', Operator),
1669
+ (r'(\[)(Compact|Immutable|(?:Boolean|Simple)Type)(\])',
1670
+ bygroups(Punctuation, Name.Decorator, Punctuation)),
1671
+ # TODO: "correctly" parse complex code attributes
1672
+ (r'(\[)(CCode|(?:Integer|Floating)Type)',
1673
+ bygroups(Punctuation, Name.Decorator)),
1674
+ (r'[()\[\],.]', Punctuation),
1675
+ (r'(as|base|break|case|catch|construct|continue|default|delete|do|'
1676
+ r'else|enum|finally|for|foreach|get|if|in|is|lock|new|out|params|'
1677
+ r'return|set|sizeof|switch|this|throw|try|typeof|while|yield)\b',
1678
+ Keyword),
1679
+ (r'(abstract|const|delegate|dynamic|ensures|extern|inline|internal|'
1680
+ r'override|owned|private|protected|public|ref|requires|signal|'
1681
+ r'static|throws|unowned|var|virtual|volatile|weak|yields)\b',
1682
+ Keyword.Declaration),
1683
+ (r'(namespace|using)(\s+)', bygroups(Keyword.Namespace, Text),
1684
+ 'namespace'),
1685
+ (r'(class|errordomain|interface|struct)(\s+)',
1686
+ bygroups(Keyword.Declaration, Text), 'class'),
1687
+ (r'(\.)([a-zA-Z_][a-zA-Z0-9_]*)',
1688
+ bygroups(Operator, Name.Attribute)),
1689
+ # void is an actual keyword, others are in glib-2.0.vapi
1690
+ (r'(void|bool|char|double|float|int|int8|int16|int32|int64|long|'
1691
+ r'short|size_t|ssize_t|string|time_t|uchar|uint|uint8|uint16|'
1692
+ r'uint32|uint64|ulong|unichar|ushort)\b', Keyword.Type),
1693
+ (r'(true|false|null)\b', Name.Builtin),
1694
+ ('[a-zA-Z_][a-zA-Z0-9_]*', Name),
1695
+ ],
1696
+ 'root': [
1697
+ include('whitespace'),
1698
+ ('', Text, 'statement'),
1699
+ ],
1700
+ 'statement' : [
1701
+ include('whitespace'),
1702
+ include('statements'),
1703
+ ('[{}]', Punctuation),
1704
+ (';', Punctuation, '#pop'),
1705
+ ],
1706
+ 'string': [
1707
+ (r'"', String, '#pop'),
1708
+ (r'\\([\\abfnrtv"\']|x[a-fA-F0-9]{2,4}|[0-7]{1,3})', String.Escape),
1709
+ (r'[^\\"\n]+', String), # all other characters
1710
+ (r'\\\n', String), # line continuation
1711
+ (r'\\', String), # stray backslash
1712
+ ],
1713
+ 'if0': [
1714
+ (r'^\s*#if.*?(?<!\\)\n', Comment.Preproc, '#push'),
1715
+ (r'^\s*#el(?:se|if).*\n', Comment.Preproc, '#pop'),
1716
+ (r'^\s*#endif.*?(?<!\\)\n', Comment.Preproc, '#pop'),
1717
+ (r'.*?\n', Comment),
1718
+ ],
1719
+ 'class': [
1720
+ (r'[a-zA-Z_][a-zA-Z0-9_]*', Name.Class, '#pop')
1721
+ ],
1722
+ 'namespace': [
1723
+ (r'[a-zA-Z_][a-zA-Z0-9_.]*', Name.Namespace, '#pop')
1724
+ ],
1725
+ }
1726
+
1727
+
1728
+ class OocLexer(RegexLexer):
1729
+ """
1730
+ For `Ooc <http://ooc-lang.org/>`_ source code
1731
+
1732
+ *New in Pygments 1.2.*
1733
+ """
1734
+ name = 'Ooc'
1735
+ aliases = ['ooc']
1736
+ filenames = ['*.ooc']
1737
+ mimetypes = ['text/x-ooc']
1738
+
1739
+ tokens = {
1740
+ 'root': [
1741
+ (r'\b(class|interface|implement|abstract|extends|from|'
1742
+ r'this|super|new|const|final|static|import|use|extern|'
1743
+ r'inline|proto|break|continue|fallthrough|operator|if|else|for|'
1744
+ r'while|do|switch|case|as|in|version|return|true|false|null)\b',
1745
+ Keyword),
1746
+ (r'include\b', Keyword, 'include'),
1747
+ (r'(cover)([ \t]+)(from)([ \t]+)([a-zA-Z0-9_]+[*@]?)',
1748
+ bygroups(Keyword, Text, Keyword, Text, Name.Class)),
1749
+ (r'(func)((?:[ \t]|\\\n)+)(~[a-z_][a-zA-Z0-9_]*)',
1750
+ bygroups(Keyword, Text, Name.Function)),
1751
+ (r'\bfunc\b', Keyword),
1752
+ # Note: %= and ^= not listed on http://ooc-lang.org/syntax
1753
+ (r'//.*', Comment),
1754
+ (r'(?s)/\*.*?\*/', Comment.Multiline),
1755
+ (r'(==?|\+=?|-[=>]?|\*=?|/=?|:=|!=?|%=?|\?|>{1,3}=?|<{1,3}=?|\.\.|'
1756
+ r'&&?|\|\|?|\^=?)', Operator),
1757
+ (r'(\.)([ \t]*)([a-z]\w*)', bygroups(Operator, Text,
1758
+ Name.Function)),
1759
+ (r'[A-Z][A-Z0-9_]+', Name.Constant),
1760
+ (r'[A-Z][a-zA-Z0-9_]*([@*]|\[[ \t]*\])?', Name.Class),
1761
+
1762
+ (r'([a-z][a-zA-Z0-9_]*(?:~[a-z][a-zA-Z0-9_]*)?)((?:[ \t]|\\\n)*)(?=\()',
1763
+ bygroups(Name.Function, Text)),
1764
+ (r'[a-z][a-zA-Z0-9_]*', Name.Variable),
1765
+
1766
+ # : introduces types
1767
+ (r'[:(){}\[\];,]', Punctuation),
1768
+
1769
+ (r'0x[0-9a-fA-F]+', Number.Hex),
1770
+ (r'0c[0-9]+', Number.Oct),
1771
+ (r'0b[01]+', Number.Binary),
1772
+ (r'[0-9_]\.[0-9_]*(?!\.)', Number.Float),
1773
+ (r'[0-9_]+', Number.Decimal),
1774
+
1775
+ (r'"(?:\\.|\\[0-7]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\"])*"',
1776
+ String.Double),
1777
+ (r"'(?:\\.|\\[0-9]{1,3}|\\x[a-fA-F0-9]{1,2}|[^\\\'\n])'",
1778
+ String.Char),
1779
+ (r'@', Punctuation), # pointer dereference
1780
+ (r'\.', Punctuation), # imports or chain operator
1781
+
1782
+ (r'\\[ \t\n]', Text),
1783
+ (r'[ \t]+', Text),
1784
+ ],
1785
+ 'include': [
1786
+ (r'[\w/]+', Name),
1787
+ (r',', Punctuation),
1788
+ (r'[ \t]', Text),
1789
+ (r'[;\n]', Text, '#pop'),
1790
+ ],
1791
+ }
1792
+
1793
+
1794
+ class GoLexer(RegexLexer):
1795
+ """
1796
+ For `Go <http://golang.org>`_ source.
1797
+ """
1798
+ name = 'Go'
1799
+ filenames = ['*.go']
1800
+ aliases = ['go']
1801
+ mimetypes = ['text/x-gosrc']
1802
+
1803
+ tokens = {
1804
+ 'root': [
1805
+ (r'\n', Text),
1806
+ (r'\s+', Text),
1807
+ (r'\\\n', Text), # line continuations
1808
+ (r'//(.*?)\n', Comment.Single),
1809
+ (r'/(\\\n)?[*](.|\n)*?[*](\\\n)?/', Comment.Multiline),
1810
+ (r'(break|default|func|interface|select'
1811
+ r'|case|defer|go|map|struct'
1812
+ r'|chan|else|goto|package|switch'
1813
+ r'|const|fallthrough|if|range|type'
1814
+ r'|continue|for|import|return|var)\b', Keyword
1815
+ ),
1816
+ # It seems the builtin types aren't actually keywords.
1817
+ (r'(uint8|uint16|uint32|uint64'
1818
+ r'|int8|int16|int32|int64'
1819
+ r'|float32|float64|byte'
1820
+ r'|uint|int|float|uintptr'
1821
+ r'|string|close|closed|len|cap|new|make)\b', Name.Builtin
1822
+ ),
1823
+ # float_lit
1824
+ (r'\d+(\.\d+[eE][+\-]?\d+|'
1825
+ r'\.\d*|[eE][+\-]?\d+)', Number.Float),
1826
+ (r'\.\d+([eE][+\-]?\d+)?', Number.Float),
1827
+ # int_lit
1828
+ # -- octal_lit
1829
+ (r'0[0-7]+', Number.Oct),
1830
+ # -- hex_lit
1831
+ (r'0[xX][0-9a-fA-F]+', Number.Hex),
1832
+ # -- decimal_lit
1833
+ (r'(0|[1-9][0-9]*)', Number.Integer),
1834
+ # char_lit
1835
+ (r"""'(\\['"\\abfnrtv]|\\x[0-9a-fA-F]{2}|\\[0-7]{1,3}"""
1836
+ r"""|\\u[0-9a-fA-F]{4}|\\U[0-9a-fA-F]{8}|[^\\])'""",
1837
+ String.Char
1838
+ ),
1839
+ # StringLiteral
1840
+ # -- raw_string_lit
1841
+ (r'`[^`]*`', String),
1842
+ # -- interpreted_string_lit
1843
+ (r'"(\\\\|\\"|[^"])*"', String),
1844
+ # Tokens
1845
+ (r'(<<=|>>=|<<|>>|<=|>=|&\^=|&\^|\+=|-=|\*=|/=|%=|&=|\|=|&&|\|\|'
1846
+ r'|<-|\+\+|--|==|!=|:=|\.\.\.)|[+\-*/%&|^<>=!()\[\]{}.,;:]',
1847
+ Punctuation
1848
+ ),
1849
+ # identifier
1850
+ (r'[a-zA-Z_]\w*', Name),
1851
+ ]
1852
+ }
1853
+
1854
+
1855
+ class FelixLexer(RegexLexer):
1856
+ """
1857
+ For `Felix <http://www.felix-lang.org>`_ source code.
1858
+
1859
+ *New in Pygments 1.2.*
1860
+ """
1861
+
1862
+ name = 'Felix'
1863
+ aliases = ['felix', 'flx']
1864
+ filenames = ['*.flx', '*.flxh']
1865
+ mimetypes = ['text/x-felix']
1866
+
1867
+ preproc = [
1868
+ 'elif', 'else', 'endif', 'if', 'ifdef', 'ifndef',
1869
+ ]
1870
+
1871
+ keywords = [
1872
+ '_', '_deref', 'all', 'as',
1873
+ 'assert', 'attempt', 'call', 'callback', 'case', 'caseno', 'cclass',
1874
+ 'code', 'compound', 'ctypes', 'do', 'done', 'downto', 'elif', 'else',
1875
+ 'endattempt', 'endcase', 'endif', 'endmatch', 'enum', 'except',
1876
+ 'exceptions', 'expect', 'finally', 'for', 'forall', 'forget', 'fork',
1877
+ 'functor', 'goto', 'ident', 'if', 'incomplete', 'inherit', 'instance',
1878
+ 'interface', 'jump', 'lambda', 'loop', 'match', 'module', 'namespace',
1879
+ 'new', 'noexpand', 'nonterm', 'obj', 'of', 'open', 'parse', 'raise',
1880
+ 'regexp', 'reglex', 'regmatch', 'rename', 'return', 'the', 'then',
1881
+ 'to', 'type', 'typecase', 'typedef', 'typematch', 'typeof', 'upto',
1882
+ 'when', 'whilst', 'with', 'yield',
1883
+ ]
1884
+
1885
+ keyword_directives = [
1886
+ '_gc_pointer', '_gc_type', 'body', 'comment', 'const', 'export',
1887
+ 'header', 'inline', 'lval', 'macro', 'noinline', 'noreturn',
1888
+ 'package', 'private', 'pod', 'property', 'public', 'publish',
1889
+ 'requires', 'todo', 'virtual', 'use',
1890
+ ]
1891
+
1892
+ keyword_declarations = [
1893
+ 'def', 'let', 'ref', 'val', 'var',
1894
+ ]
1895
+
1896
+ keyword_types = [
1897
+ 'unit', 'void', 'any', 'bool',
1898
+ 'byte', 'offset',
1899
+ 'address', 'caddress', 'cvaddress', 'vaddress',
1900
+ 'tiny', 'short', 'int', 'long', 'vlong',
1901
+ 'utiny', 'ushort', 'vshort', 'uint', 'ulong', 'uvlong',
1902
+ 'int8', 'int16', 'int32', 'int64',
1903
+ 'uint8', 'uint16', 'uint32', 'uint64',
1904
+ 'float', 'double', 'ldouble',
1905
+ 'complex', 'dcomplex', 'lcomplex',
1906
+ 'imaginary', 'dimaginary', 'limaginary',
1907
+ 'char', 'wchar', 'uchar',
1908
+ 'charp', 'charcp', 'ucharp', 'ucharcp',
1909
+ 'string', 'wstring', 'ustring',
1910
+ 'cont',
1911
+ 'array', 'varray', 'list',
1912
+ 'lvalue', 'opt', 'slice',
1913
+ ]
1914
+
1915
+ keyword_constants = [
1916
+ 'false', 'true',
1917
+ ]
1918
+
1919
+ operator_words = [
1920
+ 'and', 'not', 'in', 'is', 'isin', 'or', 'xor',
1921
+ ]
1922
+
1923
+ name_builtins = [
1924
+ '_svc', 'while',
1925
+ ]
1926
+
1927
+ name_pseudo = [
1928
+ 'root', 'self', 'this',
1929
+ ]
1930
+
1931
+ decimal_suffixes = '([tTsSiIlLvV]|ll|LL|([iIuU])(8|16|32|64))?'
1932
+
1933
+ tokens = {
1934
+ 'root': [
1935
+ include('whitespace'),
1936
+
1937
+ # Keywords
1938
+ (r'(axiom|ctor|fun|gen|proc|reduce|union)\b', Keyword,
1939
+ 'funcname'),
1940
+ (r'(class|cclass|cstruct|obj|struct)\b', Keyword, 'classname'),
1941
+ (r'(instance|module|typeclass)\b', Keyword, 'modulename'),
1942
+
1943
+ (r'(%s)\b' % '|'.join(keywords), Keyword),
1944
+ (r'(%s)\b' % '|'.join(keyword_directives), Name.Decorator),
1945
+ (r'(%s)\b' % '|'.join(keyword_declarations), Keyword.Declaration),
1946
+ (r'(%s)\b' % '|'.join(keyword_types), Keyword.Type),
1947
+ (r'(%s)\b' % '|'.join(keyword_constants), Keyword.Constant),
1948
+
1949
+ # Operators
1950
+ include('operators'),
1951
+
1952
+ # Float Literal
1953
+ # -- Hex Float
1954
+ (r'0[xX]([0-9a-fA-F_]*\.[0-9a-fA-F_]+|[0-9a-fA-F_]+)'
1955
+ r'[pP][+\-]?[0-9_]+[lLfFdD]?', Number.Float),
1956
+ # -- DecimalFloat
1957
+ (r'[0-9_]+(\.[0-9_]+[eE][+\-]?[0-9_]+|'
1958
+ r'\.[0-9_]*|[eE][+\-]?[0-9_]+)[lLfFdD]?', Number.Float),
1959
+ (r'\.(0|[1-9][0-9_]*)([eE][+\-]?[0-9_]+)?[lLfFdD]?',
1960
+ Number.Float),
1961
+
1962
+ # IntegerLiteral
1963
+ # -- Binary
1964
+ (r'0[Bb][01_]+%s' % decimal_suffixes, Number),
1965
+ # -- Octal
1966
+ (r'0[0-7_]+%s' % decimal_suffixes, Number.Oct),
1967
+ # -- Hexadecimal
1968
+ (r'0[xX][0-9a-fA-F_]+%s' % decimal_suffixes, Number.Hex),
1969
+ # -- Decimal
1970
+ (r'(0|[1-9][0-9_]*)%s' % decimal_suffixes, Number.Integer),
1971
+
1972
+ # Strings
1973
+ ('([rR][cC]?|[cC][rR])"""', String, 'tdqs'),
1974
+ ("([rR][cC]?|[cC][rR])'''", String, 'tsqs'),
1975
+ ('([rR][cC]?|[cC][rR])"', String, 'dqs'),
1976
+ ("([rR][cC]?|[cC][rR])'", String, 'sqs'),
1977
+ ('[cCfFqQwWuU]?"""', String, combined('stringescape', 'tdqs')),
1978
+ ("[cCfFqQwWuU]?'''", String, combined('stringescape', 'tsqs')),
1979
+ ('[cCfFqQwWuU]?"', String, combined('stringescape', 'dqs')),
1980
+ ("[cCfFqQwWuU]?'", String, combined('stringescape', 'sqs')),
1981
+
1982
+ # Punctuation
1983
+ (r'[\[\]{}:(),;?]', Punctuation),
1984
+
1985
+ # Labels
1986
+ (r'[a-zA-Z_]\w*:>', Name.Label),
1987
+
1988
+ # Identifiers
1989
+ (r'(%s)\b' % '|'.join(name_builtins), Name.Builtin),
1990
+ (r'(%s)\b' % '|'.join(name_pseudo), Name.Builtin.Pseudo),
1991
+ (r'[a-zA-Z_]\w*', Name),
1992
+ ],
1993
+ 'whitespace': [
1994
+ (r'\n', Text),
1995
+ (r'\s+', Text),
1996
+
1997
+ include('comment'),
1998
+
1999
+ # Preprocessor
2000
+ (r'#\s*if\s+0', Comment.Preproc, 'if0'),
2001
+ (r'#', Comment.Preproc, 'macro'),
2002
+ ],
2003
+ 'operators': [
2004
+ (r'(%s)\b' % '|'.join(operator_words), Operator.Word),
2005
+ (r'!=|==|<<|>>|\|\||&&|[-~+/*%=<>&^|.$]', Operator),
2006
+ ],
2007
+ 'comment': [
2008
+ (r'//(.*?)\n', Comment.Single),
2009
+ (r'/[*]', Comment.Multiline, 'comment2'),
2010
+ ],
2011
+ 'comment2': [
2012
+ (r'[^\/*]', Comment.Multiline),
2013
+ (r'/[*]', Comment.Multiline, '#push'),
2014
+ (r'[*]/', Comment.Multiline, '#pop'),
2015
+ (r'[\/*]', Comment.Multiline),
2016
+ ],
2017
+ 'if0': [
2018
+ (r'^\s*#if.*?(?<!\\)\n', Comment, '#push'),
2019
+ (r'^\s*#endif.*?(?<!\\)\n', Comment, '#pop'),
2020
+ (r'.*?\n', Comment),
2021
+ ],
2022
+ 'macro': [
2023
+ include('comment'),
2024
+ (r'(import|include)(\s+)(<[^>]*?>)',
2025
+ bygroups(Comment.Preproc, Text, String), '#pop'),
2026
+ (r'(import|include)(\s+)("[^"]*?")',
2027
+ bygroups(Comment.Preproc, Text, String), '#pop'),
2028
+ (r"(import|include)(\s+)('[^']*?')",
2029
+ bygroups(Comment.Preproc, Text, String), '#pop'),
2030
+ (r'[^/\n]+', Comment.Preproc),
2031
+ ##(r'/[*](.|\n)*?[*]/', Comment),
2032
+ ##(r'//.*?\n', Comment, '#pop'),
2033
+ (r'/', Comment.Preproc),
2034
+ (r'(?<=\\)\n', Comment.Preproc),
2035
+ (r'\n', Comment.Preproc, '#pop'),
2036
+ ],
2037
+ 'funcname': [
2038
+ include('whitespace'),
2039
+ (r'[a-zA-Z_]\w*', Name.Function, '#pop'),
2040
+ # anonymous functions
2041
+ (r'(?=\()', Text, '#pop'),
2042
+ ],
2043
+ 'classname': [
2044
+ include('whitespace'),
2045
+ (r'[a-zA-Z_]\w*', Name.Class, '#pop'),
2046
+ # anonymous classes
2047
+ (r'(?=\{)', Text, '#pop'),
2048
+ ],
2049
+ 'modulename': [
2050
+ include('whitespace'),
2051
+ (r'\[', Punctuation, ('modulename2', 'tvarlist')),
2052
+ (r'', Error, 'modulename2'),
2053
+ ],
2054
+ 'modulename2': [
2055
+ include('whitespace'),
2056
+ (r'([a-zA-Z_]\w*)', Name.Namespace, '#pop:2'),
2057
+ ],
2058
+ 'tvarlist': [
2059
+ include('whitespace'),
2060
+ include('operators'),
2061
+ (r'\[', Punctuation, '#push'),
2062
+ (r'\]', Punctuation, '#pop'),
2063
+ (r',', Punctuation),
2064
+ (r'(with|where)\b', Keyword),
2065
+ (r'[a-zA-Z_]\w*', Name),
2066
+ ],
2067
+ 'stringescape': [
2068
+ (r'\\([\\abfnrtv"\']|\n|N{.*?}|u[a-fA-F0-9]{4}|'
2069
+ r'U[a-fA-F0-9]{8}|x[a-fA-F0-9]{2}|[0-7]{1,3})', String.Escape)
2070
+ ],
2071
+ 'strings': [
2072
+ (r'%(\([a-zA-Z0-9]+\))?[-#0 +]*([0-9]+|[*])?(\.([0-9]+|[*]))?'
2073
+ '[hlL]?[diouxXeEfFgGcrs%]', String.Interpol),
2074
+ (r'[^\\\'"%\n]+', String),
2075
+ # quotes, percents and backslashes must be parsed one at a time
2076
+ (r'[\'"\\]', String),
2077
+ # unhandled string formatting sign
2078
+ (r'%', String)
2079
+ # newlines are an error (use "nl" state)
2080
+ ],
2081
+ 'nl': [
2082
+ (r'\n', String)
2083
+ ],
2084
+ 'dqs': [
2085
+ (r'"', String, '#pop'),
2086
+ # included here again for raw strings
2087
+ (r'\\\\|\\"|\\\n', String.Escape),
2088
+ include('strings')
2089
+ ],
2090
+ 'sqs': [
2091
+ (r"'", String, '#pop'),
2092
+ # included here again for raw strings
2093
+ (r"\\\\|\\'|\\\n", String.Escape),
2094
+ include('strings')
2095
+ ],
2096
+ 'tdqs': [
2097
+ (r'"""', String, '#pop'),
2098
+ include('strings'),
2099
+ include('nl')
2100
+ ],
2101
+ 'tsqs': [
2102
+ (r"'''", String, '#pop'),
2103
+ include('strings'),
2104
+ include('nl')
2105
+ ],
2106
+ }
2107
+
2108
+
2109
+ class AdaLexer(RegexLexer):
2110
+ """
2111
+ For Ada source code.
2112
+
2113
+ *New in Pygments 1.3.*
2114
+ """
2115
+
2116
+ name = 'Ada'
2117
+ aliases = ['ada', 'ada95' 'ada2005']
2118
+ filenames = ['*.adb', '*.ads', '*.ada']
2119
+ mimetypes = ['text/x-ada']
2120
+
2121
+ flags = re.MULTILINE | re.I # Ignore case
2122
+
2123
+ _ws = r'(?:\s|//.*?\n|/[*].*?[*]/)+'
2124
+
2125
+ tokens = {
2126
+ 'root': [
2127
+ (r'[^\S\n]+', Text),
2128
+ (r'--.*?\n', Comment.Single),
2129
+ (r'[^\S\n]+', Text),
2130
+ (r'function|procedure|entry', Keyword.Declaration, 'subprogram'),
2131
+ (r'(subtype|type)(\s+)([a-z0-9_]+)',
2132
+ bygroups(Keyword.Declaration, Text, Keyword.Type), 'type_def'),
2133
+ (r'task|protected', Keyword.Declaration),
2134
+ (r'(subtype)(\s+)', bygroups(Keyword.Declaration, Text)),
2135
+ (r'(end)(\s+)', bygroups(Keyword.Reserved, Text), 'end'),
2136
+ (r'(pragma)(\s+)([a-zA-Z0-9_]+)', bygroups(Keyword.Reserved, Text,
2137
+ Comment.Preproc)),
2138
+ (r'(true|false|null)\b', Keyword.Constant),
2139
+ (r'(Byte|Character|Float|Integer|Long_Float|Long_Integer|'
2140
+ r'Long_Long_Float|Long_Long_Integer|Natural|Positive|Short_Float|'
2141
+ r'Short_Integer|Short_Short_Float|Short_Short_Integer|String|'
2142
+ r'Wide_String|Duration)\b', Keyword.Type),
2143
+ (r'(and(\s+then)?|in|mod|not|or(\s+else)|rem)\b', Operator.Word),
2144
+ (r'generic|private', Keyword.Declaration),
2145
+ (r'package', Keyword.Declaration, 'package'),
2146
+ (r'array\b', Keyword.Reserved, 'array_def'),
2147
+ (r'(with|use)(\s+)', bygroups(Keyword.Namespace, Text), 'import'),
2148
+ (r'([a-z0-9_]+)(\s*)(:)(\s*)(constant)',
2149
+ bygroups(Name.Constant, Text, Punctuation, Text,
2150
+ Keyword.Reserved)),
2151
+ (r'<<[a-z0-9_]+>>', Name.Label),
2152
+ (r'([a-z0-9_]+)(\s*)(:)(\s*)(declare|begin|loop|for|while)',
2153
+ bygroups(Name.Label, Text, Punctuation, Text, Keyword.Reserved)),
2154
+ (r'\b(abort|abs|abstract|accept|access|aliased|all|array|at|begin|'
2155
+ r'body|case|constant|declare|delay|delta|digits|do|else|elsif|end|'
2156
+ r'entry|exception|exit|interface|for|goto|if|is|limited|loop|new|'
2157
+ r'null|of|or|others|out|overriding|pragma|protected|raise|range|'
2158
+ r'record|renames|requeue|return|reverse|select|separate|subtype|'
2159
+ r'synchronized|task|tagged|terminate|then|type|until|when|while|'
2160
+ r'xor)\b',
2161
+ Keyword.Reserved),
2162
+ (r'"[^"]*"', String),
2163
+ include('attribute'),
2164
+ include('numbers'),
2165
+ (r"'[^']'", String.Character),
2166
+ (r'([a-z0-9_]+)(\s*|[(,])', bygroups(Name, using(this))),
2167
+ (r"(<>|=>|:=|[()|:;,.'])", Punctuation),
2168
+ (r'[*<>+=/&-]', Operator),
2169
+ (r'\n+', Text),
2170
+ ],
2171
+ 'numbers' : [
2172
+ (r'[0-9_]+#[0-9a-f]+#', Number.Hex),
2173
+ (r'[0-9_]+\.[0-9_]*', Number.Float),
2174
+ (r'[0-9_]+', Number.Integer),
2175
+ ],
2176
+ 'attribute' : [
2177
+ (r"(')([a-zA-Z0-9_]+)", bygroups(Punctuation, Name.Attribute)),
2178
+ ],
2179
+ 'subprogram' : [
2180
+ (r'\(', Punctuation, ('#pop', 'formal_part')),
2181
+ (r';', Punctuation, '#pop'),
2182
+ (r'is\b', Keyword.Reserved, '#pop'),
2183
+ (r'"[^"]+"|[a-z0-9_]+', Name.Function),
2184
+ include('root'),
2185
+ ],
2186
+ 'end' : [
2187
+ ('(if|case|record|loop|select)', Keyword.Reserved),
2188
+ ('"[^"]+"|[a-zA-Z0-9_.]+', Name.Function),
2189
+ ('\s+', Text),
2190
+ (';', Punctuation, '#pop'),
2191
+ ],
2192
+ 'type_def': [
2193
+ (r';', Punctuation, '#pop'),
2194
+ (r'\(', Punctuation, 'formal_part'),
2195
+ (r'with|and|use', Keyword.Reserved),
2196
+ (r'array\b', Keyword.Reserved, ('#pop', 'array_def')),
2197
+ (r'record\b', Keyword.Reserved, ('formal_part')),
2198
+ include('root'),
2199
+ ],
2200
+ 'array_def' : [
2201
+ (r';', Punctuation, '#pop'),
2202
+ (r'([a-z0-9_]+)(\s+)(range)', bygroups(Keyword.Type, Text,
2203
+ Keyword.Reserved)),
2204
+ include('root'),
2205
+ ],
2206
+ 'import': [
2207
+ (r'[a-z0-9_.]+', Name.Namespace, '#pop'),
2208
+ (r'', Text, '#pop'),
2209
+ ],
2210
+ 'formal_part' : [
2211
+ (r'\)', Punctuation, '#pop'),
2212
+ (r'[a-z0-9_]+', Name.Variable),
2213
+ (r',|:[^=]', Punctuation),
2214
+ (r'(in|not|null|out|access)\b', Keyword.Reserved),
2215
+ include('root'),
2216
+ ],
2217
+ 'package': [
2218
+ ('body', Keyword.Declaration),
2219
+ ('is\s+new|renames', Keyword.Reserved),
2220
+ ('is', Keyword.Reserved, '#pop'),
2221
+ (';', Punctuation, '#pop'),
2222
+ ('\(', Punctuation, 'package_instantiation'),
2223
+ ('([a-zA-Z0-9_.]+)', Name.Class),
2224
+ include('root'),
2225
+ ],
2226
+ 'package_instantiation': [
2227
+ (r'("[^"]+"|[a-z0-9_]+)(\s+)(=>)', bygroups(Name.Variable,
2228
+ Text, Punctuation)),
2229
+ (r'[a-z0-9._\'"]', Text),
2230
+ (r'\)', Punctuation, '#pop'),
2231
+ include('root'),
2232
+ ],
2233
+ }
2234
+
2235
+
2236
+ class Modula2Lexer(RegexLexer):
2237
+ """
2238
+ For `Modula-2 <http://www.modula2.org/>`_ source code.
2239
+
2240
+ Additional options that determine which keywords are highlighted:
2241
+
2242
+ `pim`
2243
+ Select PIM Modula-2 dialect (default: True).
2244
+ `iso`
2245
+ Select ISO Modula-2 dialect (default: False).
2246
+ `objm2`
2247
+ Select Objective Modula-2 dialect (default: False).
2248
+ `gm2ext`
2249
+ Also highlight GNU extensions (default: False).
2250
+
2251
+ *New in Pygments 1.3.*
2252
+ """
2253
+ name = 'Modula-2'
2254
+ aliases = ['modula2', 'm2']
2255
+ filenames = ['*.def', '*.mod']
2256
+ mimetypes = ['text/x-modula2']
2257
+
2258
+ flags = re.MULTILINE | re.DOTALL
2259
+
2260
+ tokens = {
2261
+ 'whitespace': [
2262
+ (r'\n+', Text), # blank lines
2263
+ (r'\s+', Text), # whitespace
2264
+ ],
2265
+ 'identifiers': [
2266
+ (r'([a-zA-Z_\$][a-zA-Z0-9_\$]*)', Name),
2267
+ ],
2268
+ 'numliterals': [
2269
+ (r'[01]+B', Number.Binary), # binary number (ObjM2)
2270
+ (r'[0-7]+B', Number.Oct), # octal number (PIM + ISO)
2271
+ (r'[0-7]+C', Number.Oct), # char code (PIM + ISO)
2272
+ (r'[0-9A-F]+C', Number.Hex), # char code (ObjM2)
2273
+ (r'[0-9A-F]+H', Number.Hex), # hexadecimal number
2274
+ (r'[0-9]+\.[0-9]+E[+-][0-9]+', Number.Float), # real number
2275
+ (r'[0-9]+\.[0-9]+', Number.Float), # real number
2276
+ (r'[0-9]+', Number.Integer), # decimal whole number
2277
+ ],
2278
+ 'strings': [
2279
+ (r"'(\\\\|\\'|[^'])*'", String), # single quoted string
2280
+ (r'"(\\\\|\\"|[^"])*"', String), # double quoted string
2281
+ ],
2282
+ 'operators': [
2283
+ (r'[*/+=#~&<>\^-]', Operator),
2284
+ (r':=', Operator), # assignment
2285
+ (r'@', Operator), # pointer deref (ISO)
2286
+ (r'\.\.', Operator), # ellipsis or range
2287
+ (r'`', Operator), # Smalltalk message (ObjM2)
2288
+ (r'::', Operator), # type conversion (ObjM2)
2289
+ ],
2290
+ 'punctuation': [
2291
+ (r'[\(\)\[\]{},.:;|]', Punctuation),
2292
+ ],
2293
+ 'comments': [
2294
+ (r'//.*?\n', Comment.Single), # ObjM2
2295
+ (r'/\*(.*?)\*/', Comment.Multiline), # ObjM2
2296
+ (r'\(\*([^\$].*?)\*\)', Comment.Multiline),
2297
+ # TO DO: nesting of (* ... *) comments
2298
+ ],
2299
+ 'pragmas': [
2300
+ (r'\(\*\$(.*?)\*\)', Comment.Preproc), # PIM
2301
+ (r'<\*(.*?)\*>', Comment.Preproc), # ISO + ObjM2
2302
+ ],
2303
+ 'root': [
2304
+ include('whitespace'),
2305
+ include('comments'),
2306
+ include('pragmas'),
2307
+ include('identifiers'),
2308
+ include('numliterals'),
2309
+ include('strings'),
2310
+ include('operators'),
2311
+ include('punctuation'),
2312
+ ]
2313
+ }
2314
+
2315
+ pim_reserved_words = [
2316
+ # 40 reserved words
2317
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION',
2318
+ 'DIV', 'DO', 'ELSE', 'ELSIF', 'END', 'EXIT', 'EXPORT', 'FOR',
2319
+ 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN', 'LOOP', 'MOD',
2320
+ 'MODULE', 'NOT', 'OF', 'OR', 'POINTER', 'PROCEDURE', 'QUALIFIED',
2321
+ 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2322
+ 'UNTIL', 'VAR', 'WHILE', 'WITH',
2323
+ ]
2324
+
2325
+ pim_pervasives = [
2326
+ # 31 pervasives
2327
+ 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'DEC',
2328
+ 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH', 'INC', 'INCL',
2329
+ 'INTEGER', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW', 'NIL', 'ODD',
2330
+ 'ORD', 'PROC', 'REAL', 'SIZE', 'TRUE', 'TRUNC', 'VAL',
2331
+ ]
2332
+
2333
+ iso_reserved_words = [
2334
+ # 46 reserved words
2335
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2336
+ 'DO', 'ELSE', 'ELSIF', 'END', 'EXCEPT', 'EXIT', 'EXPORT', 'FINALLY',
2337
+ 'FOR', 'FORWARD', 'FROM', 'IF', 'IMPLEMENTATION', 'IMPORT', 'IN',
2338
+ 'LOOP', 'MOD', 'MODULE', 'NOT', 'OF', 'OR', 'PACKEDSET', 'POINTER',
2339
+ 'PROCEDURE', 'QUALIFIED', 'RECORD', 'REPEAT', 'REM', 'RETRY',
2340
+ 'RETURN', 'SET', 'THEN', 'TO', 'TYPE', 'UNTIL', 'VAR', 'WHILE',
2341
+ 'WITH',
2342
+ ]
2343
+
2344
+ iso_pervasives = [
2345
+ # 42 pervasives
2346
+ 'ABS', 'BITSET', 'BOOLEAN', 'CAP', 'CARDINAL', 'CHAR', 'CHR', 'CMPLX',
2347
+ 'COMPLEX', 'DEC', 'DISPOSE', 'EXCL', 'FALSE', 'FLOAT', 'HALT', 'HIGH',
2348
+ 'IM', 'INC', 'INCL', 'INT', 'INTEGER', 'INTERRUPTIBLE', 'LENGTH',
2349
+ 'LFLOAT', 'LONGCOMPLEX', 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEW',
2350
+ 'NIL', 'ODD', 'ORD', 'PROC', 'PROTECTION', 'RE', 'REAL', 'SIZE',
2351
+ 'TRUE', 'TRUNC', 'UNINTERRUBTIBLE', 'VAL',
2352
+ ]
2353
+
2354
+ objm2_reserved_words = [
2355
+ # base language, 42 reserved words
2356
+ 'AND', 'ARRAY', 'BEGIN', 'BY', 'CASE', 'CONST', 'DEFINITION', 'DIV',
2357
+ 'DO', 'ELSE', 'ELSIF', 'END', 'ENUM', 'EXIT', 'FOR', 'FROM', 'IF',
2358
+ 'IMMUTABLE', 'IMPLEMENTATION', 'IMPORT', 'IN', 'IS', 'LOOP', 'MOD',
2359
+ 'MODULE', 'NOT', 'OF', 'OPAQUE', 'OR', 'POINTER', 'PROCEDURE',
2360
+ 'RECORD', 'REPEAT', 'RETURN', 'SET', 'THEN', 'TO', 'TYPE',
2361
+ 'UNTIL', 'VAR', 'VARIADIC', 'WHILE',
2362
+ # OO extensions, 16 reserved words
2363
+ 'BYCOPY', 'BYREF', 'CLASS', 'CONTINUE', 'CRITICAL', 'INOUT', 'METHOD',
2364
+ 'ON', 'OPTIONAL', 'OUT', 'PRIVATE', 'PROTECTED', 'PROTOCOL', 'PUBLIC',
2365
+ 'SUPER', 'TRY',
2366
+ ]
2367
+
2368
+ objm2_pervasives = [
2369
+ # base language, 38 pervasives
2370
+ 'ABS', 'BITSET', 'BOOLEAN', 'CARDINAL', 'CHAR', 'CHR', 'DISPOSE',
2371
+ 'FALSE', 'HALT', 'HIGH', 'INTEGER', 'INRANGE', 'LENGTH', 'LONGCARD',
2372
+ 'LONGINT', 'LONGREAL', 'MAX', 'MIN', 'NEG', 'NEW', 'NEXTV', 'NIL',
2373
+ 'OCTET', 'ODD', 'ORD', 'PRED', 'PROC', 'READ', 'REAL', 'SUCC', 'TMAX',
2374
+ 'TMIN', 'TRUE', 'TSIZE', 'UNICHAR', 'VAL', 'WRITE', 'WRITEF',
2375
+ # OO extensions, 3 pervasives
2376
+ 'OBJECT', 'NO', 'YES',
2377
+ ]
2378
+
2379
+ gnu_reserved_words = [
2380
+ # 10 additional reserved words
2381
+ 'ASM', '__ATTRIBUTE__', '__BUILTIN__', '__COLUMN__', '__DATE__',
2382
+ '__FILE__', '__FUNCTION__', '__LINE__', '__MODULE__', 'VOLATILE',
2383
+ ]
2384
+
2385
+ gnu_pervasives = [
2386
+ # 21 identifiers, actually from pseudo-module SYSTEM
2387
+ # but we will highlight them as if they were pervasives
2388
+ 'BITSET8', 'BITSET16', 'BITSET32', 'CARDINAL8', 'CARDINAL16',
2389
+ 'CARDINAL32', 'CARDINAL64', 'COMPLEX32', 'COMPLEX64', 'COMPLEX96',
2390
+ 'COMPLEX128', 'INTEGER8', 'INTEGER16', 'INTEGER32', 'INTEGER64',
2391
+ 'REAL8', 'REAL16', 'REAL32', 'REAL96', 'REAL128', 'THROW',
2392
+ ]
2393
+
2394
+ def __init__(self, **options):
2395
+ self.reserved_words = set()
2396
+ self.pervasives = set()
2397
+ # ISO Modula-2
2398
+ if get_bool_opt(options, 'iso', False):
2399
+ self.reserved_words.update(self.iso_reserved_words)
2400
+ self.pervasives.update(self.iso_pervasives)
2401
+ # Objective Modula-2
2402
+ elif get_bool_opt(options, 'objm2', False):
2403
+ self.reserved_words.update(self.objm2_reserved_words)
2404
+ self.pervasives.update(self.objm2_pervasives)
2405
+ # PIM Modula-2 (DEFAULT)
2406
+ else:
2407
+ self.reserved_words.update(self.pim_reserved_words)
2408
+ self.pervasives.update(self.pim_pervasives)
2409
+ # GNU extensions
2410
+ if get_bool_opt(options, 'gm2ext', False):
2411
+ self.reserved_words.update(self.gnu_reserved_words)
2412
+ self.pervasives.update(self.gnu_pervasives)
2413
+ # initialise
2414
+ RegexLexer.__init__(self, **options)
2415
+
2416
+ def get_tokens_unprocessed(self, text):
2417
+ for index, token, value in \
2418
+ RegexLexer.get_tokens_unprocessed(self, text):
2419
+ # check for reserved words and pervasives
2420
+ if token is Name:
2421
+ if value in self.reserved_words:
2422
+ token = Keyword.Reserved
2423
+ elif value in self.pervasives:
2424
+ token = Keyword.Pervasive
2425
+ # return result
2426
+ yield index, token, value
2427
+
2428
+
2429
+ class BlitzMaxLexer(RegexLexer):
2430
+ """
2431
+ For `BlitzMax <http://blitzbasic.com>`_ source code.
2432
+
2433
+ *New in Pygments 1.4.*
2434
+ """
2435
+
2436
+ name = 'BlitzMax'
2437
+ aliases = ['blitzmax', 'bmax']
2438
+ filenames = ['*.bmx']
2439
+ mimetypes = ['text/x-bmx']
2440
+
2441
+ bmax_vopwords = r'\b(Shl|Shr|Sar|Mod)\b'
2442
+ bmax_sktypes = r'@{1,2}|[!#$%]'
2443
+ bmax_lktypes = r'\b(Int|Byte|Short|Float|Double|Long)\b'
2444
+ bmax_name = r'[a-z_][a-z0-9_]*'
2445
+ bmax_var = r'(%s)(?:(?:([ \t]*)(%s)|([ \t]*:[ \t]*\b(?:Shl|Shr|Sar|Mod)\b)|([ \t]*)([:])([ \t]*)(?:%s|(%s)))(?:([ \t]*)(Ptr))?)' % (bmax_name, bmax_sktypes, bmax_lktypes, bmax_name)
2446
+ bmax_func = bmax_var + r'?((?:[ \t]|\.\.\n)*)([(])'
2447
+
2448
+ flags = re.MULTILINE | re.IGNORECASE
2449
+ tokens = {
2450
+ 'root': [
2451
+ # Text
2452
+ (r'[ \t]+', Text),
2453
+ (r'\.\.\n', Text), # Line continuation
2454
+ # Comments
2455
+ (r"'.*?\n", Comment.Single),
2456
+ (r'([ \t]*)\bRem\n(\n|.)*?\s*\bEnd([ \t]*)Rem', Comment.Multiline),
2457
+ # Data types
2458
+ ('"', String.Double, 'string'),
2459
+ # Numbers
2460
+ (r'[0-9]+\.[0-9]*(?!\.)', Number.Float),
2461
+ (r'\.[0-9]*(?!\.)', Number.Float),
2462
+ (r'[0-9]+', Number.Integer),
2463
+ (r'\$[0-9a-f]+', Number.Hex),
2464
+ (r'\%[10]+', Number), # Binary
2465
+ # Other
2466
+ (r'(?:(?:(:)?([ \t]*)(:?%s|([+\-*/&|~]))|Or|And|Not|[=<>^]))' %
2467
+ (bmax_vopwords), Operator),
2468
+ (r'[(),.:\[\]]', Punctuation),
2469
+ (r'(?:#[\w \t]*)', Name.Label),
2470
+ (r'(?:\?[\w \t]*)', Comment.Preproc),
2471
+ # Identifiers
2472
+ (r'\b(New)\b([ \t]?)([(]?)(%s)' % (bmax_name),
2473
+ bygroups(Keyword.Reserved, Text, Punctuation, Name.Class)),
2474
+ (r'\b(Import|Framework|Module)([ \t]+)(%s\.%s)' %
2475
+ (bmax_name, bmax_name),
2476
+ bygroups(Keyword.Reserved, Text, Keyword.Namespace)),
2477
+ (bmax_func, bygroups(Name.Function, Text, Keyword.Type,
2478
+ Operator, Text, Punctuation, Text,
2479
+ Keyword.Type, Name.Class, Text,
2480
+ Keyword.Type, Text, Punctuation)),
2481
+ (bmax_var, bygroups(Name.Variable, Text, Keyword.Type, Operator,
2482
+ Text, Punctuation, Text, Keyword.Type,
2483
+ Name.Class, Text, Keyword.Type)),
2484
+ (r'\b(Type|Extends)([ \t]+)(%s)' % (bmax_name),
2485
+ bygroups(Keyword.Reserved, Text, Name.Class)),
2486
+ # Keywords
2487
+ (r'\b(Ptr)\b', Keyword.Type),
2488
+ (r'\b(Pi|True|False|Null|Self|Super)\b', Keyword.Constant),
2489
+ (r'\b(Local|Global|Const|Field)\b', Keyword.Declaration),
2490
+ (r'\b(TNullMethodException|TNullFunctionException|'
2491
+ r'TNullObjectException|TArrayBoundsException|'
2492
+ r'TRuntimeException)\b', Name.Exception),
2493
+ (r'\b(Strict|SuperStrict|Module|ModuleInfo|'
2494
+ r'End|Return|Continue|Exit|Public|Private|'
2495
+ r'Var|VarPtr|Chr|Len|Asc|SizeOf|Sgn|Abs|Min|Max|'
2496
+ r'New|Release|Delete|'
2497
+ r'Incbin|IncbinPtr|IncbinLen|'
2498
+ r'Framework|Include|Import|Extern|EndExtern|'
2499
+ r'Function|EndFunction|'
2500
+ r'Type|EndType|Extends|'
2501
+ r'Method|EndMethod|'
2502
+ r'Abstract|Final|'
2503
+ r'If|Then|Else|ElseIf|EndIf|'
2504
+ r'For|To|Next|Step|EachIn|'
2505
+ r'While|Wend|EndWhile|'
2506
+ r'Repeat|Until|Forever|'
2507
+ r'Select|Case|Default|EndSelect|'
2508
+ r'Try|Catch|EndTry|Throw|Assert|'
2509
+ r'Goto|DefData|ReadData|RestoreData)\b', Keyword.Reserved),
2510
+ # Final resolve (for variable names and such)
2511
+ (r'(%s)' % (bmax_name), Name.Variable),
2512
+ ],
2513
+ 'string': [
2514
+ (r'""', String.Double),
2515
+ (r'"C?', String.Double, '#pop'),
2516
+ (r'[^"]+', String.Double),
2517
+ ],
2518
+ }
2519
+
2520
+
2521
+ class NimrodLexer(RegexLexer):
2522
+ """
2523
+ For `Nimrod <http://nimrod-code.org/>`_ source code.
2524
+
2525
+ *New in Pygments 1.5.*
2526
+ """
2527
+
2528
+ name = 'Nimrod'
2529
+ aliases = ['nimrod', 'nim']
2530
+ filenames = ['*.nim', '*.nimrod']
2531
+ mimetypes = ['text/x-nimrod']
2532
+
2533
+ flags = re.MULTILINE | re.IGNORECASE | re.UNICODE
2534
+
2535
+ def underscorize(words):
2536
+ newWords = []
2537
+ new = ""
2538
+ for word in words:
2539
+ for ch in word:
2540
+ new += (ch + "_?")
2541
+ newWords.append(new)
2542
+ new = ""
2543
+ return "|".join(newWords)
2544
+
2545
+ keywords = [
2546
+ 'addr', 'and', 'as', 'asm', 'atomic', 'bind', 'block', 'break',
2547
+ 'case', 'cast', 'const', 'continue', 'converter', 'discard',
2548
+ 'distinct', 'div', 'elif', 'else', 'end', 'enum', 'except', 'finally',
2549
+ 'for', 'generic', 'if', 'implies', 'in', 'yield',
2550
+ 'is', 'isnot', 'iterator', 'lambda', 'let', 'macro', 'method',
2551
+ 'mod', 'not', 'notin', 'object', 'of', 'or', 'out', 'proc',
2552
+ 'ptr', 'raise', 'ref', 'return', 'shl', 'shr', 'template', 'try',
2553
+ 'tuple', 'type' , 'when', 'while', 'with', 'without', 'xor'
2554
+ ]
2555
+
2556
+ keywordsPseudo = [
2557
+ 'nil', 'true', 'false'
2558
+ ]
2559
+
2560
+ opWords = [
2561
+ 'and', 'or', 'not', 'xor', 'shl', 'shr', 'div', 'mod', 'in',
2562
+ 'notin', 'is', 'isnot'
2563
+ ]
2564
+
2565
+ types = [
2566
+ 'int', 'int8', 'int16', 'int32', 'int64', 'float', 'float32', 'float64',
2567
+ 'bool', 'char', 'range', 'array', 'seq', 'set', 'string'
2568
+ ]
2569
+
2570
+ tokens = {
2571
+ 'root': [
2572
+ (r'##.*$', String.Doc),
2573
+ (r'#.*$', Comment),
2574
+ (r'\*|=|>|<|\+|-|/|@|\$|~|&|%|\!|\?|\||\\|\[|\]', Operator),
2575
+ (r'\.\.|\.|,|\[\.|\.\]|{\.|\.}|\(\.|\.\)|{|}|\(|\)|:|\^|`|;',
2576
+ Punctuation),
2577
+
2578
+ # Strings
2579
+ (r'(?:[\w]+)"', String, 'rdqs'),
2580
+ (r'"""', String, 'tdqs'),
2581
+ ('"', String, 'dqs'),
2582
+
2583
+ # Char
2584
+ ("'", String.Char, 'chars'),
2585
+
2586
+ # Keywords
2587
+ (r'(%s)\b' % underscorize(opWords), Operator.Word),
2588
+ (r'(p_?r_?o_?c_?\s)(?![\(\[\]])', Keyword, 'funcname'),
2589
+ (r'(%s)\b' % underscorize(keywords), Keyword),
2590
+ (r'(%s)\b' % underscorize(['from', 'import', 'include']),
2591
+ Keyword.Namespace),
2592
+ (r'(v_?a_?r)\b', Keyword.Declaration),
2593
+ (r'(%s)\b' % underscorize(types), Keyword.Type),
2594
+ (r'(%s)\b' % underscorize(keywordsPseudo), Keyword.Pseudo),
2595
+ # Identifiers
2596
+ (r'\b((?![_\d])\w)(((?!_)\w)|(_(?!_)\w))*', Name),
2597
+ # Numbers
2598
+ (r'[0-9][0-9_]*(?=([eE.]|\'[fF](32|64)))',
2599
+ Number.Float, ('float-suffix', 'float-number')),
2600
+ (r'0[xX][a-fA-F0-9][a-fA-F0-9_]*', Number.Hex, 'int-suffix'),
2601
+ (r'0[bB][01][01_]*', Number, 'int-suffix'),
2602
+ (r'0o[0-7][0-7_]*', Number.Oct, 'int-suffix'),
2603
+ (r'[0-9][0-9_]*', Number.Integer, 'int-suffix'),
2604
+ # Whitespace
2605
+ (r'\s+', Text),
2606
+ (r'.+$', Error),
2607
+ ],
2608
+ 'chars': [
2609
+ (r'\\([\\abcefnrtvl"\']|x[a-fA-F0-9]{2}|[0-9]{1,3})', String.Escape),
2610
+ (r"'", String.Char, '#pop'),
2611
+ (r".", String.Char)
2612
+ ],
2613
+ 'strings': [
2614
+ (r'(?<!\$)\$(\d+|#|\w+)+', String.Interpol),
2615
+ (r'[^\\\'"\$\n]+', String),
2616
+ # quotes, dollars and backslashes must be parsed one at a time
2617
+ (r'[\'"\\]', String),
2618
+ # unhandled string formatting sign
2619
+ (r'\$', String)
2620
+ # newlines are an error (use "nl" state)
2621
+ ],
2622
+ 'dqs': [
2623
+ (r'\\([\\abcefnrtvl"\']|\n|x[a-fA-F0-9]{2}|[0-9]{1,3})',
2624
+ String.Escape),
2625
+ (r'"', String, '#pop'),
2626
+ include('strings')
2627
+ ],
2628
+ 'rdqs': [
2629
+ (r'"(?!")', String, '#pop'),
2630
+ (r'""', String.Escape),
2631
+ include('strings')
2632
+ ],
2633
+ 'tdqs': [
2634
+ (r'"""(?!")', String, '#pop'),
2635
+ include('strings'),
2636
+ include('nl')
2637
+ ],
2638
+ 'funcname': [
2639
+ (r'((?![\d_])\w)(((?!_)\w)|(_(?!_)\w))*', Name.Function, '#pop'),
2640
+ (r'`.+`', Name.Function, '#pop')
2641
+ ],
2642
+ 'nl': [
2643
+ (r'\n', String)
2644
+ ],
2645
+ 'float-number': [
2646
+ (r'\.(?!\.)[0-9_]*', Number.Float),
2647
+ (r'[eE][+-]?[0-9][0-9_]*', Number.Float),
2648
+ (r'', Text, '#pop')
2649
+ ],
2650
+ 'float-suffix': [
2651
+ (r'\'[fF](32|64)', Number.Float),
2652
+ (r'', Text, '#pop')
2653
+ ],
2654
+ 'int-suffix': [
2655
+ (r'\'[iI](32|64)', Number.Integer.Long),
2656
+ (r'\'[iI](8|16)', Number.Integer),
2657
+ (r'', Text, '#pop')
2658
+ ],
2659
+ }
2660
+
2661
+
2662
+ class FantomLexer(RegexLexer):
2663
+ """
2664
+ For Fantom source code.
2665
+
2666
+ *New in Pygments 1.5.*
2667
+ """
2668
+ name = 'Fantom'
2669
+ aliases = ['fan']
2670
+ filenames = ['*.fan']
2671
+ mimetypes = ['application/x-fantom']
2672
+
2673
+ # often used regexes
2674
+ def s(str):
2675
+ return Template(str).substitute(
2676
+ dict (
2677
+ pod = r'[\"\w\.]+',
2678
+ eos = r'\n|;',
2679
+ id = r'[a-zA-Z_][a-zA-Z0-9_]*',
2680
+ # all chars which can be part of type definition. Starts with
2681
+ # either letter, or [ (maps), or | (funcs)
2682
+ type = r'(?:\[|[a-zA-Z_]|\|)[:\w\[\]\|\->\?]*?',
2683
+ )
2684
+ )
2685
+
2686
+
2687
+ tokens = {
2688
+ 'comments': [
2689
+ (r'(?s)/\*.*?\*/', Comment.Multiline), #Multiline
2690
+ (r'//.*?\n', Comment.Single), #Single line
2691
+ #todo: highlight references in fandocs
2692
+ (r'\*\*.*?\n', Comment.Special), #Fandoc
2693
+ (r'#.*\n', Comment.Single) #Shell-style
2694
+ ],
2695
+ 'literals': [
2696
+ (r'\b-?[\d_]+(ns|ms|sec|min|hr|day)', Number), #Duration
2697
+ (r'\b-?[\d_]*\.[\d_]+(ns|ms|sec|min|hr|day)', Number),
2698
+ #Duration with dot
2699
+ (r'\b-?(\d+)?\.\d+(f|F|d|D)?', Number.Float), #Float/Decimal
2700
+ (r'\b-?0x[0-9a-fA-F_]+', Number.Hex), #Hex
2701
+ (r'\b-?[\d_]+', Number.Integer), #Int
2702
+ (r"'\\.'|'[^\\]'|'\\u[0-9a-f]{4}'", String.Char), #Char
2703
+ (r'"', Punctuation, 'insideStr'), #Opening quote
2704
+ (r'`', Punctuation, 'insideUri'), #Opening accent
2705
+ (r'\b(true|false|null)\b', Keyword.Constant), #Bool & null
2706
+ (r'(?:(\w+)(::))?(\w+)(<\|)(.*?)(\|>)', #DSL
2707
+ bygroups(Name.Namespace, Punctuation, Name.Class,
2708
+ Punctuation, String, Punctuation)),
2709
+ (r'(?:(\w+)(::))?(\w+)?(#)(\w+)?', #Type/slot literal
2710
+ bygroups(Name.Namespace, Punctuation, Name.Class,
2711
+ Punctuation, Name.Function)),
2712
+ (r'\[,\]', Literal), # Empty list
2713
+ (s(r'($type)(\[,\])'), # Typed empty list
2714
+ bygroups(using(this, state = 'inType'), Literal)),
2715
+ (r'\[:\]', Literal), # Empty Map
2716
+ (s(r'($type)(\[:\])'),
2717
+ bygroups(using(this, state = 'inType'), Literal)),
2718
+ ],
2719
+ 'insideStr': [
2720
+ (r'\\\\', String.Escape), #Escaped backslash
2721
+ (r'\\"', String.Escape), #Escaped "
2722
+ (r'\\`', String.Escape), #Escaped `
2723
+ (r'\$\w+', String.Interpol), #Subst var
2724
+ (r'\${.*?}', String.Interpol), #Subst expr
2725
+ (r'"', Punctuation, '#pop'), #Closing quot
2726
+ (r'.', String) #String content
2727
+ ],
2728
+ 'insideUri': [ #TODO: remove copy/paste str/uri
2729
+ (r'\\\\', String.Escape), #Escaped backslash
2730
+ (r'\\"', String.Escape), #Escaped "
2731
+ (r'\\`', String.Escape), #Escaped `
2732
+ (r'\$\w+', String.Interpol), #Subst var
2733
+ (r'\${.*?}', String.Interpol), #Subst expr
2734
+ (r'`', Punctuation, '#pop'), #Closing tick
2735
+ (r'.', String.Backtick) #URI content
2736
+ ],
2737
+ 'protectionKeywords': [
2738
+ (r'\b(public|protected|private|internal)\b', Keyword),
2739
+ ],
2740
+ 'typeKeywords': [
2741
+ (r'\b(abstract|final|const|native|facet|enum)\b', Keyword),
2742
+ ],
2743
+ 'methodKeywords': [
2744
+ (r'\b(abstract|native|once|override|static|virtual|final)\b',
2745
+ Keyword),
2746
+ ],
2747
+ 'fieldKeywords': [
2748
+ (r'\b(abstract|const|final|native|override|static|virtual|'
2749
+ r'readonly)\b', Keyword)
2750
+ ],
2751
+ 'otherKeywords': [
2752
+ (r'\b(try|catch|throw|finally|for|if|else|while|as|is|isnot|'
2753
+ r'switch|case|default|continue|break|do|return|get|set)\b',
2754
+ Keyword),
2755
+ (r'\b(it|this|super)\b', Name.Builtin.Pseudo),
2756
+ ],
2757
+ 'operators': [
2758
+ (r'\+\+|\-\-|\+|\-|\*|/|\|\||&&|<=>|<=|<|>=|>|=|!|\[|\]', Operator)
2759
+ ],
2760
+ 'inType': [
2761
+ (r'[\[\]\|\->:\?]', Punctuation),
2762
+ (s(r'$id'), Name.Class),
2763
+ (r'', Text, '#pop'),
2764
+
2765
+ ],
2766
+ 'root': [
2767
+ include('comments'),
2768
+ include('protectionKeywords'),
2769
+ include('typeKeywords'),
2770
+ include('methodKeywords'),
2771
+ include('fieldKeywords'),
2772
+ include('literals'),
2773
+ include('otherKeywords'),
2774
+ include('operators'),
2775
+ (r'using\b', Keyword.Namespace, 'using'), # Using stmt
2776
+ (r'@\w+', Name.Decorator, 'facet'), # Symbol
2777
+ (r'(class|mixin)(\s+)(\w+)', bygroups(Keyword, Text, Name.Class),
2778
+ 'inheritance'), # Inheritance list
2779
+
2780
+
2781
+ ### Type var := val
2782
+ (s(r'($type)([ \t]+)($id)(\s*)(:=)'),
2783
+ bygroups(using(this, state = 'inType'), Text,
2784
+ Name.Variable, Text, Operator)),
2785
+
2786
+ ### var := val
2787
+ (s(r'($id)(\s*)(:=)'),
2788
+ bygroups(Name.Variable, Text, Operator)),
2789
+
2790
+ ### .someId( or ->someId( ###
2791
+ (s(r'(\.|(?:\->))($id)(\s*)(\()'),
2792
+ bygroups(Operator, Name.Function, Text, Punctuation),
2793
+ 'insideParen'),
2794
+
2795
+ ### .someId or ->someId
2796
+ (s(r'(\.|(?:\->))($id)'),
2797
+ bygroups(Operator, Name.Function)),
2798
+
2799
+ ### new makeXXX ( ####
2800
+ (r'(new)(\s+)(make\w*)(\s*)(\()',
2801
+ bygroups(Keyword, Text, Name.Function, Text, Punctuation),
2802
+ 'insideMethodDeclArgs'),
2803
+
2804
+ ### Type name ( ####
2805
+ (s(r'($type)([ \t]+)' #Return type and whitespace
2806
+ r'($id)(\s*)(\()'), #method name + open brace
2807
+ bygroups(using(this, state = 'inType'), Text,
2808
+ Name.Function, Text, Punctuation),
2809
+ 'insideMethodDeclArgs'),
2810
+
2811
+ ### ArgType argName, #####
2812
+ (s(r'($type)(\s+)($id)(\s*)(,)'),
2813
+ bygroups(using(this, state='inType'), Text, Name.Variable,
2814
+ Text, Punctuation)),
2815
+
2816
+ #### ArgType argName) ####
2817
+ ## Covered in 'insideParen' state
2818
+
2819
+ ### ArgType argName -> ArgType| ###
2820
+ (s(r'($type)(\s+)($id)(\s*)(\->)(\s*)($type)(\|)'),
2821
+ bygroups(using(this, state='inType'), Text, Name.Variable,
2822
+ Text, Punctuation, Text, using(this, state = 'inType'),
2823
+ Punctuation)),
2824
+
2825
+ ### ArgType argName| ###
2826
+ (s(r'($type)(\s+)($id)(\s*)(\|)'),
2827
+ bygroups(using(this, state='inType'), Text, Name.Variable,
2828
+ Text, Punctuation)),
2829
+
2830
+ ### Type var
2831
+ (s(r'($type)([ \t]+)($id)'),
2832
+ bygroups(using(this, state='inType'), Text,
2833
+ Name.Variable)),
2834
+
2835
+ (r'\(', Punctuation, 'insideParen'),
2836
+ (r'\{', Punctuation, 'insideBrace'),
2837
+ (r'.', Text)
2838
+ ],
2839
+ 'insideParen': [
2840
+ (r'\)', Punctuation, '#pop'),
2841
+ include('root'),
2842
+ ],
2843
+ 'insideMethodDeclArgs': [
2844
+ (r'\)', Punctuation, '#pop'),
2845
+ (s(r'($type)(\s+)($id)(\s*)(\))'),
2846
+ bygroups(using(this, state='inType'), Text, Name.Variable,
2847
+ Text, Punctuation), '#pop'),
2848
+ include('root'),
2849
+ ],
2850
+ 'insideBrace': [
2851
+ (r'\}', Punctuation, '#pop'),
2852
+ include('root'),
2853
+ ],
2854
+ 'inheritance': [
2855
+ (r'\s+', Text), #Whitespace
2856
+ (r':|,', Punctuation),
2857
+ (r'(?:(\w+)(::))?(\w+)',
2858
+ bygroups(Name.Namespace, Punctuation, Name.Class)),
2859
+ (r'{', Punctuation, '#pop')
2860
+ ],
2861
+ 'using': [
2862
+ (r'[ \t]+', Text), # consume whitespaces
2863
+ (r'(\[)(\w+)(\])',
2864
+ bygroups(Punctuation, Comment.Special, Punctuation)), #ffi
2865
+ (r'(\")?([\w\.]+)(\")?',
2866
+ bygroups(Punctuation, Name.Namespace, Punctuation)), #podname
2867
+ (r'::', Punctuation, 'usingClass'),
2868
+ (r'', Text, '#pop')
2869
+ ],
2870
+ 'usingClass': [
2871
+ (r'[ \t]+', Text), # consume whitespaces
2872
+ (r'(as)(\s+)(\w+)',
2873
+ bygroups(Keyword.Declaration, Text, Name.Class), '#pop:2'),
2874
+ (r'[\w\$]+', Name.Class),
2875
+ (r'', Text, '#pop:2') # jump out to root state
2876
+ ],
2877
+ 'facet': [
2878
+ (r'\s+', Text),
2879
+ (r'{', Punctuation, 'facetFields'),
2880
+ (r'', Text, '#pop')
2881
+ ],
2882
+ 'facetFields': [
2883
+ include('comments'),
2884
+ include('literals'),
2885
+ include('operators'),
2886
+ (r'\s+', Text),
2887
+ (r'(\s*)(\w+)(\s*)(=)', bygroups(Text, Name, Text, Operator)),
2888
+ (r'}', Punctuation, '#pop'),
2889
+ (r'.', Text)
2890
+ ],
2891
+ }