Commits

gbrandl  committed 73f9206 Merge

merge with Tim

  • Participants
  • Parent commits 7ba42d3, 2c43740

Comments (0)

Files changed (6)

   * 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).
   the Scala lexer (#392), the INI lexer (#391), the Clojure lexer (#387)
   and the AS3 lexer (#389).
 
-- Fix a Perl heredoc bug (#729).
+- Fix two Perl heredoc lexing bugs (#729, #400).
 
 - Fix a bug in the image formatter which misdetected lines (#380).
 
 
 - Fix a bug lexing the empty commit in the PHP lexer (#405).
 
+- Fix a bug causing Python numbers to be mishighlighted as floats (#397).
+
 
 Version 1.0
 -----------

File pygments/lexers/_mapping.py

     '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')),
     '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')),

File pygments/lexers/agile.py

              r')\b', Name.Exception),
         ],
         'numbers': [
-            (r'(\d+\.?\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
+            (r'(\d+\.\d*|\d*\.\d+)([eE][+-]?[0-9]+)?', Number.Float),
+            (r'\d+[eE][+-]?[0-9]+', Number.Float),
             (r'0\d+', Number.Oct),
             (r'0[xX][a-fA-F0-9]+', Number.Hex),
             (r'\d+L', Number.Integer.Long),
         ],
         'root': [
             (r'\#.*?$', Comment.Single),
-            (r'=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
+            (r'^=[a-zA-Z0-9]+\s+.*?\n=cut', Comment.Multiline),
             (r'(case|continue|do|else|elsif|for|foreach|if|last|my|'
              r'next|our|redo|reset|then|unless|until|while|use|'
              r'print|new|BEGIN|END|return)\b', Keyword),

File pygments/lexers/dotnet.py

 """
 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):
             (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

File tests/examplefiles/example.aspx

+<%@ 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>

File tests/examplefiles/example2.aspx

+<%@ 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>