summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorthatch <devnull@localhost>2009-03-25 15:53:18 -0700
committerthatch <devnull@localhost>2009-03-25 15:53:18 -0700
commitf550b69af7bb0fbaca40280a25aae72b99e9d9b2 (patch)
tree9949ee6804bc413ef25b6cf24d80119ca2598319
parent25f08c4c1952bd4edfc6d92e5ac25e9d80b55034 (diff)
parenta7f3b6f2d38102f02a789f08066a5ca402aa4efb (diff)
downloadpygments-f550b69af7bb0fbaca40280a25aae72b99e9d9b2.tar.gz
Merge ASP.net lexers to -main
-rw-r--r--CHANGES1
-rw-r--r--pygments/lexers/_mapping.py2
-rw-r--r--pygments/lexers/dotnet.py73
-rw-r--r--tests/examplefiles/example.aspx27
-rw-r--r--tests/examplefiles/example2.aspx29
5 files changed, 129 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index e0cdf459..4df7888c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -18,6 +18,7 @@ Version 1.1
* MXML
* Cython
* ABAP
+ * ASP.net (VB/C#)
- Fix the LaTeX formatter's output so that output generated for one style
can be used with the style definitions of another (#384).
diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py
index ee1233ea..9fec1a0b 100644
--- a/pygments/lexers/_mapping.py
+++ b/pygments/lexers/_mapping.py
@@ -38,6 +38,7 @@ LEXERS = {
'BrainfuckLexer': ('pygments.lexers.other', 'Brainfuck', ('brainfuck', 'bf'), ('*.bf', '*.b'), ('application/x-brainfuck',)),
'CLexer': ('pygments.lexers.compiled', 'C', ('c',), ('*.c', '*.h'), ('text/x-chdr', 'text/x-csrc')),
'CObjdumpLexer': ('pygments.lexers.asm', 'c-objdump', ('c-objdump',), ('*.c-objdump',), ('text/x-c-objdump',)),
+ 'CSharpAspxLexer': ('pygments.lexers.dotnet', 'aspx-cs', ('aspx-cs',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()),
'CSharpLexer': ('pygments.lexers.dotnet', 'C#', ('csharp', 'c#'), ('*.cs',), ('text/x-csharp',)),
'CheetahHtmlLexer': ('pygments.lexers.templates', 'HTML+Cheetah', ('html+cheetah', 'html+spitfire'), (), ('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')),
@@ -162,6 +163,7 @@ LEXERS = {
'TcshLexer': ('pygments.lexers.other', 'Tcsh', ('tcsh', 'csh'), ('*.tcsh', '*.csh'), ('application/x-csh',)),
'TexLexer': ('pygments.lexers.text', 'TeX', ('tex', 'latex'), ('*.tex', '*.aux', '*.toc'), ('text/x-tex', 'text/x-latex')),
'TextLexer': ('pygments.lexers.special', 'Text only', ('text',), ('*.txt',), ('text/plain',)),
+ 'VbNetAspxLexer': ('pygments.lexers.dotnet', 'aspx-vb', ('aspx-vb',), ('*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd'), ()),
'VbNetLexer': ('pygments.lexers.dotnet', 'VB.net', ('vb.net', 'vbnet'), ('*.vb', '*.bas'), ('text/x-vbnet', 'text/x-vba')),
'VimLexer': ('pygments.lexers.text', 'VimL', ('vim',), ('*.vim', '.vimrc'), ('text/x-vim',)),
'XmlDjangoLexer': ('pygments.lexers.templates', 'XML+Django/Jinja', ('xml+django', 'xml+jinja'), (), ('application/xml+django', 'application/xml+jinja')),
diff --git a/pygments/lexers/dotnet.py b/pygments/lexers/dotnet.py
index b9782ab7..0379f3b6 100644
--- a/pygments/lexers/dotnet.py
+++ b/pygments/lexers/dotnet.py
@@ -10,13 +10,16 @@
"""
import re
-from pygments.lexer import RegexLexer, bygroups, using, this
+from pygments.lexer import RegexLexer, DelegatingLexer, bygroups, using, this
from pygments.token import Punctuation, \
- Text, Comment, Operator, Keyword, Name, String, Number, Literal
+ Text, Comment, Operator, Keyword, Name, String, Number, Literal, Other
from pygments.util import get_choice_opt
from pygments import unistring as uni
-__all__ = ['CSharpLexer', 'BooLexer', 'VbNetLexer']
+from pygments.lexers.web import XmlLexer
+
+__all__ = ['CSharpLexer', 'BooLexer', 'VbNetLexer', 'CSharpAspxLexer',
+ 'VbNetAspxLexer']
def _escape(st):
@@ -286,3 +289,67 @@ class VbNetLexer(RegexLexer):
(r'[a-z_][a-z0-9_.]*', Name.Namespace, '#pop')
],
}
+
+class GenericAspxLexer(RegexLexer):
+ """
+ Lexer for ASP.NET pages.
+ """
+
+ name = 'aspx-gen'
+ filenames = []
+ mimetypes = []
+
+ flags = re.DOTALL
+
+ tokens = {
+ 'root': [
+ (r'(<%[@=#]?)(.*?)(%>)', bygroups(Name.Tag, Other, Name.Tag)),
+ (r'(<script.*?>)(.*?)(</script>)', bygroups(using(XmlLexer),
+ Other,
+ using(XmlLexer))),
+ (r'(.+?)(?=<)', using(XmlLexer)),
+ (r'.+', using(XmlLexer)),
+ ],
+ }
+
+#TODO support multiple languages within the same source file
+class CSharpAspxLexer(DelegatingLexer):
+ """
+ Lexer for highligting C# within ASP.NET pages.
+ """
+
+ name = 'aspx-cs'
+ aliases = ['aspx-cs']
+ filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']
+ mimetypes = []
+
+ def __init__(self, **options):
+ super(CSharpAspxLexer, self).__init__(CSharpLexer,GenericAspxLexer,
+ **options)
+
+ def analyse_text(text):
+ if re.search(r'Page\s*Language="C#"', text, re.I) is not None:
+ return 0.2
+ elif re.search(r'script[^>]+language=["\']C#', text, re.I) is not None:
+ return 0.15
+ return 0.001 # TODO really only for when filename matched...
+
+class VbNetAspxLexer(DelegatingLexer):
+ """
+ Lexer for highligting Visual Basic.net within ASP.NET pages.
+ """
+
+ name = 'aspx-vb'
+ aliases = ['aspx-vb']
+ filenames = ['*.aspx', '*.asax', '*.ascx', '*.ashx', '*.asmx', '*.axd']
+ mimetypes = []
+
+ def __init__(self, **options):
+ super(VbNetAspxLexer, self).__init__(VbNetLexer,GenericAspxLexer,
+ **options)
+
+ def analyse_text(text):
+ if re.search(r'Page\s*Language="Vb"', text, re.I) is not None:
+ return 0.2
+ elif re.search(r'script[^>]+language=["\']vb', text, re.I) is not None:
+ return 0.15
diff --git a/tests/examplefiles/example.aspx b/tests/examplefiles/example.aspx
new file mode 100644
index 00000000..01de00e4
--- /dev/null
+++ b/tests/examplefiles/example.aspx
@@ -0,0 +1,27 @@
+<%@ Page Language="C#" %>
+
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
+"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+
+<script runat="server">
+
+ protected void Page_Load(object sender, EventArgs e)
+ {
+ Label1.Text = DateTime.Now.ToLongDateString();
+ }
+
+</script>
+
+<html xmlns="http://www.w3.org/1999/xhtml">
+<head runat="server">
+ <title>Sample page</title>
+</head>
+<body>
+ <form id="form1" runat="server">
+ <div>
+ The current time is: <asp:Label runat="server" id="Label1" />
+ </div>
+ </form>
+
+</body>
+</html>
diff --git a/tests/examplefiles/example2.aspx b/tests/examplefiles/example2.aspx
new file mode 100644
index 00000000..52b7c001
--- /dev/null
+++ b/tests/examplefiles/example2.aspx
@@ -0,0 +1,29 @@
+<%@ Register TagPrefix="Acme" TagName="Message" Src="userctrl2_vb.ascx" %>
+
+<html>
+
+ <script language="VB" runat="server">
+
+ Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
+ MyMessage.MessageText = "Message text changed!"
+ MyMessage.Color = "red"
+ End Sub
+
+ </script>
+
+<body style="font: 10pt verdana">
+
+ <h3>A Simple User Control w/ Properties</h3>
+
+ <form runat="server">
+
+ <Acme:Message id="MyMessage" MessageText="This is a custom message!" Color="blue" runat="server"/>
+
+ <p>
+
+ <asp:button text="Change Properties" OnClick="SubmitBtn_Click" runat=server/>
+
+ </form>
+
+</body>
+</html>