gitlab-pygments.rb 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +6 -0
- data/Gemfile +2 -0
- data/README.md +91 -0
- data/Rakefile +78 -0
- data/bench.rb +22 -0
- data/cache-lexers.rb +8 -0
- data/lexers +0 -0
- data/lib/pygments/lexer.rb +148 -0
- data/lib/pygments/mentos.py +344 -0
- data/lib/pygments/popen.rb +389 -0
- data/lib/pygments/version.rb +3 -0
- data/lib/pygments.rb +8 -0
- data/pygments.rb.gemspec +24 -0
- data/test/test_data.c +2581 -0
- data/test/test_data.py +514 -0
- data/test/test_data_generated +2582 -0
- data/test/test_pygments.rb +276 -0
- data/vendor/custom_formatters/gitlab.py +171 -0
- data/vendor/custom_lexers/github.py +362 -0
- data/vendor/pygments-main/AUTHORS +115 -0
- data/vendor/pygments-main/CHANGES +762 -0
- data/vendor/pygments-main/LICENSE +25 -0
- data/vendor/pygments-main/MANIFEST.in +6 -0
- data/vendor/pygments-main/Makefile +59 -0
- data/vendor/pygments-main/REVISION +1 -0
- data/vendor/pygments-main/TODO +15 -0
- data/vendor/pygments-main/docs/generate.py +472 -0
- data/vendor/pygments-main/docs/pygmentize.1 +94 -0
- data/vendor/pygments-main/docs/src/api.txt +270 -0
- data/vendor/pygments-main/docs/src/authors.txt +5 -0
- data/vendor/pygments-main/docs/src/changelog.txt +5 -0
- data/vendor/pygments-main/docs/src/cmdline.txt +147 -0
- data/vendor/pygments-main/docs/src/filterdevelopment.txt +70 -0
- data/vendor/pygments-main/docs/src/filters.txt +42 -0
- data/vendor/pygments-main/docs/src/formatterdevelopment.txt +169 -0
- data/vendor/pygments-main/docs/src/formatters.txt +48 -0
- data/vendor/pygments-main/docs/src/index.txt +69 -0
- data/vendor/pygments-main/docs/src/installation.txt +71 -0
- data/vendor/pygments-main/docs/src/integrate.txt +43 -0
- data/vendor/pygments-main/docs/src/lexerdevelopment.txt +551 -0
- data/vendor/pygments-main/docs/src/lexers.txt +67 -0
- data/vendor/pygments-main/docs/src/moinmoin.txt +39 -0
- data/vendor/pygments-main/docs/src/plugins.txt +93 -0
- data/vendor/pygments-main/docs/src/quickstart.txt +202 -0
- data/vendor/pygments-main/docs/src/rstdirective.txt +22 -0
- data/vendor/pygments-main/docs/src/styles.txt +143 -0
- data/vendor/pygments-main/docs/src/tokens.txt +349 -0
- data/vendor/pygments-main/docs/src/unicode.txt +49 -0
- data/vendor/pygments-main/external/markdown-processor.py +67 -0
- data/vendor/pygments-main/external/moin-parser.py +112 -0
- data/vendor/pygments-main/external/pygments.bashcomp +38 -0
- data/vendor/pygments-main/external/rst-directive-old.py +77 -0
- data/vendor/pygments-main/external/rst-directive.py +83 -0
- data/vendor/pygments-main/ez_setup.py +276 -0
- data/vendor/pygments-main/pygmentize +7 -0
- data/vendor/pygments-main/pygments/__init__.py +91 -0
- data/vendor/pygments-main/pygments/cmdline.py +433 -0
- data/vendor/pygments-main/pygments/console.py +74 -0
- data/vendor/pygments-main/pygments/filter.py +74 -0
- data/vendor/pygments-main/pygments/filters/__init__.py +357 -0
- data/vendor/pygments-main/pygments/formatter.py +92 -0
- data/vendor/pygments-main/pygments/formatters/__init__.py +68 -0
- data/vendor/pygments-main/pygments/formatters/_mapping.py +94 -0
- data/vendor/pygments-main/pygments/formatters/bbcode.py +109 -0
- data/vendor/pygments-main/pygments/formatters/gitlab.py +171 -0
- data/vendor/pygments-main/pygments/formatters/html.py +750 -0
- data/vendor/pygments-main/pygments/formatters/img.py +553 -0
- data/vendor/pygments-main/pygments/formatters/latex.py +378 -0
- data/vendor/pygments-main/pygments/formatters/other.py +117 -0
- data/vendor/pygments-main/pygments/formatters/rtf.py +136 -0
- data/vendor/pygments-main/pygments/formatters/svg.py +154 -0
- data/vendor/pygments-main/pygments/formatters/terminal.py +112 -0
- data/vendor/pygments-main/pygments/formatters/terminal256.py +222 -0
- data/vendor/pygments-main/pygments/lexer.py +697 -0
- data/vendor/pygments-main/pygments/lexers/__init__.py +229 -0
- data/vendor/pygments-main/pygments/lexers/_asybuiltins.py +1645 -0
- data/vendor/pygments-main/pygments/lexers/_clbuiltins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_luabuiltins.py +249 -0
- data/vendor/pygments-main/pygments/lexers/_mapping.py +298 -0
- data/vendor/pygments-main/pygments/lexers/_phpbuiltins.py +3787 -0
- data/vendor/pygments-main/pygments/lexers/_postgres_builtins.py +232 -0
- data/vendor/pygments-main/pygments/lexers/_scilab_builtins.py +29 -0
- data/vendor/pygments-main/pygments/lexers/_vimbuiltins.py +3 -0
- data/vendor/pygments-main/pygments/lexers/agile.py +1803 -0
- data/vendor/pygments-main/pygments/lexers/asm.py +360 -0
- data/vendor/pygments-main/pygments/lexers/compiled.py +2891 -0
- data/vendor/pygments-main/pygments/lexers/dotnet.py +636 -0
- data/vendor/pygments-main/pygments/lexers/functional.py +1832 -0
- data/vendor/pygments-main/pygments/lexers/github.py +362 -0
- data/vendor/pygments-main/pygments/lexers/hdl.py +356 -0
- data/vendor/pygments-main/pygments/lexers/jvm.py +847 -0
- data/vendor/pygments-main/pygments/lexers/math.py +1072 -0
- data/vendor/pygments-main/pygments/lexers/other.py +3339 -0
- data/vendor/pygments-main/pygments/lexers/parsers.py +695 -0
- data/vendor/pygments-main/pygments/lexers/shell.py +361 -0
- data/vendor/pygments-main/pygments/lexers/special.py +100 -0
- data/vendor/pygments-main/pygments/lexers/sql.py +559 -0
- data/vendor/pygments-main/pygments/lexers/templates.py +1631 -0
- data/vendor/pygments-main/pygments/lexers/text.py +1753 -0
- data/vendor/pygments-main/pygments/lexers/web.py +2864 -0
- data/vendor/pygments-main/pygments/plugin.py +74 -0
- data/vendor/pygments-main/pygments/scanner.py +104 -0
- data/vendor/pygments-main/pygments/style.py +117 -0
- data/vendor/pygments-main/pygments/styles/__init__.py +70 -0
- data/vendor/pygments-main/pygments/styles/autumn.py +65 -0
- data/vendor/pygments-main/pygments/styles/borland.py +51 -0
- data/vendor/pygments-main/pygments/styles/bw.py +49 -0
- data/vendor/pygments-main/pygments/styles/colorful.py +81 -0
- data/vendor/pygments-main/pygments/styles/default.py +73 -0
- data/vendor/pygments-main/pygments/styles/emacs.py +72 -0
- data/vendor/pygments-main/pygments/styles/friendly.py +72 -0
- data/vendor/pygments-main/pygments/styles/fruity.py +42 -0
- data/vendor/pygments-main/pygments/styles/manni.py +75 -0
- data/vendor/pygments-main/pygments/styles/monokai.py +106 -0
- data/vendor/pygments-main/pygments/styles/murphy.py +80 -0
- data/vendor/pygments-main/pygments/styles/native.py +65 -0
- data/vendor/pygments-main/pygments/styles/pastie.py +75 -0
- data/vendor/pygments-main/pygments/styles/perldoc.py +69 -0
- data/vendor/pygments-main/pygments/styles/rrt.py +33 -0
- data/vendor/pygments-main/pygments/styles/tango.py +141 -0
- data/vendor/pygments-main/pygments/styles/trac.py +63 -0
- data/vendor/pygments-main/pygments/styles/vim.py +63 -0
- data/vendor/pygments-main/pygments/styles/vs.py +38 -0
- data/vendor/pygments-main/pygments/token.py +195 -0
- data/vendor/pygments-main/pygments/unistring.py +130 -0
- data/vendor/pygments-main/pygments/util.py +232 -0
- data/vendor/pygments-main/scripts/check_sources.py +242 -0
- data/vendor/pygments-main/scripts/detect_missing_analyse_text.py +30 -0
- data/vendor/pygments-main/scripts/epydoc.css +280 -0
- data/vendor/pygments-main/scripts/find_codetags.py +205 -0
- data/vendor/pygments-main/scripts/find_error.py +171 -0
- data/vendor/pygments-main/scripts/get_vimkw.py +43 -0
- data/vendor/pygments-main/scripts/pylintrc +301 -0
- data/vendor/pygments-main/scripts/reindent.py +291 -0
- data/vendor/pygments-main/scripts/vim2pygments.py +933 -0
- data/vendor/pygments-main/setup.cfg +6 -0
- data/vendor/pygments-main/setup.py +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4-f.dtd +37 -0
- data/vendor/pygments-main/tests/dtds/HTML4-s.dtd +869 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dcl +88 -0
- data/vendor/pygments-main/tests/dtds/HTML4.dtd +1092 -0
- data/vendor/pygments-main/tests/dtds/HTML4.soc +9 -0
- data/vendor/pygments-main/tests/dtds/HTMLlat1.ent +195 -0
- data/vendor/pygments-main/tests/dtds/HTMLspec.ent +77 -0
- data/vendor/pygments-main/tests/dtds/HTMLsym.ent +241 -0
- data/vendor/pygments-main/tests/examplefiles/ANTLRv3.g +608 -0
- data/vendor/pygments-main/tests/examplefiles/AcidStateAdvanced.hs +209 -0
- data/vendor/pygments-main/tests/examplefiles/AlternatingGroup.mu +102 -0
- data/vendor/pygments-main/tests/examplefiles/CPDictionary.j +611 -0
- data/vendor/pygments-main/tests/examplefiles/Constants.mo +158 -0
- data/vendor/pygments-main/tests/examplefiles/DancingSudoku.lhs +411 -0
- data/vendor/pygments-main/tests/examplefiles/Errors.scala +18 -0
- data/vendor/pygments-main/tests/examplefiles/File.hy +174 -0
- data/vendor/pygments-main/tests/examplefiles/Intro.java +1660 -0
- data/vendor/pygments-main/tests/examplefiles/Makefile +1131 -0
- data/vendor/pygments-main/tests/examplefiles/Object.st +4394 -0
- data/vendor/pygments-main/tests/examplefiles/OrderedMap.hx +584 -0
- data/vendor/pygments-main/tests/examplefiles/SmallCheck.hs +378 -0
- data/vendor/pygments-main/tests/examplefiles/Sorting.mod +470 -0
- data/vendor/pygments-main/tests/examplefiles/Sudoku.lhs +382 -0
- data/vendor/pygments-main/tests/examplefiles/addressbook.proto +30 -0
- data/vendor/pygments-main/tests/examplefiles/antlr_throws +1 -0
- data/vendor/pygments-main/tests/examplefiles/apache2.conf +393 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test.as +143 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test2.as +46 -0
- data/vendor/pygments-main/tests/examplefiles/as3_test3.as +3 -0
- data/vendor/pygments-main/tests/examplefiles/aspx-cs_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/badcase.java +2 -0
- data/vendor/pygments-main/tests/examplefiles/batchfile.bat +49 -0
- data/vendor/pygments-main/tests/examplefiles/boot-9.scm +1557 -0
- data/vendor/pygments-main/tests/examplefiles/cells.ps +515 -0
- data/vendor/pygments-main/tests/examplefiles/ceval.c +2604 -0
- data/vendor/pygments-main/tests/examplefiles/cheetah_example.html +13 -0
- data/vendor/pygments-main/tests/examplefiles/classes.dylan +40 -0
- data/vendor/pygments-main/tests/examplefiles/condensed_ruby.rb +10 -0
- data/vendor/pygments-main/tests/examplefiles/coq_RelationClasses +447 -0
- data/vendor/pygments-main/tests/examplefiles/database.pytb +20 -0
- data/vendor/pygments-main/tests/examplefiles/de.MoinMoin.po +2461 -0
- data/vendor/pygments-main/tests/examplefiles/demo.ahk +181 -0
- data/vendor/pygments-main/tests/examplefiles/demo.cfm +38 -0
- data/vendor/pygments-main/tests/examplefiles/django_sample.html+django +68 -0
- data/vendor/pygments-main/tests/examplefiles/dwarf.cw +17 -0
- data/vendor/pygments-main/tests/examplefiles/erl_session +10 -0
- data/vendor/pygments-main/tests/examplefiles/escape_semicolon.clj +1 -0
- data/vendor/pygments-main/tests/examplefiles/evil_regex.js +48 -0
- data/vendor/pygments-main/tests/examplefiles/example.c +2080 -0
- data/vendor/pygments-main/tests/examplefiles/example.cls +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.cpp +2363 -0
- data/vendor/pygments-main/tests/examplefiles/example.gs +106 -0
- data/vendor/pygments-main/tests/examplefiles/example.gst +7 -0
- data/vendor/pygments-main/tests/examplefiles/example.kt +47 -0
- data/vendor/pygments-main/tests/examplefiles/example.lua +250 -0
- data/vendor/pygments-main/tests/examplefiles/example.moo +26 -0
- data/vendor/pygments-main/tests/examplefiles/example.moon +629 -0
- data/vendor/pygments-main/tests/examplefiles/example.nim +1010 -0
- data/vendor/pygments-main/tests/examplefiles/example.ns2 +69 -0
- data/vendor/pygments-main/tests/examplefiles/example.p +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.pas +2708 -0
- data/vendor/pygments-main/tests/examplefiles/example.rb +1852 -0
- data/vendor/pygments-main/tests/examplefiles/example.rhtml +561 -0
- data/vendor/pygments-main/tests/examplefiles/example.sh-session +19 -0
- data/vendor/pygments-main/tests/examplefiles/example.sml +156 -0
- data/vendor/pygments-main/tests/examplefiles/example.snobol +15 -0
- data/vendor/pygments-main/tests/examplefiles/example.tea +34 -0
- data/vendor/pygments-main/tests/examplefiles/example.u +548 -0
- data/vendor/pygments-main/tests/examplefiles/example.weechatlog +9 -0
- data/vendor/pygments-main/tests/examplefiles/example.xhtml +376 -0
- data/vendor/pygments-main/tests/examplefiles/example.yaml +302 -0
- data/vendor/pygments-main/tests/examplefiles/example2.aspx +29 -0
- data/vendor/pygments-main/tests/examplefiles/example_elixir.ex +363 -0
- data/vendor/pygments-main/tests/examplefiles/example_file.fy +128 -0
- data/vendor/pygments-main/tests/examplefiles/firefox.mak +586 -0
- data/vendor/pygments-main/tests/examplefiles/flipflop.sv +19 -0
- data/vendor/pygments-main/tests/examplefiles/foo.sce +6 -0
- data/vendor/pygments-main/tests/examplefiles/format.ml +1213 -0
- data/vendor/pygments-main/tests/examplefiles/fucked_up.rb +77 -0
- data/vendor/pygments-main/tests/examplefiles/function.mu +1 -0
- data/vendor/pygments-main/tests/examplefiles/functional.rst +1472 -0
- data/vendor/pygments-main/tests/examplefiles/genclass.clj +510 -0
- data/vendor/pygments-main/tests/examplefiles/genshi_example.xml+genshi +193 -0
- data/vendor/pygments-main/tests/examplefiles/genshitext_example.genshitext +33 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.frag +7 -0
- data/vendor/pygments-main/tests/examplefiles/glsl.vert +13 -0
- data/vendor/pygments-main/tests/examplefiles/html+php_faulty.php +1 -0
- data/vendor/pygments-main/tests/examplefiles/http_request_example +14 -0
- data/vendor/pygments-main/tests/examplefiles/http_response_example +27 -0
- data/vendor/pygments-main/tests/examplefiles/import.hs +4 -0
- data/vendor/pygments-main/tests/examplefiles/intro.ik +24 -0
- data/vendor/pygments-main/tests/examplefiles/ints.php +10 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.fun +675 -0
- data/vendor/pygments-main/tests/examplefiles/intsyn.sig +286 -0
- data/vendor/pygments-main/tests/examplefiles/irb_heredoc +8 -0
- data/vendor/pygments-main/tests/examplefiles/irc.lsp +214 -0
- data/vendor/pygments-main/tests/examplefiles/java.properties +16 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example1.jbst +28 -0
- data/vendor/pygments-main/tests/examplefiles/jbst_example2.jbst +45 -0
- data/vendor/pygments-main/tests/examplefiles/jinjadesignerdoc.rst +713 -0
- data/vendor/pygments-main/tests/examplefiles/lighttpd_config.conf +13 -0
- data/vendor/pygments-main/tests/examplefiles/linecontinuation.py +47 -0
- data/vendor/pygments-main/tests/examplefiles/ltmain.sh +2849 -0
- data/vendor/pygments-main/tests/examplefiles/main.cmake +42 -0
- data/vendor/pygments-main/tests/examplefiles/markdown.lsp +679 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_noreturn +3 -0
- data/vendor/pygments-main/tests/examplefiles/matlab_sample +27 -0
- data/vendor/pygments-main/tests/examplefiles/matlabsession_sample.txt +37 -0
- data/vendor/pygments-main/tests/examplefiles/minimal.ns2 +4 -0
- data/vendor/pygments-main/tests/examplefiles/moin_SyntaxReference.txt +340 -0
- data/vendor/pygments-main/tests/examplefiles/multiline_regexes.rb +38 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_aoutso.asm +96 -0
- data/vendor/pygments-main/tests/examplefiles/nasm_objexe.asm +30 -0
- data/vendor/pygments-main/tests/examplefiles/nemerle_sample.n +87 -0
- data/vendor/pygments-main/tests/examplefiles/nginx_nginx.conf +118 -0
- data/vendor/pygments-main/tests/examplefiles/numbers.c +12 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example.m +25 -0
- data/vendor/pygments-main/tests/examplefiles/objc_example2.m +24 -0
- data/vendor/pygments-main/tests/examplefiles/perl_misc +62 -0
- data/vendor/pygments-main/tests/examplefiles/perl_perl5db +998 -0
- data/vendor/pygments-main/tests/examplefiles/perl_regex-delims +120 -0
- data/vendor/pygments-main/tests/examplefiles/perlfunc.1 +856 -0
- data/vendor/pygments-main/tests/examplefiles/phpcomplete.vim +567 -0
- data/vendor/pygments-main/tests/examplefiles/pleac.in.rb +1223 -0
- data/vendor/pygments-main/tests/examplefiles/postgresql_test.txt +47 -0
- data/vendor/pygments-main/tests/examplefiles/pppoe.applescript +10 -0
- data/vendor/pygments-main/tests/examplefiles/psql_session.txt +122 -0
- data/vendor/pygments-main/tests/examplefiles/py3_test.txt +2 -0
- data/vendor/pygments-main/tests/examplefiles/pycon_test.pycon +14 -0
- data/vendor/pygments-main/tests/examplefiles/pytb_test2.pytb +2 -0
- data/vendor/pygments-main/tests/examplefiles/python25-bsd.mak +234 -0
- data/vendor/pygments-main/tests/examplefiles/qsort.prolog +13 -0
- data/vendor/pygments-main/tests/examplefiles/r-console-transcript.Rout +38 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_rlscan +280 -0
- data/vendor/pygments-main/tests/examplefiles/ragel-cpp_snippet +2 -0
- data/vendor/pygments-main/tests/examplefiles/regex.js +22 -0
- data/vendor/pygments-main/tests/examplefiles/reversi.lsp +427 -0
- data/vendor/pygments-main/tests/examplefiles/ruby_func_def.rb +11 -0
- data/vendor/pygments-main/tests/examplefiles/scilab.sci +30 -0
- data/vendor/pygments-main/tests/examplefiles/sibling.prolog +19 -0
- data/vendor/pygments-main/tests/examplefiles/simple.md +747 -0
- data/vendor/pygments-main/tests/examplefiles/smarty_example.html +209 -0
- data/vendor/pygments-main/tests/examplefiles/source.lgt +343 -0
- data/vendor/pygments-main/tests/examplefiles/sources.list +62 -0
- data/vendor/pygments-main/tests/examplefiles/sphere.pov +18 -0
- data/vendor/pygments-main/tests/examplefiles/sqlite3.sqlite3-console +27 -0
- data/vendor/pygments-main/tests/examplefiles/squid.conf +30 -0
- data/vendor/pygments-main/tests/examplefiles/string.jl +1031 -0
- data/vendor/pygments-main/tests/examplefiles/string_delimiters.d +21 -0
- data/vendor/pygments-main/tests/examplefiles/stripheredoc.sh +3 -0
- data/vendor/pygments-main/tests/examplefiles/test.R +119 -0
- data/vendor/pygments-main/tests/examplefiles/test.adb +211 -0
- data/vendor/pygments-main/tests/examplefiles/test.asy +131 -0
- data/vendor/pygments-main/tests/examplefiles/test.awk +121 -0
- data/vendor/pygments-main/tests/examplefiles/test.bas +29 -0
- data/vendor/pygments-main/tests/examplefiles/test.bmx +145 -0
- data/vendor/pygments-main/tests/examplefiles/test.boo +39 -0
- data/vendor/pygments-main/tests/examplefiles/test.bro +250 -0
- data/vendor/pygments-main/tests/examplefiles/test.cs +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.css +54 -0
- data/vendor/pygments-main/tests/examplefiles/test.d +135 -0
- data/vendor/pygments-main/tests/examplefiles/test.dart +23 -0
- data/vendor/pygments-main/tests/examplefiles/test.dtd +89 -0
- data/vendor/pygments-main/tests/examplefiles/test.ec +605 -0
- data/vendor/pygments-main/tests/examplefiles/test.ecl +58 -0
- data/vendor/pygments-main/tests/examplefiles/test.eh +315 -0
- data/vendor/pygments-main/tests/examplefiles/test.erl +169 -0
- data/vendor/pygments-main/tests/examplefiles/test.evoque +33 -0
- data/vendor/pygments-main/tests/examplefiles/test.fan +818 -0
- data/vendor/pygments-main/tests/examplefiles/test.flx +57 -0
- data/vendor/pygments-main/tests/examplefiles/test.gdc +13 -0
- data/vendor/pygments-main/tests/examplefiles/test.groovy +97 -0
- data/vendor/pygments-main/tests/examplefiles/test.html +339 -0
- data/vendor/pygments-main/tests/examplefiles/test.ini +10 -0
- data/vendor/pygments-main/tests/examplefiles/test.java +653 -0
- data/vendor/pygments-main/tests/examplefiles/test.jsp +24 -0
- data/vendor/pygments-main/tests/examplefiles/test.maql +45 -0
- data/vendor/pygments-main/tests/examplefiles/test.mod +374 -0
- data/vendor/pygments-main/tests/examplefiles/test.moo +51 -0
- data/vendor/pygments-main/tests/examplefiles/test.myt +166 -0
- data/vendor/pygments-main/tests/examplefiles/test.nim +93 -0
- data/vendor/pygments-main/tests/examplefiles/test.pas +743 -0
- data/vendor/pygments-main/tests/examplefiles/test.php +505 -0
- data/vendor/pygments-main/tests/examplefiles/test.plot +333 -0
- data/vendor/pygments-main/tests/examplefiles/test.ps1 +108 -0
- data/vendor/pygments-main/tests/examplefiles/test.pypylog +1839 -0
- data/vendor/pygments-main/tests/examplefiles/test.r3 +94 -0
- data/vendor/pygments-main/tests/examplefiles/test.rb +177 -0
- data/vendor/pygments-main/tests/examplefiles/test.rhtml +43 -0
- data/vendor/pygments-main/tests/examplefiles/test.scaml +8 -0
- data/vendor/pygments-main/tests/examplefiles/test.ssp +12 -0
- data/vendor/pygments-main/tests/examplefiles/test.tcsh +830 -0
- data/vendor/pygments-main/tests/examplefiles/test.vb +407 -0
- data/vendor/pygments-main/tests/examplefiles/test.vhdl +161 -0
- data/vendor/pygments-main/tests/examplefiles/test.xqy +138 -0
- data/vendor/pygments-main/tests/examplefiles/test.xsl +23 -0
- data/vendor/pygments-main/tests/examplefiles/truncated.pytb +15 -0
- data/vendor/pygments-main/tests/examplefiles/type.lisp +1202 -0
- data/vendor/pygments-main/tests/examplefiles/underscore.coffee +603 -0
- data/vendor/pygments-main/tests/examplefiles/unicode.applescript +5 -0
- data/vendor/pygments-main/tests/examplefiles/unicodedoc.py +11 -0
- data/vendor/pygments-main/tests/examplefiles/webkit-transition.css +3 -0
- data/vendor/pygments-main/tests/examplefiles/while.pov +13 -0
- data/vendor/pygments-main/tests/examplefiles/wiki.factor +384 -0
- data/vendor/pygments-main/tests/examplefiles/xml_example +1897 -0
- data/vendor/pygments-main/tests/examplefiles/zmlrpc.f90 +798 -0
- data/vendor/pygments-main/tests/old_run.py +138 -0
- data/vendor/pygments-main/tests/run.py +48 -0
- data/vendor/pygments-main/tests/support.py +15 -0
- data/vendor/pygments-main/tests/test_basic_api.py +294 -0
- data/vendor/pygments-main/tests/test_clexer.py +31 -0
- data/vendor/pygments-main/tests/test_cmdline.py +105 -0
- data/vendor/pygments-main/tests/test_examplefiles.py +97 -0
- data/vendor/pygments-main/tests/test_html_formatter.py +162 -0
- data/vendor/pygments-main/tests/test_latex_formatter.py +55 -0
- data/vendor/pygments-main/tests/test_perllexer.py +137 -0
- data/vendor/pygments-main/tests/test_regexlexer.py +47 -0
- data/vendor/pygments-main/tests/test_token.py +46 -0
- data/vendor/pygments-main/tests/test_using_api.py +40 -0
- data/vendor/pygments-main/tests/test_util.py +116 -0
- data/vendor/simplejson/.gitignore +10 -0
- data/vendor/simplejson/.travis.yml +5 -0
- data/vendor/simplejson/CHANGES.txt +291 -0
- data/vendor/simplejson/LICENSE.txt +19 -0
- data/vendor/simplejson/MANIFEST.in +5 -0
- data/vendor/simplejson/README.rst +19 -0
- data/vendor/simplejson/conf.py +179 -0
- data/vendor/simplejson/index.rst +628 -0
- data/vendor/simplejson/scripts/make_docs.py +18 -0
- data/vendor/simplejson/setup.py +104 -0
- data/vendor/simplejson/simplejson/__init__.py +510 -0
- data/vendor/simplejson/simplejson/_speedups.c +2745 -0
- data/vendor/simplejson/simplejson/decoder.py +425 -0
- data/vendor/simplejson/simplejson/encoder.py +567 -0
- data/vendor/simplejson/simplejson/ordered_dict.py +119 -0
- data/vendor/simplejson/simplejson/scanner.py +77 -0
- data/vendor/simplejson/simplejson/tests/__init__.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_bigint_as_string.py +55 -0
- data/vendor/simplejson/simplejson/tests/test_check_circular.py +30 -0
- data/vendor/simplejson/simplejson/tests/test_decimal.py +66 -0
- data/vendor/simplejson/simplejson/tests/test_decode.py +83 -0
- data/vendor/simplejson/simplejson/tests/test_default.py +9 -0
- data/vendor/simplejson/simplejson/tests/test_dump.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_encode_basestring_ascii.py +46 -0
- data/vendor/simplejson/simplejson/tests/test_encode_for_html.py +32 -0
- data/vendor/simplejson/simplejson/tests/test_errors.py +34 -0
- data/vendor/simplejson/simplejson/tests/test_fail.py +91 -0
- data/vendor/simplejson/simplejson/tests/test_float.py +19 -0
- data/vendor/simplejson/simplejson/tests/test_indent.py +86 -0
- data/vendor/simplejson/simplejson/tests/test_item_sort_key.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_namedtuple.py +121 -0
- data/vendor/simplejson/simplejson/tests/test_pass1.py +76 -0
- data/vendor/simplejson/simplejson/tests/test_pass2.py +14 -0
- data/vendor/simplejson/simplejson/tests/test_pass3.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_recursion.py +67 -0
- data/vendor/simplejson/simplejson/tests/test_scanstring.py +117 -0
- data/vendor/simplejson/simplejson/tests/test_separators.py +42 -0
- data/vendor/simplejson/simplejson/tests/test_speedups.py +20 -0
- data/vendor/simplejson/simplejson/tests/test_tuple.py +49 -0
- data/vendor/simplejson/simplejson/tests/test_unicode.py +109 -0
- data/vendor/simplejson/simplejson/tool.py +39 -0
- metadata +492 -0
@@ -0,0 +1,1832 @@
|
|
1
|
+
# -*- coding: utf-8 -*-
|
2
|
+
"""
|
3
|
+
pygments.lexers.functional
|
4
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
5
|
+
|
6
|
+
Lexers for functional 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 Lexer, RegexLexer, bygroups, include, do_insertions
|
15
|
+
from pygments.token import Text, Comment, Operator, Keyword, Name, \
|
16
|
+
String, Number, Punctuation, Literal, Generic, Error
|
17
|
+
|
18
|
+
__all__ = ['SchemeLexer', 'CommonLispLexer', 'HaskellLexer',
|
19
|
+
'LiterateHaskellLexer', 'SMLLexer', 'OcamlLexer', 'ErlangLexer',
|
20
|
+
'ErlangShellLexer', 'OpaLexer', 'CoqLexer', 'NewLispLexer',
|
21
|
+
'ElixirLexer', 'ElixirConsoleLexer']
|
22
|
+
|
23
|
+
|
24
|
+
class SchemeLexer(RegexLexer):
|
25
|
+
"""
|
26
|
+
A Scheme lexer, parsing a stream and outputting the tokens
|
27
|
+
needed to highlight scheme code.
|
28
|
+
This lexer could be most probably easily subclassed to parse
|
29
|
+
other LISP-Dialects like Common Lisp, Emacs Lisp or AutoLisp.
|
30
|
+
|
31
|
+
This parser is checked with pastes from the LISP pastebin
|
32
|
+
at http://paste.lisp.org/ to cover as much syntax as possible.
|
33
|
+
|
34
|
+
It supports the full Scheme syntax as defined in R5RS.
|
35
|
+
|
36
|
+
*New in Pygments 0.6.*
|
37
|
+
"""
|
38
|
+
name = 'Scheme'
|
39
|
+
aliases = ['scheme', 'scm']
|
40
|
+
filenames = ['*.scm', '*.ss', '*.rkt']
|
41
|
+
mimetypes = ['text/x-scheme', 'application/x-scheme']
|
42
|
+
|
43
|
+
# list of known keywords and builtins taken form vim 6.4 scheme.vim
|
44
|
+
# syntax file.
|
45
|
+
keywords = [
|
46
|
+
'lambda', 'define', 'if', 'else', 'cond', 'and', 'or', 'case', 'let',
|
47
|
+
'let*', 'letrec', 'begin', 'do', 'delay', 'set!', '=>', 'quote',
|
48
|
+
'quasiquote', 'unquote', 'unquote-splicing', 'define-syntax',
|
49
|
+
'let-syntax', 'letrec-syntax', 'syntax-rules'
|
50
|
+
]
|
51
|
+
builtins = [
|
52
|
+
'*', '+', '-', '/', '<', '<=', '=', '>', '>=', 'abs', 'acos', 'angle',
|
53
|
+
'append', 'apply', 'asin', 'assoc', 'assq', 'assv', 'atan',
|
54
|
+
'boolean?', 'caaaar', 'caaadr', 'caaar', 'caadar', 'caaddr', 'caadr',
|
55
|
+
'caar', 'cadaar', 'cadadr', 'cadar', 'caddar', 'cadddr', 'caddr',
|
56
|
+
'cadr', 'call-with-current-continuation', 'call-with-input-file',
|
57
|
+
'call-with-output-file', 'call-with-values', 'call/cc', 'car',
|
58
|
+
'cdaaar', 'cdaadr', 'cdaar', 'cdadar', 'cdaddr', 'cdadr', 'cdar',
|
59
|
+
'cddaar', 'cddadr', 'cddar', 'cdddar', 'cddddr', 'cdddr', 'cddr',
|
60
|
+
'cdr', 'ceiling', 'char->integer', 'char-alphabetic?', 'char-ci<=?',
|
61
|
+
'char-ci<?', 'char-ci=?', 'char-ci>=?', 'char-ci>?', 'char-downcase',
|
62
|
+
'char-lower-case?', 'char-numeric?', 'char-ready?', 'char-upcase',
|
63
|
+
'char-upper-case?', 'char-whitespace?', 'char<=?', 'char<?', 'char=?',
|
64
|
+
'char>=?', 'char>?', 'char?', 'close-input-port', 'close-output-port',
|
65
|
+
'complex?', 'cons', 'cos', 'current-input-port', 'current-output-port',
|
66
|
+
'denominator', 'display', 'dynamic-wind', 'eof-object?', 'eq?',
|
67
|
+
'equal?', 'eqv?', 'eval', 'even?', 'exact->inexact', 'exact?', 'exp',
|
68
|
+
'expt', 'floor', 'for-each', 'force', 'gcd', 'imag-part',
|
69
|
+
'inexact->exact', 'inexact?', 'input-port?', 'integer->char',
|
70
|
+
'integer?', 'interaction-environment', 'lcm', 'length', 'list',
|
71
|
+
'list->string', 'list->vector', 'list-ref', 'list-tail', 'list?',
|
72
|
+
'load', 'log', 'magnitude', 'make-polar', 'make-rectangular',
|
73
|
+
'make-string', 'make-vector', 'map', 'max', 'member', 'memq', 'memv',
|
74
|
+
'min', 'modulo', 'negative?', 'newline', 'not', 'null-environment',
|
75
|
+
'null?', 'number->string', 'number?', 'numerator', 'odd?',
|
76
|
+
'open-input-file', 'open-output-file', 'output-port?', 'pair?',
|
77
|
+
'peek-char', 'port?', 'positive?', 'procedure?', 'quotient',
|
78
|
+
'rational?', 'rationalize', 'read', 'read-char', 'real-part', 'real?',
|
79
|
+
'remainder', 'reverse', 'round', 'scheme-report-environment',
|
80
|
+
'set-car!', 'set-cdr!', 'sin', 'sqrt', 'string', 'string->list',
|
81
|
+
'string->number', 'string->symbol', 'string-append', 'string-ci<=?',
|
82
|
+
'string-ci<?', 'string-ci=?', 'string-ci>=?', 'string-ci>?',
|
83
|
+
'string-copy', 'string-fill!', 'string-length', 'string-ref',
|
84
|
+
'string-set!', 'string<=?', 'string<?', 'string=?', 'string>=?',
|
85
|
+
'string>?', 'string?', 'substring', 'symbol->string', 'symbol?',
|
86
|
+
'tan', 'transcript-off', 'transcript-on', 'truncate', 'values',
|
87
|
+
'vector', 'vector->list', 'vector-fill!', 'vector-length',
|
88
|
+
'vector-ref', 'vector-set!', 'vector?', 'with-input-from-file',
|
89
|
+
'with-output-to-file', 'write', 'write-char', 'zero?'
|
90
|
+
]
|
91
|
+
|
92
|
+
# valid names for identifiers
|
93
|
+
# well, names can only not consist fully of numbers
|
94
|
+
# but this should be good enough for now
|
95
|
+
valid_name = r'[a-zA-Z0-9!$%&*+,/:<=>?@^_~|-]+'
|
96
|
+
|
97
|
+
tokens = {
|
98
|
+
'root' : [
|
99
|
+
# the comments - always starting with semicolon
|
100
|
+
# and going to the end of the line
|
101
|
+
(r';.*$', Comment.Single),
|
102
|
+
|
103
|
+
# whitespaces - usually not relevant
|
104
|
+
(r'\s+', Text),
|
105
|
+
|
106
|
+
# numbers
|
107
|
+
(r'-?\d+\.\d+', Number.Float),
|
108
|
+
(r'-?\d+', Number.Integer),
|
109
|
+
# support for uncommon kinds of numbers -
|
110
|
+
# have to figure out what the characters mean
|
111
|
+
#(r'(#e|#i|#b|#o|#d|#x)[\d.]+', Number),
|
112
|
+
|
113
|
+
# strings, symbols and characters
|
114
|
+
(r'"(\\\\|\\"|[^"])*"', String),
|
115
|
+
(r"'" + valid_name, String.Symbol),
|
116
|
+
(r"#\\([()/'\"._!§$%& ?=+-]{1}|[a-zA-Z0-9]+)", String.Char),
|
117
|
+
|
118
|
+
# constants
|
119
|
+
(r'(#t|#f)', Name.Constant),
|
120
|
+
|
121
|
+
# special operators
|
122
|
+
(r"('|#|`|,@|,|\.)", Operator),
|
123
|
+
|
124
|
+
# highlight the keywords
|
125
|
+
('(%s)' % '|'.join([
|
126
|
+
re.escape(entry) + ' ' for entry in keywords]),
|
127
|
+
Keyword
|
128
|
+
),
|
129
|
+
|
130
|
+
# first variable in a quoted string like
|
131
|
+
# '(this is syntactic sugar)
|
132
|
+
(r"(?<='\()" + valid_name, Name.Variable),
|
133
|
+
(r"(?<=#\()" + valid_name, Name.Variable),
|
134
|
+
|
135
|
+
# highlight the builtins
|
136
|
+
("(?<=\()(%s)" % '|'.join([
|
137
|
+
re.escape(entry) + ' ' for entry in builtins]),
|
138
|
+
Name.Builtin
|
139
|
+
),
|
140
|
+
|
141
|
+
# the remaining functions
|
142
|
+
(r'(?<=\()' + valid_name, Name.Function),
|
143
|
+
# find the remaining variables
|
144
|
+
(valid_name, Name.Variable),
|
145
|
+
|
146
|
+
# the famous parentheses!
|
147
|
+
(r'(\(|\))', Punctuation),
|
148
|
+
],
|
149
|
+
}
|
150
|
+
|
151
|
+
|
152
|
+
class CommonLispLexer(RegexLexer):
|
153
|
+
"""
|
154
|
+
A Common Lisp lexer.
|
155
|
+
|
156
|
+
*New in Pygments 0.9.*
|
157
|
+
"""
|
158
|
+
name = 'Common Lisp'
|
159
|
+
aliases = ['common-lisp', 'cl']
|
160
|
+
filenames = ['*.cl', '*.lisp', '*.el'] # use for Elisp too
|
161
|
+
mimetypes = ['text/x-common-lisp']
|
162
|
+
|
163
|
+
flags = re.IGNORECASE | re.MULTILINE
|
164
|
+
|
165
|
+
### couple of useful regexes
|
166
|
+
|
167
|
+
# characters that are not macro-characters and can be used to begin a symbol
|
168
|
+
nonmacro = r'\\.|[a-zA-Z0-9!$%&*+-/<=>?@\[\]^_{}~]'
|
169
|
+
constituent = nonmacro + '|[#.:]'
|
170
|
+
terminated = r'(?=[ "()\'\n,;`])' # whitespace or terminating macro characters
|
171
|
+
|
172
|
+
### symbol token, reverse-engineered from hyperspec
|
173
|
+
# Take a deep breath...
|
174
|
+
symbol = r'(\|[^|]+\||(?:%s)(?:%s)*)' % (nonmacro, constituent)
|
175
|
+
|
176
|
+
def __init__(self, **options):
|
177
|
+
from pygments.lexers._clbuiltins import BUILTIN_FUNCTIONS, \
|
178
|
+
SPECIAL_FORMS, MACROS, LAMBDA_LIST_KEYWORDS, DECLARATIONS, \
|
179
|
+
BUILTIN_TYPES, BUILTIN_CLASSES
|
180
|
+
self.builtin_function = BUILTIN_FUNCTIONS
|
181
|
+
self.special_forms = SPECIAL_FORMS
|
182
|
+
self.macros = MACROS
|
183
|
+
self.lambda_list_keywords = LAMBDA_LIST_KEYWORDS
|
184
|
+
self.declarations = DECLARATIONS
|
185
|
+
self.builtin_types = BUILTIN_TYPES
|
186
|
+
self.builtin_classes = BUILTIN_CLASSES
|
187
|
+
RegexLexer.__init__(self, **options)
|
188
|
+
|
189
|
+
def get_tokens_unprocessed(self, text):
|
190
|
+
stack = ['root']
|
191
|
+
for index, token, value in RegexLexer.get_tokens_unprocessed(self, text, stack):
|
192
|
+
if token is Name.Variable:
|
193
|
+
if value in self.builtin_function:
|
194
|
+
yield index, Name.Builtin, value
|
195
|
+
continue
|
196
|
+
if value in self.special_forms:
|
197
|
+
yield index, Keyword, value
|
198
|
+
continue
|
199
|
+
if value in self.macros:
|
200
|
+
yield index, Name.Builtin, value
|
201
|
+
continue
|
202
|
+
if value in self.lambda_list_keywords:
|
203
|
+
yield index, Keyword, value
|
204
|
+
continue
|
205
|
+
if value in self.declarations:
|
206
|
+
yield index, Keyword, value
|
207
|
+
continue
|
208
|
+
if value in self.builtin_types:
|
209
|
+
yield index, Keyword.Type, value
|
210
|
+
continue
|
211
|
+
if value in self.builtin_classes:
|
212
|
+
yield index, Name.Class, value
|
213
|
+
continue
|
214
|
+
yield index, token, value
|
215
|
+
|
216
|
+
tokens = {
|
217
|
+
'root' : [
|
218
|
+
('', Text, 'body'),
|
219
|
+
],
|
220
|
+
'multiline-comment' : [
|
221
|
+
(r'#\|', Comment.Multiline, '#push'), # (cf. Hyperspec 2.4.8.19)
|
222
|
+
(r'\|#', Comment.Multiline, '#pop'),
|
223
|
+
(r'[^|#]+', Comment.Multiline),
|
224
|
+
(r'[|#]', Comment.Multiline),
|
225
|
+
],
|
226
|
+
'commented-form' : [
|
227
|
+
(r'\(', Comment.Preproc, '#push'),
|
228
|
+
(r'\)', Comment.Preproc, '#pop'),
|
229
|
+
(r'[^()]+', Comment.Preproc),
|
230
|
+
],
|
231
|
+
'body' : [
|
232
|
+
# whitespace
|
233
|
+
(r'\s+', Text),
|
234
|
+
|
235
|
+
# single-line comment
|
236
|
+
(r';.*$', Comment.Single),
|
237
|
+
|
238
|
+
# multi-line comment
|
239
|
+
(r'#\|', Comment.Multiline, 'multiline-comment'),
|
240
|
+
|
241
|
+
# encoding comment (?)
|
242
|
+
(r'#\d*Y.*$', Comment.Special),
|
243
|
+
|
244
|
+
# strings and characters
|
245
|
+
(r'"(\\.|[^"\\])*"', String),
|
246
|
+
# quoting
|
247
|
+
(r":" + symbol, String.Symbol),
|
248
|
+
(r"'" + symbol, String.Symbol),
|
249
|
+
(r"'", Operator),
|
250
|
+
(r"`", Operator),
|
251
|
+
|
252
|
+
# decimal numbers
|
253
|
+
(r'[-+]?\d+\.?' + terminated, Number.Integer),
|
254
|
+
(r'[-+]?\d+/\d+' + terminated, Number),
|
255
|
+
(r'[-+]?(\d*\.\d+([defls][-+]?\d+)?|\d+(\.\d*)?[defls][-+]?\d+)' \
|
256
|
+
+ terminated, Number.Float),
|
257
|
+
|
258
|
+
# sharpsign strings and characters
|
259
|
+
(r"#\\." + terminated, String.Char),
|
260
|
+
(r"#\\" + symbol, String.Char),
|
261
|
+
|
262
|
+
# vector
|
263
|
+
(r'#\(', Operator, 'body'),
|
264
|
+
|
265
|
+
# bitstring
|
266
|
+
(r'#\d*\*[01]*', Literal.Other),
|
267
|
+
|
268
|
+
# uninterned symbol
|
269
|
+
(r'#:' + symbol, String.Symbol),
|
270
|
+
|
271
|
+
# read-time and load-time evaluation
|
272
|
+
(r'#[.,]', Operator),
|
273
|
+
|
274
|
+
# function shorthand
|
275
|
+
(r'#\'', Name.Function),
|
276
|
+
|
277
|
+
# binary rational
|
278
|
+
(r'#[bB][+-]?[01]+(/[01]+)?', Number),
|
279
|
+
|
280
|
+
# octal rational
|
281
|
+
(r'#[oO][+-]?[0-7]+(/[0-7]+)?', Number.Oct),
|
282
|
+
|
283
|
+
# hex rational
|
284
|
+
(r'#[xX][+-]?[0-9a-fA-F]+(/[0-9a-fA-F]+)?', Number.Hex),
|
285
|
+
|
286
|
+
# radix rational
|
287
|
+
(r'#\d+[rR][+-]?[0-9a-zA-Z]+(/[0-9a-zA-Z]+)?', Number),
|
288
|
+
|
289
|
+
# complex
|
290
|
+
(r'(#[cC])(\()', bygroups(Number, Punctuation), 'body'),
|
291
|
+
|
292
|
+
# array
|
293
|
+
(r'(#\d+[aA])(\()', bygroups(Literal.Other, Punctuation), 'body'),
|
294
|
+
|
295
|
+
# structure
|
296
|
+
(r'(#[sS])(\()', bygroups(Literal.Other, Punctuation), 'body'),
|
297
|
+
|
298
|
+
# path
|
299
|
+
(r'#[pP]?"(\\.|[^"])*"', Literal.Other),
|
300
|
+
|
301
|
+
# reference
|
302
|
+
(r'#\d+=', Operator),
|
303
|
+
(r'#\d+#', Operator),
|
304
|
+
|
305
|
+
# read-time comment
|
306
|
+
(r'#+nil' + terminated + '\s*\(', Comment.Preproc, 'commented-form'),
|
307
|
+
|
308
|
+
# read-time conditional
|
309
|
+
(r'#[+-]', Operator),
|
310
|
+
|
311
|
+
# special operators that should have been parsed already
|
312
|
+
(r'(,@|,|\.)', Operator),
|
313
|
+
|
314
|
+
# special constants
|
315
|
+
(r'(t|nil)' + terminated, Name.Constant),
|
316
|
+
|
317
|
+
# functions and variables
|
318
|
+
(r'\*' + symbol + '\*', Name.Variable.Global),
|
319
|
+
(symbol, Name.Variable),
|
320
|
+
|
321
|
+
# parentheses
|
322
|
+
(r'\(', Punctuation, 'body'),
|
323
|
+
(r'\)', Punctuation, '#pop'),
|
324
|
+
],
|
325
|
+
}
|
326
|
+
|
327
|
+
|
328
|
+
class HaskellLexer(RegexLexer):
|
329
|
+
"""
|
330
|
+
A Haskell lexer based on the lexemes defined in the Haskell 98 Report.
|
331
|
+
|
332
|
+
*New in Pygments 0.8.*
|
333
|
+
"""
|
334
|
+
name = 'Haskell'
|
335
|
+
aliases = ['haskell', 'hs']
|
336
|
+
filenames = ['*.hs']
|
337
|
+
mimetypes = ['text/x-haskell']
|
338
|
+
|
339
|
+
reserved = ['case','class','data','default','deriving','do','else',
|
340
|
+
'if','in','infix[lr]?','instance',
|
341
|
+
'let','newtype','of','then','type','where','_']
|
342
|
+
ascii = ['NUL','SOH','[SE]TX','EOT','ENQ','ACK',
|
343
|
+
'BEL','BS','HT','LF','VT','FF','CR','S[OI]','DLE',
|
344
|
+
'DC[1-4]','NAK','SYN','ETB','CAN',
|
345
|
+
'EM','SUB','ESC','[FGRU]S','SP','DEL']
|
346
|
+
|
347
|
+
tokens = {
|
348
|
+
'root': [
|
349
|
+
# Whitespace:
|
350
|
+
(r'\s+', Text),
|
351
|
+
#(r'--\s*|.*$', Comment.Doc),
|
352
|
+
(r'--(?![!#$%&*+./<=>?@\^|_~]).*?$', Comment.Single),
|
353
|
+
(r'{-', Comment.Multiline, 'comment'),
|
354
|
+
# Lexemes:
|
355
|
+
# Identifiers
|
356
|
+
(r'\bimport\b', Keyword.Reserved, 'import'),
|
357
|
+
(r'\bmodule\b', Keyword.Reserved, 'module'),
|
358
|
+
(r'\berror\b', Name.Exception),
|
359
|
+
(r'\b(%s)(?!\')\b' % '|'.join(reserved), Keyword.Reserved),
|
360
|
+
(r'^[_a-z][\w\']*', Name.Function),
|
361
|
+
(r"'?[_a-z][\w']*", Name),
|
362
|
+
(r"('')?[A-Z][\w\']*", Keyword.Type),
|
363
|
+
# Operators
|
364
|
+
(r'\\(?![:!#$%&*+.\\/<=>?@^|~-]+)', Name.Function), # lambda operator
|
365
|
+
(r'(<-|::|->|=>|=)(?![:!#$%&*+.\\/<=>?@^|~-]+)', Operator.Word), # specials
|
366
|
+
(r':[:!#$%&*+.\\/<=>?@^|~-]*', Keyword.Type), # Constructor operators
|
367
|
+
(r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator), # Other operators
|
368
|
+
# Numbers
|
369
|
+
(r'\d+[eE][+-]?\d+', Number.Float),
|
370
|
+
(r'\d+\.\d+([eE][+-]?\d+)?', Number.Float),
|
371
|
+
(r'0[oO][0-7]+', Number.Oct),
|
372
|
+
(r'0[xX][\da-fA-F]+', Number.Hex),
|
373
|
+
(r'\d+', Number.Integer),
|
374
|
+
# Character/String Literals
|
375
|
+
(r"'", String.Char, 'character'),
|
376
|
+
(r'"', String, 'string'),
|
377
|
+
# Special
|
378
|
+
(r'\[\]', Keyword.Type),
|
379
|
+
(r'\(\)', Name.Builtin),
|
380
|
+
(r'[][(),;`{}]', Punctuation),
|
381
|
+
],
|
382
|
+
'import': [
|
383
|
+
# Import statements
|
384
|
+
(r'\s+', Text),
|
385
|
+
(r'"', String, 'string'),
|
386
|
+
# after "funclist" state
|
387
|
+
(r'\)', Punctuation, '#pop'),
|
388
|
+
(r'qualified\b', Keyword),
|
389
|
+
# import X as Y
|
390
|
+
(r'([A-Z][a-zA-Z0-9_.]*)(\s+)(as)(\s+)([A-Z][a-zA-Z0-9_.]*)',
|
391
|
+
bygroups(Name.Namespace, Text, Keyword, Text, Name), '#pop'),
|
392
|
+
# import X hiding (functions)
|
393
|
+
(r'([A-Z][a-zA-Z0-9_.]*)(\s+)(hiding)(\s+)(\()',
|
394
|
+
bygroups(Name.Namespace, Text, Keyword, Text, Punctuation), 'funclist'),
|
395
|
+
# import X (functions)
|
396
|
+
(r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
|
397
|
+
bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
|
398
|
+
# import X
|
399
|
+
(r'[a-zA-Z0-9_.]+', Name.Namespace, '#pop'),
|
400
|
+
],
|
401
|
+
'module': [
|
402
|
+
(r'\s+', Text),
|
403
|
+
(r'([A-Z][a-zA-Z0-9_.]*)(\s+)(\()',
|
404
|
+
bygroups(Name.Namespace, Text, Punctuation), 'funclist'),
|
405
|
+
(r'[A-Z][a-zA-Z0-9_.]*', Name.Namespace, '#pop'),
|
406
|
+
],
|
407
|
+
'funclist': [
|
408
|
+
(r'\s+', Text),
|
409
|
+
(r'[A-Z][a-zA-Z0-9_]*', Keyword.Type),
|
410
|
+
(r'(_[\w\']+|[a-z][\w\']*)', Name.Function),
|
411
|
+
(r'--.*$', Comment.Single),
|
412
|
+
(r'{-', Comment.Multiline, 'comment'),
|
413
|
+
(r',', Punctuation),
|
414
|
+
(r'[:!#$%&*+.\\/<=>?@^|~-]+', Operator),
|
415
|
+
# (HACK, but it makes sense to push two instances, believe me)
|
416
|
+
(r'\(', Punctuation, ('funclist', 'funclist')),
|
417
|
+
(r'\)', Punctuation, '#pop:2'),
|
418
|
+
],
|
419
|
+
'comment': [
|
420
|
+
# Multiline Comments
|
421
|
+
(r'[^-{}]+', Comment.Multiline),
|
422
|
+
(r'{-', Comment.Multiline, '#push'),
|
423
|
+
(r'-}', Comment.Multiline, '#pop'),
|
424
|
+
(r'[-{}]', Comment.Multiline),
|
425
|
+
],
|
426
|
+
'character': [
|
427
|
+
# Allows multi-chars, incorrectly.
|
428
|
+
(r"[^\\']", String.Char),
|
429
|
+
(r"\\", String.Escape, 'escape'),
|
430
|
+
("'", String.Char, '#pop'),
|
431
|
+
],
|
432
|
+
'string': [
|
433
|
+
(r'[^\\"]+', String),
|
434
|
+
(r"\\", String.Escape, 'escape'),
|
435
|
+
('"', String, '#pop'),
|
436
|
+
],
|
437
|
+
'escape': [
|
438
|
+
(r'[abfnrtv"\'&\\]', String.Escape, '#pop'),
|
439
|
+
(r'\^[][A-Z@\^_]', String.Escape, '#pop'),
|
440
|
+
('|'.join(ascii), String.Escape, '#pop'),
|
441
|
+
(r'o[0-7]+', String.Escape, '#pop'),
|
442
|
+
(r'x[\da-fA-F]+', String.Escape, '#pop'),
|
443
|
+
(r'\d+', String.Escape, '#pop'),
|
444
|
+
(r'\s+\\', String.Escape, '#pop'),
|
445
|
+
],
|
446
|
+
}
|
447
|
+
|
448
|
+
|
449
|
+
line_re = re.compile('.*?\n')
|
450
|
+
bird_re = re.compile(r'(>[ \t]*)(.*\n)')
|
451
|
+
|
452
|
+
class LiterateHaskellLexer(Lexer):
|
453
|
+
"""
|
454
|
+
For Literate Haskell (Bird-style or LaTeX) source.
|
455
|
+
|
456
|
+
Additional options accepted:
|
457
|
+
|
458
|
+
`litstyle`
|
459
|
+
If given, must be ``"bird"`` or ``"latex"``. If not given, the style
|
460
|
+
is autodetected: if the first non-whitespace character in the source
|
461
|
+
is a backslash or percent character, LaTeX is assumed, else Bird.
|
462
|
+
|
463
|
+
*New in Pygments 0.9.*
|
464
|
+
"""
|
465
|
+
name = 'Literate Haskell'
|
466
|
+
aliases = ['lhs', 'literate-haskell']
|
467
|
+
filenames = ['*.lhs']
|
468
|
+
mimetypes = ['text/x-literate-haskell']
|
469
|
+
|
470
|
+
def get_tokens_unprocessed(self, text):
|
471
|
+
hslexer = HaskellLexer(**self.options)
|
472
|
+
|
473
|
+
style = self.options.get('litstyle')
|
474
|
+
if style is None:
|
475
|
+
style = (text.lstrip()[0:1] in '%\\') and 'latex' or 'bird'
|
476
|
+
|
477
|
+
code = ''
|
478
|
+
insertions = []
|
479
|
+
if style == 'bird':
|
480
|
+
# bird-style
|
481
|
+
for match in line_re.finditer(text):
|
482
|
+
line = match.group()
|
483
|
+
m = bird_re.match(line)
|
484
|
+
if m:
|
485
|
+
insertions.append((len(code),
|
486
|
+
[(0, Comment.Special, m.group(1))]))
|
487
|
+
code += m.group(2)
|
488
|
+
else:
|
489
|
+
insertions.append((len(code), [(0, Text, line)]))
|
490
|
+
else:
|
491
|
+
# latex-style
|
492
|
+
from pygments.lexers.text import TexLexer
|
493
|
+
lxlexer = TexLexer(**self.options)
|
494
|
+
|
495
|
+
codelines = 0
|
496
|
+
latex = ''
|
497
|
+
for match in line_re.finditer(text):
|
498
|
+
line = match.group()
|
499
|
+
if codelines:
|
500
|
+
if line.lstrip().startswith('\\end{code}'):
|
501
|
+
codelines = 0
|
502
|
+
latex += line
|
503
|
+
else:
|
504
|
+
code += line
|
505
|
+
elif line.lstrip().startswith('\\begin{code}'):
|
506
|
+
codelines = 1
|
507
|
+
latex += line
|
508
|
+
insertions.append((len(code),
|
509
|
+
list(lxlexer.get_tokens_unprocessed(latex))))
|
510
|
+
latex = ''
|
511
|
+
else:
|
512
|
+
latex += line
|
513
|
+
insertions.append((len(code),
|
514
|
+
list(lxlexer.get_tokens_unprocessed(latex))))
|
515
|
+
for item in do_insertions(insertions, hslexer.get_tokens_unprocessed(code)):
|
516
|
+
yield item
|
517
|
+
|
518
|
+
|
519
|
+
class SMLLexer(RegexLexer):
|
520
|
+
"""
|
521
|
+
For the Standard ML language.
|
522
|
+
|
523
|
+
*New in Pygments 1.5.*
|
524
|
+
"""
|
525
|
+
|
526
|
+
name = 'Standard ML'
|
527
|
+
aliases = ['sml']
|
528
|
+
filenames = ['*.sml', '*.sig', '*.fun',]
|
529
|
+
mimetypes = ['text/x-standardml', 'application/x-standardml']
|
530
|
+
|
531
|
+
alphanumid_reserved = [
|
532
|
+
# Core
|
533
|
+
'abstype', 'and', 'andalso', 'as', 'case', 'datatype', 'do', 'else',
|
534
|
+
'end', 'exception', 'fn', 'fun', 'handle', 'if', 'in', 'infix',
|
535
|
+
'infixr', 'let', 'local', 'nonfix', 'of', 'op', 'open', 'orelse',
|
536
|
+
'raise', 'rec', 'then', 'type', 'val', 'with', 'withtype', 'while',
|
537
|
+
# Modules
|
538
|
+
'eqtype', 'functor', 'include', 'sharing', 'sig', 'signature',
|
539
|
+
'struct', 'structure', 'where',
|
540
|
+
]
|
541
|
+
|
542
|
+
symbolicid_reserved = [
|
543
|
+
# Core
|
544
|
+
':', '\|', '=', '=>', '->', '#',
|
545
|
+
# Modules
|
546
|
+
':>',
|
547
|
+
]
|
548
|
+
|
549
|
+
nonid_reserved = [ '(', ')', '[', ']', '{', '}', ',', ';', '...', '_' ]
|
550
|
+
|
551
|
+
alphanumid_re = r"[a-zA-Z][a-zA-Z0-9_']*"
|
552
|
+
symbolicid_re = r"[!%&$#+\-/:<=>?@\\~`^|*]+"
|
553
|
+
|
554
|
+
# A character constant is a sequence of the form #s, where s is a string
|
555
|
+
# constant denoting a string of size one character. This setup just parses
|
556
|
+
# the entire string as either a String.Double or a String.Char (depending
|
557
|
+
# on the argument), even if the String.Char is an erronous
|
558
|
+
# multiple-character string.
|
559
|
+
def stringy (whatkind):
|
560
|
+
return [
|
561
|
+
(r'[^"\\]', whatkind),
|
562
|
+
(r'\\[\\\"abtnvfr]', String.Escape),
|
563
|
+
# Control-character notation is used for codes < 32,
|
564
|
+
# where \^@ == \000
|
565
|
+
(r'\\\^[\x40-\x5e]', String.Escape),
|
566
|
+
# Docs say 'decimal digits'
|
567
|
+
(r'\\[0-9]{3}', String.Escape),
|
568
|
+
(r'\\u[0-9a-fA-F]{4}', String.Escape),
|
569
|
+
(r'\\\s+\\', String.Interpol),
|
570
|
+
(r'"', whatkind, '#pop'),
|
571
|
+
]
|
572
|
+
|
573
|
+
# Callbacks for distinguishing tokens and reserved words
|
574
|
+
def long_id_callback(self, match):
|
575
|
+
if match.group(1) in self.alphanumid_reserved: token = Error
|
576
|
+
else: token = Name.Namespace
|
577
|
+
yield match.start(1), token, match.group(1)
|
578
|
+
yield match.start(2), Punctuation, match.group(2)
|
579
|
+
|
580
|
+
def end_id_callback(self, match):
|
581
|
+
if match.group(1) in self.alphanumid_reserved: token = Error
|
582
|
+
elif match.group(1) in self.symbolicid_reserved: token = Error
|
583
|
+
else: token = Name
|
584
|
+
yield match.start(1), token, match.group(1)
|
585
|
+
|
586
|
+
def id_callback(self, match):
|
587
|
+
str = match.group(1)
|
588
|
+
if str in self.alphanumid_reserved: token = Keyword.Reserved
|
589
|
+
elif str in self.symbolicid_reserved: token = Punctuation
|
590
|
+
else: token = Name
|
591
|
+
yield match.start(1), token, str
|
592
|
+
|
593
|
+
tokens = {
|
594
|
+
# Whitespace and comments are (almost) everywhere
|
595
|
+
'whitespace': [
|
596
|
+
(r'\s+', Text),
|
597
|
+
(r'\(\*', Comment.Multiline, 'comment'),
|
598
|
+
],
|
599
|
+
|
600
|
+
'delimiters': [
|
601
|
+
# This lexer treats these delimiters specially:
|
602
|
+
# Delimiters define scopes, and the scope is how the meaning of
|
603
|
+
# the `|' is resolved - is it a case/handle expression, or function
|
604
|
+
# definition by cases? (This is not how the Definition works, but
|
605
|
+
# it's how MLton behaves, see http://mlton.org/SMLNJDeviations)
|
606
|
+
(r'\(|\[|{', Punctuation, 'main'),
|
607
|
+
(r'\)|\]|}', Punctuation, '#pop'),
|
608
|
+
(r'\b(let|if|local)\b(?!\')', Keyword.Reserved, ('main', 'main')),
|
609
|
+
(r'\b(struct|sig|while)\b(?!\')', Keyword.Reserved, 'main'),
|
610
|
+
(r'\b(do|else|end|in|then)\b(?!\')', Keyword.Reserved, '#pop'),
|
611
|
+
],
|
612
|
+
|
613
|
+
'core': [
|
614
|
+
# Punctuation that doesn't overlap symbolic identifiers
|
615
|
+
(r'(%s)' % '|'.join([re.escape(z) for z in nonid_reserved]),
|
616
|
+
Punctuation),
|
617
|
+
|
618
|
+
# Special constants: strings, floats, numbers in decimal and hex
|
619
|
+
(r'#"', String.Char, 'char'),
|
620
|
+
(r'"', String.Double, 'string'),
|
621
|
+
(r'~?0x[0-9a-fA-F]+', Number.Hex),
|
622
|
+
(r'0wx[0-9a-fA-F]+', Number.Hex),
|
623
|
+
(r'0w\d+', Number.Integer),
|
624
|
+
(r'~?\d+\.\d+[eE]~?\d+', Number.Float),
|
625
|
+
(r'~?\d+\.\d+', Number.Float),
|
626
|
+
(r'~?\d+[eE]~?\d+', Number.Float),
|
627
|
+
(r'~?\d+', Number.Integer),
|
628
|
+
|
629
|
+
# Labels
|
630
|
+
(r'#\s*[1-9][0-9]*', Name.Label),
|
631
|
+
(r'#\s*(%s)' % alphanumid_re, Name.Label),
|
632
|
+
(r'#\s+(%s)' % symbolicid_re, Name.Label),
|
633
|
+
# Some reserved words trigger a special, local lexer state change
|
634
|
+
(r'\b(datatype|abstype)\b(?!\')', Keyword.Reserved, 'dname'),
|
635
|
+
(r'(?=\b(exception)\b(?!\'))', Text, ('ename')),
|
636
|
+
(r'\b(functor|include|open|signature|structure)\b(?!\')',
|
637
|
+
Keyword.Reserved, 'sname'),
|
638
|
+
(r'\b(type|eqtype)\b(?!\')', Keyword.Reserved, 'tname'),
|
639
|
+
|
640
|
+
# Regular identifiers, long and otherwise
|
641
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
642
|
+
(r'(%s)(\.)' % alphanumid_re, long_id_callback, "dotted"),
|
643
|
+
(r'(%s)' % alphanumid_re, id_callback),
|
644
|
+
(r'(%s)' % symbolicid_re, id_callback),
|
645
|
+
],
|
646
|
+
'dotted': [
|
647
|
+
(r'(%s)(\.)' % alphanumid_re, long_id_callback),
|
648
|
+
(r'(%s)' % alphanumid_re, end_id_callback, "#pop"),
|
649
|
+
(r'(%s)' % symbolicid_re, end_id_callback, "#pop"),
|
650
|
+
(r'\s+', Error),
|
651
|
+
(r'\S+', Error),
|
652
|
+
],
|
653
|
+
|
654
|
+
|
655
|
+
# Main parser (prevents errors in files that have scoping errors)
|
656
|
+
'root': [ (r'', Text, 'main') ],
|
657
|
+
|
658
|
+
# In this scope, I expect '|' to not be followed by a function name,
|
659
|
+
# and I expect 'and' to be followed by a binding site
|
660
|
+
'main': [
|
661
|
+
include('whitespace'),
|
662
|
+
|
663
|
+
# Special behavior of val/and/fun
|
664
|
+
(r'\b(val|and)\b(?!\')', Keyword.Reserved, 'vname'),
|
665
|
+
(r'\b(fun)\b(?!\')', Keyword.Reserved,
|
666
|
+
('#pop', 'main-fun', 'fname')),
|
667
|
+
|
668
|
+
include('delimiters'),
|
669
|
+
include('core'),
|
670
|
+
(r'\S+', Error),
|
671
|
+
],
|
672
|
+
|
673
|
+
# In this scope, I expect '|' and 'and' to be followed by a function
|
674
|
+
'main-fun': [
|
675
|
+
include('whitespace'),
|
676
|
+
|
677
|
+
(r'\s', Text),
|
678
|
+
(r'\(\*', Comment.Multiline, 'comment'),
|
679
|
+
|
680
|
+
# Special behavior of val/and/fun
|
681
|
+
(r'\b(fun|and)\b(?!\')', Keyword.Reserved, 'fname'),
|
682
|
+
(r'\b(val)\b(?!\')', Keyword.Reserved,
|
683
|
+
('#pop', 'main', 'vname')),
|
684
|
+
|
685
|
+
# Special behavior of '|' and '|'-manipulating keywords
|
686
|
+
(r'\|', Punctuation, 'fname'),
|
687
|
+
(r'\b(case|handle)\b(?!\')', Keyword.Reserved,
|
688
|
+
('#pop', 'main')),
|
689
|
+
|
690
|
+
include('delimiters'),
|
691
|
+
include('core'),
|
692
|
+
(r'\S+', Error),
|
693
|
+
],
|
694
|
+
|
695
|
+
# Character and string parsers
|
696
|
+
'char': stringy(String.Char),
|
697
|
+
'string': stringy(String.Double),
|
698
|
+
|
699
|
+
'breakout': [
|
700
|
+
(r'(?=\b(%s)\b(?!\'))' % '|'.join(alphanumid_reserved), Text, '#pop'),
|
701
|
+
],
|
702
|
+
|
703
|
+
# Dealing with what comes after module system keywords
|
704
|
+
'sname': [
|
705
|
+
include('whitespace'),
|
706
|
+
include('breakout'),
|
707
|
+
|
708
|
+
(r'(%s)' % alphanumid_re, Name.Namespace),
|
709
|
+
(r'', Text, '#pop'),
|
710
|
+
],
|
711
|
+
|
712
|
+
# Dealing with what comes after the 'fun' (or 'and' or '|') keyword
|
713
|
+
'fname': [
|
714
|
+
include('whitespace'),
|
715
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
716
|
+
(r'\(', Punctuation, 'tyvarseq'),
|
717
|
+
|
718
|
+
(r'(%s)' % alphanumid_re, Name.Function, '#pop'),
|
719
|
+
(r'(%s)' % symbolicid_re, Name.Function, '#pop'),
|
720
|
+
|
721
|
+
# Ignore interesting function declarations like "fun (x + y) = ..."
|
722
|
+
(r'', Text, '#pop'),
|
723
|
+
],
|
724
|
+
|
725
|
+
# Dealing with what comes after the 'val' (or 'and') keyword
|
726
|
+
'vname': [
|
727
|
+
include('whitespace'),
|
728
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
729
|
+
(r'\(', Punctuation, 'tyvarseq'),
|
730
|
+
|
731
|
+
(r'(%s)(\s*)(=(?!%s))' % (alphanumid_re, symbolicid_re),
|
732
|
+
bygroups(Name.Variable, Text, Punctuation), '#pop'),
|
733
|
+
(r'(%s)(\s*)(=(?!%s))' % (symbolicid_re, symbolicid_re),
|
734
|
+
bygroups(Name.Variable, Text, Punctuation), '#pop'),
|
735
|
+
(r'(%s)' % alphanumid_re, Name.Variable, '#pop'),
|
736
|
+
(r'(%s)' % symbolicid_re, Name.Variable, '#pop'),
|
737
|
+
|
738
|
+
# Ignore interesting patterns like 'val (x, y)'
|
739
|
+
(r'', Text, '#pop'),
|
740
|
+
],
|
741
|
+
|
742
|
+
# Dealing with what comes after the 'type' (or 'and') keyword
|
743
|
+
'tname': [
|
744
|
+
include('whitespace'),
|
745
|
+
include('breakout'),
|
746
|
+
|
747
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
748
|
+
(r'\(', Punctuation, 'tyvarseq'),
|
749
|
+
(r'=(?!%s)' % symbolicid_re, Punctuation, ('#pop', 'typbind')),
|
750
|
+
|
751
|
+
(r'(%s)' % alphanumid_re, Keyword.Type),
|
752
|
+
(r'(%s)' % symbolicid_re, Keyword.Type),
|
753
|
+
(r'\S+', Error, '#pop'),
|
754
|
+
],
|
755
|
+
|
756
|
+
# A type binding includes most identifiers
|
757
|
+
'typbind': [
|
758
|
+
include('whitespace'),
|
759
|
+
|
760
|
+
(r'\b(and)\b(?!\')', Keyword.Reserved, ('#pop', 'tname')),
|
761
|
+
|
762
|
+
include('breakout'),
|
763
|
+
include('core'),
|
764
|
+
(r'\S+', Error, '#pop'),
|
765
|
+
],
|
766
|
+
|
767
|
+
# Dealing with what comes after the 'datatype' (or 'and') keyword
|
768
|
+
'dname': [
|
769
|
+
include('whitespace'),
|
770
|
+
include('breakout'),
|
771
|
+
|
772
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
773
|
+
(r'\(', Punctuation, 'tyvarseq'),
|
774
|
+
(r'(=)(\s*)(datatype)',
|
775
|
+
bygroups(Punctuation, Text, Keyword.Reserved), '#pop'),
|
776
|
+
(r'=(?!%s)' % symbolicid_re, Punctuation,
|
777
|
+
('#pop', 'datbind', 'datcon')),
|
778
|
+
|
779
|
+
(r'(%s)' % alphanumid_re, Keyword.Type),
|
780
|
+
(r'(%s)' % symbolicid_re, Keyword.Type),
|
781
|
+
(r'\S+', Error, '#pop'),
|
782
|
+
],
|
783
|
+
|
784
|
+
# common case - A | B | C of int
|
785
|
+
'datbind': [
|
786
|
+
include('whitespace'),
|
787
|
+
|
788
|
+
(r'\b(and)\b(?!\')', Keyword.Reserved, ('#pop', 'dname')),
|
789
|
+
(r'\b(withtype)\b(?!\')', Keyword.Reserved, ('#pop', 'tname')),
|
790
|
+
(r'\b(of)\b(?!\')', Keyword.Reserved),
|
791
|
+
|
792
|
+
(r'(\|)(\s*)(%s)' % alphanumid_re,
|
793
|
+
bygroups(Punctuation, Text, Name.Class)),
|
794
|
+
(r'(\|)(\s+)(%s)' % symbolicid_re,
|
795
|
+
bygroups(Punctuation, Text, Name.Class)),
|
796
|
+
|
797
|
+
include('breakout'),
|
798
|
+
include('core'),
|
799
|
+
(r'\S+', Error),
|
800
|
+
],
|
801
|
+
|
802
|
+
# Dealing with what comes after an exception
|
803
|
+
'ename': [
|
804
|
+
include('whitespace'),
|
805
|
+
|
806
|
+
(r'(exception|and)\b(\s+)(%s)' % alphanumid_re,
|
807
|
+
bygroups(Keyword.Reserved, Text, Name.Class)),
|
808
|
+
(r'(exception|and)\b(\s*)(%s)' % symbolicid_re,
|
809
|
+
bygroups(Keyword.Reserved, Text, Name.Class)),
|
810
|
+
(r'\b(of)\b(?!\')', Keyword.Reserved),
|
811
|
+
|
812
|
+
include('breakout'),
|
813
|
+
include('core'),
|
814
|
+
(r'\S+', Error),
|
815
|
+
],
|
816
|
+
|
817
|
+
'datcon': [
|
818
|
+
include('whitespace'),
|
819
|
+
(r'(%s)' % alphanumid_re, Name.Class, '#pop'),
|
820
|
+
(r'(%s)' % symbolicid_re, Name.Class, '#pop'),
|
821
|
+
(r'\S+', Error, '#pop'),
|
822
|
+
],
|
823
|
+
|
824
|
+
# Series of type variables
|
825
|
+
'tyvarseq': [
|
826
|
+
(r'\s', Text),
|
827
|
+
(r'\(\*', Comment.Multiline, 'comment'),
|
828
|
+
|
829
|
+
(r'\'[0-9a-zA-Z_\']*', Name.Decorator),
|
830
|
+
(alphanumid_re, Name),
|
831
|
+
(r',', Punctuation),
|
832
|
+
(r'\)', Punctuation, '#pop'),
|
833
|
+
(symbolicid_re, Name),
|
834
|
+
],
|
835
|
+
|
836
|
+
'comment': [
|
837
|
+
(r'[^(*)]', Comment.Multiline),
|
838
|
+
(r'\(\*', Comment.Multiline, '#push'),
|
839
|
+
(r'\*\)', Comment.Multiline, '#pop'),
|
840
|
+
(r'[(*)]', Comment.Multiline),
|
841
|
+
],
|
842
|
+
}
|
843
|
+
|
844
|
+
|
845
|
+
class OcamlLexer(RegexLexer):
|
846
|
+
"""
|
847
|
+
For the OCaml language.
|
848
|
+
|
849
|
+
*New in Pygments 0.7.*
|
850
|
+
"""
|
851
|
+
|
852
|
+
name = 'OCaml'
|
853
|
+
aliases = ['ocaml']
|
854
|
+
filenames = ['*.ml', '*.mli', '*.mll', '*.mly']
|
855
|
+
mimetypes = ['text/x-ocaml']
|
856
|
+
|
857
|
+
keywords = [
|
858
|
+
'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done',
|
859
|
+
'downto', 'else', 'end', 'exception', 'external', 'false',
|
860
|
+
'for', 'fun', 'function', 'functor', 'if', 'in', 'include',
|
861
|
+
'inherit', 'initializer', 'lazy', 'let', 'match', 'method',
|
862
|
+
'module', 'mutable', 'new', 'object', 'of', 'open', 'private',
|
863
|
+
'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
|
864
|
+
'type', 'val', 'virtual', 'when', 'while', 'with'
|
865
|
+
]
|
866
|
+
keyopts = [
|
867
|
+
'!=','#','&','&&','\(','\)','\*','\+',',','-',
|
868
|
+
'-\.','->','\.','\.\.',':','::',':=',':>',';',';;','<',
|
869
|
+
'<-','=','>','>]','>}','\?','\?\?','\[','\[<','\[>','\[\|',
|
870
|
+
']','_','`','{','{<','\|','\|]','}','~'
|
871
|
+
]
|
872
|
+
|
873
|
+
operators = r'[!$%&*+\./:<=>?@^|~-]'
|
874
|
+
word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'or']
|
875
|
+
prefix_syms = r'[!?~]'
|
876
|
+
infix_syms = r'[=<>@^|&+\*/$%-]'
|
877
|
+
primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list', 'array']
|
878
|
+
|
879
|
+
tokens = {
|
880
|
+
'escape-sequence': [
|
881
|
+
(r'\\[\\\"\'ntbr]', String.Escape),
|
882
|
+
(r'\\[0-9]{3}', String.Escape),
|
883
|
+
(r'\\x[0-9a-fA-F]{2}', String.Escape),
|
884
|
+
],
|
885
|
+
'root': [
|
886
|
+
(r'\s+', Text),
|
887
|
+
(r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
|
888
|
+
(r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)',
|
889
|
+
Name.Namespace, 'dotted'),
|
890
|
+
(r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class),
|
891
|
+
(r'\(\*(?![)])', Comment, 'comment'),
|
892
|
+
(r'\b(%s)\b' % '|'.join(keywords), Keyword),
|
893
|
+
(r'(%s)' % '|'.join(keyopts[::-1]), Operator),
|
894
|
+
(r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
|
895
|
+
(r'\b(%s)\b' % '|'.join(word_operators), Operator.Word),
|
896
|
+
(r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
|
897
|
+
|
898
|
+
(r"[^\W\d][\w']*", Name),
|
899
|
+
|
900
|
+
(r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
|
901
|
+
(r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
|
902
|
+
(r'0[oO][0-7][0-7_]*', Number.Oct),
|
903
|
+
(r'0[bB][01][01_]*', Number.Binary),
|
904
|
+
(r'\d[\d_]*', Number.Integer),
|
905
|
+
|
906
|
+
(r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
|
907
|
+
String.Char),
|
908
|
+
(r"'.'", String.Char),
|
909
|
+
(r"'", Keyword), # a stray quote is another syntax element
|
910
|
+
|
911
|
+
(r'"', String.Double, 'string'),
|
912
|
+
|
913
|
+
(r'[~?][a-z][\w\']*:', Name.Variable),
|
914
|
+
],
|
915
|
+
'comment': [
|
916
|
+
(r'[^(*)]+', Comment),
|
917
|
+
(r'\(\*', Comment, '#push'),
|
918
|
+
(r'\*\)', Comment, '#pop'),
|
919
|
+
(r'[(*)]', Comment),
|
920
|
+
],
|
921
|
+
'string': [
|
922
|
+
(r'[^\\"]+', String.Double),
|
923
|
+
include('escape-sequence'),
|
924
|
+
(r'\\\n', String.Double),
|
925
|
+
(r'"', String.Double, '#pop'),
|
926
|
+
],
|
927
|
+
'dotted': [
|
928
|
+
(r'\s+', Text),
|
929
|
+
(r'\.', Punctuation),
|
930
|
+
(r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace),
|
931
|
+
(r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'),
|
932
|
+
(r'[a-z_][A-Za-z0-9_\']*', Name, '#pop'),
|
933
|
+
],
|
934
|
+
}
|
935
|
+
|
936
|
+
|
937
|
+
class ErlangLexer(RegexLexer):
|
938
|
+
"""
|
939
|
+
For the Erlang functional programming language.
|
940
|
+
|
941
|
+
Blame Jeremy Thurgood (http://jerith.za.net/).
|
942
|
+
|
943
|
+
*New in Pygments 0.9.*
|
944
|
+
"""
|
945
|
+
|
946
|
+
name = 'Erlang'
|
947
|
+
aliases = ['erlang']
|
948
|
+
filenames = ['*.erl', '*.hrl', '*.es', '*.escript']
|
949
|
+
mimetypes = ['text/x-erlang']
|
950
|
+
|
951
|
+
keywords = [
|
952
|
+
'after', 'begin', 'case', 'catch', 'cond', 'end', 'fun', 'if',
|
953
|
+
'let', 'of', 'query', 'receive', 'try', 'when',
|
954
|
+
]
|
955
|
+
|
956
|
+
builtins = [ # See erlang(3) man page
|
957
|
+
'abs', 'append_element', 'apply', 'atom_to_list', 'binary_to_list',
|
958
|
+
'bitstring_to_list', 'binary_to_term', 'bit_size', 'bump_reductions',
|
959
|
+
'byte_size', 'cancel_timer', 'check_process_code', 'delete_module',
|
960
|
+
'demonitor', 'disconnect_node', 'display', 'element', 'erase', 'exit',
|
961
|
+
'float', 'float_to_list', 'fun_info', 'fun_to_list',
|
962
|
+
'function_exported', 'garbage_collect', 'get', 'get_keys',
|
963
|
+
'group_leader', 'hash', 'hd', 'integer_to_list', 'iolist_to_binary',
|
964
|
+
'iolist_size', 'is_atom', 'is_binary', 'is_bitstring', 'is_boolean',
|
965
|
+
'is_builtin', 'is_float', 'is_function', 'is_integer', 'is_list',
|
966
|
+
'is_number', 'is_pid', 'is_port', 'is_process_alive', 'is_record',
|
967
|
+
'is_reference', 'is_tuple', 'length', 'link', 'list_to_atom',
|
968
|
+
'list_to_binary', 'list_to_bitstring', 'list_to_existing_atom',
|
969
|
+
'list_to_float', 'list_to_integer', 'list_to_pid', 'list_to_tuple',
|
970
|
+
'load_module', 'localtime_to_universaltime', 'make_tuple', 'md5',
|
971
|
+
'md5_final', 'md5_update', 'memory', 'module_loaded', 'monitor',
|
972
|
+
'monitor_node', 'node', 'nodes', 'open_port', 'phash', 'phash2',
|
973
|
+
'pid_to_list', 'port_close', 'port_command', 'port_connect',
|
974
|
+
'port_control', 'port_call', 'port_info', 'port_to_list',
|
975
|
+
'process_display', 'process_flag', 'process_info', 'purge_module',
|
976
|
+
'put', 'read_timer', 'ref_to_list', 'register', 'resume_process',
|
977
|
+
'round', 'send', 'send_after', 'send_nosuspend', 'set_cookie',
|
978
|
+
'setelement', 'size', 'spawn', 'spawn_link', 'spawn_monitor',
|
979
|
+
'spawn_opt', 'split_binary', 'start_timer', 'statistics',
|
980
|
+
'suspend_process', 'system_flag', 'system_info', 'system_monitor',
|
981
|
+
'system_profile', 'term_to_binary', 'tl', 'trace', 'trace_delivered',
|
982
|
+
'trace_info', 'trace_pattern', 'trunc', 'tuple_size', 'tuple_to_list',
|
983
|
+
'universaltime_to_localtime', 'unlink', 'unregister', 'whereis'
|
984
|
+
]
|
985
|
+
|
986
|
+
operators = r'(\+\+?|--?|\*|/|<|>|/=|=:=|=/=|=<|>=|==?|<-|!|\?)'
|
987
|
+
word_operators = [
|
988
|
+
'and', 'andalso', 'band', 'bnot', 'bor', 'bsl', 'bsr', 'bxor',
|
989
|
+
'div', 'not', 'or', 'orelse', 'rem', 'xor'
|
990
|
+
]
|
991
|
+
|
992
|
+
atom_re = r"(?:[a-z][a-zA-Z0-9_]*|'[^\n']*[^\\]')"
|
993
|
+
|
994
|
+
variable_re = r'(?:[A-Z_][a-zA-Z0-9_]*)'
|
995
|
+
|
996
|
+
escape_re = r'(?:\\(?:[bdefnrstv\'"\\/]|[0-7][0-7]?[0-7]?|\^[a-zA-Z]))'
|
997
|
+
|
998
|
+
macro_re = r'(?:'+variable_re+r'|'+atom_re+r')'
|
999
|
+
|
1000
|
+
base_re = r'(?:[2-9]|[12][0-9]|3[0-6])'
|
1001
|
+
|
1002
|
+
tokens = {
|
1003
|
+
'root': [
|
1004
|
+
(r'\s+', Text),
|
1005
|
+
(r'%.*\n', Comment),
|
1006
|
+
('(' + '|'.join(keywords) + r')\b', Keyword),
|
1007
|
+
('(' + '|'.join(builtins) + r')\b', Name.Builtin),
|
1008
|
+
('(' + '|'.join(word_operators) + r')\b', Operator.Word),
|
1009
|
+
(r'^-', Punctuation, 'directive'),
|
1010
|
+
(operators, Operator),
|
1011
|
+
(r'"', String, 'string'),
|
1012
|
+
(r'<<', Name.Label),
|
1013
|
+
(r'>>', Name.Label),
|
1014
|
+
(r'('+atom_re+')(:)', bygroups(Name.Namespace, Punctuation)),
|
1015
|
+
(r'^('+atom_re+r')(\s*)(\()', bygroups(Name.Function, Text, Punctuation)),
|
1016
|
+
(r'[+-]?'+base_re+r'#[0-9a-zA-Z]+', Number.Integer),
|
1017
|
+
(r'[+-]?\d+', Number.Integer),
|
1018
|
+
(r'[+-]?\d+.\d+', Number.Float),
|
1019
|
+
(r'[]\[:_@\".{}()|;,]', Punctuation),
|
1020
|
+
(variable_re, Name.Variable),
|
1021
|
+
(atom_re, Name),
|
1022
|
+
(r'\?'+macro_re, Name.Constant),
|
1023
|
+
(r'\$(?:'+escape_re+r'|\\[ %]|[^\\])', String.Char),
|
1024
|
+
(r'#'+atom_re+r'(:?\.'+atom_re+r')?', Name.Label),
|
1025
|
+
],
|
1026
|
+
'string': [
|
1027
|
+
(escape_re, String.Escape),
|
1028
|
+
(r'"', String, '#pop'),
|
1029
|
+
(r'~[0-9.*]*[~#+bBcdefginpPswWxX]', String.Interpol),
|
1030
|
+
(r'[^"\\~]+', String),
|
1031
|
+
(r'~', String),
|
1032
|
+
],
|
1033
|
+
'directive': [
|
1034
|
+
(r'(define)(\s*)(\()('+macro_re+r')',
|
1035
|
+
bygroups(Name.Entity, Text, Punctuation, Name.Constant), '#pop'),
|
1036
|
+
(r'(record)(\s*)(\()('+macro_re+r')',
|
1037
|
+
bygroups(Name.Entity, Text, Punctuation, Name.Label), '#pop'),
|
1038
|
+
(atom_re, Name.Entity, '#pop'),
|
1039
|
+
],
|
1040
|
+
}
|
1041
|
+
|
1042
|
+
|
1043
|
+
class ErlangShellLexer(Lexer):
|
1044
|
+
"""
|
1045
|
+
Shell sessions in erl (for Erlang code).
|
1046
|
+
|
1047
|
+
*New in Pygments 1.1.*
|
1048
|
+
"""
|
1049
|
+
name = 'Erlang erl session'
|
1050
|
+
aliases = ['erl']
|
1051
|
+
filenames = ['*.erl-sh']
|
1052
|
+
mimetypes = ['text/x-erl-shellsession']
|
1053
|
+
|
1054
|
+
_prompt_re = re.compile(r'\d+>(?=\s|\Z)')
|
1055
|
+
|
1056
|
+
def get_tokens_unprocessed(self, text):
|
1057
|
+
erlexer = ErlangLexer(**self.options)
|
1058
|
+
|
1059
|
+
curcode = ''
|
1060
|
+
insertions = []
|
1061
|
+
for match in line_re.finditer(text):
|
1062
|
+
line = match.group()
|
1063
|
+
m = self._prompt_re.match(line)
|
1064
|
+
if m is not None:
|
1065
|
+
end = m.end()
|
1066
|
+
insertions.append((len(curcode),
|
1067
|
+
[(0, Generic.Prompt, line[:end])]))
|
1068
|
+
curcode += line[end:]
|
1069
|
+
else:
|
1070
|
+
if curcode:
|
1071
|
+
for item in do_insertions(insertions,
|
1072
|
+
erlexer.get_tokens_unprocessed(curcode)):
|
1073
|
+
yield item
|
1074
|
+
curcode = ''
|
1075
|
+
insertions = []
|
1076
|
+
if line.startswith('*'):
|
1077
|
+
yield match.start(), Generic.Traceback, line
|
1078
|
+
else:
|
1079
|
+
yield match.start(), Generic.Output, line
|
1080
|
+
if curcode:
|
1081
|
+
for item in do_insertions(insertions,
|
1082
|
+
erlexer.get_tokens_unprocessed(curcode)):
|
1083
|
+
yield item
|
1084
|
+
|
1085
|
+
|
1086
|
+
class OpaLexer(RegexLexer):
|
1087
|
+
"""
|
1088
|
+
Lexer for the Opa language (http://opalang.org).
|
1089
|
+
|
1090
|
+
*New in Pygments 1.5.*
|
1091
|
+
"""
|
1092
|
+
|
1093
|
+
name = 'Opa'
|
1094
|
+
aliases = ['opa']
|
1095
|
+
filenames = ['*.opa']
|
1096
|
+
mimetypes = ['text/x-opa']
|
1097
|
+
|
1098
|
+
# most of these aren't strictly keywords
|
1099
|
+
# but if you color only real keywords, you might just
|
1100
|
+
# as well not color anything
|
1101
|
+
keywords = [
|
1102
|
+
'and', 'as', 'begin', 'css', 'database', 'db', 'do', 'else', 'end',
|
1103
|
+
'external', 'forall', 'if', 'import', 'match', 'package', 'parser',
|
1104
|
+
'rec', 'server', 'then', 'type', 'val', 'with', 'xml_parser'
|
1105
|
+
]
|
1106
|
+
|
1107
|
+
# matches both stuff and `stuff`
|
1108
|
+
ident_re = r'(([a-zA-Z_]\w*)|(`[^`]*`))'
|
1109
|
+
|
1110
|
+
op_re = r'[.=\-<>,@~%/+?*&^!]'
|
1111
|
+
punc_re = r'[()\[\],;|]' # '{' and '}' are treated elsewhere
|
1112
|
+
# because they are also used for inserts
|
1113
|
+
|
1114
|
+
tokens = {
|
1115
|
+
# copied from the caml lexer, should be adapted
|
1116
|
+
'escape-sequence': [
|
1117
|
+
(r'\\[\\\"\'ntr}]', String.Escape),
|
1118
|
+
(r'\\[0-9]{3}', String.Escape),
|
1119
|
+
(r'\\x[0-9a-fA-F]{2}', String.Escape),
|
1120
|
+
],
|
1121
|
+
|
1122
|
+
# factorizing these rules, because they are inserted many times
|
1123
|
+
'comments': [
|
1124
|
+
(r'/\*', Comment, 'nested-comment'),
|
1125
|
+
(r'//.*?$', Comment),
|
1126
|
+
],
|
1127
|
+
'comments-and-spaces': [
|
1128
|
+
include('comments'),
|
1129
|
+
(r'\s+', Text),
|
1130
|
+
],
|
1131
|
+
|
1132
|
+
'root': [
|
1133
|
+
include('comments-and-spaces'),
|
1134
|
+
# keywords
|
1135
|
+
(r'\b(%s)\b' % '|'.join(keywords), Keyword),
|
1136
|
+
# directives
|
1137
|
+
# we could parse the actual set of directives instead of anything
|
1138
|
+
# starting with @, but this is troublesome
|
1139
|
+
# because it needs to be adjusted all the time
|
1140
|
+
# and assuming we parse only sources that compile, it is useless
|
1141
|
+
(r'@'+ident_re+r'\b', Name.Builtin.Pseudo),
|
1142
|
+
|
1143
|
+
# number literals
|
1144
|
+
(r'-?.[\d]+([eE][+\-]?\d+)', Number.Float),
|
1145
|
+
(r'-?\d+.\d*([eE][+\-]?\d+)', Number.Float),
|
1146
|
+
(r'-?\d+[eE][+\-]?\d+', Number.Float),
|
1147
|
+
(r'0[xX][\da-fA-F]+', Number.Hex),
|
1148
|
+
(r'0[oO][0-7]+', Number.Oct),
|
1149
|
+
(r'0[bB][01]+', Number.Binary),
|
1150
|
+
(r'\d+', Number.Integer),
|
1151
|
+
# color literals
|
1152
|
+
(r'#[\da-fA-F]{3,6}', Number.Integer),
|
1153
|
+
|
1154
|
+
# string literals
|
1155
|
+
(r'"', String.Double, 'string'),
|
1156
|
+
# char literal, should be checked because this is the regexp from
|
1157
|
+
# the caml lexer
|
1158
|
+
(r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2})|.)'",
|
1159
|
+
String.Char),
|
1160
|
+
|
1161
|
+
# this is meant to deal with embedded exprs in strings
|
1162
|
+
# every time we find a '}' we pop a state so that if we were
|
1163
|
+
# inside a string, we are back in the string state
|
1164
|
+
# as a consequence, we must also push a state every time we find a
|
1165
|
+
# '{' or else we will have errors when parsing {} for instance
|
1166
|
+
(r'{', Operator, '#push'),
|
1167
|
+
(r'}', Operator, '#pop'),
|
1168
|
+
|
1169
|
+
# html literals
|
1170
|
+
# this is a much more strict that the actual parser,
|
1171
|
+
# since a<b would not be parsed as html
|
1172
|
+
# but then again, the parser is way too lax, and we can't hope
|
1173
|
+
# to have something as tolerant
|
1174
|
+
(r'<(?=[a-zA-Z>])', String.Single, 'html-open-tag'),
|
1175
|
+
|
1176
|
+
# db path
|
1177
|
+
# matching the '[_]' in '/a[_]' because it is a part
|
1178
|
+
# of the syntax of the db path definition
|
1179
|
+
# unfortunately, i don't know how to match the ']' in
|
1180
|
+
# /a[1], so this is somewhat inconsistent
|
1181
|
+
(r'[@?!]?(/\w+)+(\[_\])?', Name.Variable),
|
1182
|
+
# putting the same color on <- as on db path, since
|
1183
|
+
# it can be used only to mean Db.write
|
1184
|
+
(r'<-(?!'+op_re+r')', Name.Variable),
|
1185
|
+
|
1186
|
+
# 'modules'
|
1187
|
+
# although modules are not distinguished by their names as in caml
|
1188
|
+
# the standard library seems to follow the convention that modules
|
1189
|
+
# only area capitalized
|
1190
|
+
(r'\b([A-Z]\w*)(?=\.)', Name.Namespace),
|
1191
|
+
|
1192
|
+
# operators
|
1193
|
+
# = has a special role because this is the only
|
1194
|
+
# way to syntactic distinguish binding constructions
|
1195
|
+
# unfortunately, this colors the equal in {x=2} too
|
1196
|
+
(r'=(?!'+op_re+r')', Keyword),
|
1197
|
+
(r'(%s)+' % op_re, Operator),
|
1198
|
+
(r'(%s)+' % punc_re, Operator),
|
1199
|
+
|
1200
|
+
# coercions
|
1201
|
+
(r':', Operator, 'type'),
|
1202
|
+
# type variables
|
1203
|
+
# we need this rule because we don't parse specially type
|
1204
|
+
# definitions so in "type t('a) = ...", "'a" is parsed by 'root'
|
1205
|
+
("'"+ident_re, Keyword.Type),
|
1206
|
+
|
1207
|
+
# id literal, #something, or #{expr}
|
1208
|
+
(r'#'+ident_re, String.Single),
|
1209
|
+
(r'#(?={)', String.Single),
|
1210
|
+
|
1211
|
+
# identifiers
|
1212
|
+
# this avoids to color '2' in 'a2' as an integer
|
1213
|
+
(ident_re, Text),
|
1214
|
+
|
1215
|
+
# default, not sure if that is needed or not
|
1216
|
+
# (r'.', Text),
|
1217
|
+
],
|
1218
|
+
|
1219
|
+
# it is quite painful to have to parse types to know where they end
|
1220
|
+
# this is the general rule for a type
|
1221
|
+
# a type is either:
|
1222
|
+
# * -> ty
|
1223
|
+
# * type-with-slash
|
1224
|
+
# * type-with-slash -> ty
|
1225
|
+
# * type-with-slash (, type-with-slash)+ -> ty
|
1226
|
+
#
|
1227
|
+
# the code is pretty funky in here, but this code would roughly
|
1228
|
+
# translate in caml to:
|
1229
|
+
# let rec type stream =
|
1230
|
+
# match stream with
|
1231
|
+
# | [< "->"; stream >] -> type stream
|
1232
|
+
# | [< ""; stream >] ->
|
1233
|
+
# type_with_slash stream
|
1234
|
+
# type_lhs_1 stream;
|
1235
|
+
# and type_1 stream = ...
|
1236
|
+
'type': [
|
1237
|
+
include('comments-and-spaces'),
|
1238
|
+
(r'->', Keyword.Type),
|
1239
|
+
(r'', Keyword.Type, ('#pop', 'type-lhs-1', 'type-with-slash')),
|
1240
|
+
],
|
1241
|
+
|
1242
|
+
# parses all the atomic or closed constructions in the syntax of type
|
1243
|
+
# expressions: record types, tuple types, type constructors, basic type
|
1244
|
+
# and type variables
|
1245
|
+
'type-1': [
|
1246
|
+
include('comments-and-spaces'),
|
1247
|
+
(r'\(', Keyword.Type, ('#pop', 'type-tuple')),
|
1248
|
+
(r'~?{', Keyword.Type, ('#pop', 'type-record')),
|
1249
|
+
(ident_re+r'\(', Keyword.Type, ('#pop', 'type-tuple')),
|
1250
|
+
(ident_re, Keyword.Type, '#pop'),
|
1251
|
+
("'"+ident_re, Keyword.Type),
|
1252
|
+
# this case is not in the syntax but sometimes
|
1253
|
+
# we think we are parsing types when in fact we are parsing
|
1254
|
+
# some css, so we just pop the states until we get back into
|
1255
|
+
# the root state
|
1256
|
+
(r'', Keyword.Type, '#pop'),
|
1257
|
+
],
|
1258
|
+
|
1259
|
+
# type-with-slash is either:
|
1260
|
+
# * type-1
|
1261
|
+
# * type-1 (/ type-1)+
|
1262
|
+
'type-with-slash': [
|
1263
|
+
include('comments-and-spaces'),
|
1264
|
+
(r'', Keyword.Type, ('#pop', 'slash-type-1', 'type-1')),
|
1265
|
+
],
|
1266
|
+
'slash-type-1': [
|
1267
|
+
include('comments-and-spaces'),
|
1268
|
+
('/', Keyword.Type, ('#pop', 'type-1')),
|
1269
|
+
# same remark as above
|
1270
|
+
(r'', Keyword.Type, '#pop'),
|
1271
|
+
],
|
1272
|
+
|
1273
|
+
# we go in this state after having parsed a type-with-slash
|
1274
|
+
# while trying to parse a type
|
1275
|
+
# and at this point we must determine if we are parsing an arrow
|
1276
|
+
# type (in which case we must continue parsing) or not (in which
|
1277
|
+
# case we stop)
|
1278
|
+
'type-lhs-1': [
|
1279
|
+
include('comments-and-spaces'),
|
1280
|
+
(r'->', Keyword.Type, ('#pop', 'type')),
|
1281
|
+
(r'(?=,)', Keyword.Type, ('#pop', 'type-arrow')),
|
1282
|
+
(r'', Keyword.Type, '#pop'),
|
1283
|
+
],
|
1284
|
+
'type-arrow': [
|
1285
|
+
include('comments-and-spaces'),
|
1286
|
+
# the look ahead here allows to parse f(x : int, y : float -> truc)
|
1287
|
+
# correctly
|
1288
|
+
(r',(?=[^:]*?->)', Keyword.Type, 'type-with-slash'),
|
1289
|
+
(r'->', Keyword.Type, ('#pop', 'type')),
|
1290
|
+
# same remark as above
|
1291
|
+
(r'', Keyword.Type, '#pop'),
|
1292
|
+
],
|
1293
|
+
|
1294
|
+
# no need to do precise parsing for tuples and records
|
1295
|
+
# because they are closed constructions, so we can simply
|
1296
|
+
# find the closing delimiter
|
1297
|
+
# note that this function would be not work if the source
|
1298
|
+
# contained identifiers like `{)` (although it could be patched
|
1299
|
+
# to support it)
|
1300
|
+
'type-tuple': [
|
1301
|
+
include('comments-and-spaces'),
|
1302
|
+
(r'[^\(\)/*]+', Keyword.Type),
|
1303
|
+
(r'[/*]', Keyword.Type),
|
1304
|
+
(r'\(', Keyword.Type, '#push'),
|
1305
|
+
(r'\)', Keyword.Type, '#pop'),
|
1306
|
+
],
|
1307
|
+
'type-record': [
|
1308
|
+
include('comments-and-spaces'),
|
1309
|
+
(r'[^{}/*]+', Keyword.Type),
|
1310
|
+
(r'[/*]', Keyword.Type),
|
1311
|
+
(r'{', Keyword.Type, '#push'),
|
1312
|
+
(r'}', Keyword.Type, '#pop'),
|
1313
|
+
],
|
1314
|
+
|
1315
|
+
# 'type-tuple': [
|
1316
|
+
# include('comments-and-spaces'),
|
1317
|
+
# (r'\)', Keyword.Type, '#pop'),
|
1318
|
+
# (r'', Keyword.Type, ('#pop', 'type-tuple-1', 'type-1')),
|
1319
|
+
# ],
|
1320
|
+
# 'type-tuple-1': [
|
1321
|
+
# include('comments-and-spaces'),
|
1322
|
+
# (r',?\s*\)', Keyword.Type, '#pop'), # ,) is a valid end of tuple, in (1,)
|
1323
|
+
# (r',', Keyword.Type, 'type-1'),
|
1324
|
+
# ],
|
1325
|
+
# 'type-record':[
|
1326
|
+
# include('comments-and-spaces'),
|
1327
|
+
# (r'}', Keyword.Type, '#pop'),
|
1328
|
+
# (r'~?(?:\w+|`[^`]*`)', Keyword.Type, 'type-record-field-expr'),
|
1329
|
+
# ],
|
1330
|
+
# 'type-record-field-expr': [
|
1331
|
+
#
|
1332
|
+
# ],
|
1333
|
+
|
1334
|
+
'nested-comment': [
|
1335
|
+
(r'[^/*]+', Comment),
|
1336
|
+
(r'/\*', Comment, '#push'),
|
1337
|
+
(r'\*/', Comment, '#pop'),
|
1338
|
+
(r'[/*]', Comment),
|
1339
|
+
],
|
1340
|
+
|
1341
|
+
# the coy pasting between string and single-string
|
1342
|
+
# is kinda sad. Is there a way to avoid that??
|
1343
|
+
'string': [
|
1344
|
+
(r'[^\\"{]+', String.Double),
|
1345
|
+
(r'"', String.Double, '#pop'),
|
1346
|
+
(r'{', Operator, 'root'),
|
1347
|
+
include('escape-sequence'),
|
1348
|
+
],
|
1349
|
+
'single-string': [
|
1350
|
+
(r'[^\\\'{]+', String.Double),
|
1351
|
+
(r'\'', String.Double, '#pop'),
|
1352
|
+
(r'{', Operator, 'root'),
|
1353
|
+
include('escape-sequence'),
|
1354
|
+
],
|
1355
|
+
|
1356
|
+
# all the html stuff
|
1357
|
+
# can't really reuse some existing html parser
|
1358
|
+
# because we must be able to parse embedded expressions
|
1359
|
+
|
1360
|
+
# we are in this state after someone parsed the '<' that
|
1361
|
+
# started the html literal
|
1362
|
+
'html-open-tag': [
|
1363
|
+
(r'[\w\-:]+', String.Single, ('#pop', 'html-attr')),
|
1364
|
+
(r'>', String.Single, ('#pop', 'html-content')),
|
1365
|
+
],
|
1366
|
+
|
1367
|
+
# we are in this state after someone parsed the '</' that
|
1368
|
+
# started the end of the closing tag
|
1369
|
+
'html-end-tag': [
|
1370
|
+
# this is a star, because </> is allowed
|
1371
|
+
(r'[\w\-:]*>', String.Single, '#pop'),
|
1372
|
+
],
|
1373
|
+
|
1374
|
+
# we are in this state after having parsed '<ident(:ident)?'
|
1375
|
+
# we thus parse a possibly empty list of attributes
|
1376
|
+
'html-attr': [
|
1377
|
+
(r'\s+', Text),
|
1378
|
+
(r'[\w\-:]+=', String.Single, 'html-attr-value'),
|
1379
|
+
(r'/>', String.Single, '#pop'),
|
1380
|
+
(r'>', String.Single, ('#pop', 'html-content')),
|
1381
|
+
],
|
1382
|
+
|
1383
|
+
'html-attr-value': [
|
1384
|
+
(r"'", String.Single, ('#pop', 'single-string')),
|
1385
|
+
(r'"', String.Single, ('#pop', 'string')),
|
1386
|
+
(r'#'+ident_re, String.Single, '#pop'),
|
1387
|
+
(r'#(?={)', String.Single, ('#pop', 'root')),
|
1388
|
+
(r'{', Operator, ('#pop', 'root')), # this is a tail call!
|
1389
|
+
],
|
1390
|
+
|
1391
|
+
# we should probably deal with '\' escapes here
|
1392
|
+
'html-content': [
|
1393
|
+
(r'<!--', Comment, 'html-comment'),
|
1394
|
+
(r'</', String.Single, ('#pop', 'html-end-tag')),
|
1395
|
+
(r'<', String.Single, 'html-open-tag'),
|
1396
|
+
(r'{', Operator, 'root'),
|
1397
|
+
(r'.|\s+', String.Single),
|
1398
|
+
],
|
1399
|
+
|
1400
|
+
'html-comment': [
|
1401
|
+
(r'-->', Comment, '#pop'),
|
1402
|
+
(r'[^\-]+|-', Comment),
|
1403
|
+
],
|
1404
|
+
}
|
1405
|
+
|
1406
|
+
|
1407
|
+
class CoqLexer(RegexLexer):
|
1408
|
+
"""
|
1409
|
+
For the `Coq <http://coq.inria.fr/>`_ theorem prover.
|
1410
|
+
|
1411
|
+
*New in Pygments 1.5.*
|
1412
|
+
"""
|
1413
|
+
|
1414
|
+
name = 'Coq'
|
1415
|
+
aliases = ['coq']
|
1416
|
+
filenames = ['*.v']
|
1417
|
+
mimetypes = ['text/x-coq']
|
1418
|
+
|
1419
|
+
keywords1 = [
|
1420
|
+
# Vernacular commands
|
1421
|
+
'Section', 'Module', 'End', 'Require', 'Import', 'Export', 'Variable',
|
1422
|
+
'Variables', 'Parameter', 'Parameters', 'Axiom', 'Hypothesis',
|
1423
|
+
'Hypotheses', 'Notation', 'Local', 'Tactic', 'Reserved', 'Scope',
|
1424
|
+
'Open', 'Close', 'Bind', 'Delimit', 'Definition', 'Let', 'Ltac',
|
1425
|
+
'Fixpoint', 'CoFixpoint', 'Morphism', 'Relation', 'Implicit',
|
1426
|
+
'Arguments', 'Set', 'Unset', 'Contextual', 'Strict', 'Prenex',
|
1427
|
+
'Implicits', 'Inductive', 'CoInductive', 'Record', 'Structure',
|
1428
|
+
'Canonical', 'Coercion', 'Theorem', 'Lemma', 'Corollary',
|
1429
|
+
'Proposition', 'Fact', 'Remark', 'Example', 'Proof', 'Goal', 'Save',
|
1430
|
+
'Qed', 'Defined', 'Hint', 'Resolve', 'Rewrite', 'View', 'Search',
|
1431
|
+
'Show', 'Print', 'Printing', 'All', 'Graph', 'Projections', 'inside',
|
1432
|
+
'outside',
|
1433
|
+
]
|
1434
|
+
keywords2 = [
|
1435
|
+
# Gallina
|
1436
|
+
'forall', 'exists', 'exists2', 'fun', 'fix', 'cofix', 'struct',
|
1437
|
+
'match', 'end', 'in', 'return', 'let', 'if', 'is', 'then', 'else',
|
1438
|
+
'for', 'of', 'nosimpl', 'with', 'as',
|
1439
|
+
]
|
1440
|
+
keywords3 = [
|
1441
|
+
# Sorts
|
1442
|
+
'Type', 'Prop',
|
1443
|
+
]
|
1444
|
+
keywords4 = [
|
1445
|
+
# Tactics
|
1446
|
+
'pose', 'set', 'move', 'case', 'elim', 'apply', 'clear', 'hnf', 'intro',
|
1447
|
+
'intros', 'generalize', 'rename', 'pattern', 'after', 'destruct',
|
1448
|
+
'induction', 'using', 'refine', 'inversion', 'injection', 'rewrite',
|
1449
|
+
'congr', 'unlock', 'compute', 'ring', 'field', 'replace', 'fold',
|
1450
|
+
'unfold', 'change', 'cutrewrite', 'simpl', 'have', 'suff', 'wlog',
|
1451
|
+
'suffices', 'without', 'loss', 'nat_norm', 'assert', 'cut', 'trivial',
|
1452
|
+
'revert', 'bool_congr', 'nat_congr', 'symmetry', 'transitivity', 'auto',
|
1453
|
+
'split', 'left', 'right', 'autorewrite',
|
1454
|
+
]
|
1455
|
+
keywords5 = [
|
1456
|
+
# Terminators
|
1457
|
+
'by', 'done', 'exact', 'reflexivity', 'tauto', 'romega', 'omega',
|
1458
|
+
'assumption', 'solve', 'contradiction', 'discriminate',
|
1459
|
+
]
|
1460
|
+
keywords6 = [
|
1461
|
+
# Control
|
1462
|
+
'do', 'last', 'first', 'try', 'idtac', 'repeat',
|
1463
|
+
]
|
1464
|
+
# 'as', 'assert', 'begin', 'class', 'constraint', 'do', 'done',
|
1465
|
+
# 'downto', 'else', 'end', 'exception', 'external', 'false',
|
1466
|
+
# 'for', 'fun', 'function', 'functor', 'if', 'in', 'include',
|
1467
|
+
# 'inherit', 'initializer', 'lazy', 'let', 'match', 'method',
|
1468
|
+
# 'module', 'mutable', 'new', 'object', 'of', 'open', 'private',
|
1469
|
+
# 'raise', 'rec', 'sig', 'struct', 'then', 'to', 'true', 'try',
|
1470
|
+
# 'type', 'val', 'virtual', 'when', 'while', 'with'
|
1471
|
+
keyopts = [
|
1472
|
+
'!=', '#', '&', '&&', r'\(', r'\)', r'\*', r'\+', ',', '-',
|
1473
|
+
r'-\.', '->', r'\.', r'\.\.', ':', '::', ':=', ':>', ';', ';;', '<',
|
1474
|
+
'<-', '=', '>', '>]', '>}', r'\?', r'\?\?', r'\[', r'\[<', r'\[>',
|
1475
|
+
r'\[\|', ']', '_', '`', '{', '{<', r'\|', r'\|]', '}', '~', '=>',
|
1476
|
+
r'/\\', r'\\/',
|
1477
|
+
u'Π', u'λ',
|
1478
|
+
]
|
1479
|
+
operators = r'[!$%&*+\./:<=>?@^|~-]'
|
1480
|
+
word_operators = ['and', 'asr', 'land', 'lor', 'lsl', 'lxor', 'mod', 'or']
|
1481
|
+
prefix_syms = r'[!?~]'
|
1482
|
+
infix_syms = r'[=<>@^|&+\*/$%-]'
|
1483
|
+
primitives = ['unit', 'int', 'float', 'bool', 'string', 'char', 'list',
|
1484
|
+
'array']
|
1485
|
+
|
1486
|
+
tokens = {
|
1487
|
+
'root': [
|
1488
|
+
(r'\s+', Text),
|
1489
|
+
(r'false|true|\(\)|\[\]', Name.Builtin.Pseudo),
|
1490
|
+
(r'\(\*', Comment, 'comment'),
|
1491
|
+
(r'\b(%s)\b' % '|'.join(keywords1), Keyword.Namespace),
|
1492
|
+
(r'\b(%s)\b' % '|'.join(keywords2), Keyword),
|
1493
|
+
(r'\b(%s)\b' % '|'.join(keywords3), Keyword.Type),
|
1494
|
+
(r'\b(%s)\b' % '|'.join(keywords4), Keyword),
|
1495
|
+
(r'\b(%s)\b' % '|'.join(keywords5), Keyword.Pseudo),
|
1496
|
+
(r'\b(%s)\b' % '|'.join(keywords6), Keyword.Reserved),
|
1497
|
+
(r'\b([A-Z][A-Za-z0-9_\']*)(?=\s*\.)',
|
1498
|
+
Name.Namespace, 'dotted'),
|
1499
|
+
(r'\b([A-Z][A-Za-z0-9_\']*)', Name.Class),
|
1500
|
+
(r'(%s)' % '|'.join(keyopts[::-1]), Operator),
|
1501
|
+
(r'(%s|%s)?%s' % (infix_syms, prefix_syms, operators), Operator),
|
1502
|
+
(r'\b(%s)\b' % '|'.join(word_operators), Operator.Word),
|
1503
|
+
(r'\b(%s)\b' % '|'.join(primitives), Keyword.Type),
|
1504
|
+
|
1505
|
+
(r"[^\W\d][\w']*", Name),
|
1506
|
+
|
1507
|
+
(r'\d[\d_]*', Number.Integer),
|
1508
|
+
(r'0[xX][\da-fA-F][\da-fA-F_]*', Number.Hex),
|
1509
|
+
(r'0[oO][0-7][0-7_]*', Number.Oct),
|
1510
|
+
(r'0[bB][01][01_]*', Number.Binary),
|
1511
|
+
(r'-?\d[\d_]*(.[\d_]*)?([eE][+\-]?\d[\d_]*)', Number.Float),
|
1512
|
+
|
1513
|
+
(r"'(?:(\\[\\\"'ntbr ])|(\\[0-9]{3})|(\\x[0-9a-fA-F]{2}))'",
|
1514
|
+
String.Char),
|
1515
|
+
(r"'.'", String.Char),
|
1516
|
+
(r"'", Keyword), # a stray quote is another syntax element
|
1517
|
+
|
1518
|
+
(r'"', String.Double, 'string'),
|
1519
|
+
|
1520
|
+
(r'[~?][a-z][\w\']*:', Name.Variable),
|
1521
|
+
],
|
1522
|
+
'comment': [
|
1523
|
+
(r'[^(*)]+', Comment),
|
1524
|
+
(r'\(\*', Comment, '#push'),
|
1525
|
+
(r'\*\)', Comment, '#pop'),
|
1526
|
+
(r'[(*)]', Comment),
|
1527
|
+
],
|
1528
|
+
'string': [
|
1529
|
+
(r'[^"]+', String.Double),
|
1530
|
+
(r'""', String.Double),
|
1531
|
+
(r'"', String.Double, '#pop'),
|
1532
|
+
],
|
1533
|
+
'dotted': [
|
1534
|
+
(r'\s+', Text),
|
1535
|
+
(r'\.', Punctuation),
|
1536
|
+
(r'[A-Z][A-Za-z0-9_\']*(?=\s*\.)', Name.Namespace),
|
1537
|
+
(r'[A-Z][A-Za-z0-9_\']*', Name.Class, '#pop'),
|
1538
|
+
(r'[a-z][a-z0-9_\']*', Name, '#pop'),
|
1539
|
+
(r'', Text, '#pop')
|
1540
|
+
],
|
1541
|
+
}
|
1542
|
+
|
1543
|
+
def analyse_text(text):
|
1544
|
+
if text.startswith('(*'):
|
1545
|
+
return True
|
1546
|
+
|
1547
|
+
|
1548
|
+
class NewLispLexer(RegexLexer):
|
1549
|
+
"""
|
1550
|
+
For `newLISP. <www.newlisp.org>`_ source code (version 10.3.0).
|
1551
|
+
|
1552
|
+
*New in Pygments 1.5.*
|
1553
|
+
"""
|
1554
|
+
|
1555
|
+
name = 'NewLisp'
|
1556
|
+
aliases = ['newlisp']
|
1557
|
+
filenames = ['*.lsp', '*.nl']
|
1558
|
+
mimetypes = ['text/x-newlisp', 'application/x-newlisp']
|
1559
|
+
|
1560
|
+
flags = re.IGNORECASE | re.MULTILINE | re.UNICODE
|
1561
|
+
|
1562
|
+
# list of built-in functions for newLISP version 10.3
|
1563
|
+
builtins = [
|
1564
|
+
'^', '--', '-', ':', '!', '!=', '?', '@', '*', '/', '&', '%', '+', '++',
|
1565
|
+
'<', '<<', '<=', '=', '>', '>=', '>>', '|', '~', '$', '$0', '$1', '$10',
|
1566
|
+
'$11', '$12', '$13', '$14', '$15', '$2', '$3', '$4', '$5', '$6', '$7',
|
1567
|
+
'$8', '$9', '$args', '$idx', '$it', '$main-args', 'abort', 'abs',
|
1568
|
+
'acos', 'acosh', 'add', 'address', 'amb', 'and', 'and', 'append-file',
|
1569
|
+
'append', 'apply', 'args', 'array-list', 'array?', 'array', 'asin',
|
1570
|
+
'asinh', 'assoc', 'atan', 'atan2', 'atanh', 'atom?', 'base64-dec',
|
1571
|
+
'base64-enc', 'bayes-query', 'bayes-train', 'begin', 'begin', 'begin',
|
1572
|
+
'beta', 'betai', 'bind', 'binomial', 'bits', 'callback', 'case', 'case',
|
1573
|
+
'case', 'catch', 'ceil', 'change-dir', 'char', 'chop', 'Class', 'clean',
|
1574
|
+
'close', 'command-event', 'cond', 'cond', 'cond', 'cons', 'constant',
|
1575
|
+
'context?', 'context', 'copy-file', 'copy', 'cos', 'cosh', 'count',
|
1576
|
+
'cpymem', 'crc32', 'crit-chi2', 'crit-z', 'current-line', 'curry',
|
1577
|
+
'date-list', 'date-parse', 'date-value', 'date', 'debug', 'dec',
|
1578
|
+
'def-new', 'default', 'define-macro', 'define-macro', 'define',
|
1579
|
+
'delete-file', 'delete-url', 'delete', 'destroy', 'det', 'device',
|
1580
|
+
'difference', 'directory?', 'directory', 'div', 'do-until', 'do-while',
|
1581
|
+
'doargs', 'dolist', 'dostring', 'dotimes', 'dotree', 'dump', 'dup',
|
1582
|
+
'empty?', 'encrypt', 'ends-with', 'env', 'erf', 'error-event',
|
1583
|
+
'eval-string', 'eval', 'exec', 'exists', 'exit', 'exp', 'expand',
|
1584
|
+
'explode', 'extend', 'factor', 'fft', 'file-info', 'file?', 'filter',
|
1585
|
+
'find-all', 'find', 'first', 'flat', 'float?', 'float', 'floor', 'flt',
|
1586
|
+
'fn', 'for-all', 'for', 'fork', 'format', 'fv', 'gammai', 'gammaln',
|
1587
|
+
'gcd', 'get-char', 'get-float', 'get-int', 'get-long', 'get-string',
|
1588
|
+
'get-url', 'global?', 'global', 'if-not', 'if', 'ifft', 'import', 'inc',
|
1589
|
+
'index', 'inf?', 'int', 'integer?', 'integer', 'intersect', 'invert',
|
1590
|
+
'irr', 'join', 'lambda-macro', 'lambda?', 'lambda', 'last-error',
|
1591
|
+
'last', 'legal?', 'length', 'let', 'let', 'let', 'letex', 'letn',
|
1592
|
+
'letn', 'letn', 'list?', 'list', 'load', 'local', 'log', 'lookup',
|
1593
|
+
'lower-case', 'macro?', 'main-args', 'MAIN', 'make-dir', 'map', 'mat',
|
1594
|
+
'match', 'max', 'member', 'min', 'mod', 'module', 'mul', 'multiply',
|
1595
|
+
'NaN?', 'net-accept', 'net-close', 'net-connect', 'net-error',
|
1596
|
+
'net-eval', 'net-interface', 'net-ipv', 'net-listen', 'net-local',
|
1597
|
+
'net-lookup', 'net-packet', 'net-peek', 'net-peer', 'net-ping',
|
1598
|
+
'net-receive-from', 'net-receive-udp', 'net-receive', 'net-select',
|
1599
|
+
'net-send-to', 'net-send-udp', 'net-send', 'net-service',
|
1600
|
+
'net-sessions', 'new', 'nil?', 'nil', 'normal', 'not', 'now', 'nper',
|
1601
|
+
'npv', 'nth', 'null?', 'number?', 'open', 'or', 'ostype', 'pack',
|
1602
|
+
'parse-date', 'parse', 'peek', 'pipe', 'pmt', 'pop-assoc', 'pop',
|
1603
|
+
'post-url', 'pow', 'prefix', 'pretty-print', 'primitive?', 'print',
|
1604
|
+
'println', 'prob-chi2', 'prob-z', 'process', 'prompt-event',
|
1605
|
+
'protected?', 'push', 'put-url', 'pv', 'quote?', 'quote', 'rand',
|
1606
|
+
'random', 'randomize', 'read', 'read-char', 'read-expr', 'read-file',
|
1607
|
+
'read-key', 'read-line', 'read-utf8', 'read', 'reader-event',
|
1608
|
+
'real-path', 'receive', 'ref-all', 'ref', 'regex-comp', 'regex',
|
1609
|
+
'remove-dir', 'rename-file', 'replace', 'reset', 'rest', 'reverse',
|
1610
|
+
'rotate', 'round', 'save', 'search', 'seed', 'seek', 'select', 'self',
|
1611
|
+
'semaphore', 'send', 'sequence', 'series', 'set-locale', 'set-ref-all',
|
1612
|
+
'set-ref', 'set', 'setf', 'setq', 'sgn', 'share', 'signal', 'silent',
|
1613
|
+
'sin', 'sinh', 'sleep', 'slice', 'sort', 'source', 'spawn', 'sqrt',
|
1614
|
+
'starts-with', 'string?', 'string', 'sub', 'swap', 'sym', 'symbol?',
|
1615
|
+
'symbols', 'sync', 'sys-error', 'sys-info', 'tan', 'tanh', 'term',
|
1616
|
+
'throw-error', 'throw', 'time-of-day', 'time', 'timer', 'title-case',
|
1617
|
+
'trace-highlight', 'trace', 'transpose', 'Tree', 'trim', 'true?',
|
1618
|
+
'true', 'unicode', 'unify', 'unique', 'unless', 'unpack', 'until',
|
1619
|
+
'upper-case', 'utf8', 'utf8len', 'uuid', 'wait-pid', 'when', 'while',
|
1620
|
+
'write', 'write-char', 'write-file', 'write-line', 'write',
|
1621
|
+
'xfer-event', 'xml-error', 'xml-parse', 'xml-type-tags', 'zero?',
|
1622
|
+
]
|
1623
|
+
|
1624
|
+
# valid names
|
1625
|
+
valid_name = r'([a-zA-Z0-9!$%&*+.,/<=>?@^_~|-])+|(\[.*?\])+'
|
1626
|
+
|
1627
|
+
tokens = {
|
1628
|
+
'root': [
|
1629
|
+
# shebang
|
1630
|
+
(r'#!(.*?)$', Comment.Preproc),
|
1631
|
+
# comments starting with semicolon
|
1632
|
+
(r';.*$', Comment.Single),
|
1633
|
+
# comments starting with #
|
1634
|
+
(r'#.*$', Comment.Single),
|
1635
|
+
|
1636
|
+
# whitespace
|
1637
|
+
(r'\s+', Text),
|
1638
|
+
|
1639
|
+
# strings, symbols and characters
|
1640
|
+
(r'"(\\\\|\\"|[^"])*"', String),
|
1641
|
+
|
1642
|
+
# braces
|
1643
|
+
(r"{", String, "bracestring"),
|
1644
|
+
|
1645
|
+
# [text] ... [/text] delimited strings
|
1646
|
+
(r'\[text\]*', String, "tagstring"),
|
1647
|
+
|
1648
|
+
# 'special' operators...
|
1649
|
+
(r"('|:)", Operator),
|
1650
|
+
|
1651
|
+
# highlight the builtins
|
1652
|
+
('(%s)' % '|'.join(re.escape(entry) + '\\b' for entry in builtins),
|
1653
|
+
Keyword),
|
1654
|
+
|
1655
|
+
# the remaining functions
|
1656
|
+
(r'(?<=\()' + valid_name, Name.Variable),
|
1657
|
+
|
1658
|
+
# the remaining variables
|
1659
|
+
(valid_name, String.Symbol),
|
1660
|
+
|
1661
|
+
# parentheses
|
1662
|
+
(r'(\(|\))', Punctuation),
|
1663
|
+
],
|
1664
|
+
|
1665
|
+
# braced strings...
|
1666
|
+
'bracestring': [
|
1667
|
+
("{", String, "#push"),
|
1668
|
+
("}", String, "#pop"),
|
1669
|
+
("[^{}]+", String),
|
1670
|
+
],
|
1671
|
+
|
1672
|
+
# tagged [text]...[/text] delimited strings...
|
1673
|
+
'tagstring': [
|
1674
|
+
(r'(?s)(.*?)(\[/text\])', String, '#pop'),
|
1675
|
+
],
|
1676
|
+
}
|
1677
|
+
|
1678
|
+
|
1679
|
+
class ElixirLexer(RegexLexer):
|
1680
|
+
"""
|
1681
|
+
For the `Elixir language <http://elixir-lang.org>`_.
|
1682
|
+
|
1683
|
+
*New in Pygments 1.5.*
|
1684
|
+
"""
|
1685
|
+
|
1686
|
+
name = 'Elixir'
|
1687
|
+
aliases = ['elixir', 'ex', 'exs']
|
1688
|
+
filenames = ['*.ex', '*.exs']
|
1689
|
+
mimetypes = ['text/x-elixir']
|
1690
|
+
|
1691
|
+
def gen_elixir_sigil_rules():
|
1692
|
+
states = {}
|
1693
|
+
|
1694
|
+
states['strings'] = [
|
1695
|
+
(r'(%[A-Ba-z])?"""(?:.|\n)*?"""', String.Doc),
|
1696
|
+
(r"'''(?:.|\n)*?'''", String.Doc),
|
1697
|
+
(r'"', String.Double, 'dqs'),
|
1698
|
+
(r"'.*'", String.Single),
|
1699
|
+
(r'(?<!\w)\?(\\(x\d{1,2}|\h{1,2}(?!\h)\b|0[0-7]{0,2}(?![0-7])\b|'
|
1700
|
+
r'[^x0MC])|(\\[MC]-)+\w|[^\s\\])', String.Other)
|
1701
|
+
]
|
1702
|
+
|
1703
|
+
for lbrace, rbrace, name, in ('\\{', '\\}', 'cb'), \
|
1704
|
+
('\\[', '\\]', 'sb'), \
|
1705
|
+
('\\(', '\\)', 'pa'), \
|
1706
|
+
('\\<', '\\>', 'lt'):
|
1707
|
+
|
1708
|
+
states['strings'] += [
|
1709
|
+
(r'%[a-z]' + lbrace, String.Double, name + 'intp'),
|
1710
|
+
(r'%[A-Z]' + lbrace, String.Double, name + 'no-intp')
|
1711
|
+
]
|
1712
|
+
|
1713
|
+
states[name +'intp'] = [
|
1714
|
+
(r'' + rbrace + '[a-z]*', String.Double, "#pop"),
|
1715
|
+
include('enddoublestr')
|
1716
|
+
]
|
1717
|
+
|
1718
|
+
states[name +'no-intp'] = [
|
1719
|
+
(r'.*' + rbrace + '[a-z]*', String.Double , "#pop")
|
1720
|
+
]
|
1721
|
+
|
1722
|
+
return states
|
1723
|
+
|
1724
|
+
tokens = {
|
1725
|
+
'root': [
|
1726
|
+
(r'\s+', Text),
|
1727
|
+
(r'#.*$', Comment.Single),
|
1728
|
+
(r'\b(case|cond|end|bc|lc|if|unless|try|loop|receive|fn|defmodule|'
|
1729
|
+
r'defp?|defprotocol|defimpl|defrecord|defmacrop?|defdelegate|'
|
1730
|
+
r'defexception|exit|raise|throw|unless|after|rescue|catch|else)\b(?![?!])|'
|
1731
|
+
r'(?<!\.)\b(do|\-\>)\b\s*', Keyword),
|
1732
|
+
(r'\b(import|require|use|recur|quote|unquote|super|refer)\b(?![?!])',
|
1733
|
+
Keyword.Namespace),
|
1734
|
+
(r'(?<!\.)\b(and|not|or|when|xor|in)\b', Operator.Word),
|
1735
|
+
(r'%=|\*=|\*\*=|\+=|\-=|\^=|\|\|=|'
|
1736
|
+
r'<=>|<(?!<|=)|>(?!<|=|>)|<=|>=|===|==|=~|!=|!~|(?=[ \t])\?|'
|
1737
|
+
r'(?<=[ \t])!+|&&|\|\||\^|\*|\+|\-|/|'
|
1738
|
+
r'\||\+\+|\-\-|\*\*|\/\/|\<\-|\<\>|<<|>>|=|\.', Operator),
|
1739
|
+
(r'(?<!:)(:)([a-zA-Z_]\w*([?!]|=(?![>=]))?|\<\>|===?|>=?|<=?|'
|
1740
|
+
r'<=>|&&?|%\(\)|%\[\]|%\{\}|\+\+?|\-\-?|\|\|?|\!|//|[%&`/\|]|'
|
1741
|
+
r'\*\*?|=?~|<\-)|([a-zA-Z_]\w*([?!])?)(:)(?!:)', String.Symbol),
|
1742
|
+
(r':"', String.Symbol, 'interpoling_symbol'),
|
1743
|
+
(r'\b(nil|true|false)\b(?![?!])|\b[A-Z]\w*\b', Name.Constant),
|
1744
|
+
(r'\b(__(FILE|LINE|MODULE|MAIN|FUNCTION)__)\b(?![?!])', Name.Builtin.Pseudo),
|
1745
|
+
(r'[a-zA-Z_!][\w_]*[!\?]?', Name),
|
1746
|
+
(r'[(){};,/\|:\\\[\]]', Punctuation),
|
1747
|
+
(r'@[a-zA-Z_]\w*|&\d', Name.Variable),
|
1748
|
+
(r'\b(0[xX][0-9A-Fa-f]+|\d(_?\d)*(\.(?![^\d\s])'
|
1749
|
+
r'(_?\d)*)?([eE][-+]?\d(_?\d)*)?|0[bB][01]+)\b', Number),
|
1750
|
+
(r'%r\/.*\/', String.Regex),
|
1751
|
+
include('strings'),
|
1752
|
+
],
|
1753
|
+
'dqs': [
|
1754
|
+
(r'"', String.Double, "#pop"),
|
1755
|
+
include('enddoublestr')
|
1756
|
+
],
|
1757
|
+
'interpoling': [
|
1758
|
+
(r'#{', String.Interpol, 'interpoling_string'),
|
1759
|
+
],
|
1760
|
+
'interpoling_string' : [
|
1761
|
+
(r'}', String.Interpol, "#pop"),
|
1762
|
+
include('root')
|
1763
|
+
],
|
1764
|
+
'interpoling_symbol': [
|
1765
|
+
(r'"', String.Symbol, "#pop"),
|
1766
|
+
include('interpoling'),
|
1767
|
+
(r'[^#"]+', String.Symbol),
|
1768
|
+
],
|
1769
|
+
'enddoublestr' : [
|
1770
|
+
include('interpoling'),
|
1771
|
+
(r'[^#"]+', String.Double),
|
1772
|
+
]
|
1773
|
+
}
|
1774
|
+
tokens.update(gen_elixir_sigil_rules())
|
1775
|
+
|
1776
|
+
|
1777
|
+
class ElixirConsoleLexer(Lexer):
|
1778
|
+
"""
|
1779
|
+
For Elixir interactive console (iex) output like:
|
1780
|
+
|
1781
|
+
.. sourcecode:: iex
|
1782
|
+
|
1783
|
+
iex> [head | tail] = [1,2,3]
|
1784
|
+
[1,2,3]
|
1785
|
+
iex> head
|
1786
|
+
1
|
1787
|
+
iex> tail
|
1788
|
+
[2,3]
|
1789
|
+
iex> [head | tail]
|
1790
|
+
[1,2,3]
|
1791
|
+
iex> length [head | tail]
|
1792
|
+
3
|
1793
|
+
|
1794
|
+
*New in Pygments 1.5.*
|
1795
|
+
"""
|
1796
|
+
|
1797
|
+
name = 'Elixir iex session'
|
1798
|
+
aliases = ['iex']
|
1799
|
+
mimetypes = ['text/x-elixir-shellsession']
|
1800
|
+
|
1801
|
+
_prompt_re = re.compile('(iex|\.{3})> ')
|
1802
|
+
|
1803
|
+
def get_tokens_unprocessed(self, text):
|
1804
|
+
exlexer = ElixirLexer(**self.options)
|
1805
|
+
|
1806
|
+
curcode = ''
|
1807
|
+
insertions = []
|
1808
|
+
for match in line_re.finditer(text):
|
1809
|
+
line = match.group()
|
1810
|
+
if line.startswith(u'** '):
|
1811
|
+
insertions.append((len(curcode),
|
1812
|
+
[(0, Generic.Error, line[:-1])]))
|
1813
|
+
curcode += line[-1:]
|
1814
|
+
else:
|
1815
|
+
m = self._prompt_re.match(line)
|
1816
|
+
if m is not None:
|
1817
|
+
end = m.end()
|
1818
|
+
insertions.append((len(curcode),
|
1819
|
+
[(0, Generic.Prompt, line[:end])]))
|
1820
|
+
curcode += line[end:]
|
1821
|
+
else:
|
1822
|
+
if curcode:
|
1823
|
+
for item in do_insertions(insertions,
|
1824
|
+
exlexer.get_tokens_unprocessed(curcode)):
|
1825
|
+
yield item
|
1826
|
+
curcode = ''
|
1827
|
+
insertions = []
|
1828
|
+
yield match.start(), Generic.Output, line
|
1829
|
+
if curcode:
|
1830
|
+
for item in do_insertions(insertions,
|
1831
|
+
exlexer.get_tokens_unprocessed(curcode)):
|
1832
|
+
yield item
|