diff options
author | gbrandl <devnull@localhost> | 2007-01-13 16:47:36 +0100 |
---|---|---|
committer | gbrandl <devnull@localhost> | 2007-01-13 16:47:36 +0100 |
commit | b298006c5d2582f465bae13d7c754c7f0ec4d7a2 (patch) | |
tree | 4c5e9ac3121f78dcc69a575a04bd815cad7eeee4 | |
parent | 5682e2a118b27ed8e0fa4e6e4f7f0d6fcac93cbe (diff) | |
download | pygments-b298006c5d2582f465bae13d7c754c7f0ec4d7a2.tar.gz |
[svn] Added JSP and Batchfile lexers by Tim Hatch.
-rw-r--r-- | CHANGES | 4 | ||||
-rw-r--r-- | TODO | 3 | ||||
-rw-r--r-- | pygments/formatters/html.py | 2 | ||||
-rw-r--r-- | pygments/formatters/latex.py | 4 | ||||
-rw-r--r-- | pygments/formatters/rtf.py | 2 | ||||
-rw-r--r-- | pygments/lexers/_mapping.py | 2 | ||||
-rw-r--r-- | pygments/lexers/agile.py | 6 | ||||
-rw-r--r-- | pygments/lexers/compiled.py | 2 | ||||
-rw-r--r-- | pygments/lexers/dotnet.py | 6 | ||||
-rw-r--r-- | pygments/lexers/other.py | 59 | ||||
-rw-r--r-- | pygments/lexers/templates.py | 67 | ||||
-rw-r--r-- | pygments/lexers/text.py | 14 | ||||
-rw-r--r-- | pygments/lexers/web.py | 8 | ||||
-rw-r--r-- | tests/examplefiles/batchfile.bat | 46 | ||||
-rw-r--r-- | tests/examplefiles/test.jsp | 24 | ||||
-rw-r--r-- | tests/run.py | 2 |
16 files changed, 212 insertions, 39 deletions
@@ -5,6 +5,10 @@ Version 0.7 ----------- (codename to be selected, released Feb XX, 2007) +- Added Java Server Pages lexer, thanks to Tim Hatch. + +- Added Windows Batchfile lexer, thanks to Tim Hatch. + - Added Trac Wiki markup lexer, thanks to Tim Hatch. - Added Python traceback lexer, thanks to Tim Hatch. @@ -6,7 +6,6 @@ for 0.7 - new lexers: * Haskell - * JSP * (Q)BASIC * Lisp * IPython sessions @@ -14,7 +13,6 @@ for 0.7 * LaTeX special formatting? * OCaml * Nemerle - * Windows batch files * Assembler * Objective C * MySQL/PostgreSQL/SQLite @@ -27,7 +25,6 @@ for 0.7 backtrack to death... * add support for function name highlighting to C++ lexer - - automatically get help for lexers/formatters/options from docstrings - a MoinMoin parser diff --git a/pygments/formatters/html.py b/pygments/formatters/html.py index d323c781..cc2a4c19 100644 --- a/pygments/formatters/html.py +++ b/pygments/formatters/html.py @@ -167,7 +167,7 @@ class HtmlFormatter(Formatter): Additional options accepted: `nowrap` - If set to ``True``, don't wrap the tokens at all, not even in a ``<pre>`` + If set to ``True``, don't wrap the tokens at all, not even inside a ``<pre>`` tag. This disables all other options (default: ``False``). `noclasses` diff --git a/pygments/formatters/latex.py b/pygments/formatters/latex.py index d8bdb8a3..69b67a9d 100644 --- a/pygments/formatters/latex.py +++ b/pygments/formatters/latex.py @@ -70,7 +70,7 @@ class LatexFormatter(Formatter): containing ``\newcommand`` commands defining the commands used inside the ``Verbatim`` environments. If the argument `arg` is true, ``\renewcommand`` is used instead. - + Additional options accepted: `docclass` @@ -84,7 +84,7 @@ class LatexFormatter(Formatter): `verboptions` Additional options given to the Verbatim environment (see the *fancyvrb* docs for possible values) (default: ``''``). - + """ def __init__(self, **options): diff --git a/pygments/formatters/rtf.py b/pygments/formatters/rtf.py index 9bfed9d8..466c555b 100644 --- a/pygments/formatters/rtf.py +++ b/pygments/formatters/rtf.py @@ -20,7 +20,7 @@ class RtfFormatter(Formatter): Formats tokens as RTF markup. This formatter automatically outputs full RTF documents with color information and other useful stuff. Perfect for Copy and Paste into Microsoft® Word® documents. - + *New in Pygments 0.6.* Additional options accepted: diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 0ee8a0e0..b41aba03 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -17,6 +17,7 @@ LEXERS = { 'ApacheConfLexer': ('pygments.lexers.text', 'ApacheConf', ('apacheconf', 'aconf', 'apache'), ('.htaccess', 'apache.conf', 'apache2.conf'), ()), 'BBCodeLexer': ('pygments.lexers.text', 'BBCode', ('bbcode',), (), ()), 'BashLexer': ('pygments.lexers.other', 'Bash', ('bash', 'sh'), ('*.sh',), ('application/x-sh', 'application/x-shellscript')), + 'BatchLexer': ('pygments.lexers.other', 'Batchfile', ('bat',), ('*.bat', '*.cmd'), ('application/x-dos-batch',)), 'BooLexer': ('pygments.lexers.dotnet', 'Boo', ('boo',), ('*.boo',), ('text/x-boo',)), 'BrainfuckLexer': ('pygments.lexers.other', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ()), 'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h'), ('text/x-chdr', 'text/x-csrc')), @@ -49,6 +50,7 @@ LEXERS = { 'JavascriptLexer': ('pygments.lexers.web', 'JavaScript', ('js', 'javascript'), ('*.js',), ('application/x-javascript', 'text/x-javascript', 'text/javascript')), 'JavascriptPhpLexer': ('pygments.lexers.templates', 'JavaScript+PHP', ('js+php', 'javascript+php'), (), ()), 'JavascriptSmartyLexer': ('pygments.lexers.templates', 'JavaScript+Smarty', ('js+smarty', 'javascript+smarty'), (), ()), + 'JspLexer': ('pygments.lexers.templates', 'Java Server Page', ('jsp',), ('*.jsp',), ()), 'LuaLexer': ('pygments.lexers.agile', 'Lua', ('lua',), ('*.lua',), ('text/x-lua', 'application/x-lua')), 'MakefileLexer': ('pygments.lexers.text', 'Makefile', ('make', 'makefile', 'mf'), ('*.mak', 'Makefile', 'makefile'), ('text/x-makefile',)), 'MakoCssLexer': ('pygments.lexers.templates', 'CSS+Mako', ('css+mako',), (), ()), diff --git a/pygments/lexers/agile.py b/pygments/lexers/agile.py index 5c91ebf9..b4c33f73 100644 --- a/pygments/lexers/agile.py +++ b/pygments/lexers/agile.py @@ -34,7 +34,7 @@ class PythonLexer(RegexLexer): """ For `Python <http://www.python.org>`_ source code. """ - + name = 'Python' aliases = ['python', 'py'] filenames = ['*.py', '*.pyw'] @@ -222,7 +222,7 @@ class PythonTracebackLexer(RegexLexer): *New in Pygments 0.7.* """ - + name = 'PythonTraceback' aliases = ['pytb'] filenames = ['*.pytb'] @@ -618,7 +618,7 @@ class PerlLexer(RegexLexer): """ For `Perl <http://www.perl.org>`_ source code. """ - + name = 'Perl' aliases = ['perl', 'pl'] filenames = ['*.pl', '*.pm'] diff --git a/pygments/lexers/compiled.py b/pygments/lexers/compiled.py index 36d80d66..6c33b10b 100644 --- a/pygments/lexers/compiled.py +++ b/pygments/lexers/compiled.py @@ -689,7 +689,7 @@ class JavaLexer(RegexLexer): """ For `Java <http://www.sun.com/java/>`_ source code. """ - + name = 'Java' aliases = ['java'] filenames = ['*.java'] diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py index f47532ba..63ae8e6a 100644 --- a/pygments/lexers/dotnet.py +++ b/pygments/lexers/dotnet.py @@ -22,7 +22,7 @@ class CSharpLexer(RegexLexer): For `C# <http://msdn2.microsoft.com/en-us/vcsharp/default.aspx>`_ source code. """ - + name = 'C#' aliases = ['csharp', 'c#'] filenames = ['*.cs'] @@ -83,7 +83,7 @@ class BooLexer(RegexLexer): """ For `Boo <http://boo.codehaus.org/>`_ source code. """ - + name = 'Boo' aliases = ['boo'] filenames = ['*.boo'] @@ -152,7 +152,7 @@ class VbNetLexer(RegexLexer): `Visual Basic.NET <http://msdn2.microsoft.com/en-us/vbasic/default.aspx>`_ source code. """ - + name = 'VB.net' aliases = ['vb.net', 'vbnet'] filenames = ['*.vb', '*.bas'] diff --git a/pygments/lexers/other.py b/pygments/lexers/other.py index cec162b4..37132e4f 100644 --- a/pygments/lexers/other.py +++ b/pygments/lexers/other.py @@ -17,7 +17,7 @@ from pygments.token import Error, Punctuation, \ from pygments.util import shebang_matches -__all__ = ['SqlLexer', 'BrainfuckLexer', 'BashLexer'] +__all__ = ['SqlLexer', 'BrainfuckLexer', 'BashLexer', 'BatchLexer'] class SqlLexer(RegexLexer): @@ -171,7 +171,7 @@ class BashLexer(RegexLexer): *New in Pygments 0.6.* """ - + name = 'Bash' aliases = ['bash', 'sh'] filenames = ['*.sh'] @@ -218,3 +218,58 @@ class BashLexer(RegexLexer): def analyse_text(text): return shebang_matches(text, r'(ba|z|)sh') + + +class BatchLexer(RegexLexer): + """ + Lexer for the DOS/Windows Batch file format. + + *New in Pygments 0.7.* + """ + name = 'Batchfile' + aliases = ['bat'] + filenames = ['*.bat', '*.cmd'] + mimetypes = ['application/x-dos-batch'] + + flags = re.MULTILINE | re.IGNORECASE + + tokens = { + 'root': [ + # Lines can start with @ to prevent echo + (r'^\s*@', Punctuation), + (r'".*?"', String.Double), + (r"'.*?'", String.Single), + # If made more specific, make sure you still allow expansions + # like %~$VAR:zlt + (r'%%?[~$:\w]+%?', Name.Variable), + (r'(::|rem).*', Comment), # Technically :: only works at BOL + (r'(set)(\s+)(\w+)', bygroups(Keyword, Text, Name.Variable)), + (r'(call)(\s+)(:\w+)', bygroups(Keyword, Text, Name.Label)), + (r'(goto)(\s+)(\w+)', bygroups(Keyword, Text, Name.Label)), + (r'\b(set|call|echo|on|off|endlocal|for|do|goto|if|pause|rem|' + r'setlocal|shift|errorlevel|exist|defined|cmdextversion|' + r'errorlevel|else|cd|md|del|deltree|cls|choice)\b', Keyword), + (r'equ|neq|lss|leq|gtr|geq', Operator), + include('basic'), + (r'.', Text), + ], + 'echo': [ + # Escapes only valid within echo args? + (r'\^\^|\^<|\^>|\^\|', String.Escape), + (r'\n', Text, '#pop'), + include('basic'), + (r'[^\'"^]+', Text), + ], + 'basic': [ + (r'".*?"', String.Double), + (r"'.*?'", String.Single), + (r'`.*?`', String.Backtick), + (r'-?\d+', Number), + (r',', Punctuation), + (r'=', Operator), + (r'/\S+', Name), + (r':\w+', Name.Label), + (r'\w:\w+', Text), + (r'([<>|])(\s*)(\w+)', bygroups(Punctuation, Text, Name)), + ], + } diff --git a/pygments/lexers/templates.py b/pygments/lexers/templates.py index 7c8c356d..5b6d5e0e 100644 --- a/pygments/lexers/templates.py +++ b/pygments/lexers/templates.py @@ -19,6 +19,7 @@ except NameError: from pygments.lexers.web import \ PhpLexer, HtmlLexer, XmlLexer, JavascriptLexer, CssLexer from pygments.lexers.agile import PythonLexer +from pygments.lexers.compiled import JavaLexer from pygments.lexer import Lexer, DelegatingLexer, RegexLexer, bygroups, \ include, using, this from pygments.token import Error, Punctuation, \ @@ -36,7 +37,7 @@ __all__ = ['HtmlPhpLexer', 'XmlPhpLexer', 'CssPhpLexer', 'MyghtyLexer', 'MyghtyHtmlLexer', 'MyghtyXmlLexer', 'MyghtyCssLexer', 'MyghtyJavascriptLexer', 'MakoLexer', 'MakoHtmlLexer', 'MakoXmlLexer', 'MakoJavascriptLexer', - 'MakoCssLexer'] + 'MakoCssLexer', 'JspLexer'] class ErbLexer(Lexer): @@ -464,7 +465,7 @@ class MakoJavascriptLexer(DelegatingLexer): *New in Pygments 0.7.* """ - + name = 'JavaScript+Mako' aliases = ['js+mako', 'javascript+mako'] @@ -529,7 +530,7 @@ class GenshiMarkupLexer(RegexLexer): Base lexer for Genshi markup, used by `HtmlGenshiLexer` and `GenshiLexer`. """ - + flags = re.DOTALL tokens = { @@ -678,7 +679,7 @@ class RhtmlLexer(DelegatingLexer): Nested Javascript and CSS is highlighted too. """ - + name = 'RHTML' aliases = ['rhtml', 'html+erb', 'html+ruby'] filenames = ['*.rhtml'] @@ -700,7 +701,7 @@ class XmlErbLexer(DelegatingLexer): Subclass of `ErbLexer` which highlights data outside preprocessor directives with the `XmlLexer`. """ - + name = 'XML+Ruby' aliases = ['xml+erb', 'xml+ruby'] alias_filenames = ['*.xml'] @@ -719,7 +720,7 @@ class CssErbLexer(DelegatingLexer): """ Subclass of `ErbLexer` which highlights unlexed data with the `CssLexer`. """ - + name = 'CSS+Ruby' aliases = ['css+erb', 'css+ruby'] alias_filenames = ['*.xml'] @@ -755,7 +756,7 @@ class HtmlPhpLexer(DelegatingLexer): Nested Javascript and CSS is highlighted too. """ - + name = 'HTML+PHP' aliases = ['html+php'] filenames = ['*.phtml'] @@ -779,7 +780,7 @@ class XmlPhpLexer(DelegatingLexer): """ Subclass of `PhpLexer` that higlights unhandled data with the `XmlLexer`. """ - + name = 'XML+PHP' aliases = ['xml+php'] alias_filenames = ['*.xml', '*.php', '*.php[345]'] @@ -798,7 +799,7 @@ class CssPhpLexer(DelegatingLexer): """ Subclass of `PhpLexer` which highlights unmatched data with the `CssLexer`. """ - + name = 'CSS+PHP' aliases = ['css+php'] alias_filenames = ['*.css'] @@ -855,7 +856,7 @@ class XmlSmartyLexer(DelegatingLexer): Subclass of the `SmartyLexer` that highlights unlexed data with the `XmlLexer`. """ - + name = 'XML+Smarty' aliases = ['xml+smarty'] alias_filenames = ['*.xml', '*.tpl'] @@ -952,7 +953,7 @@ class CssDjangoLexer(DelegatingLexer): Subclass of the `DjangoLexer` that highlights unlexed data with the `CssLexer`. """ - + name = 'CSS+Django/Jinja' aliases = ['css+django', 'css+jinja'] alias_filenames = ['*.css'] @@ -981,3 +982,47 @@ class JavascriptDjangoLexer(DelegatingLexer): def analyse_text(text): return DjangoLexer.analyse_text(text) - 0.05 + +class JspRootLexer(RegexLexer): + """ + Base for the `JspLexer`. Yields `Token.Other` for area outside of + JSP tags. + + *New in Pygments 0.7.* + """ + + tokens = { + 'root': [ + (r'<%\S?', Keyword, 'sec'), + # FIXME: I want to make these keywords but still parse attributes. + (r'</?jsp:(forward|getProperty|include|plugin|setProperty|useBean).*?>', + Keyword), + (r'[^<]+', Other), + (r'<', Other), + ], + 'sec': [ + (r'%>', Keyword, '#pop'), + (r'[\w\W]+?(?=%>|\Z)', using(JavaLexer)), + ], + } + +class JspLexer(DelegatingLexer): + """ + Lexer for Java Server Pages. + + *New in Pygments 0.7.* + """ + name = 'Java Server Page' + aliases = ['jsp'] + filenames = ['*.jsp'] + + def __init__(self, **options): + super(JspLexer, self).__init__(XmlLexer, JspRootLexer, **options) + + def analyse_text(text): + rv = JavaLexer.analyse_text(text) - 0.01 + if looks_like_xml(text): + rv += 0.4 + if '<%' in text and '%>' in text: + rv += 0.1 + return rv diff --git a/pygments/lexers/text.py b/pygments/lexers/text.py index ba03ff01..29f569aa 100644 --- a/pygments/lexers/text.py +++ b/pygments/lexers/text.py @@ -60,7 +60,7 @@ class SourcesListLexer(RegexLexer): *New in Pygments 0.7.* """ - + name= 'Debian Sourcelist' aliases = ['sourceslist', 'sources.list'] filenames = ['sources.list'] @@ -107,7 +107,7 @@ class MakefileLexer(RegexLexer): """ Lexer for Makefiles. """ - + name = 'Makefile' aliases = ['make', 'makefile', 'mf'] filenames = ['*.mak', 'Makefile', 'makefile'] @@ -154,7 +154,7 @@ class DiffLexer(RegexLexer): """ Lexer for unified or context-style diffs or patches. """ - + name = 'Diff' aliases = ['diff'] filenames = ['*.diff', '*.patch'] @@ -186,7 +186,7 @@ class IrcLogsLexer(RegexLexer): """ Lexer for IRC logs in **irssi** or **xchat** style. """ - + name = 'IRC logs' aliases = ['irc'] @@ -232,7 +232,7 @@ class BBCodeLexer(RegexLexer): *New in Pygments 0.6.* """ - + name = 'BBCode' aliases = ['bbcode'] @@ -251,7 +251,7 @@ class TexLexer(RegexLexer): """ Lexer for the TeX and LaTeX typesetting languages. """ - + name = 'TeX' aliases = ['tex', 'latex'] filenames = ['*.tex', '*.aux', '*.toc'] @@ -366,7 +366,7 @@ class ApacheConfLexer(RegexLexer): *New in Pygments 0.6.* """ - + name = 'ApacheConf' aliases = ['apacheconf', 'aconf', 'apache'] filenames = ['.htaccess', 'apache.conf', 'apache2.conf'] diff --git a/pygments/lexers/web.py b/pygments/lexers/web.py index bbd6d76e..ef480894 100644 --- a/pygments/lexers/web.py +++ b/pygments/lexers/web.py @@ -31,7 +31,7 @@ class JavascriptLexer(RegexLexer): """ For JavaScript source code. """ - + name = 'JavaScript' aliases = ['js', 'javascript'] filenames = ['*.js'] @@ -68,7 +68,7 @@ class CssLexer(RegexLexer): """ For CSS (Cascading Style Sheets). """ - + name = 'CSS' aliases = ['css'] filenames = ['*.css'] @@ -202,7 +202,7 @@ class HtmlLexer(RegexLexer): For HTML 4 and XHTML 1 markup. Nested JavaScript and CSS is highlighted by the appropriate lexer. """ - + name = 'HTML' aliases = ['html'] filenames = ['*.html', '*.htm', '*.xhtml'] @@ -397,7 +397,7 @@ class XmlLexer(RegexLexer): """ Generic lexer for XML (eXtensible Markup Language). """ - + flags = re.MULTILINE | re.DOTALL name = 'XML' diff --git a/tests/examplefiles/batchfile.bat b/tests/examplefiles/batchfile.bat new file mode 100644 index 00000000..49a53cec --- /dev/null +++ b/tests/examplefiles/batchfile.bat @@ -0,0 +1,46 @@ +rem this is a demo file. +@rem +@echo off + +call c:\temp.bat somearg +call :lab somearg +rem This next one is wrong in the vim lexer! +call c:temp.bat + +echo "Hi!" +echo hi +echo on +echo off +echo. +@echo off +if exist *.log echo The log file has arrived. +rem These are all escapes, also done incorrectly by the vim lexer +echo ^^ ^> ^< ^| + +x=beginning +setlocal +x = new text +endlocal + +for %%var in (*.jpg) do echo %%var +for /D %%var in (a b c) do echo %%var +for /R C:\temp %%var in (*.jpg) do iexplore.exe %%var +rem Vim has this one wrong too. +for /L %%var in (10,-1,1) do echo %%var +for /F %%var in ("hi!") do echo %%var +for /F "eol=c,skip=1,usebackq" %%var in (`command`) do echo %%var %~l %~fl %~dl %~pl %~nl %~xl %~sl %~al %~tl %~zl %~$PATH:l %~dpl %~dp$PATH:l %~ftzal + +echo some file ?! > somefile.txt + +set PATH=%PATH%;c:\windows + +goto answer%errorlevel% + :answer0 + echo Hi it's zero + :answer1 + echo New + +if exist a del a +else echo A is missing! + + diff --git a/tests/examplefiles/test.jsp b/tests/examplefiles/test.jsp new file mode 100644 index 00000000..1c6664da --- /dev/null +++ b/tests/examplefiles/test.jsp @@ -0,0 +1,24 @@ +<!-- This page was loaded on <%= (new java.util.Date()).toLocaleString() %> --> +<%= var x = 1; +%> +<%! int i = 0; %> +<%! int a, b, c; %> +<%! Circle a = new Circle(2.0); %> + +<% + String name = null; + if (request.getParameter("name") == null) { +%> +<%@ include file="error.html" %> +<% + } else { + foo.setName(request.getParameter("name")); + if (foo.getName().equalsIgnoreCase("integra")) + name = "acura"; + if (name.equalsIgnoreCase( "acura" )) { +%> + +<jsp:useBean id="calendar" scope="page" class="employee.Calendar" /> +<h2> +Calendar of <jsp:getProperty name="calendar" property="username" /> +</h2> diff --git a/tests/run.py b/tests/run.py index 590ae8df..d2599331 100644 --- a/tests/run.py +++ b/tests/run.py @@ -71,7 +71,7 @@ def run_tests(): if (entry.startswith('test_') and entry.endswith('.py'))] files.sort() - WIDTH = 60 + WIDTH = 70 print >>sys.stderr, 'Pygments Test Suite running, stand by...'.center(WIDTH) print >>sys.stderr, ('(using Python %s)' % sys.version.split()[0]).center(WIDTH) |