summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2013-05-19 09:57:20 +0200
committerGeorg Brandl <georg@python.org>2013-05-19 09:57:20 +0200
commit979add1852fc4147cc5cb2640dc43eb084748c66 (patch)
tree84241027ffbb7c9aeabc0a6745ddc328497d075b
parentf1d5639c5783544422ac8703ed51cd7f17bb2a36 (diff)
parent845149fc5be259ddff2393a357b978f06defcb11 (diff)
downloadpygments-979add1852fc4147cc5cb2640dc43eb084748c66.tar.gz
Merged in roskakori/pygments-main (pull request #199)
Added lexer for Rexx
-rw-r--r--AUTHORS9
-rw-r--r--CHANGES27
-rw-r--r--[-rwxr-xr-x]pygmentize2
-rw-r--r--pygments/lexers/__init__.py11
-rw-r--r--pygments/lexers/_mapping.py39
-rw-r--r--pygments/lexers/agile.py7
-rw-r--r--pygments/lexers/asm.py2
-rw-r--r--pygments/lexers/compiled.py67
-rw-r--r--pygments/lexers/functional.py99
-rw-r--r--pygments/lexers/math.py261
-rw-r--r--pygments/lexers/other.py10
-rw-r--r--pygments/lexers/shell.py19
-rw-r--r--pygments/lexers/templates.py4
-rw-r--r--pygments/lexers/text.py60
-rw-r--r--pygments/lexers/web.py963
-rw-r--r--pygments/modeline.py40
-rw-r--r--tests/examplefiles/example.hx142
-rw-r--r--tests/examplefiles/garcia-wachs.kk70
-rw-r--r--tests/examplefiles/py3tb_test.py3tb4
-rw-r--r--tests/examplefiles/swig_java.swg1329
-rw-r--r--tests/examplefiles/swig_std_vector.i225
-rw-r--r--tests/examplefiles/test.ebnf31
22 files changed, 3127 insertions, 294 deletions
diff --git a/AUTHORS b/AUTHORS
index 3b6908f5..7e38aea0 100644
--- a/AUTHORS
+++ b/AUTHORS
@@ -30,20 +30,25 @@ Other contributors, listed alphabetically, are:
* Christian Jann -- ShellSession lexer
* Christopher Creutzig -- MuPAD lexer
* Pete Curry -- bugfixes
-* Owen Durni -- haXe lexer
+* Bryan Davis -- EBNF lexer
+* Owen Durni -- Haxe lexer
* Nick Efford -- Python 3 lexer
* Sven Efftinge -- Xtend lexer
* Artem Egorkine -- terminal256 formatter
* James H. Fisher -- PostScript lexer
+* William S. Fulton -- SWIG lexer
* Carlos Galdino -- Elixir and Elixir Console lexers
* Michael Galloy -- IDL lexer
* Naveen Garg -- Autohotkey lexer
* Laurent Gautier -- R/S lexer
* Alex Gaynor -- PyPy log lexer
+* Richard Gerkin -- Igor Pro lexer
* Alain Gilbert -- TypeScript lexer
+* Alex Gilding -- BlitzBasic lexer
* Bertrand Goetzmann -- Groovy lexer
* Krzysiek Goj -- Scala lexer
* Matt Good -- Genshi, Cheetah lexers
+* Michał Górny -- vim modeline support
* Patrick Gotthardt -- PHP namespaces support
* Olivier Guibe -- Asymptote lexer
* Jordi Gutiérrez Hermoso -- Octave lexer
@@ -54,6 +59,7 @@ Other contributors, listed alphabetically, are:
* Greg Hendershott -- Racket lexer
* David Hess, Fish Software, Inc. -- Objective-J lexer
* Varun Hiremath -- Debian control lexer
+* Rob Hoelz -- Perl 6 lexer
* Doug Hogan -- Mscgen lexer
* Ben Hollis -- Mason lexer
* Dustin Howett -- Logos lexer
@@ -99,6 +105,7 @@ Other contributors, listed alphabetically, are:
* Mike Nolta -- Julia lexer
* Jonas Obrist -- BBCode lexer
* David Oliva -- Rebol lexer
+* Pat Pannuto -- nesC lexer
* Jon Parise -- Protocol buffers lexer
* Ronny Pfannschmidt -- BBCode lexer
* Benjamin Peterson -- Test suite refactoring
diff --git a/CHANGES b/CHANGES
index a422db88..3cad33ea 100644
--- a/CHANGES
+++ b/CHANGES
@@ -13,6 +13,15 @@ Version 1.7
- Lexers added:
* Clay (PR#184)
+ * Perl 6 (PR#181)
+ * Swig (PR#168)
+ * nesC (PR#166)
+ * BlitzBasic (PR#197)
+ * EBNF (PR#193)
+ * Igor Pro (PR#172)
+
+- Pygments will now recognize "vim" modelines when guessing the lexer for
+ a file based on content (PR#118).
- Python 3 lexer: add new exceptions from PEP 3151.
@@ -24,6 +33,20 @@ Version 1.7
- Lasso lexer: fix method highlighting, update builtins. Fix
guessing so that plain XML isn't always taken as Lasso (PR#163).
+- Objective C/C++ lexers: allow "@" prefixing any expression (#871).
+
+- Ruby lexer: fix lexing of Name::Space tokens (#860).
+
+- Stan lexer: update for version 1.3.0 of the language (PR#162).
+
+- JavaScript lexer: add the "yield" keyword (PR#196).
+
+- HTTP lexer: support for PATCH method (PR#190).
+
+- Koka lexer: update to newest language spec (PR#201).
+
+- Haxe lexer: rewrite and support for Haxe 3 (PR#174).
+
Version 1.6
-----------
@@ -278,7 +301,7 @@ Version 1.3
* Ada
* Coldfusion
* Modula-2
- * haXe
+ * Haxe
* R console
* Objective-J
* Haml and Sass
@@ -337,7 +360,7 @@ Version 1.2
* CMake
* Ooc
* Coldfusion
- * haXe
+ * Haxe
* R console
- Added options for rendering LaTeX in source code comments in the
diff --git a/pygmentize b/pygmentize
index e2379199..8b3b2067 100755..100644
--- a/pygmentize
+++ b/pygmentize
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python2
import sys, pygments.cmdline
try:
diff --git a/pygments/lexers/__init__.py b/pygments/lexers/__init__.py
index 9af6ce68..dbfe4351 100644
--- a/pygments/lexers/__init__.py
+++ b/pygments/lexers/__init__.py
@@ -15,6 +15,7 @@ import fnmatch
from os.path import basename
from pygments.lexers._mapping import LEXERS
+from pygments.modeline import get_filetype_from_buffer
from pygments.plugin import find_plugin_lexers
from pygments.util import ClassNotFound, bytes
@@ -197,6 +198,16 @@ def guess_lexer(_text, **options):
"""
Guess a lexer by strong distinctions in the text (eg, shebang).
"""
+
+ # try to get a vim modeline first
+ ft = get_filetype_from_buffer(_text)
+
+ if ft is not None:
+ try:
+ return get_lexer_by_name(ft, **options)
+ except ClassNotFound:
+ pass
+
best_lexer = [0.0, None]
for lexer in _iter_lexerclasses():
rv = lexer.analyse_text(_text)
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index f05b510b..a8c54d39 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -32,13 +32,13 @@ LEXERS = {
'AspectJLexer': ('pygments.lexers.jvm', 'AspectJ', ('aspectj',), ('*.aj',), ('text/x-aspectj',)),
'AsymptoteLexer': ('pygments.lexers.other', 'Asymptote', ('asy', 'asymptote'), ('*.asy',), ('text/x-asymptote',)),
'AutoItLexer': ('pygments.lexers.other', 'AutoIt', ('autoit', 'Autoit'), ('*.au3',), ('text/x-autoit',)),
- 'AutohotkeyLexer': ('pygments.lexers.other', 'autohotkey', ('ahk',), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)),
+ 'AutohotkeyLexer': ('pygments.lexers.other', 'autohotkey', ('ahk', 'autohotkey'), ('*.ahk', '*.ahkl'), ('text/x-autohotkey',)),
'AwkLexer': ('pygments.lexers.other', 'Awk', ('awk', 'gawk', 'mawk', 'nawk'), ('*.awk',), ('application/x-awk',)),
'BBCodeLexer': ('pygments.lexers.text', 'BBCode', ('bbcode',), (), ('text/x-bbcode',)),
'BaseMakefileLexer': ('pygments.lexers.text', 'Base Makefile', ('basemake',), (), ()),
'BashLexer': ('pygments.lexers.shell', 'Bash', ('bash', 'sh', 'ksh'), ('*.sh', '*.ksh', '*.bash', '*.ebuild', '*.eclass', '.bashrc', 'bashrc', '.bash_*', 'bash_*'), ('application/x-sh', 'application/x-shellscript')),
'BashSessionLexer': ('pygments.lexers.shell', 'Bash Session', ('console',), ('*.sh-session',), ('application/x-shell-session',)),
- 'BatchLexer': ('pygments.lexers.shell', 'Batchfile', ('bat',), ('*.bat', '*.cmd'), ('application/x-dos-batch',)),
+ 'BatchLexer': ('pygments.lexers.shell', 'Batchfile', ('bat', 'dosbatch', 'winbatch'), ('*.bat', '*.cmd'), ('application/x-dos-batch',)),
'BefungeLexer': ('pygments.lexers.other', 'Befunge', ('befunge',), ('*.befunge',), ('application/x-befunge',)),
'BlitzBasicLexer': ('pygments.lexers.compiled', 'BlitzBasic', ('blitzbasic', 'b3d', 'bplus'), ('*.bb', '*.decls'), ('text/x-bb',)),
'BlitzMaxLexer': ('pygments.lexers.compiled', 'BlitzMax', ('blitzmax', 'bmax'), ('*.bmx',), ('text/x-bmx',)),
@@ -55,7 +55,7 @@ LEXERS = {
'CbmBasicV2Lexer': ('pygments.lexers.other', 'CBM BASIC V2', ('cbmbas',), ('*.bas',), ()),
'CeylonLexer': ('pygments.lexers.jvm', 'Ceylon', ('ceylon',), ('*.ceylon',), ('text/x-ceylon',)),
'Cfengine3Lexer': ('pygments.lexers.other', 'CFEngine3', ('cfengine3', 'cf3'), ('*.cf',), ()),
- 'CheetahHtmlLexer': ('pygments.lexers.templates', 'HTML+Cheetah', ('html+cheetah', 'html+spitfire'), (), ('text/html+cheetah', 'text/html+spitfire')),
+ 'CheetahHtmlLexer': ('pygments.lexers.templates', 'HTML+Cheetah', ('html+cheetah', 'html+spitfire', 'htmlcheetah'), (), ('text/html+cheetah', 'text/html+spitfire')),
'CheetahJavascriptLexer': ('pygments.lexers.templates', 'JavaScript+Cheetah', ('js+cheetah', 'javascript+cheetah', 'js+spitfire', 'javascript+spitfire'), (), ('application/x-javascript+cheetah', 'text/x-javascript+cheetah', 'text/javascript+cheetah', 'application/x-javascript+spitfire', 'text/x-javascript+spitfire', 'text/javascript+spitfire')),
'CheetahLexer': ('pygments.lexers.templates', 'Cheetah', ('cheetah', 'spitfire'), ('*.tmpl', '*.spt'), ('application/x-cheetah', 'application/x-spitfire')),
'CheetahXmlLexer': ('pygments.lexers.templates', 'XML+Cheetah', ('xml+cheetah', 'xml+spitfire'), (), ('application/xml+cheetah', 'application/xml+spitfire')),
@@ -63,10 +63,10 @@ LEXERS = {
'ClojureLexer': ('pygments.lexers.jvm', 'Clojure', ('clojure', 'clj'), ('*.clj',), ('text/x-clojure', 'application/x-clojure')),
'CobolFreeformatLexer': ('pygments.lexers.compiled', 'COBOLFree', ('cobolfree',), ('*.cbl', '*.CBL'), ()),
'CobolLexer': ('pygments.lexers.compiled', 'COBOL', ('cobol',), ('*.cob', '*.COB', '*.cpy', '*.CPY'), ('text/x-cobol',)),
- 'CoffeeScriptLexer': ('pygments.lexers.web', 'CoffeeScript', ('coffee-script', 'coffeescript'), ('*.coffee',), ('text/coffeescript',)),
+ 'CoffeeScriptLexer': ('pygments.lexers.web', 'CoffeeScript', ('coffee-script', 'coffeescript', 'coffee'), ('*.coffee',), ('text/coffeescript',)),
'ColdfusionHtmlLexer': ('pygments.lexers.templates', 'Coldfusion HTML', ('cfm',), ('*.cfm', '*.cfml', '*.cfc'), ('application/x-coldfusion',)),
'ColdfusionLexer': ('pygments.lexers.templates', 'cfstatement', ('cfs',), (), ()),
- 'CommonLispLexer': ('pygments.lexers.functional', 'Common Lisp', ('common-lisp', 'cl'), ('*.cl', '*.lisp', '*.el'), ('text/x-common-lisp',)),
+ 'CommonLispLexer': ('pygments.lexers.functional', 'Common Lisp', ('common-lisp', 'cl', 'lisp'), ('*.cl', '*.lisp', '*.el'), ('text/x-common-lisp',)),
'CoqLexer': ('pygments.lexers.functional', 'Coq', ('coq',), ('*.v',), ('text/x-coq',)),
'CppLexer': ('pygments.lexers.compiled', 'C++', ('cpp', 'c++'), ('*.cpp', '*.hpp', '*.c++', '*.h++', '*.cc', '*.hh', '*.cxx', '*.hxx', '*.C', '*.H', '*.cp', '*.CPP'), ('text/x-c++hdr', 'text/x-c++src')),
'CppObjdumpLexer': ('pygments.lexers.asm', 'cpp-objdump', ('cpp-objdump', 'c++-objdumb', 'cxx-objdump'), ('*.cpp-objdump', '*.c++-objdump', '*.cxx-objdump'), ('text/x-cpp-objdump',)),
@@ -78,12 +78,12 @@ LEXERS = {
'CssPhpLexer': ('pygments.lexers.templates', 'CSS+PHP', ('css+php',), (), ('text/css+php',)),
'CssSmartyLexer': ('pygments.lexers.templates', 'CSS+Smarty', ('css+smarty',), (), ('text/css+smarty',)),
'CudaLexer': ('pygments.lexers.compiled', 'CUDA', ('cuda', 'cu'), ('*.cu', '*.cuh'), ('text/x-cuda',)),
- 'CythonLexer': ('pygments.lexers.compiled', 'Cython', ('cython', 'pyx'), ('*.pyx', '*.pxd', '*.pxi'), ('text/x-cython', 'application/x-cython')),
+ 'CythonLexer': ('pygments.lexers.compiled', 'Cython', ('cython', 'pyx', 'pyrex'), ('*.pyx', '*.pxd', '*.pxi'), ('text/x-cython', 'application/x-cython')),
'DLexer': ('pygments.lexers.compiled', 'D', ('d',), ('*.d', '*.di'), ('text/x-dsrc',)),
'DObjdumpLexer': ('pygments.lexers.asm', 'd-objdump', ('d-objdump',), ('*.d-objdump',), ('text/x-d-objdump',)),
'DarcsPatchLexer': ('pygments.lexers.text', 'Darcs Patch', ('dpatch',), ('*.dpatch', '*.darcspatch'), ()),
'DartLexer': ('pygments.lexers.web', 'Dart', ('dart',), ('*.dart',), ('text/x-dart',)),
- 'DebianControlLexer': ('pygments.lexers.text', 'Debian Control file', ('control',), ('control',), ()),
+ 'DebianControlLexer': ('pygments.lexers.text', 'Debian Control file', ('control', 'debcontrol'), ('control',), ()),
'DelphiLexer': ('pygments.lexers.compiled', 'Delphi', ('delphi', 'pas', 'pascal', 'objectpascal'), ('*.pas',), ('text/x-pascal',)),
'DgLexer': ('pygments.lexers.agile', 'dg', ('dg',), ('*.dg',), ('text/x-dg',)),
'DiffLexer': ('pygments.lexers.text', 'Diff', ('diff', 'udiff'), ('*.diff', '*.patch'), ('text/x-diff', 'text/x-patch')),
@@ -95,6 +95,7 @@ LEXERS = {
'DylanLidLexer': ('pygments.lexers.compiled', 'DylanLID', ('dylan-lid', 'lid'), ('*.lid', '*.hdp'), ('text/x-dylan-lid',)),
'ECLLexer': ('pygments.lexers.other', 'ECL', ('ecl',), ('*.ecl',), ('application/x-ecl',)),
'ECLexer': ('pygments.lexers.compiled', 'eC', ('ec',), ('*.ec', '*.eh'), ('text/x-echdr', 'text/x-ecsrc')),
+ 'EbnfLexer': ('pygments.lexers.text', 'EBNF', ('ebnf',), ('*.ebnf',), ('text/x-ebnf',)),
'ElixirConsoleLexer': ('pygments.lexers.functional', 'Elixir iex session', ('iex',), (), ('text/x-elixir-shellsession',)),
'ElixirLexer': ('pygments.lexers.functional', 'Elixir', ('elixir', 'ex', 'exs'), ('*.ex', '*.exs'), ('text/x-elixir',)),
'ErbLexer': ('pygments.lexers.templates', 'ERB', ('erb',), (), ('application/x-ruby-templating',)),
@@ -111,7 +112,7 @@ LEXERS = {
'FortranLexer': ('pygments.lexers.compiled', 'Fortran', ('fortran',), ('*.f', '*.f90', '*.F', '*.F90'), ('text/x-fortran',)),
'FoxProLexer': ('pygments.lexers.foxpro', 'FoxPro', ('Clipper', 'XBase'), ('*.PRG', '*.prg'), ()),
'GLShaderLexer': ('pygments.lexers.compiled', 'GLSL', ('glsl',), ('*.vert', '*.frag', '*.geo'), ('text/x-glslsrc',)),
- 'GasLexer': ('pygments.lexers.asm', 'GAS', ('gas',), ('*.s', '*.S'), ('text/x-gas',)),
+ 'GasLexer': ('pygments.lexers.asm', 'GAS', ('gas', 'asm'), ('*.s', '*.S'), ('text/x-gas',)),
'GenshiLexer': ('pygments.lexers.templates', 'Genshi', ('genshi', 'kid', 'xml+genshi', 'xml+kid'), ('*.kid',), ('application/x-genshi', 'application/x-kid')),
'GenshiTextLexer': ('pygments.lexers.templates', 'Genshi Text', ('genshitext',), (), ('application/x-genshi-text', 'text/x-genshi')),
'GettextLexer': ('pygments.lexers.text', 'Gettext Catalog', ('pot', 'po'), ('*.pot', '*.po'), ('application/x-gettext', 'text/x-gettext', 'text/gettext')),
@@ -125,8 +126,8 @@ LEXERS = {
'GroovyLexer': ('pygments.lexers.jvm', 'Groovy', ('groovy',), ('*.groovy',), ('text/x-groovy',)),
'HamlLexer': ('pygments.lexers.web', 'Haml', ('haml', 'HAML'), ('*.haml',), ('text/x-haml',)),
'HaskellLexer': ('pygments.lexers.functional', 'Haskell', ('haskell', 'hs'), ('*.hs',), ('text/x-haskell',)),
- 'HaxeLexer': ('pygments.lexers.web', 'haXe', ('hx', 'haXe'), ('*.hx',), ('text/haxe',)),
- 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja'), (), ('text/html+django', 'text/html+jinja')),
+ 'HaxeLexer': ('pygments.lexers.web', 'Haxe', ('hx', 'Haxe', 'haxe', 'haXe', 'hxsl'), ('*.hx', '*.hxsl'), ('text/haxe', 'text/x-haxe', 'text/x-hx')),
+ 'HtmlDjangoLexer': ('pygments.lexers.templates', 'HTML+Django/Jinja', ('html+django', 'html+jinja', 'htmldjango'), (), ('text/html+django', 'text/html+jinja')),
'HtmlGenshiLexer': ('pygments.lexers.templates', 'HTML+Genshi', ('html+genshi', 'html+kid'), (), ('text/html+genshi',)),
'HtmlLexer': ('pygments.lexers.web', 'HTML', ('html',), ('*.html', '*.htm', '*.xhtml', '*.xslt'), ('text/html', 'application/xhtml+xml')),
'HtmlPhpLexer': ('pygments.lexers.templates', 'HTML+PHP', ('html+php',), ('*.phtml',), ('application/x-php', 'application/x-httpd-php', 'application/x-httpd-php3', 'application/x-httpd-php4', 'application/x-httpd-php5')),
@@ -135,7 +136,8 @@ LEXERS = {
'HxmlLexer': ('pygments.lexers.text', 'Hxml', ('haxeml', 'hxml'), ('*.hxml',), ()),
'HybrisLexer': ('pygments.lexers.other', 'Hybris', ('hybris', 'hy'), ('*.hy', '*.hyb'), ('text/x-hybris', 'application/x-hybris')),
'IDLLexer': ('pygments.lexers.math', 'IDL', ('idl',), ('*.pro',), ('text/idl',)),
- 'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg'), ('*.ini', '*.cfg'), ('text/x-ini',)),
+ 'IgorLexer': ('pygments.lexers.math', 'Igor', ('igor', 'igorpro'), ('*.ipf',), ('text/ipf',)),
+ 'IniLexer': ('pygments.lexers.text', 'INI', ('ini', 'cfg', 'dosini'), ('*.ini', '*.cfg'), ('text/x-ini',)),
'IoLexer': ('pygments.lexers.agile', 'Io', ('io',), ('*.io',), ('text/x-iosrc',)),
'IokeLexer': ('pygments.lexers.jvm', 'Ioke', ('ioke', 'ik'), ('*.ik',), ('text/x-iokesrc',)),
'IrcLogsLexer': ('pygments.lexers.text', 'IRC logs', ('irc',), ('*.weechatlog',), ('text/x-irclog',)),
@@ -161,13 +163,13 @@ LEXERS = {
'LassoLexer': ('pygments.lexers.web', 'Lasso', ('lasso', 'lassoscript'), ('*.lasso', '*.lasso[89]'), ('text/x-lasso',)),
'LassoXmlLexer': ('pygments.lexers.templates', 'XML+Lasso', ('xml+lasso',), (), ('application/xml+lasso',)),
'LighttpdConfLexer': ('pygments.lexers.text', 'Lighttpd configuration file', ('lighty', 'lighttpd'), (), ('text/x-lighttpd-conf',)),
- 'LiterateHaskellLexer': ('pygments.lexers.functional', 'Literate Haskell', ('lhs', 'literate-haskell'), ('*.lhs',), ('text/x-literate-haskell',)),
+ 'LiterateHaskellLexer': ('pygments.lexers.functional', 'Literate Haskell', ('lhs', 'literate-haskell', 'lhaskell'), ('*.lhs',), ('text/x-literate-haskell',)),
'LiveScriptLexer': ('pygments.lexers.web', 'LiveScript', ('live-script', 'livescript'), ('*.ls',), ('text/livescript',)),
'LlvmLexer': ('pygments.lexers.asm', 'LLVM', ('llvm',), ('*.ll',), ('text/x-llvm',)),
'LogosLexer': ('pygments.lexers.compiled', 'Logos', ('logos',), ('*.x', '*.xi', '*.xm', '*.xmi'), ('text/x-logos',)),
'LogtalkLexer': ('pygments.lexers.other', 'Logtalk', ('logtalk',), ('*.lgt',), ('text/x-logtalk',)),
'LuaLexer': ('pygments.lexers.agile', 'Lua', ('lua',), ('*.lua', '*.wlua'), ('text/x-lua', 'application/x-lua')),
- 'MOOCodeLexer': ('pygments.lexers.other', 'MOOCode', ('moocode',), ('*.moo',), ('text/x-moocode',)),
+ 'MOOCodeLexer': ('pygments.lexers.other', 'MOOCode', ('moocode', 'moo'), ('*.moo',), ('text/x-moocode',)),
'MakefileLexer': ('pygments.lexers.text', 'Makefile', ('make', 'makefile', 'mf', 'bsdmake'), ('*.mak', 'Makefile', 'makefile', 'Makefile.*', 'GNUmakefile'), ('text/x-makefile',)),
'MakoCssLexer': ('pygments.lexers.templates', 'CSS+Mako', ('css+mako',), (), ('text/css+mako',)),
'MakoHtmlLexer': ('pygments.lexers.templates', 'HTML+Mako', ('html+mako',), (), ('text/html+mako',)),
@@ -215,14 +217,14 @@ LEXERS = {
'PerlLexer': ('pygments.lexers.agile', 'Perl', ('perl', 'pl'), ('*.pl', '*.pm'), ('text/x-perl', 'application/x-perl')),
'PhpLexer': ('pygments.lexers.web', 'PHP', ('php', 'php3', 'php4', 'php5'), ('*.php', '*.php[345]', '*.inc'), ('text/x-php',)),
'PlPgsqlLexer': ('pygments.lexers.sql', 'PL/pgSQL', ('plpgsql',), (), ('text/x-plpgsql',)),
- 'PostScriptLexer': ('pygments.lexers.other', 'PostScript', ('postscript',), ('*.ps', '*.eps'), ('application/postscript',)),
+ 'PostScriptLexer': ('pygments.lexers.other', 'PostScript', ('postscript', 'postscr'), ('*.ps', '*.eps'), ('application/postscript',)),
'PostgresConsoleLexer': ('pygments.lexers.sql', 'PostgreSQL console (psql)', ('psql', 'postgresql-console', 'postgres-console'), (), ('text/x-postgresql-psql',)),
'PostgresLexer': ('pygments.lexers.sql', 'PostgreSQL SQL dialect', ('postgresql', 'postgres'), (), ('text/x-postgresql',)),
'PovrayLexer': ('pygments.lexers.other', 'POVRay', ('pov',), ('*.pov', '*.inc'), ('text/x-povray',)),
'PowerShellLexer': ('pygments.lexers.shell', 'PowerShell', ('powershell', 'posh', 'ps1', 'psm1'), ('*.ps1', '*.psm1'), ('text/x-powershell',)),
'PrologLexer': ('pygments.lexers.compiled', 'Prolog', ('prolog',), ('*.prolog', '*.pro', '*.pl'), ('text/x-prolog',)),
- 'PropertiesLexer': ('pygments.lexers.text', 'Properties', ('properties',), ('*.properties',), ('text/x-java-properties',)),
- 'ProtoBufLexer': ('pygments.lexers.other', 'Protocol Buffer', ('protobuf',), ('*.proto',), ()),
+ 'PropertiesLexer': ('pygments.lexers.text', 'Properties', ('properties', 'jproperties'), ('*.properties',), ('text/x-java-properties',)),
+ 'ProtoBufLexer': ('pygments.lexers.other', 'Protocol Buffer', ('protobuf', 'proto'), ('*.proto',), ()),
'PuppetLexer': ('pygments.lexers.other', 'Puppet', ('puppet',), ('*.pp',), ()),
'PyPyLogLexer': ('pygments.lexers.text', 'PyPy Log', ('pypylog', 'pypy'), ('*.pypylog',), ('application/x-pypylog',)),
'Python3Lexer': ('pygments.lexers.agile', 'Python 3', ('python3', 'py3'), (), ('text/x-python3', 'application/x-python3')),
@@ -264,16 +266,17 @@ LEXERS = {
'ScssLexer': ('pygments.lexers.web', 'SCSS', ('scss',), ('*.scss',), ('text/x-scss',)),
'ShellSessionLexer': ('pygments.lexers.shell', 'Shell Session', ('shell-session',), ('*.shell-session',), ('application/x-sh-session',)),
'SmaliLexer': ('pygments.lexers.dalvik', 'Smali', ('smali',), ('*.smali',), ('text/smali',)),
- 'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak'), ('*.st',), ('text/x-smalltalk',)),
+ 'SmalltalkLexer': ('pygments.lexers.other', 'Smalltalk', ('smalltalk', 'squeak', 'st'), ('*.st',), ('text/x-smalltalk',)),
'SmartyLexer': ('pygments.lexers.templates', 'Smarty', ('smarty',), ('*.tpl',), ('application/x-smarty',)),
'SnobolLexer': ('pygments.lexers.other', 'Snobol', ('snobol',), ('*.snobol',), ('text/x-snobol',)),
'SourcePawnLexer': ('pygments.lexers.other', 'SourcePawn', ('sp',), ('*.sp',), ('text/x-sourcepawn',)),
- 'SourcesListLexer': ('pygments.lexers.text', 'Debian Sourcelist', ('sourceslist', 'sources.list'), ('sources.list',), ()),
+ 'SourcesListLexer': ('pygments.lexers.text', 'Debian Sourcelist', ('sourceslist', 'sources.list', 'debsources'), ('sources.list',), ()),
'SqlLexer': ('pygments.lexers.sql', 'SQL', ('sql',), ('*.sql',), ('text/x-sql',)),
'SqliteConsoleLexer': ('pygments.lexers.sql', 'sqlite3con', ('sqlite3',), ('*.sqlite3-console',), ('text/x-sqlite3-console',)),
'SquidConfLexer': ('pygments.lexers.text', 'SquidConf', ('squidconf', 'squid.conf', 'squid'), ('squid.conf',), ('text/x-squidconf',)),
'SspLexer': ('pygments.lexers.templates', 'Scalate Server Page', ('ssp',), ('*.ssp',), ('application/x-ssp',)),
'StanLexer': ('pygments.lexers.math', 'Stan', ('stan',), ('*.stan',), ()),
+ 'SwigLexer': ('pygments.lexers.compiled', 'SWIG', ('Swig', 'swig'), ('*.swg', '*.i'), ('text/swig',)),
'SystemVerilogLexer': ('pygments.lexers.hdl', 'systemverilog', ('systemverilog', 'sv'), ('*.sv', '*.svh'), ('text/x-systemverilog',)),
'TclLexer': ('pygments.lexers.agile', 'Tcl', ('tcl',), ('*.tcl',), ('text/x-tcl', 'text/x-script.tcl', 'application/x-tcl')),
'TcshLexer': ('pygments.lexers.shell', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)),
diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py
index 078f0181..896a3deb 100644
--- a/pygments/lexers/agile.py
+++ b/pygments/lexers/agile.py
@@ -428,10 +428,13 @@ class Python3TracebackLexer(RegexLexer):
r'exception occurred:\n\n', Generic.Traceback),
(r'^The above exception was the direct cause of the '
r'following exception:\n\n', Generic.Traceback),
+ (r'^(?= File "[^"]+", line \d+)', Generic.Traceback, 'intb'),
],
'intb': [
(r'^( File )("[^"]+")(, line )(\d+)(, in )(.+)(\n)',
bygroups(Text, Name.Builtin, Text, Number, Text, Name, Text)),
+ (r'^( File )("[^"]+")(, line )(\d+)(\n)',
+ bygroups(Text, Name.Builtin, Text, Number, Text)),
(r'^( )(.+)(\n)',
bygroups(Text, using(Python3Lexer), Text)),
(r'^([ \t]*)(\.\.\.)(\n)',
@@ -528,7 +531,7 @@ class RubyLexer(ExtendedRegexLexer):
(r":'(\\\\|\\'|[^'])*'", String.Symbol),
(r"'(\\\\|\\'|[^'])*'", String.Single),
(r':"', String.Symbol, 'simple-sym'),
- (r'([a-zA-Z_][a-zA-Z0-9]*)(:)',
+ (r'([a-zA-Z_][a-zA-Z0-9]*)(:)(?!:)',
bygroups(String.Symbol, Punctuation)), # Since Ruby 1.9
(r'"', String.Double, 'simple-string'),
(r'(?<!\.)`', String.Backtick, 'simple-backtick'),
@@ -1926,6 +1929,8 @@ class DgLexer(RegexLexer):
class Perl6Lexer(ExtendedRegexLexer):
"""
For `Perl 6 <http://www.perl6.org>`_ source code.
+
+ *New in Pygments 1.7.*
"""
name = 'Perl6'
diff --git a/pygments/lexers/asm.py b/pygments/lexers/asm.py
index f080327b..3f67862c 100644
--- a/pygments/lexers/asm.py
+++ b/pygments/lexers/asm.py
@@ -25,7 +25,7 @@ class GasLexer(RegexLexer):
For Gas (AT&T) assembly code.
"""
name = 'GAS'
- aliases = ['gas']
+ aliases = ['gas', 'asm']
filenames = ['*.s', '*.S']
mimetypes = ['text/x-gas']
diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py
index 3b99f46c..c3b0909d 100644
--- a/pygments/lexers/compiled.py
+++ b/pygments/lexers/compiled.py
@@ -28,7 +28,7 @@ __all__ = ['CLexer', 'CppLexer', 'DLexer', 'DelphiLexer', 'ECLexer',
'FortranLexer', 'GLShaderLexer', 'PrologLexer', 'CythonLexer',
'ValaLexer', 'OocLexer', 'GoLexer', 'FelixLexer', 'AdaLexer',
'Modula2Lexer', 'BlitzMaxLexer', 'BlitzBasicLexer', 'NimrodLexer',
- 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer',
+ 'FantomLexer', 'RustLexer', 'CudaLexer', 'MonkeyLexer', 'SwigLexer',
'DylanLidLexer', 'DylanConsoleLexer', 'CobolLexer',
'CobolFreeformatLexer', 'LogosLexer', 'ClayLexer']
@@ -232,6 +232,63 @@ class CppLexer(CFamilyLexer):
return 0.1
+class SwigLexer(CppLexer):
+ """
+ For `SWIG <http://www.swig.org/>`_ source code.
+
+ *New in Pygments 1.7.*
+ """
+ name = 'SWIG'
+ aliases = ['Swig', 'swig']
+ filenames = ['*.swg', '*.i']
+ mimetypes = ['text/swig']
+ priority = 0.04 # Lower than C/C++ and Objective C/C++
+
+ tokens = {
+ 'statements': [
+ (r'(%[a-z_][a-z0-9_]*)', Name.Function), # SWIG directives
+ ('\$\**\&?[a-zA-Z0-9_]+', Name), # Special variables
+ (r'##*[a-zA-Z_][a-zA-Z0-9_]*', Comment.Preproc), # Stringification / additional preprocessor directives
+ inherit,
+ ],
+ }
+
+ # This is a far from complete set of SWIG directives
+ swig_directives = (
+ # Most common directives
+ '%apply', '%define', '%director', '%enddef', '%exception', '%extend',
+ '%feature', '%fragment', '%ignore', '%immutable', '%import', '%include',
+ '%inline', '%insert', '%module', '%newobject', '%nspace', '%pragma',
+ '%rename', '%shared_ptr', '%template', '%typecheck', '%typemap',
+ # Less common directives
+ '%arg', '%attribute', '%bang', '%begin', '%callback', '%catches', '%clear',
+ '%constant', '%copyctor', '%csconst', '%csconstvalue', '%csenum',
+ '%csmethodmodifiers', '%csnothrowexception', '%default', '%defaultctor',
+ '%defaultdtor', '%defined', '%delete', '%delobject', '%descriptor',
+ '%exceptionclass', '%exceptionvar', '%extend_smart_pointer', '%fragments',
+ '%header', '%ifcplusplus', '%ignorewarn', '%implicit', '%implicitconv',
+ '%init', '%javaconst', '%javaconstvalue', '%javaenum', '%javaexception',
+ '%javamethodmodifiers', '%kwargs', '%luacode', '%mutable', '%naturalvar',
+ '%nestedworkaround', '%perlcode', '%pythonabc', '%pythonappend',
+ '%pythoncallback', '%pythoncode', '%pythondynamic', '%pythonmaybecall',
+ '%pythonnondynamic', '%pythonprepend', '%refobject', '%shadow', '%sizeof',
+ '%trackobjects', '%types', '%unrefobject', '%varargs', '%warn', '%warnfilter')
+
+ def analyse_text(text):
+ rv = 0.1 # Same as C/C++
+ # Search for SWIG directives, which are conventionally at the beginning of
+ # a line. The probability of them being within a line is low, so let another
+ # lexer win in this case.
+ matches = re.findall(r'^\s*(%[a-z_][a-z0-9_]*)', text, re.M)
+ for m in matches:
+ if m in SwigLexer.swig_directives:
+ rv = 0.98
+ break
+ else:
+ rv = 0.91 # Fraction higher than MatlabLexer
+ return rv
+
+
class ECLexer(CLexer):
"""
For eC source code with preprocessor directives.
@@ -271,6 +328,8 @@ class NesCLexer(CLexer):
"""
For `nesC <https://github.com/tinyos/nesc>`_ source code with preprocessor
directives.
+
+ *New in Pygments 1.7.*
"""
name = 'nesC'
aliases = ['nesc']
@@ -1292,6 +1351,8 @@ def objective(baselexer):
('#pop', 'oc_classname')),
(r'(@class|@protocol)(\s+)', bygroups(Keyword, Text),
('#pop', 'oc_forward_classname')),
+ # @ can also prefix other expressions like @{...} or @(...)
+ (r'@', Punctuation),
inherit,
],
'oc_classname' : [
@@ -1598,7 +1659,7 @@ class CythonLexer(RegexLexer):
"""
name = 'Cython'
- aliases = ['cython', 'pyx']
+ aliases = ['cython', 'pyx', 'pyrex']
filenames = ['*.pyx', '*.pxd', '*.pxi']
mimetypes = ['text/x-cython', 'application/x-cython']
@@ -2660,6 +2721,8 @@ class BlitzMaxLexer(RegexLexer):
class BlitzBasicLexer(RegexLexer):
"""
For `BlitzBasic <http://blitzbasic.com>`_ source code.
+
+ *New in Pygments 1.7.*
"""
name = 'BlitzBasic'
diff --git a/pygments/lexers/functional.py b/pygments/lexers/functional.py
index 613be987..77fe4723 100644
--- a/pygments/lexers/functional.py
+++ b/pygments/lexers/functional.py
@@ -719,7 +719,7 @@ class CommonLispLexer(RegexLexer):
*New in Pygments 0.9.*
"""
name = 'Common Lisp'
- aliases = ['common-lisp', 'cl']
+ aliases = ['common-lisp', 'cl', 'lisp']
filenames = ['*.cl', '*.lisp', '*.el'] # use for Elisp too
mimetypes = ['text/x-common-lisp']
@@ -1028,7 +1028,7 @@ class LiterateHaskellLexer(Lexer):
*New in Pygments 0.9.*
"""
name = 'Literate Haskell'
- aliases = ['lhs', 'literate-haskell']
+ aliases = ['lhs', 'literate-haskell', 'lhaskell']
filenames = ['*.lhs']
mimetypes = ['text/x-literate-haskell']
@@ -2402,7 +2402,7 @@ class ElixirConsoleLexer(Lexer):
class KokaLexer(RegexLexer):
"""
- Lexer for the `Koka <http://research.microsoft.com/en-us/projects/koka/>`_
+ Lexer for the `Koka <http://koka.codeplex.com>`_
language.
*New in Pygments 1.6.*
@@ -2414,7 +2414,7 @@ class KokaLexer(RegexLexer):
mimetypes = ['text/x-koka']
keywords = [
- 'infix', 'infixr', 'infixl', 'prefix', 'postfix',
+ 'infix', 'infixr', 'infixl',
'type', 'cotype', 'rectype', 'alias',
'struct', 'con',
'fun', 'function', 'val', 'var',
@@ -2453,7 +2453,12 @@ class KokaLexer(RegexLexer):
sboundary = '(?!'+symbols+')'
# name boundary: a keyword should not be followed by any of these
- boundary = '(?![a-zA-Z0-9_\\-])'
+ boundary = '(?![\w/])'
+
+ # koka token abstractions
+ tokenType = Name.Attribute
+ tokenTypeDef = Name.Class
+ tokenConstructor = Generic.Emph
# main lexer
tokens = {
@@ -2461,41 +2466,51 @@ class KokaLexer(RegexLexer):
include('whitespace'),
# go into type mode
- (r'::?' + sboundary, Keyword.Type, 'type'),
- (r'alias' + boundary, Keyword, 'alias-type'),
- (r'struct' + boundary, Keyword, 'struct-type'),
- (r'(%s)' % '|'.join(typeStartKeywords) + boundary, Keyword, 'type'),
+ (r'::?' + sboundary, tokenType, 'type'),
+ (r'(alias)(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef),
+ 'alias-type'),
+ (r'(struct)(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef),
+ 'struct-type'),
+ ((r'(%s)' % '|'.join(typeStartKeywords)) +
+ r'(\s+)([a-z]\w*)?', bygroups(Keyword, Text, tokenTypeDef),
+ 'type'),
# special sequences of tokens (we use ?: for non-capturing group as
# required by 'bygroups')
- (r'(module)(\s*)((?:interface)?)(\s*)'
- r'((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*'
- r'[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)',
- bygroups(Keyword, Text, Keyword, Text, Name.Namespace)),
- (r'(import)(\s+)((?:[a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*\.)*[a-z]'
- r'(?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)((?:as)?)'
- r'((?:[A-Z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)?)',
- bygroups(Keyword, Text, Name.Namespace, Text, Keyword,
- Name.Namespace)),
+ (r'(module)(\s+)(interface\s+)?((?:[a-z]\w*/)*[a-z]\w*)',
+ bygroups(Keyword, Text, Keyword, Name.Namespace)),
+ (r'(import)(\s+)((?:[a-z]\w*/)*[a-z]\w*)'
+ r'(?:(\s*)(=)(\s*)((?:qualified\s*)?)'
+ r'((?:[a-z]\w*/)*[a-z]\w*))?',
+ bygroups(Keyword, Text, Name.Namespace, Text, Keyword, Text,
+ Keyword, Name.Namespace)),
+
+ (r'(^(?:(?:public|private)\s*)?(?:function|fun|val))'
+ r'(\s+)([a-z]\w*|\((?:' + symbols + r'|/)\))',
+ bygroups(Keyword, Text, Name.Function)),
+ (r'(^(?:(?:public|private)\s*)?external)(\s+)(inline\s+)?'
+ r'([a-z]\w*|\((?:' + symbols + r'|/)\))',
+ bygroups(Keyword, Text, Keyword, Name.Function)),
# keywords
(r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
(r'(%s)' % '|'.join(keywords) + boundary, Keyword),
(r'(%s)' % '|'.join(builtin) + boundary, Keyword.Pseudo),
- (r'::|:=|\->|[=\.:]' + sboundary, Keyword),
- (r'\-' + sboundary, Generic.Strong),
+ (r'::?|:=|\->|[=\.]' + sboundary, Keyword),
# names
- (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
- (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
- (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Name),
- (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Name.Variable),
+ (r'((?:[a-z]\w*/)*)([A-Z]\w*)',
+ bygroups(Name.Namespace, tokenConstructor)),
+ (r'((?:[a-z]\w*/)*)([a-z]\w*)', bygroups(Name.Namespace, Name)),
+ (r'((?:[a-z]\w*/)*)(\((?:' + symbols + r'|/)\))',
+ bygroups(Name.Namespace, Name)),
+ (r'_\w*', Name.Variable),
# literal string
(r'@"', String.Double, 'litstring'),
# operators
- (symbols, Operator),
+ (symbols + "|/(?![\*/])", Operator),
(r'`', Operator),
(r'[\{\}\(\)\[\];,]', Punctuation),
@@ -2522,17 +2537,17 @@ class KokaLexer(RegexLexer):
# type started by colon
'type': [
- (r'[\(\[<]', Keyword.Type, 'type-nested'),
+ (r'[\(\[<]', tokenType, 'type-nested'),
include('type-content')
],
# type nested in brackets: can contain parameters, comma etc.
'type-nested': [
- (r'[\)\]>]', Keyword.Type, '#pop'),
- (r'[\(\[<]', Keyword.Type, 'type-nested'),
- (r',', Keyword.Type),
- (r'([a-z](?:[a-zA-Z0-9_]|\-[a-zA-Z])*)(\s*)(:)(?!:)',
- bygroups(Name.Variable,Text,Keyword.Type)), # parameter name
+ (r'[\)\]>]', tokenType, '#pop'),
+ (r'[\(\[<]', tokenType, 'type-nested'),
+ (r',', tokenType),
+ (r'([a-z]\w*)(\s*)(:)(?!:)',
+ bygroups(Name, Text, tokenType)), # parameter name
include('type-content')
],
@@ -2541,23 +2556,23 @@ class KokaLexer(RegexLexer):
include('whitespace'),
# keywords
- (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword.Type),
+ (r'(%s)' % '|'.join(typekeywords) + boundary, Keyword),
(r'(?=((%s)' % '|'.join(keywords) + boundary + '))',
Keyword, '#pop'), # need to match because names overlap...
# kinds
- (r'[EPH]' + boundary, Keyword.Type),
- (r'[*!]', Keyword.Type),
+ (r'[EPHVX]' + boundary, tokenType),
# type names
- (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?=\.)', Name.Namespace),
- (r'[A-Z]([a-zA-Z0-9_]|\-[a-zA-Z])*(?!\.)', Name.Class),
- (r'[a-z][0-9]*(?![a-zA-Z_\-])', Keyword.Type), # Generic.Emph
- (r'_([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type), # Generic.Emph
- (r'[a-z]([a-zA-Z0-9_]|\-[a-zA-Z])*', Keyword.Type),
+ (r'[a-z][0-9]*(?![\w/])', tokenType ),
+ (r'_\w*', tokenType.Variable), # Generic.Emph
+ (r'((?:[a-z]\w*/)*)([A-Z]\w*)',
+ bygroups(Name.Namespace, tokenType)),
+ (r'((?:[a-z]\w*/)*)([a-z]\w+)',
+ bygroups(Name.Namespace, tokenType)),
# type keyword operators
- (r'::|\->|[\.:|]', Keyword.Type),
+ (r'::|\->|[\.:|]', tokenType),
#catchall
(r'', Text, '#pop')
@@ -2565,6 +2580,7 @@ class KokaLexer(RegexLexer):
# comments and literals
'whitespace': [
+ (r'\n\s*#.*$', Comment.Preproc),
(r'\s+', Text),
(r'/\*', Comment.Multiline, 'comment'),
(r'//.*$', Comment.Single)
@@ -2591,11 +2607,10 @@ class KokaLexer(RegexLexer):
(r'[\'\n]', String.Char, '#pop'),
],
'escape-sequence': [
- (r'\\[abfnrtv0\\\"\'\?]', String.Escape),
+ (r'\\[nrt\\\"\']', String.Escape),
(r'\\x[0-9a-fA-F]{2}', String.Escape),
(r'\\u[0-9a-fA-F]{4}', String.Escape),
# Yes, \U literals are 6 hex digits.
(r'\\U[0-9a-fA-F]{6}', String.Escape)
]
}
-
diff --git a/pygments/lexers/math.py b/pygments/lexers/math.py
index 0b757e44..f52e85e8 100644
--- a/pygments/lexers/math.py
+++ b/pygments/lexers/math.py
@@ -24,7 +24,7 @@ from pygments.lexers import _stan_builtins
__all__ = ['JuliaLexer', 'JuliaConsoleLexer', 'MuPADLexer', 'MatlabLexer',
'MatlabSessionLexer', 'OctaveLexer', 'ScilabLexer', 'NumPyLexer',
'RConsoleLexer', 'SLexer', 'JagsLexer', 'BugsLexer', 'StanLexer',
- 'IDLLexer', 'RdLexer']
+ 'IDLLexer', 'RdLexer', 'IgorLexer']
class JuliaLexer(RegexLexer):
@@ -1300,7 +1300,7 @@ class JagsLexer(RegexLexer):
return 0
class StanLexer(RegexLexer):
- """Pygments Lexer for Stan models.
+ """Pygments Lexer for Stan models.
The Stan modeling language is specified in the *Stan 1.3.0
Modeling Language Manual* `pdf
@@ -1653,3 +1653,260 @@ class RdLexer(RegexLexer):
(r'.', Text),
]
}
+
+
+class IgorLexer(RegexLexer):
+ """
+ Pygments Lexer for Igor Pro procedure files (.ipf).
+ See http://www.wavemetrics.com/ and http://www.igorexchange.com/.
+
+ *New in Pygments 1.7.*
+ """
+
+ name = 'Igor'
+ aliases = ['igor', 'igorpro']
+ filenames = ['*.ipf']
+ mimetypes = ['text/ipf']
+
+ flags = re.IGNORECASE
+
+ flowControl = [
+ 'if', 'else', 'elseif', 'endif', 'for', 'endfor', 'strswitch', 'switch',
+ 'case', 'endswitch', 'do', 'while', 'try', 'catch', 'endtry', 'break',
+ 'continue', 'return',
+ ]
+ types = [
+ 'variable', 'string', 'constant', 'strconstant', 'NVAR', 'SVAR', 'WAVE',
+ 'STRUCT', 'ThreadSafe', 'function', 'end', 'static', 'macro', 'window',
+ 'graph', 'Structure', 'EndStructure', 'EndMacro', 'FuncFit', 'Proc',
+ 'Picture', 'Menu', 'SubMenu', 'Prompt', 'DoPrompt',
+ ]
+ operations = [
+ 'Abort', 'AddFIFOData', 'AddFIFOVectData', 'AddMovieAudio',
+ 'AddMovieFrame', 'APMath', 'Append', 'AppendImage',
+ 'AppendLayoutObject', 'AppendMatrixContour', 'AppendText',
+ 'AppendToGraph', 'AppendToLayout', 'AppendToTable', 'AppendXYZContour',
+ 'AutoPositionWindow', 'BackgroundInfo', 'Beep', 'BoundingBall',
+ 'BrowseURL', 'BuildMenu', 'Button', 'cd', 'Chart', 'CheckBox',
+ 'CheckDisplayed', 'ChooseColor', 'Close', 'CloseMovie', 'CloseProc',
+ 'ColorScale', 'ColorTab2Wave', 'Concatenate', 'ControlBar',
+ 'ControlInfo', 'ControlUpdate', 'ConvexHull', 'Convolve', 'CopyFile',
+ 'CopyFolder', 'CopyScales', 'Correlate', 'CreateAliasShortcut', 'Cross',
+ 'CtrlBackground', 'CtrlFIFO', 'CtrlNamedBackground', 'Cursor',
+ 'CurveFit', 'CustomControl', 'CWT', 'Debugger', 'DebuggerOptions',
+ 'DefaultFont', 'DefaultGuiControls', 'DefaultGuiFont', 'DefineGuide',
+ 'DelayUpdate', 'DeleteFile', 'DeleteFolder', 'DeletePoints',
+ 'Differentiate', 'dir', 'Display', 'DisplayHelpTopic',
+ 'DisplayProcedure', 'DoAlert', 'DoIgorMenu', 'DoUpdate', 'DoWindow',
+ 'DoXOPIdle', 'DrawAction', 'DrawArc', 'DrawBezier', 'DrawLine',
+ 'DrawOval', 'DrawPICT', 'DrawPoly', 'DrawRect', 'DrawRRect', 'DrawText',
+ 'DSPDetrend', 'DSPPeriodogram', 'Duplicate', 'DuplicateDataFolder',
+ 'DWT', 'EdgeStats', 'Edit', 'ErrorBars', 'Execute', 'ExecuteScriptText',
+ 'ExperimentModified', 'Extract', 'FastGaussTransform', 'FastOp',
+ 'FBinRead', 'FBinWrite', 'FFT', 'FIFO2Wave', 'FIFOStatus', 'FilterFIR',
+ 'FilterIIR', 'FindLevel', 'FindLevels', 'FindPeak', 'FindPointsInPoly',
+ 'FindRoots', 'FindSequence', 'FindValue', 'FPClustering', 'fprintf',
+ 'FReadLine', 'FSetPos', 'FStatus', 'FTPDelete', 'FTPDownload',
+ 'FTPUpload', 'FuncFit', 'FuncFitMD', 'GetAxis', 'GetFileFolderInfo',
+ 'GetLastUserMenuInfo', 'GetMarquee', 'GetSelection', 'GetWindow',
+ 'GraphNormal', 'GraphWaveDraw', 'GraphWaveEdit', 'Grep', 'GroupBox',
+ 'Hanning', 'HideIgorMenus', 'HideInfo', 'HideProcedures', 'HideTools',
+ 'HilbertTransform', 'Histogram', 'IFFT', 'ImageAnalyzeParticles',
+ 'ImageBlend', 'ImageBoundaryToMask', 'ImageEdgeDetection',
+ 'ImageFileInfo', 'ImageFilter', 'ImageFocus', 'ImageGenerateROIMask',
+ 'ImageHistModification', 'ImageHistogram', 'ImageInterpolate',
+ 'ImageLineProfile', 'ImageLoad', 'ImageMorphology', 'ImageRegistration',
+ 'ImageRemoveBackground', 'ImageRestore', 'ImageRotate', 'ImageSave',
+ 'ImageSeedFill', 'ImageSnake', 'ImageStats', 'ImageThreshold',
+ 'ImageTransform', 'ImageUnwrapPhase', 'ImageWindow', 'IndexSort',
+ 'InsertPoints', 'Integrate', 'IntegrateODE', 'Interp3DPath',
+ 'Interpolate3D', 'KillBackground', 'KillControl', 'KillDataFolder',
+ 'KillFIFO', 'KillFreeAxis', 'KillPath', 'KillPICTs', 'KillStrings',
+ 'KillVariables', 'KillWaves', 'KillWindow', 'KMeans', 'Label', 'Layout',
+ 'Legend', 'LinearFeedbackShiftRegister', 'ListBox', 'LoadData',
+ 'LoadPackagePreferences', 'LoadPICT', 'LoadWave', 'Loess',
+ 'LombPeriodogram', 'Make', 'MakeIndex', 'MarkPerfTestTime',
+ 'MatrixConvolve', 'MatrixCorr', 'MatrixEigenV', 'MatrixFilter',
+ 'MatrixGaussJ', 'MatrixInverse', 'MatrixLinearSolve',
+ 'MatrixLinearSolveTD', 'MatrixLLS', 'MatrixLUBkSub', 'MatrixLUD',
+ 'MatrixMultiply', 'MatrixOP', 'MatrixSchur', 'MatrixSolve',
+ 'MatrixSVBkSub', 'MatrixSVD', 'MatrixTranspose', 'MeasureStyledText',
+ 'Modify', 'ModifyContour', 'ModifyControl', 'ModifyControlList',
+ 'ModifyFreeAxis', 'ModifyGraph', 'ModifyImage', 'ModifyLayout',
+ 'ModifyPanel', 'ModifyTable', 'ModifyWaterfall', 'MoveDataFolder',
+ 'MoveFile', 'MoveFolder', 'MoveString', 'MoveSubwindow', 'MoveVariable',
+ 'MoveWave', 'MoveWindow', 'NeuralNetworkRun', 'NeuralNetworkTrain',
+ 'NewDataFolder', 'NewFIFO', 'NewFIFOChan', 'NewFreeAxis', 'NewImage',
+ 'NewLayout', 'NewMovie', 'NewNotebook', 'NewPanel', 'NewPath',
+ 'NewWaterfall', 'Note', 'Notebook', 'NotebookAction', 'Open',
+ 'OpenNotebook', 'Optimize', 'ParseOperationTemplate', 'PathInfo',
+ 'PauseForUser', 'PauseUpdate', 'PCA', 'PlayMovie', 'PlayMovieAction',
+ 'PlaySnd', 'PlaySound', 'PopupContextualMenu', 'PopupMenu',
+ 'Preferences', 'PrimeFactors', 'Print', 'printf', 'PrintGraphs',
+ 'PrintLayout', 'PrintNotebook', 'PrintSettings', 'PrintTable',
+ 'Project', 'PulseStats', 'PutScrapText', 'pwd', 'Quit',
+ 'RatioFromNumber', 'Redimension', 'Remove', 'RemoveContour',
+ 'RemoveFromGraph', 'RemoveFromLayout', 'RemoveFromTable', 'RemoveImage',
+ 'RemoveLayoutObjects', 'RemovePath', 'Rename', 'RenameDataFolder',
+ 'RenamePath', 'RenamePICT', 'RenameWindow', 'ReorderImages',
+ 'ReorderTraces', 'ReplaceText', 'ReplaceWave', 'Resample',
+ 'ResumeUpdate', 'Reverse', 'Rotate', 'Save', 'SaveData',
+ 'SaveExperiment', 'SaveGraphCopy', 'SaveNotebook',
+ 'SavePackagePreferences', 'SavePICT', 'SaveTableCopy',
+ 'SetActiveSubwindow', 'SetAxis', 'SetBackground', 'SetDashPattern',
+ 'SetDataFolder', 'SetDimLabel', 'SetDrawEnv', 'SetDrawLayer',
+ 'SetFileFolderInfo', 'SetFormula', 'SetIgorHook', 'SetIgorMenuMode',
+ 'SetIgorOption', 'SetMarquee', 'SetProcessSleep', 'SetRandomSeed',
+ 'SetScale', 'SetVariable', 'SetWaveLock', 'SetWindow', 'ShowIgorMenus',
+ 'ShowInfo', 'ShowTools', 'Silent', 'Sleep', 'Slider', 'Smooth',
+ 'SmoothCustom', 'Sort', 'SoundInRecord', 'SoundInSet',
+ 'SoundInStartChart', 'SoundInStatus', 'SoundInStopChart',
+ 'SphericalInterpolate', 'SphericalTriangulate', 'SplitString',
+ 'sprintf', 'sscanf', 'Stack', 'StackWindows',
+ 'StatsAngularDistanceTest', 'StatsANOVA1Test', 'StatsANOVA2NRTest',
+ 'StatsANOVA2RMTest', 'StatsANOVA2Test', 'StatsChiTest',
+ 'StatsCircularCorrelationTest', 'StatsCircularMeans',
+ 'StatsCircularMoments', 'StatsCircularTwoSampleTest',
+ 'StatsCochranTest', 'StatsContingencyTable', 'StatsDIPTest',
+ 'StatsDunnettTest', 'StatsFriedmanTest', 'StatsFTest',
+ 'StatsHodgesAjneTest', 'StatsJBTest', 'StatsKendallTauTest',
+ 'StatsKSTest', 'StatsKWTest', 'StatsLinearCorrelationTest',
+ 'StatsLinearRegression', 'StatsMultiCorrelationTest',
+ 'StatsNPMCTest', 'StatsNPNominalSRTest', 'StatsQuantiles',
+ 'StatsRankCorrelationTest', 'StatsResample', 'StatsSample',
+ 'StatsScheffeTest', 'StatsSignTest', 'StatsSRTest', 'StatsTTest',
+ 'StatsTukeyTest', 'StatsVariancesTest', 'StatsWatsonUSquaredTest',
+ 'StatsWatsonWilliamsTest', 'StatsWheelerWatsonTest',
+ 'StatsWilcoxonRankTest', 'StatsWRCorrelationTest', 'String',
+ 'StructGet', 'StructPut', 'TabControl', 'Tag', 'TextBox', 'Tile',
+ 'TileWindows', 'TitleBox', 'ToCommandLine', 'ToolsGrid',
+ 'Triangulate3d', 'Unwrap', 'ValDisplay', 'Variable', 'WaveMeanStdv',
+ 'WaveStats', 'WaveTransform', 'wfprintf', 'WignerTransform',
+ 'WindowFunction',
+ ]
+ functions = [
+ 'abs', 'acos', 'acosh', 'AiryA', 'AiryAD', 'AiryB', 'AiryBD', 'alog',
+ 'area', 'areaXY', 'asin', 'asinh', 'atan', 'atan2', 'atanh',
+ 'AxisValFromPixel', 'Besseli', 'Besselj', 'Besselk', 'Bessely', 'bessi',
+ 'bessj', 'bessk', 'bessy', 'beta', 'betai', 'BinarySearch',
+ 'BinarySearchInterp', 'binomial', 'binomialln', 'binomialNoise', 'cabs',
+ 'CaptureHistoryStart', 'ceil', 'cequal', 'char2num', 'chebyshev',
+ 'chebyshevU', 'CheckName', 'cmplx', 'cmpstr', 'conj', 'ContourZ', 'cos',
+ 'cosh', 'cot', 'CountObjects', 'CountObjectsDFR', 'cpowi',
+ 'CreationDate', 'csc', 'DataFolderExists', 'DataFolderRefsEqual',
+ 'DataFolderRefStatus', 'date2secs', 'datetime', 'DateToJulian',
+ 'Dawson', 'DDEExecute', 'DDEInitiate', 'DDEPokeString', 'DDEPokeWave',
+ 'DDERequestWave', 'DDEStatus', 'DDETerminate', 'deltax', 'digamma',
+ 'DimDelta', 'DimOffset', 'DimSize', 'ei', 'enoise', 'equalWaves', 'erf',
+ 'erfc', 'exists', 'exp', 'expInt', 'expNoise', 'factorial', 'fakedata',
+ 'faverage', 'faverageXY', 'FindDimLabel', 'FindListItem', 'floor',
+ 'FontSizeHeight', 'FontSizeStringWidth', 'FresnelCos', 'FresnelSin',
+ 'gamma', 'gammaInc', 'gammaNoise', 'gammln', 'gammp', 'gammq', 'Gauss',
+ 'Gauss1D', 'Gauss2D', 'gcd', 'GetDefaultFontSize',
+ 'GetDefaultFontStyle', 'GetKeyState', 'GetRTError', 'gnoise',
+ 'GrepString', 'hcsr', 'hermite', 'hermiteGauss', 'HyperG0F1',
+ 'HyperG1F1', 'HyperG2F1', 'HyperGNoise', 'HyperGPFQ', 'IgorVersion',
+ 'ilim', 'imag', 'Inf', 'Integrate1D', 'interp', 'Interp2D', 'Interp3D',
+ 'inverseERF', 'inverseERFC', 'ItemsInList', 'jlim', 'Laguerre',
+ 'LaguerreA', 'LaguerreGauss', 'leftx', 'LegendreA', 'limit', 'ln',
+ 'log', 'logNormalNoise', 'lorentzianNoise', 'magsqr', 'MandelbrotPoint',
+ 'MarcumQ', 'MatrixDet', 'MatrixDot', 'MatrixRank', 'MatrixTrace', 'max',
+ 'mean', 'min', 'mod', 'ModDate', 'NaN', 'norm', 'NumberByKey',
+ 'numpnts', 'numtype', 'NumVarOrDefault', 'NVAR_Exists', 'p2rect',
+ 'ParamIsDefault', 'pcsr', 'Pi', 'PixelFromAxisVal', 'pnt2x',
+ 'poissonNoise', 'poly', 'poly2D', 'PolygonArea', 'qcsr', 'r2polar',
+ 'real', 'rightx', 'round', 'sawtooth', 'ScreenResolution', 'sec',
+ 'SelectNumber', 'sign', 'sin', 'sinc', 'sinh', 'SphericalBessJ',
+ 'SphericalBessJD', 'SphericalBessY', 'SphericalBessYD',
+ 'SphericalHarmonics', 'sqrt', 'StartMSTimer', 'StatsBetaCDF',
+ 'StatsBetaPDF', 'StatsBinomialCDF', 'StatsBinomialPDF',
+ 'StatsCauchyCDF', 'StatsCauchyPDF', 'StatsChiCDF', 'StatsChiPDF',
+ 'StatsCMSSDCDF', 'StatsCorrelation', 'StatsDExpCDF', 'StatsDExpPDF',
+ 'StatsErlangCDF', 'StatsErlangPDF', 'StatsErrorPDF', 'StatsEValueCDF',
+ 'StatsEValuePDF', 'StatsExpCDF', 'StatsExpPDF', 'StatsFCDF',
+ 'StatsFPDF', 'StatsFriedmanCDF', 'StatsGammaCDF', 'StatsGammaPDF',
+ 'StatsGeometricCDF', 'StatsGeometricPDF', 'StatsHyperGCDF',
+ 'StatsHyperGPDF', 'StatsInvBetaCDF', 'StatsInvBinomialCDF',
+ 'StatsInvCauchyCDF', 'StatsInvChiCDF', 'StatsInvCMSSDCDF',
+ 'StatsInvDExpCDF', 'StatsInvEValueCDF', 'StatsInvExpCDF',
+ 'StatsInvFCDF', 'StatsInvFriedmanCDF', 'StatsInvGammaCDF',
+ 'StatsInvGeometricCDF', 'StatsInvKuiperCDF', 'StatsInvLogisticCDF',
+ 'StatsInvLogNormalCDF', 'StatsInvMaxwellCDF', 'StatsInvMooreCDF',
+ 'StatsInvNBinomialCDF', 'StatsInvNCChiCDF', 'StatsInvNCFCDF',
+ 'StatsInvNormalCDF', 'StatsInvParetoCDF', 'StatsInvPoissonCDF',
+ 'StatsInvPowerCDF', 'StatsInvQCDF', 'StatsInvQpCDF',
+ 'StatsInvRayleighCDF', 'StatsInvRectangularCDF', 'StatsInvSpearmanCDF',
+ 'StatsInvStudentCDF', 'StatsInvTopDownCDF', 'StatsInvTriangularCDF',
+ 'StatsInvUsquaredCDF', 'StatsInvVonMisesCDF', 'StatsInvWeibullCDF',
+ 'StatsKuiperCDF', 'StatsLogisticCDF', 'StatsLogisticPDF',
+ 'StatsLogNormalCDF', 'StatsLogNormalPDF', 'StatsMaxwellCDF',
+ 'StatsMaxwellPDF', 'StatsMedian', 'StatsMooreCDF', 'StatsNBinomialCDF',
+ 'StatsNBinomialPDF', 'StatsNCChiCDF', 'StatsNCChiPDF', 'StatsNCFCDF',
+ 'StatsNCFPDF', 'StatsNCTCDF', 'StatsNCTPDF', 'StatsNormalCDF',
+ 'StatsNormalPDF', 'StatsParetoCDF', 'StatsParetoPDF', 'StatsPermute',
+ 'StatsPoissonCDF', 'StatsPoissonPDF', 'StatsPowerCDF',
+ 'StatsPowerNoise', 'StatsPowerPDF', 'StatsQCDF', 'StatsQpCDF',
+ 'StatsRayleighCDF', 'StatsRayleighPDF', 'StatsRectangularCDF',
+ 'StatsRectangularPDF', 'StatsRunsCDF', 'StatsSpearmanRhoCDF',
+ 'StatsStudentCDF', 'StatsStudentPDF', 'StatsTopDownCDF',
+ 'StatsTriangularCDF', 'StatsTriangularPDF', 'StatsTrimmedMean',
+ 'StatsUSquaredCDF', 'StatsVonMisesCDF', 'StatsVonMisesNoise',
+ 'StatsVonMisesPDF', 'StatsWaldCDF', 'StatsWaldPDF', 'StatsWeibullCDF',
+ 'StatsWeibullPDF', 'StopMSTimer', 'str2num', 'stringCRC', 'stringmatch',
+ 'strlen', 'strsearch', 'StudentA', 'StudentT', 'sum', 'SVAR_Exists',
+ 'TagVal', 'tan', 'tanh', 'ThreadGroupCreate', 'ThreadGroupRelease',
+ 'ThreadGroupWait', 'ThreadProcessorCount', 'ThreadReturnValue', 'ticks',
+ 'trunc', 'Variance', 'vcsr', 'WaveCRC', 'WaveDims', 'WaveExists',
+ 'WaveMax', 'WaveMin', 'WaveRefsEqual', 'WaveType', 'WhichListItem',
+ 'WinType', 'WNoise', 'x', 'x2pnt', 'xcsr', 'y', 'z', 'zcsr', 'ZernikeR',
+ ]
+ functions += [
+ 'AddListItem', 'AnnotationInfo', 'AnnotationList', 'AxisInfo',
+ 'AxisList', 'CaptureHistory', 'ChildWindowList', 'CleanupName',
+ 'ContourInfo', 'ContourNameList', 'ControlNameList', 'CsrInfo',
+ 'CsrWave', 'CsrXWave', 'CTabList', 'DataFolderDir', 'date',
+ 'DDERequestString', 'FontList', 'FuncRefInfo', 'FunctionInfo',
+ 'FunctionList', 'FunctionPath', 'GetDataFolder', 'GetDefaultFont',
+ 'GetDimLabel', 'GetErrMessage', 'GetFormula',
+ 'GetIndependentModuleName', 'GetIndexedObjName', 'GetIndexedObjNameDFR',
+ 'GetRTErrMessage', 'GetRTStackInfo', 'GetScrapText', 'GetUserData',
+ 'GetWavesDataFolder', 'GrepList', 'GuideInfo', 'GuideNameList', 'Hash',
+ 'IgorInfo', 'ImageInfo', 'ImageNameList', 'IndexedDir', 'IndexedFile',
+ 'JulianToDate', 'LayoutInfo', 'ListMatch', 'LowerStr', 'MacroList',
+ 'NameOfWave', 'note', 'num2char', 'num2istr', 'num2str',
+ 'OperationList', 'PadString', 'ParseFilePath', 'PathList', 'PICTInfo',
+ 'PICTList', 'PossiblyQuoteName', 'ProcedureText', 'RemoveByKey',
+ 'RemoveEnding', 'RemoveFromList', 'RemoveListItem',
+ 'ReplaceNumberByKey', 'ReplaceString', 'ReplaceStringByKey',
+ 'Secs2Date', 'Secs2Time', 'SelectString', 'SortList',
+ 'SpecialCharacterInfo', 'SpecialCharacterList', 'SpecialDirPath',
+ 'StringByKey', 'StringFromList', 'StringList', 'StrVarOrDefault',
+ 'TableInfo', 'TextFile', 'ThreadGroupGetDF', 'time', 'TraceFromPixel',
+ 'TraceInfo', 'TraceNameList', 'UniqueName', 'UnPadString', 'UpperStr',
+ 'VariableList', 'WaveInfo', 'WaveList', 'WaveName', 'WaveUnits',
+ 'WinList', 'WinName', 'WinRecreation', 'XWaveName',
+ 'ContourNameToWaveRef', 'CsrWaveRef', 'CsrXWaveRef',
+ 'ImageNameToWaveRef', 'NewFreeWave', 'TagWaveRef', 'TraceNameToWaveRef',
+ 'WaveRefIndexed', 'XWaveRefFromTrace', 'GetDataFolderDFR',
+ 'GetWavesDataFolderDFR', 'NewFreeDataFolder', 'ThreadGroupGetDFR',
+ ]
+
+ tokens = {
+ 'root': [
+ (r'//.*$', Comment.Single),
+ (r'"([^"\\]|\\.)*"', String),
+ # Flow Control.
+ (r'\b(%s)\b' % '|'.join(flowControl), Keyword),
+ # Types.
+ (r'\b(%s)\b' % '|'.join(types), Keyword.Type),
+ # Built-in operations.
+ (r'\b(%s)\b' % '|'.join(operations), Name.Class),
+ # Built-in functions.
+ (r'\b(%s)\b' % '|'.join(functions), Name.Function),
+ # Compiler directives.
+ (r'^#(include|pragma|define|ifdef|ifndef|endif)',
+ Name.Decorator),
+ (r'[^a-zA-Z"/]+', Text),
+ (r'.', Text),
+ ],
+ }
diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py
index c4b458fd..ed31b218 100644
--- a/pygments/lexers/other.py
+++ b/pygments/lexers/other.py
@@ -246,7 +246,7 @@ class MOOCodeLexer(RegexLexer):
"""
name = 'MOOCode'
filenames = ['*.moo']
- aliases = ['moocode']
+ aliases = ['moocode', 'moo']
mimetypes = ['text/x-moocode']
tokens = {
@@ -290,7 +290,7 @@ class SmalltalkLexer(RegexLexer):
"""
name = 'Smalltalk'
filenames = ['*.st']
- aliases = ['smalltalk', 'squeak']
+ aliases = ['smalltalk', 'squeak', 'st']
mimetypes = ['text/x-smalltalk']
tokens = {
@@ -1980,7 +1980,7 @@ class PostScriptLexer(RegexLexer):
*New in Pygments 1.4.*
"""
name = 'PostScript'
- aliases = ['postscript']
+ aliases = ['postscript', 'postscr']
filenames = ['*.ps', '*.eps']
mimetypes = ['application/postscript']
@@ -2068,7 +2068,7 @@ class AutohotkeyLexer(RegexLexer):
*New in Pygments 1.4.*
"""
name = 'autohotkey'
- aliases = ['ahk']
+ aliases = ['ahk', 'autohotkey']
filenames = ['*.ahk', '*.ahkl']
mimetypes = ['text/x-autohotkey']
@@ -2353,7 +2353,7 @@ class ProtoBufLexer(RegexLexer):
"""
name = 'Protocol Buffer'
- aliases = ['protobuf']
+ aliases = ['protobuf', 'proto']
filenames = ['*.proto']
tokens = {
diff --git a/pygments/lexers/shell.py b/pygments/lexers/shell.py
index d117fd86..78c5c996 100644
--- a/pygments/lexers/shell.py
+++ b/pygments/lexers/shell.py
@@ -67,9 +67,11 @@ class BashLexer(RegexLexer):
'data': [
(r'(?s)\$?"(\\\\|\\[0-7]+|\\.|[^"\\])*"', String.Double),
(r"(?s)\$?'(\\\\|\\[0-7]+|\\.|[^'\\])*'", String.Single),
- (r';', Text),
+ (r';', Punctuation),
+ (r'&', Punctuation),
+ (r'\|', Punctuation),
(r'\s+', Text),
- (r'[^=\s\[\]{}()$"\'`\\<]+', Text),
+ (r'[^=\s\[\]{}()$"\'`\\<&|;]+', Text),
(r'\d+(?= |\Z)', Number),
(r'\$#?(\w+|.)', Name.Variable),
(r'<', Text),
@@ -206,7 +208,7 @@ class BatchLexer(RegexLexer):
*New in Pygments 0.7.*
"""
name = 'Batchfile'
- aliases = ['bat']
+ aliases = ['bat', 'dosbatch', 'winbatch']
filenames = ['*.bat', '*.cmd']
mimetypes = ['application/x-dos-batch']
@@ -370,8 +372,7 @@ class PowerShellLexer(RegexLexer):
'root': [
# we need to count pairs of parentheses for correct highlight
# of '$(...)' blocks in strings
- (r'\(', Punctuation, '#push'),
- (r'\)', Punctuation, '#pop'),
+ (r'\(', Punctuation, 'child'),
(r'\s+', Text),
(r'^(\s*#[#\s]*)(\.(?:%s))([^\n]*$)' % '|'.join(commenthelp),
bygroups(Comment, String.Doc, Comment)),
@@ -393,6 +394,10 @@ class PowerShellLexer(RegexLexer):
(r'\w+', Name),
(r'[.,;@{}\[\]$()=+*/\\&%!~?^`|<>-]|::', Punctuation),
],
+ 'child': [
+ (r'\)', Punctuation, '#pop'),
+ include('root'),
+ ],
'multline': [
(r'[^#&.]+', Comment.Multiline),
(r'#(>|&gt;)', Comment.Multiline, '#pop'),
@@ -402,14 +407,14 @@ class PowerShellLexer(RegexLexer):
'string': [
(r"`[0abfnrtv'\"\$]", String.Escape),
(r'[^$`"]+', String.Double),
- (r'\$\(', Punctuation, 'root'),
+ (r'\$\(', Punctuation, 'child'),
(r'""', String.Double),
(r'[`$]', String.Double),
(r'"', String.Double, '#pop'),
],
'heredoc-double': [
(r'\n"@', String.Heredoc, '#pop'),
- (r'\$\(', Punctuation, 'root'),
+ (r'\$\(', Punctuation, 'child'),
(r'[^@\n]+"]', String.Heredoc),
(r".", String.Heredoc),
]
diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py
index ff4a0453..63fc5f37 100644
--- a/pygments/lexers/templates.py
+++ b/pygments/lexers/templates.py
@@ -766,7 +766,7 @@ class CheetahHtmlLexer(DelegatingLexer):
"""
name = 'HTML+Cheetah'
- aliases = ['html+cheetah', 'html+spitfire']
+ aliases = ['html+cheetah', 'html+spitfire', 'htmlcheetah']
mimetypes = ['text/html+cheetah', 'text/html+spitfire']
def __init__(self, **options):
@@ -1258,7 +1258,7 @@ class HtmlDjangoLexer(DelegatingLexer):
"""
name = 'HTML+Django/Jinja'
- aliases = ['html+django', 'html+jinja']
+ aliases = ['html+django', 'html+jinja', 'htmldjango']
alias_filenames = ['*.html', '*.htm', '*.xhtml']
mimetypes = ['text/html+django', 'text/html+jinja']
diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py
index b47c49d2..f3feec83 100644
--- a/pygments/lexers/text.py
+++ b/pygments/lexers/text.py
@@ -25,7 +25,7 @@ __all__ = ['IniLexer', 'PropertiesLexer', 'SourcesListLexer', 'BaseMakefileLexer
'RstLexer', 'VimLexer', 'GettextLexer', 'SquidConfLexer',
'DebianControlLexer', 'DarcsPatchLexer', 'YamlLexer',
'LighttpdConfLexer', 'NginxConfLexer', 'CMakeLexer', 'HttpLexer',
- 'PyPyLogLexer', 'RegeditLexer', 'HxmlLexer']
+ 'PyPyLogLexer', 'RegeditLexer', 'HxmlLexer', 'EbnfLexer']
class IniLexer(RegexLexer):
@@ -34,7 +34,7 @@ class IniLexer(RegexLexer):
"""
name = 'INI'
- aliases = ['ini', 'cfg']
+ aliases = ['ini', 'cfg', 'dosini']
filenames = ['*.ini', '*.cfg']
mimetypes = ['text/x-ini']
@@ -106,7 +106,7 @@ class PropertiesLexer(RegexLexer):
"""
name = 'Properties'
- aliases = ['properties']
+ aliases = ['properties', 'jproperties']
filenames = ['*.properties']
mimetypes = ['text/x-java-properties']
@@ -128,7 +128,7 @@ class SourcesListLexer(RegexLexer):
"""
name = 'Debian Sourcelist'
- aliases = ['sourceslist', 'sources.list']
+ aliases = ['sourceslist', 'sources.list', 'debsources']
filenames = ['sources.list']
mimetype = ['application/x-debian-sourceslist']
@@ -1053,7 +1053,7 @@ class DebianControlLexer(RegexLexer):
*New in Pygments 0.9.*
"""
name = 'Debian Control file'
- aliases = ['control']
+ aliases = ['control', 'debcontrol']
filenames = ['control']
tokens = {
@@ -1841,3 +1841,53 @@ class HxmlLexer(RegexLexer):
(r'#.*', Comment.Single)
]
}
+
+
+class EbnfLexer(RegexLexer):
+ """
+ Lexer for `ISO/IEC 14977 EBNF
+ <http://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_Form>`_
+ grammars.
+
+ *New in Pygments 1.7.*
+ """
+
+ name = 'EBNF'
+ aliases = ['ebnf']
+ filenames = ['*.ebnf']
+ mimetypes = ['text/x-ebnf']
+
+ tokens = {
+ 'root': [
+ include('whitespace'),
+ include('comment_start'),
+ include('identifier'),
+ (r'=', Operator, 'production'),
+ ],
+ 'production': [
+ include('whitespace'),
+ include('comment_start'),
+ include('identifier'),
+ (r'"[^"]*"', String.Double),
+ (r"'[^']*'", String.Single),
+ (r'(\?[^?]*\?)', Name.Entity),
+ (r'[\[\]{}(),|]', Punctuation),
+ (r'-', Operator),
+ (r';', Punctuation, '#pop'),
+ ],
+ 'whitespace': [
+ (r'\s+', Text),
+ ],
+ 'comment_start': [
+ (r'\(\*', Comment.Multiline, 'comment'),
+ ],
+ 'comment': [
+ (r'[^*)]', Comment.Multiline),
+ include('comment_start'),
+ (r'\*\)', Comment.Multiline, '#pop'),
+ (r'[*)]', Comment.Multiline),
+ ],
+ 'identifier': [
+ (r'([a-zA-Z][a-zA-Z0-9 \-]*)', Keyword),
+ ],
+ }
diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py
index 383bf6ad..7d2c812a 100644
--- a/pygments/lexers/web.py
+++ b/pygments/lexers/web.py
@@ -1125,227 +1125,840 @@ class MxmlLexer(RegexLexer):
}
-class HaxeLexer(RegexLexer):
+class HaxeLexer(ExtendedRegexLexer):
"""
- For haXe source code (http://haxe.org/).
+ For Haxe source code (http://haxe.org/).
*New in Pygments 1.3.*
"""
- name = 'haXe'
- aliases = ['hx', 'haXe']
- filenames = ['*.hx']
- mimetypes = ['text/haxe']
+ name = 'Haxe'
+ aliases = ['hx', 'Haxe', 'haxe', 'haXe', 'hxsl']
+ filenames = ['*.hx', '*.hxsl']
+ mimetypes = ['text/haxe', 'text/x-haxe', 'text/x-hx']
- ident = r'(?:[a-zA-Z_][a-zA-Z0-9_]*)'
- typeid = r'(?:(?:[a-z0-9_\.])*[A-Z_][A-Za-z0-9_]*)'
- key_prop = r'(?:default|null|never)'
- key_decl_mod = r'(?:public|private|override|static|inline|extern|dynamic)'
+ # keywords extracted from lexer.mll in the haxe compiler source
+ keyword = (r'(?:function|class|static|var|if|else|while|do|for|'
+ r'break|return|continue|extends|implements|import|'
+ r'switch|case|default|public|private|try|untyped|'
+ r'catch|new|this|throw|extern|enum|in|interface|'
+ r'cast|override|dynamic|typedef|package|'
+ r'inline|using|null|true|false|abstract)\b')
+
+ # idtype in lexer.mll
+ typeid = r'_*[A-Z][_a-zA-Z0-9]*'
+
+ # combined ident and dollar and idtype
+ ident = r'(?:_*[a-z][_a-zA-Z0-9]*|_+[0-9][_a-zA-Z0-9]*|' + typeid + \
+ '|_+|\$[_a-zA-Z0-9]+)'
+
+ binop = (r'(?:%=|&=|\|=|\^=|\+=|\-=|\*=|/=|<<=|>\s*>\s*=|>\s*>\s*>\s*=|==|'
+ r'!=|<=|>\s*=|&&|\|\||<<|>>>|>\s*>|\.\.\.|<|>|%|&|\||\^|\+|\*|'
+ r'/|\-|=>|=)')
+
+ # ident except keywords
+ ident_no_keyword = r'(?!' + keyword + ')' + ident
flags = re.DOTALL | re.MULTILINE
+ preproc_stack = []
+
+ def preproc_callback(self, match, ctx):
+ proc = match.group(2)
+
+ if proc == 'if':
+ # store the current stack
+ self.preproc_stack.append(ctx.stack[:])
+ elif proc in ['else', 'elseif']:
+ # restore the stack back to right before #if
+ if self.preproc_stack: ctx.stack = self.preproc_stack[-1][:]
+ elif proc == 'end':
+ # remove the saved stack of previous #if
+ if self.preproc_stack: self.preproc_stack.pop()
+
+ # #if and #elseif should follow by an expr
+ if proc in ['if', 'elseif']:
+ ctx.stack.append('preproc-expr')
+
+ # #error can be optionally follow by the error msg
+ if proc in ['error']:
+ ctx.stack.append('preproc-error')
+
+ yield match.start(), Comment.Preproc, '#' + proc
+ ctx.pos = match.end()
+
+
tokens = {
'root': [
- include('whitespace'),
- include('comments'),
- (key_decl_mod, Keyword.Declaration),
- include('enumdef'),
- include('typedef'),
- include('classdef'),
- include('imports'),
+ include('spaces'),
+ include('meta'),
+ (r'(?:package)\b', Keyword.Namespace, ('semicolon', 'package')),
+ (r'(?:import)\b', Keyword.Namespace, ('semicolon', 'import')),
+ (r'(?:using)\b', Keyword.Namespace, ('semicolon', 'using')),
+ (r'(?:extern|private)\b', Keyword.Declaration),
+ (r'(?:abstract)\b', Keyword.Declaration, 'abstract'),
+ (r'(?:class|interface)\b', Keyword.Declaration, 'class'),
+ (r'(?:enum)\b', Keyword.Declaration, 'enum'),
+ (r'(?:typedef)\b', Keyword.Declaration, 'typedef'),
+
+ # top-level expression
+ # although it is not supported in haxe, but it is common to write
+ # expression in web pages the positive lookahead here is to prevent
+ # an infinite loop at the EOF
+ (r'(?=.)', Text, 'expr-statement'),
+ ],
+
+ # space/tab/comment/preproc
+ 'spaces': [
+ (r'\s+', Text),
+ (r'//[^\n\r]*', Comment.Single),
+ (r'/\*.*?\*/', Comment.Multiline),
+ (r'(#)(if|elseif|else|end|error)\b', preproc_callback),
],
- # General constructs
- 'comments': [
- (r'//.*?\n', Comment.Single),
- (r'/\*.*?\*/', Comment.Multiline),
- (r'#[^\n]*', Comment.Preproc),
+ 'string-single-interpol': [
+ (r'\$\{', String.Interpol, ('string-interpol-close', 'expr')),
+ (r'\$\$', String.Escape),
+ (r'\$(?=' + ident + ')', String.Interpol, 'ident'),
+ include('string-single'),
],
- 'whitespace': [
- include('comments'),
- (r'\s+', Text),
+
+ 'string-single': [
+ (r"'", String.Single, '#pop'),
+ (r'\\.', String.Escape),
+ (r'.', String.Single),
],
- 'codekeywords': [
- (r'\b(if|else|while|do|for|in|break|continue|'
- r'return|switch|case|try|catch|throw|null|trace|'
- r'new|this|super|untyped|cast|callback|here)\b',
- Keyword.Reserved),
+
+ 'string-double': [
+ (r'"', String.Double, '#pop'),
+ (r'\\.', String.Escape),
+ (r'.', String.Double),
],
- 'literals': [
- (r'0[xX][0-9a-fA-F]+', Number.Hex),
- (r'[0-9]+', Number.Integer),
- (r'[0-9][0-9]*\.[0-9]+([eE][0-9]+)?[fd]?', Number.Float),
- (r"'(\\\\|\\'|[^'])*'", String.Single),
- (r'"(\\\\|\\"|[^"])*"', String.Double),
- (r'~/([^\n])*?/[gisx]*', String.Regex),
- (r'\b(true|false|null)\b', Keyword.Constant),
- ],
- 'codeblock': [
- include('whitespace'),
- include('new'),
- include('case'),
- include('anonfundef'),
- include('literals'),
- include('vardef'),
- include('codekeywords'),
- (r'[();,\[\]]', Punctuation),
- (r'(?:=|\+=|-=|\*=|/=|%=|&=|\|=|\^=|<<=|>>=|>>>=|\|\||&&|'
- r'\.\.\.|==|!=|>|<|>=|<=|\||&|\^|<<|>>>|>>|\+|\-|\*|/|%|'
- r'!|\+\+|\-\-|~|\.|\?|\:)',
- Operator),
- (ident, Name),
-
- (r'}', Punctuation,'#pop'),
- (r'{', Punctuation,'#push'),
- ],
-
- # Instance/Block level constructs
- 'propertydef': [
- (r'(\()(' + key_prop + ')(,)(' + key_prop + ')(\))',
- bygroups(Punctuation, Keyword.Reserved, Punctuation,
- Keyword.Reserved, Punctuation)),
+
+ 'string-interpol-close': [
+ (r'\$'+ident, String.Interpol),
+ (r'\}', String.Interpol, '#pop'),
],
- 'new': [
- (r'\bnew\b', Keyword, 'typedecl'),
+
+ 'package': [
+ include('spaces'),
+ (ident, Name.Namespace),
+ (r'\.', Punctuation, 'import-ident'),
+ (r'', Text, '#pop'),
],
- 'case': [
- (r'\b(case)(\s+)(' + ident + ')(\s*)(\()',
- bygroups(Keyword.Reserved, Text, Name, Text, Punctuation),
- 'funargdecl'),
+
+ 'import': [
+ include('spaces'),
+ (ident, Name.Namespace),
+ (r'\*', Keyword), # wildcard import
+ (r'\.', Punctuation, 'import-ident'),
+ (r'in', Keyword.Namespace, 'ident'),
+ (r'', Text, '#pop'),
],
- 'vardef': [
- (r'\b(var)(\s+)(' + ident + ')',
- bygroups(Keyword.Declaration, Text, Name.Variable), 'vardecl'),
+
+ 'import-ident': [
+ include('spaces'),
+ (r'\*', Keyword, '#pop'), # wildcard import
+ (ident, Name.Namespace, '#pop'),
],
- 'vardecl': [
- include('whitespace'),
- include('typelabel'),
- (r'=', Operator,'#pop'),
- (r';', Punctuation,'#pop'),
+
+ 'using': [
+ include('spaces'),
+ (ident, Name.Namespace),
+ (r'\.', Punctuation, 'import-ident'),
+ (r'', Text, '#pop'),
],
- 'instancevardef': [
- (key_decl_mod,Keyword.Declaration),
- (r'\b(var)(\s+)(' + ident + ')',
- bygroups(Keyword.Declaration, Text, Name.Variable.Instance),
- 'instancevardecl'),
+
+ 'preproc-error': [
+ (r'\s+', Comment.Preproc),
+ (r"'", String.Single, ('#pop', 'string-single')),
+ (r'"', String.Double, ('#pop', 'string-double')),
+ (r'', Text, '#pop'),
],
- 'instancevardecl': [
- include('vardecl'),
- include('propertydef'),
+
+ 'preproc-expr': [
+ (r'\s+', Comment.Preproc),
+ (r'\!', Comment.Preproc),
+ (r'\(', Comment.Preproc, ('#pop', 'preproc-parenthesis')),
+
+ (ident, Comment.Preproc, '#pop'),
+ (r"'", String.Single, ('#pop', 'string-single')),
+ (r'"', String.Double, ('#pop', 'string-double')),
],
- 'anonfundef': [
- (r'\bfunction\b', Keyword.Declaration, 'fundecl'),
+ 'preproc-parenthesis': [
+ (r'\s+', Comment.Preproc),
+ (r'\)', Comment.Preproc, '#pop'),
+ ('', Text, 'preproc-expr-in-parenthesis'),
],
- 'instancefundef': [
- (key_decl_mod, Keyword.Declaration),
- (r'\b(function)(\s+)(' + ident + ')',
- bygroups(Keyword.Declaration, Text, Name.Function), 'fundecl'),
+
+ 'preproc-expr-chain': [
+ (r'\s+', Comment.Preproc),
+ (binop, Comment.Preproc, ('#pop', 'preproc-expr-in-parenthesis')),
+ (r'', Text, '#pop'),
],
- 'fundecl': [
- include('whitespace'),
- include('typelabel'),
- include('generictypedecl'),
- (r'\(',Punctuation,'funargdecl'),
- (r'(?=[a-zA-Z0-9_])',Text,'#pop'),
- (r'{',Punctuation,('#pop','codeblock')),
- (r';',Punctuation,'#pop'),
- ],
- 'funargdecl': [
- include('whitespace'),
- (ident, Name.Variable),
- include('typelabel'),
- include('literals'),
- (r'=', Operator),
+
+ # same as 'preproc-expr' but able to chain 'preproc-expr-chain'
+ 'preproc-expr-in-parenthesis': [
+ (r'\s+', Comment.Preproc),
+ (r'\!', Comment.Preproc),
+ (r'\(', Comment.Preproc,
+ ('#pop', 'preproc-expr-chain', 'preproc-parenthesis')),
+
+ (ident, Comment.Preproc, ('#pop', 'preproc-expr-chain')),
+ (r"'", String.Single,
+ ('#pop', 'preproc-expr-chain', 'string-single')),
+ (r'"', String.Double,
+ ('#pop', 'preproc-expr-chain', 'string-double')),
+ ],
+
+ 'abstract' : [
+ include('spaces'),
+ (r'', Text, ('#pop', 'abstract-body', 'abstract-relation',
+ 'abstract-opaque', 'type-param-constraint', 'type-name')),
+ ],
+
+ 'abstract-body' : [
+ include('spaces'),
+ (r'\{', Punctuation, ('#pop', 'class-body')),
+ ],
+
+ 'abstract-opaque' : [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close', 'type')),
+ (r'', Text, '#pop'),
+ ],
+
+ 'abstract-relation': [
+ include('spaces'),
+ (r'(?:to|from)', Keyword.Declaration, 'type'),
(r',', Punctuation),
+ (r'', Text, '#pop'),
+ ],
+
+ 'meta': [
+ include('spaces'),
+ (r'@', Name.Decorator, ('meta-body', 'meta-ident', 'meta-colon')),
+ ],
+
+ # optional colon
+ 'meta-colon': [
+ include('spaces'),
+ (r':', Name.Decorator, '#pop'),
+ (r'', Text, '#pop'),
+ ],
+
+ # same as 'ident' but set token as Name.Decorator instead of Name
+ 'meta-ident': [
+ include('spaces'),
+ (ident, Name.Decorator, '#pop'),
+ ],
+
+ 'meta-body': [
+ include('spaces'),
+ (r'\(', Name.Decorator, ('#pop', 'meta-call')),
+ (r'', Text, '#pop'),
+ ],
+
+ 'meta-call': [
+ include('spaces'),
+ (r'\)', Name.Decorator, '#pop'),
+ (r'', Text, ('#pop', 'meta-call-sep', 'expr')),
+ ],
+
+ 'meta-call-sep': [
+ include('spaces'),
+ (r'\)', Name.Decorator, '#pop'),
+ (r',', Punctuation, ('#pop', 'meta-call')),
+ ],
+
+ 'typedef': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'typedef-body', 'type-param-constraint',
+ 'type-name')),
+ ],
+
+ 'typedef-body': [
+ include('spaces'),
+ (r'=', Operator, ('#pop', 'optional-semicolon', 'type')),
+ ],
+
+ 'enum': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'enum-body', 'bracket-open',
+ 'type-param-constraint', 'type-name')),
+ ],
+
+ 'enum-body': [
+ include('spaces'),
+ include('meta'),
+ (r'\}', Punctuation, '#pop'),
+ (ident_no_keyword, Name, ('enum-member', 'type-param-constraint')),
+ ],
+
+ 'enum-member': [
+ include('spaces'),
+ (r'\(', Punctuation,
+ ('#pop', 'semicolon', 'flag', 'function-param')),
+ (r'', Punctuation, ('#pop', 'semicolon', 'flag')),
+ ],
+
+ 'class': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'class-body', 'bracket-open', 'extends',
+ 'type-param-constraint', 'type-name')),
+ ],
+
+ 'extends': [
+ include('spaces'),
+ (r'(?:extends|implements)\b', Keyword.Declaration, 'type'),
+ (r',', Punctuation), # the comma is made optional here, since haxe2
+ # requires the comma but haxe3 does not allow it
+ (r'', Text, '#pop'),
+ ],
+
+ 'bracket-open': [
+ include('spaces'),
+ (r'\{', Punctuation, '#pop'),
+ ],
+
+ 'bracket-close': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ ],
+
+ 'class-body': [
+ include('spaces'),
+ include('meta'),
+ (r'\}', Punctuation, '#pop'),
+ (r'(?:static|public|private|override|dynamic|inline|macro)\b',
+ Keyword.Declaration),
+ (r'', Text, 'class-member'),
+ ],
+
+ 'class-member': [
+ include('spaces'),
+ (r'(var)\b', Keyword.Declaration,
+ ('#pop', 'optional-semicolon', 'prop')),
+ (r'(function)\b', Keyword.Declaration,
+ ('#pop', 'optional-semicolon', 'class-method')),
+ ],
+
+ # local function, anonymous or not
+ 'function-local': [
+ include('spaces'),
+ (r'(' + ident_no_keyword + ')?', Name.Function,
+ ('#pop', 'expr', 'flag', 'function-param',
+ 'parenthesis-open', 'type-param-constraint')),
+ ],
+
+ 'optional-expr': [
+ include('spaces'),
+ include('expr'),
+ (r'', Text, '#pop'),
+ ],
+
+ 'class-method': [
+ include('spaces'),
+ (ident, Name.Function, ('#pop', 'optional-expr', 'flag',
+ 'function-param', 'parenthesis-open',
+ 'type-param-constraint')),
+ ],
+
+ # function arguments
+ 'function-param': [
+ include('spaces'),
+ (r'\)', Punctuation, '#pop'),
(r'\?', Punctuation),
+ (ident_no_keyword, Name,
+ ('#pop', 'function-param-sep', 'assign', 'flag')),
+ ],
+
+ 'function-param-sep': [
+ include('spaces'),
(r'\)', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'function-param')),
],
- 'typelabel': [
- (r':', Punctuation, 'type'),
+ # class property
+ # eg. var prop(default, null):String;
+ 'prop': [
+ include('spaces'),
+ (ident_no_keyword, Name, ('#pop', 'assign', 'flag', 'prop-get-set')),
],
- 'typedecl': [
- include('whitespace'),
- (typeid, Name.Class),
- (r'<', Punctuation, 'generictypedecl'),
- (r'(?=[{}()=,a-z])', Text,'#pop'),
+
+ 'prop-get-set': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close',
+ 'prop-get-set-opt', 'comma', 'prop-get-set-opt')),
+ (r'', Text, '#pop'),
],
+
+ 'prop-get-set-opt': [
+ include('spaces'),
+ (r'(?:default|null|never|dynamic|get|set)\b', Keyword, '#pop'),
+ (ident_no_keyword, Text, '#pop'), #custom getter/setter
+ ],
+
+ 'expr-statement': [
+ include('spaces'),
+ # makes semicolon optional here, just to avoid checking the last
+ # one is bracket or not.
+ (r'', Text, ('#pop', 'optional-semicolon', 'expr')),
+ ],
+
+ 'expr': [
+ include('spaces'),
+ (r'@', Name.Decorator, ('#pop', 'optional-expr', 'meta-body',
+ 'meta-ident', 'meta-colon')),
+ (r'(?:\+\+|\-\-|~(?!/)|!|\-)', Operator),
+ (r'\(', Punctuation, ('#pop', 'expr-chain', 'parenthesis')),
+ (r'(?:inline)\b', Keyword.Declaration),
+ (r'(?:function)\b', Keyword.Declaration, ('#pop', 'expr-chain',
+ 'function-local')),
+ (r'\{', Punctuation, ('#pop', 'expr-chain', 'bracket')),
+ (r'(?:true|false|null)\b', Keyword.Constant, ('#pop', 'expr-chain')),
+ (r'(?:this)\b', Keyword, ('#pop', 'expr-chain')),
+ (r'(?:cast)\b', Keyword, ('#pop', 'expr-chain', 'cast')),
+ (r'(?:try)\b', Keyword, ('#pop', 'catch', 'expr')),
+ (r'(?:var)\b', Keyword.Declaration, ('#pop', 'var')),
+ (r'(?:new)\b', Keyword, ('#pop', 'expr-chain', 'new')),
+ (r'(?:switch)\b', Keyword, ('#pop', 'switch')),
+ (r'(?:if)\b', Keyword, ('#pop', 'if')),
+ (r'(?:do)\b', Keyword, ('#pop', 'do')),
+ (r'(?:while)\b', Keyword, ('#pop', 'while')),
+ (r'(?:for)\b', Keyword, ('#pop', 'for')),
+ (r'(?:untyped|throw)\b', Keyword),
+ (r'(?:return)\b', Keyword, ('#pop', 'optional-expr')),
+ (r'(?:macro)\b', Keyword, ('#pop', 'macro')),
+ (r'(?:continue|break)\b', Keyword, '#pop'),
+ (r'(?:\$\s*[a-z]\b|\$(?!'+ident+'))', Name, ('#pop', 'dollar')),
+ (ident_no_keyword, Name, ('#pop', 'expr-chain')),
+
+ # Float
+ (r'\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
+ (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
+ (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, ('#pop', 'expr-chain')),
+ (r'[0-9]+\.[0-9]+', Number.Float, ('#pop', 'expr-chain')),
+ (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, ('#pop', 'expr-chain')),
+
+ # Int
+ (r'0x[0-9a-fA-F]+', Number.Hex, ('#pop', 'expr-chain')),
+ (r'[0-9]+', Number.Integer, ('#pop', 'expr-chain')),
+
+ # String
+ (r"'", String.Single, ('#pop', 'expr-chain', 'string-single-interpol')),
+ (r'"', String.Double, ('#pop', 'expr-chain', 'string-double')),
+
+ # EReg
+ (r'~/(\\\\|\\/|[^/\n])*/[gimsu]*', String.Regex, ('#pop', 'expr-chain')),
+
+ # Array
+ (r'\[', Punctuation, ('#pop', 'expr-chain', 'array-decl')),
+ ],
+
+ 'expr-chain': [
+ include('spaces'),
+ (r'(?:\+\+|\-\-)', Operator),
+ (binop, Operator, ('#pop', 'expr')),
+ (r'(?:in)\b', Keyword, ('#pop', 'expr')),
+ (r'\?', Operator, ('#pop', 'expr', 'ternary', 'expr')),
+ (r'(\.)(' + ident_no_keyword + ')', bygroups(Punctuation, Name)),
+ (r'\[', Punctuation, 'array-access'),
+ (r'\(', Punctuation, 'call'),
+ (r'', Text, '#pop'),
+ ],
+
+ # macro reification
+ 'macro': [
+ include('spaces'),
+ (r':', Punctuation, ('#pop', 'type')),
+ (r'', Text, ('#pop', 'expr')),
+ ],
+
+ # cast can be written as "cast expr" or "cast(expr, type)"
+ 'cast': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'parenthesis-close',
+ 'cast-type', 'expr')),
+ (r'', Text, ('#pop', 'expr')),
+ ],
+
+ # optionally give a type as the 2nd argument of cast()
+ 'cast-type': [
+ include('spaces'),
+ (r',', Punctuation, ('#pop', 'type')),
+ (r'', Text, '#pop'),
+ ],
+
+ 'catch': [
+ include('spaces'),
+ (r'(?:catch)\b', Keyword, ('expr', 'function-param',
+ 'parenthesis-open')),
+ (r'', Text, '#pop'),
+ ],
+
+ # do-while loop
+ 'do': [
+ include('spaces'),
+ (r'', Punctuation, ('#pop', 'do-while', 'expr')),
+ ],
+
+ # the while after do
+ 'do-while': [
+ include('spaces'),
+ (r'(?:while)\b', Keyword, ('#pop', 'parenthesis',
+ 'parenthesis-open')),
+ ],
+
+ 'while': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
+ ],
+
+ 'for': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'expr', 'parenthesis')),
+ ],
+
+ 'if': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'else', 'optional-semicolon', 'expr',
+ 'parenthesis')),
+ ],
+
+ 'else': [
+ include('spaces'),
+ (r'(?:else)\b', Keyword, ('#pop', 'expr')),
+ (r'', Text, '#pop'),
+ ],
+
+ 'switch': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'switch-body', 'bracket-open', 'expr')),
+ ],
+
+ 'switch-body': [
+ include('spaces'),
+ (r'(?:case|default)\b', Keyword, ('case-block', 'case')),
+ (r'\}', Punctuation, '#pop'),
+ ],
+
+ 'case': [
+ include('spaces'),
+ (r':', Punctuation, '#pop'),
+ (r'', Text, ('#pop', 'case-sep', 'case-guard', 'expr')),
+ ],
+
+ 'case-sep': [
+ include('spaces'),
+ (r':', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'case')),
+ ],
+
+ 'case-guard': [
+ include('spaces'),
+ (r'(?:if)\b', Keyword, ('#pop', 'parenthesis', 'parenthesis-open')),
+ (r'', Text, '#pop'),
+ ],
+
+ # optional multiple expr under a case
+ 'case-block': [
+ include('spaces'),
+ (r'(?!(?:case|default)\b|\})', Keyword, 'expr-statement'),
+ (r'', Text, '#pop'),
+ ],
+
+ 'new': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'call', 'parenthesis-open', 'type')),
+ ],
+
+ 'array-decl': [
+ include('spaces'),
+ (r'\]', Punctuation, '#pop'),
+ (r'', Text, ('#pop', 'array-decl-sep', 'expr')),
+ ],
+
+ 'array-decl-sep': [
+ include('spaces'),
+ (r'\]', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'array-decl')),
+ ],
+
+ 'array-access': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'array-access-close', 'expr')),
+ ],
+
+ 'array-access-close': [
+ include('spaces'),
+ (r'\]', Punctuation, '#pop'),
+ ],
+
+ 'comma': [
+ include('spaces'),
+ (r',', Punctuation, '#pop'),
+ ],
+
+ 'colon': [
+ include('spaces'),
+ (r':', Punctuation, '#pop'),
+ ],
+
+ 'semicolon': [
+ include('spaces'),
+ (r';', Punctuation, '#pop'),
+ ],
+
+ 'optional-semicolon': [
+ include('spaces'),
+ (r';', Punctuation, '#pop'),
+ (r'', Text, '#pop'),
+ ],
+
+ # identity that CAN be a Haxe keyword
+ 'ident': [
+ include('spaces'),
+ (ident, Name, '#pop'),
+ ],
+
+ 'dollar': [
+ include('spaces'),
+ (r'\{', Keyword, ('#pop', 'bracket-close', 'expr')),
+ (r'', Text, ('#pop', 'expr-chain')),
+ ],
+
+ 'type-name': [
+ include('spaces'),
+ (typeid, Name, '#pop'),
+ ],
+
+ 'type-full-name': [
+ include('spaces'),
+ (r'\.', Punctuation, 'ident'),
+ (r'', Text, '#pop'),
+ ],
+
'type': [
- include('whitespace'),
- (typeid, Name.Class),
- (r'<', Punctuation, 'generictypedecl'),
- (r'->', Keyword.Type),
- (r'(?=[{}(),;=])', Text, '#pop'),
+ include('spaces'),
+ (r'\?', Punctuation),
+ (ident, Name, ('#pop', 'type-check', 'type-full-name')),
+ (r'\{', Punctuation, ('#pop', 'type-check', 'type-struct')),
+ (r'\(', Punctuation, ('#pop', 'type-check', 'type-parenthesis')),
],
- 'generictypedecl': [
- include('whitespace'),
- (typeid, Name.Class),
- (r'<', Punctuation, '#push'),
+
+ 'type-parenthesis': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'parenthesis-close', 'type')),
+ ],
+
+ 'type-check': [
+ include('spaces'),
+ (r'->', Punctuation, ('#pop', 'type')),
+ (r'<(?!=)', Punctuation, 'type-param'),
+ (r'', Text, '#pop'),
+ ],
+
+ 'type-struct': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ (r'\?', Punctuation),
+ (r'>', Punctuation, ('comma', 'type')),
+ (ident_no_keyword, Name, ('#pop', 'type-struct-sep', 'type', 'colon')),
+ include('class-body'),
+ ],
+
+ 'type-struct-sep': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'type-struct')),
+ ],
+
+ # type-param can be a normal type or a constant literal...
+ 'type-param-type': [
+ # Float
+ (r'\.[0-9]+', Number.Float, '#pop'),
+ (r'[0-9]+[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
+ (r'[0-9]+\.[0-9]*[eE][\+\-]?[0-9]+', Number.Float, '#pop'),
+ (r'[0-9]+\.[0-9]+', Number.Float, '#pop'),
+ (r'[0-9]+\.(?!' + ident + '|\.\.)', Number.Float, '#pop'),
+
+ # Int
+ (r'0x[0-9a-fA-F]+', Number.Hex, '#pop'),
+ (r'[0-9]+', Number.Integer, '#pop'),
+
+ # String
+ (r"'", String.Single, ('#pop', 'string-single')),
+ (r'"', String.Double, ('#pop', 'string-double')),
+
+ # EReg
+ (r'~/(\\\\|\\/|[^/\n])*/[gim]*', String.Regex, '#pop'),
+
+ # Array
+ (r'\[', Operator, ('#pop', 'array-decl')),
+
+ include('type'),
+ ],
+
+ # type-param part of a type
+ # ie. the <A,B> path in Map<A,B>
+ 'type-param': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'type-param-sep', 'type-param-type')),
+ ],
+
+ 'type-param-sep': [
+ include('spaces'),
(r'>', Punctuation, '#pop'),
- (r',', Punctuation),
+ (r',', Punctuation, ('#pop', 'type-param')),
],
- # Top level constructs
- 'imports': [
- (r'(package|import|using)(\s+)([^;]+)(;)',
- bygroups(Keyword.Namespace, Text, Name.Namespace,Punctuation)),
+ # optional type-param that may include constraint
+ # ie. <T:Constraint, T2:(ConstraintA,ConstraintB)>
+ 'type-param-constraint': [
+ include('spaces'),
+ (r'<(?!=)', Punctuation, ('#pop', 'type-param-constraint-sep',
+ 'type-param-constraint-flag', 'type-name')),
+ (r'', Text, '#pop'),
],
- 'typedef': [
- (r'typedef', Keyword.Declaration, ('typedefprebody', 'typedecl')),
+
+ 'type-param-constraint-sep': [
+ include('spaces'),
+ (r'>', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'type-param-constraint-sep',
+ 'type-param-constraint-flag', 'type-name')),
],
- 'typedefprebody': [
- include('whitespace'),
- (r'(=)(\s*)({)', bygroups(Punctuation, Text, Punctuation),
- ('#pop', 'typedefbody')),
+
+ # the optional constraint inside type-param
+ 'type-param-constraint-flag': [
+ include('spaces'),
+ (r':', Punctuation, ('#pop', 'type-param-constraint-flag-type')),
+ (r'', Text, '#pop'),
],
- 'enumdef': [
- (r'enum', Keyword.Declaration, ('enumdefprebody', 'typedecl')),
+
+ 'type-param-constraint-flag-type': [
+ include('spaces'),
+ (r'\(', Punctuation, ('#pop', 'type-param-constraint-flag-type-sep',
+ 'type')),
+ (r'', Text, ('#pop', 'type')),
],
- 'enumdefprebody': [
- include('whitespace'),
- (r'{', Punctuation, ('#pop','enumdefbody')),
+
+ 'type-param-constraint-flag-type-sep': [
+ include('spaces'),
+ (r'\)', Punctuation, '#pop'),
+ (r',', Punctuation, 'type'),
],
- 'classdef': [
- (r'class', Keyword.Declaration, ('classdefprebody', 'typedecl')),
+
+ # a parenthesis expr that contain exactly one expr
+ 'parenthesis': [
+ include('spaces'),
+ (r'', Text, ('#pop', 'parenthesis-close', 'expr')),
],
- 'classdefprebody': [
- include('whitespace'),
- (r'(extends|implements)', Keyword.Declaration,'typedecl'),
- (r'{', Punctuation, ('#pop', 'classdefbody')),
+
+ 'parenthesis-open': [
+ include('spaces'),
+ (r'\(', Punctuation, '#pop'),
],
- 'interfacedef': [
- (r'interface', Keyword.Declaration,
- ('interfacedefprebody', 'typedecl')),
+
+ 'parenthesis-close': [
+ include('spaces'),
+ (r'\)', Punctuation, '#pop'),
],
- 'interfacedefprebody': [
- include('whitespace'),
- (r'(extends)', Keyword.Declaration, 'typedecl'),
- (r'{', Punctuation, ('#pop', 'classdefbody')),
- ],
-
- 'typedefbody': [
- include('whitespace'),
- include('instancevardef'),
- include('instancefundef'),
- (r'>', Punctuation, 'typedecl'),
- (r',', Punctuation),
- (r'}', Punctuation, '#pop'),
- ],
- 'enumdefbody': [
- include('whitespace'),
- (ident, Name.Variable.Instance),
- (r'\(', Punctuation, 'funargdecl'),
- (r';', Punctuation),
- (r'}', Punctuation, '#pop'),
- ],
- 'classdefbody': [
- include('whitespace'),
- include('instancevardef'),
- include('instancefundef'),
- (r'}', Punctuation, '#pop'),
- include('codeblock'),
+
+ 'var': [
+ include('spaces'),
+ (ident_no_keyword, Text, ('#pop', 'var-sep', 'assign', 'flag')),
],
+
+ # optional more var decl.
+ 'var-sep': [
+ include('spaces'),
+ (r',', Punctuation, ('#pop', 'var')),
+ (r'', Text, '#pop'),
+ ],
+
+ # optional assignment
+ 'assign': [
+ include('spaces'),
+ (r'=', Operator, ('#pop', 'expr')),
+ (r'', Text, '#pop'),
+ ],
+
+ # optional type flag
+ 'flag': [
+ include('spaces'),
+ (r':', Punctuation, ('#pop', 'type')),
+ (r'', Text, '#pop'),
+ ],
+
+ # colon as part of a ternary operator (?:)
+ 'ternary': [
+ include('spaces'),
+ (r':', Operator, '#pop'),
+ ],
+
+ # function call
+ 'call': [
+ include('spaces'),
+ (r'\)', Punctuation, '#pop'),
+ (r'', Text, ('#pop', 'call-sep', 'expr')),
+ ],
+
+ # after a call param
+ 'call-sep': [
+ include('spaces'),
+ (r'\)', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'call')),
+ ],
+
+ # bracket can be block or object
+ 'bracket': [
+ include('spaces'),
+ (r'(?!(?:\$\s*[a-z]\b|\$(?!'+ident+')))' + ident_no_keyword, Name,
+ ('#pop', 'bracket-check')),
+ (r"'", String.Single, ('#pop', 'bracket-check', 'string-single')),
+ (r'"', String.Double, ('#pop', 'bracket-check', 'string-double')),
+ (r'', Text, ('#pop', 'block')),
+ ],
+
+ 'bracket-check': [
+ include('spaces'),
+ (r':', Punctuation, ('#pop', 'object-sep', 'expr')), #is object
+ (r'', Text, ('#pop', 'block', 'optional-semicolon', 'expr-chain')), #is block
+ ],
+
+ # code block
+ 'block': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ (r'', Text, 'expr-statement'),
+ ],
+
+ # object in key-value pairs
+ 'object': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ (r'', Text, ('#pop', 'object-sep', 'expr', 'colon', 'ident-or-string'))
+ ],
+
+ # a key of an object
+ 'ident-or-string': [
+ include('spaces'),
+ (ident_no_keyword, Name, '#pop'),
+ (r"'", String.Single, ('#pop', 'string-single')),
+ (r'"', String.Double, ('#pop', 'string-double')),
+ ],
+
+ # after a key-value pair in object
+ 'object-sep': [
+ include('spaces'),
+ (r'\}', Punctuation, '#pop'),
+ (r',', Punctuation, ('#pop', 'object')),
+ ],
+
+
+
}
def analyse_text(text):
@@ -1797,7 +2410,7 @@ class CoffeeScriptLexer(RegexLexer):
"""
name = 'CoffeeScript'
- aliases = ['coffee-script', 'coffeescript']
+ aliases = ['coffee-script', 'coffeescript', 'coffee']
filenames = ['*.coffee']
mimetypes = ['text/coffeescript']
diff --git a/pygments/modeline.py b/pygments/modeline.py
new file mode 100644
index 00000000..cba1cab2
--- /dev/null
+++ b/pygments/modeline.py
@@ -0,0 +1,40 @@
+# -*- coding: utf-8 -*-
+"""
+ pygments.modeline
+ ~~~~~~~~~~~~~~~~~
+
+ A simple modeline parser (based on pymodeline).
+
+ :copyright: Copyright 2006-2013 by the Pygments team, see AUTHORS.
+ :license: BSD, see LICENSE for details.
+"""
+
+import re
+
+__all__ = ['get_filetype_from_buffer']
+
+modeline_re = re.compile(r'''
+ (?: vi | vim | ex ) (?: [<=>]? \d* )? :
+ .* (?: ft | filetype | syn | syntax ) = ( [^:\s]+ )
+''', re.VERBOSE)
+
+def get_filetype_from_line(l):
+ m = modeline_re.search(l)
+ if m:
+ return m.group(1)
+
+def get_filetype_from_buffer(buf, max_lines=5):
+ """
+ Scan the buffer for modelines and return filetype if one is found.
+ """
+ lines = buf.splitlines()
+ for l in lines[-1:-max_lines-1:-1]:
+ ret = get_filetype_from_line(l)
+ if ret:
+ return ret
+ for l in lines[max_lines:0:-1]:
+ ret = get_filetype_from_line(l)
+ if ret:
+ return ret
+
+ return None
diff --git a/tests/examplefiles/example.hx b/tests/examplefiles/example.hx
new file mode 100644
index 00000000..fd93bb49
--- /dev/null
+++ b/tests/examplefiles/example.hx
@@ -0,0 +1,142 @@
+/**
+ * This is not really a valid Haxe file, but just an demo...
+ */
+
+package;
+package net.onthewings;
+
+import net.onthewings.Test;
+import net.onthewings.*;
+
+using Lambda;
+using net.onthewings.Test;
+
+#if flash8
+// Haxe code specific for flash player 8
+#elseif flash
+// Haxe code specific for flash platform (any version)
+#elseif js
+// Haxe code specific for javascript plaform
+#elseif neko
+// Haxe code specific for neko plaform
+#else
+// do something else
+ #error // will display an error "Not implemented on this platform"
+ #error "Custom error message" // will display an error "Custom error message"
+#end
+
+0; // Int
+-134; // Int
+0xFF00; // Int
+
+123.0; // Float
+.14179; // Float
+13e50; // Float
+-1e-99; // Float
+
+"hello"; // String
+"hello \"world\" !"; // String
+'hello "world" !'; // String
+
+true; // Bool
+false; // Bool
+
+null; // Unknown<0>
+
+~/[a-z]+/i; // EReg : regular expression
+
+var point = { "x" : 1, "y" : -5 };
+
+{
+ var x;
+ var y = 3;
+ var z : String;
+ var w : String = "";
+ var a, b : Bool, c : Int = 0;
+}
+
+//haxe3 pattern matching
+switch(e.expr) {
+ case EConst(CString(s)) if (StringTools.startsWith(s, "foo")):
+ "1";
+ case EConst(CString(s)) if (StringTools.startsWith(s, "bar")):
+ "2";
+ case EConst(CInt(i)) if (switch(Std.parseInt(i) * 2) { case 4: true; case _: false; }):
+ "3";
+ case EConst(_):
+ "4";
+ case _:
+ "5";
+}
+
+switch [true, 1, "foo"] {
+ case [true, 1, "foo"]: "0";
+ case [true, 1, _]: "1";
+ case _: "_";
+}
+
+
+class Test <T:Void->Void> {
+ private function new():Void {
+ inline function innerFun(a:Int, b:Int):Int {
+ return readOnlyField = a + b;
+ }
+
+ _innerFun(1, 2.3);
+ }
+
+ static public var instance(get,null):Test;
+ static function get_instance():Test {
+ return instance != null ? instance : instance = new Test();
+ }
+}
+
+@:native("Test") private class Test2 {}
+
+extern class Ext {}
+
+@:macro class M {
+ @:macro static function test(e:Array<Expr>):ExprOf<String> {
+ return macro "ok";
+ }
+}
+
+enum Color {
+ Red;
+ Green;
+ Blue;
+ Grey( v : Int );
+ Rgb( r : Int, g : Int, b : Int );
+ Alpha( a : Int, col : Color );
+}
+
+class Colors {
+ static function toInt( c : Color ) : Int {
+ return switch( c ) {
+ case Red: 0xFF0000;
+ case Green: 0x00FF00;
+ case Blue: 0x0000FF;
+ case Grey(v): (v << 16) | (v << 8) | v;
+ case Rgb(r,g,b): (r << 16) | (g << 8) | b;
+ case Alpha(a,c): (a << 24) | (toInt(c) & 0xFFFFFF);
+ }
+ }
+}
+
+class EvtQueue<T : (Event, EventDispatcher)> {
+ var evt : T;
+}
+
+typedef DS = Dynamic<String>;
+typedef Pt = {
+ var x:Float;
+ var y:Float;
+ @:optional var z:Float; /* optional z */
+ function add(pt:Pt):Void;
+}
+typedef Pt2 = {
+ x:Float,
+ y:Float,
+ ?z:Float, //optional z
+ add : Point -> Void,
+} \ No newline at end of file
diff --git a/tests/examplefiles/garcia-wachs.kk b/tests/examplefiles/garcia-wachs.kk
index f766e051..91a01fbe 100644
--- a/tests/examplefiles/garcia-wachs.kk
+++ b/tests/examplefiles/garcia-wachs.kk
@@ -1,9 +1,25 @@
-/* This is an example in the Koka Language of the Garcia-Wachs algorithm */
-module garcia-wachs
+// Koka language test module
-public fun main()
-{
- test().print
+// This module implements the GarsiaWachs algorithm.
+// It is an adaptation of the algorithm in ML as described by JeanChristophe Filli�tre:
+// in ''A functional implementation of the GarsiaWachs algorithm. (functional pearl). ML workshop 2008, pages 91--96''.
+// See: http://www.lri.fr/~filliatr/publis/gwWml08.pdf
+//
+// The algorithm is interesting since it uses mutable references shared between a list and tree but the
+// side effects are not observable from outside. Koka automatically infers that the final algorithm is pure.
+// Note: due to a current limitation in the divergence analysis, koka cannot yet infer that mutually recursive
+// definitions in "insert" and "extract" are terminating and the final algorithm still has a divergence effect.
+// However, koka does infer that no other effect (i.e. an exception due to a partial match) can occur.
+module garcsiaWachs
+
+import test = qualified std/flags
+
+# pre processor test
+
+public function main() {
+ wlist = Cons1(('a',3), [('b',2),('c',1),('d',4),('e',5)])
+ tree = wlist.garsiaWachs()
+ tree.show.println()
}
//----------------------------------------------------
@@ -14,10 +30,9 @@ public type tree<a> {
con Node(left :tree<a>, right :tree<a>)
}
-fun show( t : tree<char> ) : string
-{
+function show( t : tree<char> ) : string {
match(t) {
- Leaf(c) -> Core.show(c)
+ Leaf(c) -> core/show(c)
Node(l,r) -> "Node(" + show(l) + "," + show(r) + ")"
}
}
@@ -30,23 +45,21 @@ public type list1<a> {
Cons1( head : a, tail : list<a> )
}
-
-fun map( xs, f ) {
+function map( xs, f ) {
val Cons1(y,ys) = xs
- return Cons1(f(y), Core.map(ys,f))
+ return Cons1(f(y), core/map(ys,f))
}
-fun zip( xs :list1<a>, ys :list1<b> ) : list1<(a,b)> {
+function zip( xs :list1<a>, ys :list1<b> ) : list1<(a,b)> {
Cons1( (xs.head, ys.head), zip(xs.tail, ys.tail))
}
-
//----------------------------------------------------
// Phase 1
//----------------------------------------------------
-fun insert( after : list<(tree<a>,int)>, t : (tree<a>,int), before : list<(tree<a>,int)> ) : div tree<a>
+function insert( after : list<(tree<a>,int)>, t : (tree<a>,int), before : list<(tree<a>,int)> ) : div tree<a>
{
match(before) {
Nil -> extract( [], Cons1(t,after) )
@@ -60,7 +73,7 @@ fun insert( after : list<(tree<a>,int)>, t : (tree<a>,int), before : list<(tree<
}
}
-fun extract( before : list<(tree<a>,int)>, after : list1<(tree<a>,int)> ) : div tree<a>
+function extract( before : list<(tree<a>,int)>, after : list1<(tree<a>,int)> ) : div tree<a>
{
val Cons1((t1,w1) as x, xs ) = after
match(xs) {
@@ -75,25 +88,24 @@ fun extract( before : list<(tree<a>,int)>, after : list1<(tree<a>,int)> ) : div
}
}
-
-
-fun balance( xs : list1<(tree<a>,int)> ) : div tree<a>
-{
+function balance( xs : list1<(tree<a>,int)> ) : div tree<a> {
extract( [], xs )
}
-fun mark( depth :int, t :tree<(a,ref<h,int>)> ) : <write<h>> ()
-{
+//----------------------------------------------------
+// Phase 2
+//----------------------------------------------------
+
+function mark( depth :int, t :tree<(a,ref<h,int>)> ) : <write<h>> () {
match(t) {
Leaf((_,d)) -> d := depth
Node(l,r) -> { mark(depth+1,l); mark(depth+1,r) }
}
}
-
-fun build( depth :int, xs :list1<(a,ref<h,int>)> ) : <read<h>,div> (tree<a>,list<(a,ref<h,int>)>)
+function build( depth :int, xs :list1<(a,ref<h,int>)> ) : <read<h>,div> (tree<a>,list<(a,ref<h,int>)>)
{
- if (!xs.head.snd == depth) return (Leaf(xs.head.fst), xs.tail)
+ if (!(xs.head.snd) == depth) return (Leaf(xs.head.fst), xs.tail)
l = build(depth+1, xs)
match(l.snd) {
@@ -105,13 +117,11 @@ fun build( depth :int, xs :list1<(a,ref<h,int>)> ) : <read<h>,div> (tree<a>,list
}
}
-public fun test() {
- wlist = Cons1(('a',3), [('b',2),('c',1),('d',4),('e',5)])
- tree = wlist.garciawachs()
- tree.show()
-}
+//----------------------------------------------------
+// Main
+//----------------------------------------------------
-public fun garciawachs( xs : list1<(a,int)> ) : div tree<a>
+public function garsiaWachs( xs : list1<(a,int)> ) : div tree<a>
{
refs = xs.map(fst).map( fun(x) { (x, ref(0)) } )
wleafs = zip( refs.map(Leaf), xs.map(snd) )
diff --git a/tests/examplefiles/py3tb_test.py3tb b/tests/examplefiles/py3tb_test.py3tb
new file mode 100644
index 00000000..706a540f
--- /dev/null
+++ b/tests/examplefiles/py3tb_test.py3tb
@@ -0,0 +1,4 @@
+ File "<stdin>", line 1
+ 1+
+ ^
+SyntaxError: invalid syntax
diff --git a/tests/examplefiles/swig_java.swg b/tests/examplefiles/swig_java.swg
new file mode 100644
index 00000000..6126a55e
--- /dev/null
+++ b/tests/examplefiles/swig_java.swg
@@ -0,0 +1,1329 @@
+/* -----------------------------------------------------------------------------
+ * java.swg
+ *
+ * Java typemaps
+ * ----------------------------------------------------------------------------- */
+
+%include <javahead.swg>
+
+/* The jni, jtype and jstype typemaps work together and so there should be one of each.
+ * The jni typemap contains the JNI type used in the JNI (C/C++) code.
+ * The jtype typemap contains the Java type used in the JNI intermediary class.
+ * The jstype typemap contains the Java type used in the Java proxy classes, type wrapper classes and module class. */
+
+/* Fragments */
+%fragment("SWIG_PackData", "header") {
+/* Pack binary data into a string */
+SWIGINTERN char * SWIG_PackData(char *c, void *ptr, size_t sz) {
+ static const char hex[17] = "0123456789abcdef";
+ register const unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register unsigned char uu = *u;
+ *(c++) = hex[(uu & 0xf0) >> 4];
+ *(c++) = hex[uu & 0xf];
+ }
+ return c;
+}
+}
+
+%fragment("SWIG_UnPackData", "header") {
+/* Unpack binary data from a string */
+SWIGINTERN const char * SWIG_UnpackData(const char *c, void *ptr, size_t sz) {
+ register unsigned char *u = (unsigned char *) ptr;
+ register const unsigned char *eu = u + sz;
+ for (; u != eu; ++u) {
+ register char d = *(c++);
+ register unsigned char uu;
+ if ((d >= '0') && (d <= '9'))
+ uu = ((d - '0') << 4);
+ else if ((d >= 'a') && (d <= 'f'))
+ uu = ((d - ('a'-10)) << 4);
+ else
+ return (char *) 0;
+ d = *(c++);
+ if ((d >= '0') && (d <= '9'))
+ uu |= (d - '0');
+ else if ((d >= 'a') && (d <= 'f'))
+ uu |= (d - ('a'-10));
+ else
+ return (char *) 0;
+ *u = uu;
+ }
+ return c;
+}
+}
+
+/* Primitive types */
+%typemap(jni) bool, const bool & "jboolean"
+%typemap(jni) char, const char & "jchar"
+%typemap(jni) signed char, const signed char & "jbyte"
+%typemap(jni) unsigned char, const unsigned char & "jshort"
+%typemap(jni) short, const short & "jshort"
+%typemap(jni) unsigned short, const unsigned short & "jint"
+%typemap(jni) int, const int & "jint"
+%typemap(jni) unsigned int, const unsigned int & "jlong"
+%typemap(jni) long, const long & "jint"
+%typemap(jni) unsigned long, const unsigned long & "jlong"
+%typemap(jni) long long, const long long & "jlong"
+%typemap(jni) unsigned long long, const unsigned long long & "jobject"
+%typemap(jni) float, const float & "jfloat"
+%typemap(jni) double, const double & "jdouble"
+%typemap(jni) void "void"
+
+%typemap(jtype) bool, const bool & "boolean"
+%typemap(jtype) char, const char & "char"
+%typemap(jtype) signed char, const signed char & "byte"
+%typemap(jtype) unsigned char, const unsigned char & "short"
+%typemap(jtype) short, const short & "short"
+%typemap(jtype) unsigned short, const unsigned short & "int"
+%typemap(jtype) int, const int & "int"
+%typemap(jtype) unsigned int, const unsigned int & "long"
+%typemap(jtype) long, const long & "int"
+%typemap(jtype) unsigned long, const unsigned long & "long"
+%typemap(jtype) long long, const long long & "long"
+%typemap(jtype) unsigned long long, const unsigned long long & "java.math.BigInteger"
+%typemap(jtype) float, const float & "float"
+%typemap(jtype) double, const double & "double"
+%typemap(jtype) void "void"
+
+%typemap(jstype) bool, const bool & "boolean"
+%typemap(jstype) char, const char & "char"
+%typemap(jstype) signed char, const signed char & "byte"
+%typemap(jstype) unsigned char, const unsigned char & "short"
+%typemap(jstype) short, const short & "short"
+%typemap(jstype) unsigned short, const unsigned short & "int"
+%typemap(jstype) int, const int & "int"
+%typemap(jstype) unsigned int, const unsigned int & "long"
+%typemap(jstype) long, const long & "int"
+%typemap(jstype) unsigned long, const unsigned long & "long"
+%typemap(jstype) long long, const long long & "long"
+%typemap(jstype) unsigned long long, const unsigned long long & "java.math.BigInteger"
+%typemap(jstype) float, const float & "float"
+%typemap(jstype) double, const double & "double"
+%typemap(jstype) void "void"
+
+%typemap(jni) char *, char *&, char[ANY], char[] "jstring"
+%typemap(jtype) char *, char *&, char[ANY], char[] "String"
+%typemap(jstype) char *, char *&, char[ANY], char[] "String"
+
+/* JNI types */
+%typemap(jni) jboolean "jboolean"
+%typemap(jni) jchar "jchar"
+%typemap(jni) jbyte "jbyte"
+%typemap(jni) jshort "jshort"
+%typemap(jni) jint "jint"
+%typemap(jni) jlong "jlong"
+%typemap(jni) jfloat "jfloat"
+%typemap(jni) jdouble "jdouble"
+%typemap(jni) jstring "jstring"
+%typemap(jni) jobject "jobject"
+%typemap(jni) jbooleanArray "jbooleanArray"
+%typemap(jni) jcharArray "jcharArray"
+%typemap(jni) jbyteArray "jbyteArray"
+%typemap(jni) jshortArray "jshortArray"
+%typemap(jni) jintArray "jintArray"
+%typemap(jni) jlongArray "jlongArray"
+%typemap(jni) jfloatArray "jfloatArray"
+%typemap(jni) jdoubleArray "jdoubleArray"
+%typemap(jni) jobjectArray "jobjectArray"
+
+%typemap(jtype) jboolean "boolean"
+%typemap(jtype) jchar "char"
+%typemap(jtype) jbyte "byte"
+%typemap(jtype) jshort "short"
+%typemap(jtype) jint "int"
+%typemap(jtype) jlong "long"
+%typemap(jtype) jfloat "float"
+%typemap(jtype) jdouble "double"
+%typemap(jtype) jstring "String"
+%typemap(jtype) jobject "Object"
+%typemap(jtype) jbooleanArray "boolean[]"
+%typemap(jtype) jcharArray "char[]"
+%typemap(jtype) jbyteArray "byte[]"
+%typemap(jtype) jshortArray "short[]"
+%typemap(jtype) jintArray "int[]"
+%typemap(jtype) jlongArray "long[]"
+%typemap(jtype) jfloatArray "float[]"
+%typemap(jtype) jdoubleArray "double[]"
+%typemap(jtype) jobjectArray "Object[]"
+
+%typemap(jstype) jboolean "boolean"
+%typemap(jstype) jchar "char"
+%typemap(jstype) jbyte "byte"
+%typemap(jstype) jshort "short"
+%typemap(jstype) jint "int"
+%typemap(jstype) jlong "long"
+%typemap(jstype) jfloat "float"
+%typemap(jstype) jdouble "double"
+%typemap(jstype) jstring "String"
+%typemap(jstype) jobject "Object"
+%typemap(jstype) jbooleanArray "boolean[]"
+%typemap(jstype) jcharArray "char[]"
+%typemap(jstype) jbyteArray "byte[]"
+%typemap(jstype) jshortArray "short[]"
+%typemap(jstype) jintArray "int[]"
+%typemap(jstype) jlongArray "long[]"
+%typemap(jstype) jfloatArray "float[]"
+%typemap(jstype) jdoubleArray "double[]"
+%typemap(jstype) jobjectArray "Object[]"
+
+/* Non primitive types */
+%typemap(jni) SWIGTYPE "jlong"
+%typemap(jtype) SWIGTYPE "long"
+%typemap(jstype) SWIGTYPE "$&javaclassname"
+
+%typemap(jni) SWIGTYPE [] "jlong"
+%typemap(jtype) SWIGTYPE [] "long"
+%typemap(jstype) SWIGTYPE [] "$javaclassname"
+
+%typemap(jni) SWIGTYPE * "jlong"
+%typemap(jtype) SWIGTYPE * "long"
+%typemap(jstype) SWIGTYPE * "$javaclassname"
+
+%typemap(jni) SWIGTYPE & "jlong"
+%typemap(jtype) SWIGTYPE & "long"
+%typemap(jstype) SWIGTYPE & "$javaclassname"
+
+/* pointer to a class member */
+%typemap(jni) SWIGTYPE (CLASS::*) "jstring"
+%typemap(jtype) SWIGTYPE (CLASS::*) "String"
+%typemap(jstype) SWIGTYPE (CLASS::*) "$javaclassname"
+
+/* The following are the in, out, freearg, argout typemaps. These are the JNI code generating typemaps for converting from Java to C and visa versa. */
+
+/* primitive types */
+%typemap(in) bool
+%{ $1 = $input ? true : false; %}
+
+%typemap(directorout) bool
+%{ $result = $input ? true : false; %}
+
+%typemap(javadirectorin) bool "$jniinput"
+%typemap(javadirectorout) bool "$javacall"
+
+%typemap(in) char,
+ signed char,
+ unsigned char,
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long,
+ long long,
+ float,
+ double
+%{ $1 = ($1_ltype)$input; %}
+
+%typemap(directorout) char,
+ signed char,
+ unsigned char,
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long,
+ long long,
+ float,
+ double
+%{ $result = ($1_ltype)$input; %}
+
+%typemap(directorin, descriptor="Z") bool "$input = (jboolean) $1;"
+%typemap(directorin, descriptor="C") char "$input = (jint) $1;"
+%typemap(directorin, descriptor="B") signed char "$input = (jbyte) $1;"
+%typemap(directorin, descriptor="S") unsigned char "$input = (jshort) $1;"
+%typemap(directorin, descriptor="S") short "$input = (jshort) $1;"
+%typemap(directorin, descriptor="I") unsigned short "$input = (jint) $1;"
+%typemap(directorin, descriptor="I") int "$input = (jint) $1;"
+%typemap(directorin, descriptor="J") unsigned int "$input = (jlong) $1;"
+%typemap(directorin, descriptor="I") long "$input = (jint) $1;"
+%typemap(directorin, descriptor="J") unsigned long "$input = (jlong) $1;"
+%typemap(directorin, descriptor="J") long long "$input = (jlong) $1;"
+%typemap(directorin, descriptor="F") float "$input = (jfloat) $1;"
+%typemap(directorin, descriptor="D") double "$input = (jdouble) $1;"
+
+%typemap(javadirectorin) char,
+ signed char,
+ unsigned char,
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long,
+ long long,
+ float,
+ double
+ "$jniinput"
+
+%typemap(javadirectorout) char,
+ signed char,
+ unsigned char,
+ short,
+ unsigned short,
+ int,
+ unsigned int,
+ long,
+ unsigned long,
+ long long,
+ float,
+ double
+ "$javacall"
+
+%typemap(out) bool %{ $result = (jboolean)$1; %}
+%typemap(out) char %{ $result = (jchar)$1; %}
+%typemap(out) signed char %{ $result = (jbyte)$1; %}
+%typemap(out) unsigned char %{ $result = (jshort)$1; %}
+%typemap(out) short %{ $result = (jshort)$1; %}
+%typemap(out) unsigned short %{ $result = (jint)$1; %}
+%typemap(out) int %{ $result = (jint)$1; %}
+%typemap(out) unsigned int %{ $result = (jlong)$1; %}
+%typemap(out) long %{ $result = (jint)$1; %}
+%typemap(out) unsigned long %{ $result = (jlong)$1; %}
+%typemap(out) long long %{ $result = (jlong)$1; %}
+%typemap(out) float %{ $result = (jfloat)$1; %}
+%typemap(out) double %{ $result = (jdouble)$1; %}
+
+/* unsigned long long */
+/* Convert from BigInteger using the toByteArray member function */
+%typemap(in) unsigned long long {
+ jclass clazz;
+ jmethodID mid;
+ jbyteArray ba;
+ jbyte* bae;
+ jsize sz;
+ int i;
+
+ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
+ return $null;
+ }
+ clazz = JCALL1(GetObjectClass, jenv, $input);
+ mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
+ ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
+ bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ sz = JCALL1(GetArrayLength, jenv, ba);
+ $1 = 0;
+ for(i=0; i<sz; i++) {
+ $1 = ($1 << 8) | ($1_type)(unsigned char)bae[i];
+ }
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+}
+
+%typemap(directorout) unsigned long long {
+ jclass clazz;
+ jmethodID mid;
+ jbyteArray ba;
+ jbyte* bae;
+ jsize sz;
+ int i;
+
+ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
+ return $null;
+ }
+ clazz = JCALL1(GetObjectClass, jenv, $input);
+ mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
+ ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
+ bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ sz = JCALL1(GetArrayLength, jenv, ba);
+ $result = 0;
+ for(i=0; i<sz; i++) {
+ $result = ($result << 8) | ($1_type)(unsigned char)bae[i];
+ }
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+}
+
+
+/* Convert to BigInteger - byte array holds number in 2's complement big endian format */
+%typemap(out) unsigned long long {
+ jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
+ jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
+ jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
+ jobject bigint;
+ int i;
+
+ bae[0] = 0;
+ for(i=1; i<9; i++ ) {
+ bae[i] = (jbyte)($1>>8*(8-i));
+ }
+
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+ bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
+ $result = bigint;
+}
+
+/* Convert to BigInteger (see out typemap) */
+%typemap(directorin, descriptor="Ljava/math/BigInteger;") unsigned long long, const unsigned long long & {
+ jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
+ jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
+ jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
+ jobject bigint;
+ int swig_i;
+
+ bae[0] = 0;
+ for(swig_i=1; swig_i<9; swig_i++ ) {
+ bae[swig_i] = (jbyte)($1>>8*(8-swig_i));
+ }
+
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+ bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
+ $input = bigint;
+}
+
+%typemap(javadirectorin) unsigned long long "$jniinput"
+%typemap(javadirectorout) unsigned long long "$javacall"
+
+/* char * - treat as String */
+%typemap(in, noblock=1) char * {
+ $1 = 0;
+ if ($input) {
+ $1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!$1) return $null;
+ }
+}
+
+%typemap(directorout, noblock=1, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) char * {
+ $1 = 0;
+ if ($input) {
+ $result = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!$result) return $null;
+ }
+}
+
+%typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char * {
+ $input = 0;
+ if ($1) {
+ $input = JCALL1(NewStringUTF, jenv, (const char *)$1);
+ if (!$input) return $null;
+ }
+}
+
+%typemap(freearg, noblock=1) char * { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); }
+%typemap(out, noblock=1) char * { if ($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); }
+%typemap(javadirectorin) char * "$jniinput"
+%typemap(javadirectorout) char * "$javacall"
+
+/* char *& - treat as String */
+%typemap(in, noblock=1) char *& ($*1_ltype temp = 0) {
+ $1 = 0;
+ if ($input) {
+ temp = ($*1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!temp) return $null;
+ }
+ $1 = &temp;
+}
+%typemap(freearg, noblock=1) char *& { if ($1 && *$1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)*$1); }
+%typemap(out, noblock=1) char *& { if (*$1) $result = JCALL1(NewStringUTF, jenv, (const char *)*$1); }
+
+%typemap(out) void ""
+%typemap(javadirectorin) void "$jniinput"
+%typemap(javadirectorout) void "$javacall"
+%typemap(directorin, descriptor="V") void ""
+
+/* primitive types by reference */
+%typemap(in) const bool & ($*1_ltype temp)
+%{ temp = $input ? true : false;
+ $1 = &temp; %}
+
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const bool &
+%{ static $*1_ltype temp;
+ temp = $input ? true : false;
+ $result = &temp; %}
+
+%typemap(javadirectorin) const bool & "$jniinput"
+%typemap(javadirectorout) const bool & "$javacall"
+
+%typemap(in) const char & ($*1_ltype temp),
+ const signed char & ($*1_ltype temp),
+ const unsigned char & ($*1_ltype temp),
+ const short & ($*1_ltype temp),
+ const unsigned short & ($*1_ltype temp),
+ const int & ($*1_ltype temp),
+ const unsigned int & ($*1_ltype temp),
+ const long & ($*1_ltype temp),
+ const unsigned long & ($*1_ltype temp),
+ const long long & ($*1_ltype temp),
+ const float & ($*1_ltype temp),
+ const double & ($*1_ltype temp)
+%{ temp = ($*1_ltype)$input;
+ $1 = &temp; %}
+
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const char &,
+ const signed char &,
+ const unsigned char &,
+ const short &,
+ const unsigned short &,
+ const int &,
+ const unsigned int &,
+ const long &,
+ const unsigned long &,
+ const long long &,
+ const float &,
+ const double &
+%{ static $*1_ltype temp;
+ temp = ($*1_ltype)$input;
+ $result = &temp; %}
+
+%typemap(directorin, descriptor="Z") const bool & "$input = (jboolean)$1;"
+%typemap(directorin, descriptor="C") const char & "$input = (jchar)$1;"
+%typemap(directorin, descriptor="B") const signed char & "$input = (jbyte)$1;"
+%typemap(directorin, descriptor="S") const unsigned char & "$input = (jshort)$1;"
+%typemap(directorin, descriptor="S") const short & "$input = (jshort)$1;"
+%typemap(directorin, descriptor="I") const unsigned short & "$input = (jint)$1;"
+%typemap(directorin, descriptor="I") const int & "$input = (jint)$1;"
+%typemap(directorin, descriptor="J") const unsigned int & "$input = (jlong)$1;"
+%typemap(directorin, descriptor="I") const long & "$input = (jint)$1;"
+%typemap(directorin, descriptor="J") const unsigned long & "$input = (jlong)$1;"
+%typemap(directorin, descriptor="J") const long long & "$input = (jlong)$1;"
+%typemap(directorin, descriptor="F") const float & "$input = (jfloat)$1;"
+%typemap(directorin, descriptor="D") const double & "$input = (jdouble)$1;"
+
+%typemap(javadirectorin) const char & ($*1_ltype temp),
+ const signed char & ($*1_ltype temp),
+ const unsigned char & ($*1_ltype temp),
+ const short & ($*1_ltype temp),
+ const unsigned short & ($*1_ltype temp),
+ const int & ($*1_ltype temp),
+ const unsigned int & ($*1_ltype temp),
+ const long & ($*1_ltype temp),
+ const unsigned long & ($*1_ltype temp),
+ const long long & ($*1_ltype temp),
+ const float & ($*1_ltype temp),
+ const double & ($*1_ltype temp)
+ "$jniinput"
+
+%typemap(javadirectorout) const char & ($*1_ltype temp),
+ const signed char & ($*1_ltype temp),
+ const unsigned char & ($*1_ltype temp),
+ const short & ($*1_ltype temp),
+ const unsigned short & ($*1_ltype temp),
+ const int & ($*1_ltype temp),
+ const unsigned int & ($*1_ltype temp),
+ const long & ($*1_ltype temp),
+ const unsigned long & ($*1_ltype temp),
+ const long long & ($*1_ltype temp),
+ const float & ($*1_ltype temp),
+ const double & ($*1_ltype temp)
+ "$javacall"
+
+
+%typemap(out) const bool & %{ $result = (jboolean)*$1; %}
+%typemap(out) const char & %{ $result = (jchar)*$1; %}
+%typemap(out) const signed char & %{ $result = (jbyte)*$1; %}
+%typemap(out) const unsigned char & %{ $result = (jshort)*$1; %}
+%typemap(out) const short & %{ $result = (jshort)*$1; %}
+%typemap(out) const unsigned short & %{ $result = (jint)*$1; %}
+%typemap(out) const int & %{ $result = (jint)*$1; %}
+%typemap(out) const unsigned int & %{ $result = (jlong)*$1; %}
+%typemap(out) const long & %{ $result = (jint)*$1; %}
+%typemap(out) const unsigned long & %{ $result = (jlong)*$1; %}
+%typemap(out) const long long & %{ $result = (jlong)*$1; %}
+%typemap(out) const float & %{ $result = (jfloat)*$1; %}
+%typemap(out) const double & %{ $result = (jdouble)*$1; %}
+
+/* const unsigned long long & */
+/* Similar to unsigned long long */
+%typemap(in) const unsigned long long & ($*1_ltype temp) {
+ jclass clazz;
+ jmethodID mid;
+ jbyteArray ba;
+ jbyte* bae;
+ jsize sz;
+ int i;
+
+ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
+ return $null;
+ }
+ clazz = JCALL1(GetObjectClass, jenv, $input);
+ mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
+ ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
+ bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ sz = JCALL1(GetArrayLength, jenv, ba);
+ $1 = &temp;
+ temp = 0;
+ for(i=0; i<sz; i++) {
+ temp = (temp << 8) | ($*1_ltype)(unsigned char)bae[i];
+ }
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+}
+
+%typemap(directorout,warning=SWIGWARN_TYPEMAP_THREAD_UNSAFE_MSG) const unsigned long long & {
+ static $*1_ltype temp;
+ jclass clazz;
+ jmethodID mid;
+ jbyteArray ba;
+ jbyte* bae;
+ jsize sz;
+ int i;
+
+ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "BigInteger null");
+ return $null;
+ }
+ clazz = JCALL1(GetObjectClass, jenv, $input);
+ mid = JCALL3(GetMethodID, jenv, clazz, "toByteArray", "()[B");
+ ba = (jbyteArray)JCALL2(CallObjectMethod, jenv, $input, mid);
+ bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ sz = JCALL1(GetArrayLength, jenv, ba);
+ $result = &temp;
+ temp = 0;
+ for(i=0; i<sz; i++) {
+ temp = (temp << 8) | ($*1_ltype)(unsigned char)bae[i];
+ }
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+}
+
+%typemap(out) const unsigned long long & {
+ jbyteArray ba = JCALL1(NewByteArray, jenv, 9);
+ jbyte* bae = JCALL2(GetByteArrayElements, jenv, ba, 0);
+ jclass clazz = JCALL1(FindClass, jenv, "java/math/BigInteger");
+ jmethodID mid = JCALL3(GetMethodID, jenv, clazz, "<init>", "([B)V");
+ jobject bigint;
+ int i;
+
+ bae[0] = 0;
+ for(i=1; i<9; i++ ) {
+ bae[i] = (jbyte)(*$1>>8*(8-i));
+ }
+
+ JCALL3(ReleaseByteArrayElements, jenv, ba, bae, 0);
+ bigint = JCALL3(NewObject, jenv, clazz, mid, ba);
+ $result = bigint;
+}
+
+%typemap(javadirectorin) const unsigned long long & "$jniinput"
+%typemap(javadirectorout) const unsigned long long & "$javacall"
+
+/* Default handling. Object passed by value. Convert to a pointer */
+%typemap(in) SWIGTYPE ($&1_type argp)
+%{ argp = *($&1_ltype*)&$input;
+ if (!argp) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Attempt to dereference null $1_type");
+ return $null;
+ }
+ $1 = *argp; %}
+
+%typemap(directorout) SWIGTYPE ($&1_type argp)
+%{ argp = *($&1_ltype*)&$input;
+ if (!argp) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = *argp; %}
+
+%typemap(out) SWIGTYPE
+#ifdef __cplusplus
+%{ *($&1_ltype*)&$result = new $1_ltype((const $1_ltype &)$1); %}
+#else
+{
+ $&1_ltype $1ptr = ($&1_ltype) malloc(sizeof($1_ltype));
+ memmove($1ptr, &$1, sizeof($1_type));
+ *($&1_ltype*)&$result = $1ptr;
+}
+#endif
+
+%typemap(directorin,descriptor="L$packagepath/$&javaclassname;") SWIGTYPE
+%{ $input = 0;
+ *(($&1_ltype*)&$input) = &$1; %}
+%typemap(javadirectorin) SWIGTYPE "new $&javaclassname($jniinput, false)"
+%typemap(javadirectorout) SWIGTYPE "$&javaclassname.getCPtr($javacall)"
+
+/* Generic pointers and references */
+%typemap(in) SWIGTYPE * %{ $1 = *($&1_ltype)&$input; %}
+%typemap(in, fragment="SWIG_UnPackData") SWIGTYPE (CLASS::*) {
+ const char *temp = 0;
+ if ($input) {
+ temp = JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!temp) return $null;
+ }
+ SWIG_UnpackData(temp, (void *)&$1, sizeof($1));
+}
+%typemap(in) SWIGTYPE & %{ $1 = *($&1_ltype)&$input;
+ if (!$1) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "$1_type reference is null");
+ return $null;
+ } %}
+%typemap(out) SWIGTYPE *
+%{ *($&1_ltype)&$result = $1; %}
+%typemap(out, fragment="SWIG_PackData", noblock=1) SWIGTYPE (CLASS::*) {
+ char buf[128];
+ char *data = SWIG_PackData(buf, (void *)&$1, sizeof($1));
+ *data = '\0';
+ $result = JCALL1(NewStringUTF, jenv, buf);
+}
+%typemap(out) SWIGTYPE &
+%{ *($&1_ltype)&$result = $1; %}
+
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE *
+%{ $result = *($&1_ltype)&$input; %}
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE (CLASS::*)
+%{ $result = *($&1_ltype)&$input; %}
+
+%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE *
+%{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
+%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE (CLASS::*)
+%{ *(($&1_ltype)&$input) = ($1_ltype) $1; %}
+
+%typemap(directorout, warning=SWIGWARN_TYPEMAP_DIRECTOROUT_PTR_MSG) SWIGTYPE &
+%{ if (!$input) {
+ SWIG_JavaThrowException(jenv, SWIG_JavaNullPointerException, "Unexpected null return for type $1_type");
+ return $null;
+ }
+ $result = *($&1_ltype)&$input; %}
+%typemap(directorin,descriptor="L$packagepath/$javaclassname;") SWIGTYPE &
+%{ *($&1_ltype)&$input = ($1_ltype) &$1; %}
+
+%typemap(javadirectorin) SWIGTYPE *, SWIGTYPE (CLASS::*) "($jniinput == 0) ? null : new $javaclassname($jniinput, false)"
+%typemap(javadirectorin) SWIGTYPE & "new $javaclassname($jniinput, false)"
+%typemap(javadirectorout) SWIGTYPE *, SWIGTYPE (CLASS::*), SWIGTYPE & "$javaclassname.getCPtr($javacall)"
+
+/* Default array handling */
+%typemap(in) SWIGTYPE [] %{ $1 = *($&1_ltype)&$input; %}
+%typemap(out) SWIGTYPE [] %{ *($&1_ltype)&$result = $1; %}
+%typemap(freearg) SWIGTYPE [ANY], SWIGTYPE [] ""
+
+/* char arrays - treat as String */
+%typemap(in, noblock=1) char[ANY], char[] {
+ $1 = 0;
+ if ($input) {
+ $1 = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!$1) return $null;
+ }
+}
+
+%typemap(directorout, noblock=1) char[ANY], char[] {
+ $1 = 0;
+ if ($input) {
+ $result = ($1_ltype)JCALL2(GetStringUTFChars, jenv, $input, 0);
+ if (!$result) return $null;
+ }
+}
+
+%typemap(directorin, descriptor="Ljava/lang/String;", noblock=1) char[ANY], char[] {
+ $input = 0;
+ if ($1) {
+ $input = JCALL1(NewStringUTF, jenv, (const char *)$1);
+ if (!$input) return $null;
+ }
+}
+
+%typemap(argout) char[ANY], char[] ""
+%typemap(freearg, noblock=1) char[ANY], char[] { if ($1) JCALL2(ReleaseStringUTFChars, jenv, $input, (const char *)$1); }
+%typemap(out, noblock=1) char[ANY], char[] { if ($1) $result = JCALL1(NewStringUTF, jenv, (const char *)$1); }
+%typemap(javadirectorin) char[ANY], char[] "$jniinput"
+%typemap(javadirectorout) char[ANY], char[] "$javacall"
+
+/* JNI types */
+%typemap(in) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+%{ $1 = $input; %}
+
+%typemap(directorout) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+%{ $result = $input; %}
+
+%typemap(out) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+%{ $result = $1; %}
+
+%typemap(directorin,descriptor="Z") jboolean "$input = $1;"
+%typemap(directorin,descriptor="C") jchar "$input = $1;"
+%typemap(directorin,descriptor="B") jbyte "$input = $1;"
+%typemap(directorin,descriptor="S") jshort "$input = $1;"
+%typemap(directorin,descriptor="I") jint "$input = $1;"
+%typemap(directorin,descriptor="J") jlong "$input = $1;"
+%typemap(directorin,descriptor="F") jfloat "$input = $1;"
+%typemap(directorin,descriptor="D") jdouble "$input = $1;"
+%typemap(directorin,descriptor="Ljava/lang/String;") jstring "$input = $1;"
+%typemap(directorin,descriptor="Ljava/lang/Object;",nouse="1") jobject "$input = $1;"
+%typemap(directorin,descriptor="[Z") jbooleanArray "$input = $1;"
+%typemap(directorin,descriptor="[C") jcharArray "$input = $1;"
+%typemap(directorin,descriptor="[B") jbyteArray "$input = $1;"
+%typemap(directorin,descriptor="[S") jshortArray "$input = $1;"
+%typemap(directorin,descriptor="[I") jintArray "$input = $1;"
+%typemap(directorin,descriptor="[J") jlongArray "$input = $1;"
+%typemap(directorin,descriptor="[F") jfloatArray "$input = $1;"
+%typemap(directorin,descriptor="[D") jdoubleArray "$input = $1;"
+%typemap(directorin,descriptor="[Ljava/lang/Object;",nouse="1") jobjectArray "$input = $1;"
+
+%typemap(javadirectorin) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+ "$jniinput"
+
+%typemap(javadirectorout) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+ "$javacall"
+
+/* Typecheck typemaps - The purpose of these is merely to issue a warning for overloaded C++ functions
+ * that cannot be overloaded in Java as more than one C++ type maps to a single Java type */
+
+%typecheck(SWIG_TYPECHECK_BOOL) /* Java boolean */
+ jboolean,
+ bool,
+ const bool &
+ ""
+
+%typecheck(SWIG_TYPECHECK_CHAR) /* Java char */
+ jchar,
+ char,
+ const char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT8) /* Java byte */
+ jbyte,
+ signed char,
+ const signed char &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT16) /* Java short */
+ jshort,
+ unsigned char,
+ short,
+ const unsigned char &,
+ const short &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT32) /* Java int */
+ jint,
+ unsigned short,
+ int,
+ long,
+ const unsigned short &,
+ const int &,
+ const long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT64) /* Java long */
+ jlong,
+ unsigned int,
+ unsigned long,
+ long long,
+ const unsigned int &,
+ const unsigned long &,
+ const long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT128) /* Java BigInteger */
+ unsigned long long,
+ const unsigned long long &
+ ""
+
+%typecheck(SWIG_TYPECHECK_FLOAT) /* Java float */
+ jfloat,
+ float,
+ const float &
+ ""
+
+%typecheck(SWIG_TYPECHECK_DOUBLE) /* Java double */
+ jdouble,
+ double,
+ const double &
+ ""
+
+%typecheck(SWIG_TYPECHECK_STRING) /* Java String */
+ jstring,
+ char *,
+ char *&,
+ char[ANY],
+ char []
+ ""
+
+%typecheck(SWIG_TYPECHECK_BOOL_ARRAY) /* Java boolean[] */
+ jbooleanArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_CHAR_ARRAY) /* Java char[] */
+ jcharArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT8_ARRAY) /* Java byte[] */
+ jbyteArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT16_ARRAY) /* Java short[] */
+ jshortArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT32_ARRAY) /* Java int[] */
+ jintArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_INT64_ARRAY) /* Java long[] */
+ jlongArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_FLOAT_ARRAY) /* Java float[] */
+ jfloatArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_DOUBLE_ARRAY) /* Java double[] */
+ jdoubleArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_OBJECT_ARRAY) /* Java jobject[] */
+ jobjectArray
+ ""
+
+%typecheck(SWIG_TYPECHECK_POINTER) /* Default */
+ SWIGTYPE,
+ SWIGTYPE *,
+ SWIGTYPE &,
+ SWIGTYPE *const&,
+ SWIGTYPE [],
+ SWIGTYPE (CLASS::*)
+ ""
+
+
+/* Exception handling */
+
+%typemap(throws) int,
+ long,
+ short,
+ unsigned int,
+ unsigned long,
+ unsigned short
+%{ char error_msg[256];
+ sprintf(error_msg, "C++ $1_type exception thrown, value: %d", $1);
+ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, error_msg);
+ return $null; %}
+
+%typemap(throws) SWIGTYPE, SWIGTYPE &, SWIGTYPE *, SWIGTYPE [], SWIGTYPE [ANY]
+%{ (void)$1;
+ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, "C++ $1_type exception thrown");
+ return $null; %}
+
+%typemap(throws) char *
+%{ SWIG_JavaThrowException(jenv, SWIG_JavaRuntimeException, $1);
+ return $null; %}
+
+
+/* Typemaps for code generation in proxy classes and Java type wrapper classes */
+
+/* The javain typemap is used for converting function parameter types from the type
+ * used in the proxy, module or type wrapper class to the type used in the JNI class. */
+%typemap(javain) bool, const bool &,
+ char, const char &,
+ signed char, const signed char &,
+ unsigned char, const unsigned char &,
+ short, const short &,
+ unsigned short, const unsigned short &,
+ int, const int &,
+ unsigned int, const unsigned int &,
+ long, const long &,
+ unsigned long, const unsigned long &,
+ long long, const long long &,
+ unsigned long long, const unsigned long long &,
+ float, const float &,
+ double, const double &
+ "$javainput"
+%typemap(javain) char *, char *&, char[ANY], char[] "$javainput"
+%typemap(javain) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray
+ "$javainput"
+%typemap(javain) SWIGTYPE "$&javaclassname.getCPtr($javainput)"
+%typemap(javain) SWIGTYPE *, SWIGTYPE &, SWIGTYPE [] "$javaclassname.getCPtr($javainput)"
+%typemap(javain) SWIGTYPE (CLASS::*) "$javaclassname.getCMemberPtr($javainput)"
+
+/* The javaout typemap is used for converting function return types from the return type
+ * used in the JNI class to the type returned by the proxy, module or type wrapper class. */
+%typemap(javaout) bool, const bool &,
+ char, const char &,
+ signed char, const signed char &,
+ unsigned char, const unsigned char &,
+ short, const short &,
+ unsigned short, const unsigned short &,
+ int, const int &,
+ unsigned int, const unsigned int &,
+ long, const long &,
+ unsigned long, const unsigned long &,
+ long long, const long long &,
+ unsigned long long, const unsigned long long &,
+ float, const float &,
+ double, const double & {
+ return $jnicall;
+ }
+%typemap(javaout) char *, char *&, char[ANY], char[] {
+ return $jnicall;
+ }
+%typemap(javaout) jboolean,
+ jchar,
+ jbyte,
+ jshort,
+ jint,
+ jlong,
+ jfloat,
+ jdouble,
+ jstring,
+ jobject,
+ jbooleanArray,
+ jcharArray,
+ jbyteArray,
+ jshortArray,
+ jintArray,
+ jlongArray,
+ jfloatArray,
+ jdoubleArray,
+ jobjectArray {
+ return $jnicall;
+ }
+%typemap(javaout) void {
+ $jnicall;
+ }
+%typemap(javaout) SWIGTYPE {
+ return new $&javaclassname($jnicall, true);
+ }
+%typemap(javaout) SWIGTYPE & {
+ return new $javaclassname($jnicall, $owner);
+ }
+%typemap(javaout) SWIGTYPE *, SWIGTYPE [] {
+ long cPtr = $jnicall;
+ return (cPtr == 0) ? null : new $javaclassname(cPtr, $owner);
+ }
+%typemap(javaout) SWIGTYPE (CLASS::*) {
+ String cMemberPtr = $jnicall;
+ return (cMemberPtr == null) ? null : new $javaclassname(cMemberPtr, $owner);
+ }
+
+/* Pointer reference typemaps */
+%typemap(jni) SWIGTYPE *const& "jlong"
+%typemap(jtype) SWIGTYPE *const& "long"
+%typemap(jstype) SWIGTYPE *const& "$*javaclassname"
+%typemap(javain) SWIGTYPE *const& "$*javaclassname.getCPtr($javainput)"
+%typemap(javaout) SWIGTYPE *const& {
+ long cPtr = $jnicall;
+ return (cPtr == 0) ? null : new $*javaclassname(cPtr, $owner);
+ }
+%typemap(in) SWIGTYPE *const& ($*1_ltype temp = 0)
+%{ temp = *($1_ltype)&$input;
+ $1 = ($1_ltype)&temp; %}
+%typemap(out) SWIGTYPE *const&
+%{ *($1_ltype)&$result = *$1; %}
+
+/* Typemaps used for the generation of proxy and type wrapper class code */
+%typemap(javabase) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(javaclassmodifiers) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) "public class"
+%typemap(javacode) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(javaimports) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+%typemap(javainterfaces) SWIGTYPE, SWIGTYPE *, SWIGTYPE &, SWIGTYPE [], SWIGTYPE (CLASS::*) ""
+
+/* javabody typemaps */
+
+%define SWIG_JAVABODY_METHODS(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...) SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE) %enddef // legacy name
+
+%define SWIG_JAVABODY_PROXY(PTRCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
+// Base proxy classes
+%typemap(javabody) TYPE %{
+ private long swigCPtr;
+ protected boolean swigCMemOwn;
+
+ PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
+ swigCMemOwn = cMemoryOwn;
+ swigCPtr = cPtr;
+ }
+
+ CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
+ return (obj == null) ? 0 : obj.swigCPtr;
+ }
+%}
+
+// Derived proxy classes
+%typemap(javabody_derived) TYPE %{
+ private long swigCPtr;
+
+ PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean cMemoryOwn) {
+ super($imclassname.$javaclazznameSWIGUpcast(cPtr), cMemoryOwn);
+ swigCPtr = cPtr;
+ }
+
+ CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
+ return (obj == null) ? 0 : obj.swigCPtr;
+ }
+%}
+%enddef
+
+%define SWIG_JAVABODY_TYPEWRAPPER(PTRCTOR_VISIBILITY, DEFAULTCTOR_VISIBILITY, CPTR_VISIBILITY, TYPE...)
+// Typewrapper classes
+%typemap(javabody) TYPE *, TYPE &, TYPE [] %{
+ private long swigCPtr;
+
+ PTRCTOR_VISIBILITY $javaclassname(long cPtr, boolean futureUse) {
+ swigCPtr = cPtr;
+ }
+
+ DEFAULTCTOR_VISIBILITY $javaclassname() {
+ swigCPtr = 0;
+ }
+
+ CPTR_VISIBILITY static long getCPtr($javaclassname obj) {
+ return (obj == null) ? 0 : obj.swigCPtr;
+ }
+%}
+
+%typemap(javabody) TYPE (CLASS::*) %{
+ private String swigCMemberPtr;
+
+ PTRCTOR_VISIBILITY $javaclassname(String cMemberPtr, boolean futureUse) {
+ swigCMemberPtr = cMemberPtr;
+ }
+
+ DEFAULTCTOR_VISIBILITY $javaclassname() {
+ swigCMemberPtr = null;
+ }
+
+ CPTR_VISIBILITY static String getCMemberPtr($javaclassname obj) {
+ return obj.swigCMemberPtr;
+ }
+%}
+%enddef
+
+/* Set the default javabody typemaps to use protected visibility.
+ Use the macros to change to public if using multiple modules. */
+SWIG_JAVABODY_PROXY(protected, protected, SWIGTYPE)
+SWIG_JAVABODY_TYPEWRAPPER(protected, protected, protected, SWIGTYPE)
+
+%typemap(javafinalize) SWIGTYPE %{
+ protected void finalize() {
+ delete();
+ }
+%}
+
+/*
+ * Java constructor typemaps:
+ *
+ * The javaconstruct typemap is inserted when a proxy class's constructor is generated.
+ * This typemap allows control over what code is executed in the constructor as
+ * well as specifying who owns the underlying C/C++ object. Normally, Java has
+ * ownership and the underlying C/C++ object is deallocated when the Java object
+ * is finalized (swigCMemOwn is true.) If swigCMemOwn is false, C/C++ is
+ * ultimately responsible for deallocating the underlying object's memory.
+ *
+ * The SWIG_PROXY_CONSTRUCTOR macro defines the javaconstruct typemap for a proxy
+ * class for a particular TYPENAME. OWNERSHIP is passed as the value of
+ * swigCMemOwn to the pointer constructor method. WEAKREF determines which kind
+ * of Java object reference will be used by the C++ director class (WeakGlobalRef
+ * vs. GlobalRef.)
+ *
+ * The SWIG_DIRECTOR_OWNED macro sets the ownership of director-based proxy
+ * classes and the weak reference flag to false, meaning that the underlying C++
+ * object will be reclaimed by C++.
+ */
+
+%define SWIG_PROXY_CONSTRUCTOR(OWNERSHIP, WEAKREF, TYPENAME...)
+%typemap(javaconstruct,directorconnect="\n $imclassname.$javaclazznamedirector_connect(this, swigCPtr, swigCMemOwn, WEAKREF);") TYPENAME {
+ this($imcall, OWNERSHIP);$directorconnect
+ }
+%enddef
+
+%define SWIG_DIRECTOR_OWNED(TYPENAME...)
+SWIG_PROXY_CONSTRUCTOR(true, false, TYPENAME)
+%enddef
+
+// Set the default for SWIGTYPE: Java owns the C/C++ object.
+SWIG_PROXY_CONSTRUCTOR(true, true, SWIGTYPE)
+
+%typemap(javadestruct, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE {
+ if (swigCPtr != 0) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $jnicall;
+ }
+ swigCPtr = 0;
+ }
+ }
+
+%typemap(javadestruct_derived, methodname="delete", methodmodifiers="public synchronized") SWIGTYPE {
+ if (swigCPtr != 0) {
+ if (swigCMemOwn) {
+ swigCMemOwn = false;
+ $jnicall;
+ }
+ swigCPtr = 0;
+ }
+ super.delete();
+ }
+
+%typemap(directordisconnect, methodname="swigDirectorDisconnect") SWIGTYPE %{
+ protected void $methodname() {
+ swigCMemOwn = false;
+ $jnicall;
+ }
+%}
+
+%typemap(directorowner_release, methodname="swigReleaseOwnership") SWIGTYPE %{
+ public void $methodname() {
+ swigCMemOwn = false;
+ $jnicall;
+ }
+%}
+
+%typemap(directorowner_take, methodname="swigTakeOwnership") SWIGTYPE %{
+ public void $methodname() {
+ swigCMemOwn = true;
+ $jnicall;
+ }
+%}
+
+/* Java specific directives */
+#define %javaconst(flag) %feature("java:const","flag")
+#define %javaconstvalue(value) %feature("java:constvalue",value)
+#define %javaenum(wrapapproach) %feature("java:enum","wrapapproach")
+#define %javamethodmodifiers %feature("java:methodmodifiers")
+#define %javaexception(exceptionclasses) %feature("except",throws=exceptionclasses)
+#define %nojavaexception %feature("except","0",throws="")
+#define %clearjavaexception %feature("except","",throws="")
+
+%pragma(java) jniclassclassmodifiers="public class"
+%pragma(java) moduleclassmodifiers="public class"
+
+/* Some ANSI C typemaps */
+
+%apply unsigned long { size_t };
+%apply const unsigned long & { const size_t & };
+
+/* Array reference typemaps */
+%apply SWIGTYPE & { SWIGTYPE ((&)[ANY]) }
+
+/* const pointers */
+%apply SWIGTYPE * { SWIGTYPE *const }
+
+/* String & length */
+%typemap(jni) (char *STRING, size_t LENGTH) "jbyteArray"
+%typemap(jtype) (char *STRING, size_t LENGTH) "byte[]"
+%typemap(jstype) (char *STRING, size_t LENGTH) "byte[]"
+%typemap(javain) (char *STRING, size_t LENGTH) "$javainput"
+%typemap(freearg) (char *STRING, size_t LENGTH) ""
+%typemap(in) (char *STRING, size_t LENGTH) {
+ if ($input) {
+ $1 = (char *) JCALL2(GetByteArrayElements, jenv, $input, 0);
+ $2 = (size_t) JCALL1(GetArrayLength, jenv, $input);
+ } else {
+ $1 = 0;
+ $2 = 0;
+ }
+}
+%typemap(argout) (char *STRING, size_t LENGTH) {
+ if ($input) JCALL3(ReleaseByteArrayElements, jenv, $input, (jbyte *)$1, 0);
+}
+%typemap(directorin, descriptor="[B") (char *STRING, size_t LENGTH) {
+ jbyteArray jb = (jenv)->NewByteArray($2);
+ (jenv)->SetByteArrayRegion(jb, 0, $2, (jbyte *)$1);
+ $input = jb;
+}
+%typemap(directorargout) (char *STRING, size_t LENGTH)
+%{(jenv)->GetByteArrayRegion($input, 0, $2, (jbyte *)$1); %}
+%apply (char *STRING, size_t LENGTH) { (char *STRING, int LENGTH) }
+
+/* java keywords */
+%include <javakw.swg>
+
+// Default enum handling
+%include <enumtypesafe.swg>
+
diff --git a/tests/examplefiles/swig_std_vector.i b/tests/examplefiles/swig_std_vector.i
new file mode 100644
index 00000000..baecf850
--- /dev/null
+++ b/tests/examplefiles/swig_std_vector.i
@@ -0,0 +1,225 @@
+//
+// std::vector
+//
+
+%include <std_container.i>
+
+// Vector
+
+%define %std_vector_methods(vector...)
+ %std_sequence_methods(vector)
+
+ void reserve(size_type n);
+ size_type capacity() const;
+%enddef
+
+
+%define %std_vector_methods_val(vector...)
+ %std_sequence_methods_val(vector)
+
+ void reserve(size_type n);
+ size_type capacity() const;
+%enddef
+
+
+// ------------------------------------------------------------------------
+// std::vector
+//
+// The aim of all that follows would be to integrate std::vector with
+// as much as possible, namely, to allow the user to pass and
+// be returned tuples or lists.
+// const declarations are used to guess the intent of the function being
+// exported; therefore, the following rationale is applied:
+//
+// -- f(std::vector<T>), f(const std::vector<T>&):
+// the parameter being read-only, either a sequence or a
+// previously wrapped std::vector<T> can be passed.
+// -- f(std::vector<T>&), f(std::vector<T>*):
+// the parameter may be modified; therefore, only a wrapped std::vector
+// can be passed.
+// -- std::vector<T> f(), const std::vector<T>& f():
+// the vector is returned by copy; therefore, a sequence of T:s
+// is returned which is most easily used in other functions
+// -- std::vector<T>& f(), std::vector<T>* f():
+// the vector is returned by reference; therefore, a wrapped std::vector
+// is returned
+// -- const std::vector<T>* f(), f(const std::vector<T>*):
+// for consistency, they expect and return a plain vector pointer.
+// ------------------------------------------------------------------------
+
+%{
+#include <vector>
+%}
+
+// exported classes
+
+
+namespace std {
+
+ template<class _Tp, class _Alloc = allocator< _Tp > >
+ class vector {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef _Tp& reference;
+ typedef const _Tp& const_reference;
+ typedef _Alloc allocator_type;
+
+ %traits_swigtype(_Tp);
+ %traits_enum(_Tp);
+
+ %fragment(SWIG_Traits_frag(std::vector<_Tp, _Alloc >), "header",
+ fragment=SWIG_Traits_frag(_Tp),
+ fragment="StdVectorTraits") {
+ namespace swig {
+ template <> struct traits<std::vector<_Tp, _Alloc > > {
+ typedef pointer_category category;
+ static const char* type_name() {
+ return "std::vector<" #_Tp "," #_Alloc " >";
+ }
+ };
+ }
+ }
+
+ %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp, _Alloc >);
+
+#ifdef %swig_vector_methods
+ // Add swig/language extra methods
+ %swig_vector_methods(std::vector<_Tp, _Alloc >);
+#endif
+
+ %std_vector_methods(vector);
+ };
+
+ // ***
+ // This specialization should disappear or get simplified when
+ // a 'const SWIGTYPE*&' can be defined
+ // ***
+ template<class _Tp, class _Alloc >
+ class vector<_Tp*, _Alloc > {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp* value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type reference;
+ typedef value_type const_reference;
+ typedef _Alloc allocator_type;
+
+ %traits_swigtype(_Tp);
+
+ %fragment(SWIG_Traits_frag(std::vector<_Tp*, _Alloc >), "header",
+ fragment=SWIG_Traits_frag(_Tp),
+ fragment="StdVectorTraits") {
+ namespace swig {
+ template <> struct traits<std::vector<_Tp*, _Alloc > > {
+ typedef value_category category;
+ static const char* type_name() {
+ return "std::vector<" #_Tp " *," #_Alloc " >";
+ }
+ };
+ }
+ }
+
+ %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp*, _Alloc >);
+
+#ifdef %swig_vector_methods_val
+ // Add swig/language extra methods
+ %swig_vector_methods_val(std::vector<_Tp*, _Alloc >);
+#endif
+
+ %std_vector_methods_val(vector);
+ };
+
+ // ***
+ // const pointer specialization
+ // ***
+ template<class _Tp, class _Alloc >
+ class vector<_Tp const *, _Alloc > {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef _Tp const * value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type reference;
+ typedef value_type const_reference;
+ typedef _Alloc allocator_type;
+
+ %traits_swigtype(_Tp);
+
+ %fragment(SWIG_Traits_frag(std::vector<_Tp const*, _Alloc >), "header",
+ fragment=SWIG_Traits_frag(_Tp),
+ fragment="StdVectorTraits") {
+ namespace swig {
+ template <> struct traits<std::vector<_Tp const*, _Alloc > > {
+ typedef value_category category;
+ static const char* type_name() {
+ return "std::vector<" #_Tp " const*," #_Alloc " >";
+ }
+ };
+ }
+ }
+
+ %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<_Tp const*, _Alloc >);
+
+#ifdef %swig_vector_methods_val
+ // Add swig/language extra methods
+ %swig_vector_methods_val(std::vector<_Tp const*, _Alloc >);
+#endif
+
+ %std_vector_methods_val(vector);
+ };
+
+ // ***
+ // bool specialization
+ // ***
+
+ template<class _Alloc >
+ class vector<bool,_Alloc > {
+ public:
+ typedef size_t size_type;
+ typedef ptrdiff_t difference_type;
+ typedef bool value_type;
+ typedef value_type* pointer;
+ typedef const value_type* const_pointer;
+ typedef value_type reference;
+ typedef value_type const_reference;
+ typedef _Alloc allocator_type;
+
+ %traits_swigtype(bool);
+
+ %fragment(SWIG_Traits_frag(std::vector<bool, _Alloc >), "header",
+ fragment=SWIG_Traits_frag(bool),
+ fragment="StdVectorTraits") {
+ namespace swig {
+ template <> struct traits<std::vector<bool, _Alloc > > {
+ typedef value_category category;
+ static const char* type_name() {
+ return "std::vector<bool, _Alloc >";
+ }
+ };
+ }
+ }
+
+ %typemap_traits_ptr(SWIG_TYPECHECK_VECTOR, std::vector<bool, _Alloc >);
+
+
+#ifdef %swig_vector_methods_val
+ // Add swig/language extra methods
+ %swig_vector_methods_val(std::vector<bool, _Alloc >);
+#endif
+
+ %std_vector_methods_val(vector);
+
+#if defined(SWIG_STD_MODERN_STL) && !defined(SWIG_STD_NOMODERN_STL)
+ void flip();
+#endif
+
+ };
+
+}
diff --git a/tests/examplefiles/test.ebnf b/tests/examplefiles/test.ebnf
new file mode 100644
index 00000000..a96171b0
--- /dev/null
+++ b/tests/examplefiles/test.ebnf
@@ -0,0 +1,31 @@
+letter = "A" | "B" | "C" | "D" | "E" | "F" | "G"
+ | "H" | "I" | "J" | "K" | "L" | "M" | "N"
+ | "O" | "P" | "Q" | "R" | "S" | "T" | "U"
+ | "V" | "W" | "X" | "Y" | "Z" ;
+digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" ;
+symbol = "[" | "]" | "{" | "}" | "(" | ")" | "<" | ">"
+ | "'" | '"' | "=" | "|" | "." | "," | ";" ;
+character = letter | digit | symbol | " " ;
+
+identifier = letter , { letter | digit | " " } ;
+terminal = "'" , character , { character } , "'"
+ | '"' , character , { character } , '"' ;
+
+special = "?" , any , "?" ;
+
+comment = (* this is a comment "" *) "(*" , any-symbol , "*)" ;
+any-symbol = ? any visible character ? ; (* ? ... ? *)
+
+lhs = identifier ;
+rhs = identifier
+ | terminal
+ | comment , rhs
+ | rhs , comment
+ | "[" , rhs , "]"
+ | "{" , rhs , "}"
+ | "(" , rhs , ")"
+ | rhs , "|" , rhs
+ | rhs , "," , rhs ;
+
+rule = lhs , "=" , rhs , ";" | comment ;
+grammar = { rule } ;