from pygments.lexer import RegexLexer, bygroups, include
from pygments.token import (Text, Keyword, Number, Comment, Punctuation, Name,
    String, Literal)


__all__ = [
    "PyPyLogLexer",
]

class PyPyLogLexer(RegexLexer):
    """
    Lexer for PyPy log files.

    *New in Pygments 1.5.*
    """
    name = "PyPy Log"
    aliases = ["pypylog", "pypy"]
    filenames = ["*.pypylog"]
    mimetypes = ['application/x-pypylog']

    tokens = {
        "root": [
            (r"\[\w+\] {jit-log-.*?$", Keyword, "jit-log"),
            (r"\[\w+\] {jit-backend-counts$", Keyword, "jit-backend-counts"),
            include("extra-stuff"),
        ],
        "jit-log": [
            (r"\[\w+\] jit-log-.*?}$", Keyword, "#pop"),

            (r"[ifp]\d+", Name),
            (r"ptr\d+", Name),
            (r"(\()([\w_]+(?:\.[\w_]+)?)(\))", bygroups(Punctuation, Name.Builtin, Punctuation)),
            (r"[\[\]=,()]", Punctuation),
            (r"(\d+\.\d+|inf|-inf)", Number.Float),
            (r"-?\d+", Number.Integer),
            (r"'.*'", String),
            (r"(None|descr|ConstClass|ConstPtr)", Name),
            (r"<.*?>", Name.Builtin),
            (r"(debug_merge_point|jump|finish)", Name.Class),
            (r"(int_add_ovf|int_add|int_sub_ovf|int_sub|int_mul_ovf|int_mul|int_rshift|int_and|int_or|int_xor|"
             r"int_eq|int_ne|int_ge|int_gt|int_le|int_lt|int_is_zero|int_is_true|"
             r"uint_floordiv|"
             r"uint_ge|uint_lt|"
             r"float_add|float_sub|float_mul|float_truediv|"
             r"float_eq|float_ne|float_gt|"
             r"ptr_eq|"
             r"force_token|"
             r"call_may_force|call_assembler|call|"
             r"new_with_vtable|new_array|newstr|newunicode|new|"
             r"arraylen_gc|"
             r"getarrayitem_gc_pure|getarrayitem_gc|setarrayitem_gc|getarrayitem_raw|setarrayitem_raw|"
             r"getfield_gc_pure|getfield_gc|getfield_raw|setfield_gc|setfield_raw|"
             r"strgetitem|strsetitem|strlen|copystrcontent|"
             r"unicodegetitem|unicodesetitem|unicodelen|"
             r"guard_true|guard_false|guard_value|guard_isnull|guard_nonnull_class|guard_nonnull|guard_class|guard_no_overflow|guard_not_forced|guard_no_exception|guard_not_invalidated)", Name.Builtin),
            include("extra-stuff"),
        ],
        "jit-backend-counts": [
            (r"\[\w+\] jit-backend-counts}$", Keyword, "#pop"),
            (r"[:]", Punctuation),
            (r"\d+", Number),
            include("extra-stuff"),
        ],
        "extra-stuff": [
            (r"[\n\s]+", Text),
            (r"#.*?$", Comment),
        ],
    }

@@ -1,20 +1,256 @@
+# -*- coding: utf-8 -*-%0A%22%22%22%0A    pygments.lexers.pypylog%0A    ~~~~~~~~~~~~~~~~~~~~~~~%0A%0A    Lexer for pypy log files.%0A%0A    :copyright: Copyright 2006-2010 by the Pygments team, see AUTHORS.%0A    :license: BSD, see LICENSE for details.%0A%22%22%22%0A%0A
 from pygments.lexer 
@@ -313,17 +313,16 @@
  import 
-(
 Text, Ke
@@ -363,16 +363,18 @@
 n, Name,
+ %5C
 %0A    Str
@@ -380,18 +380,8 @@
 ring
-, Literal)
 %0A%0A%0A_
@@ -390,21 +390,16 @@
 ll__ = %5B
-%0A    
 %22PyPyLog
@@ -408,11 +408,10 @@
 xer%22
-,%0A
 %5D
+%0A
 %0A%0Acl
@@ -1050,16 +1050,29 @@
 ?)(%5C))%22,
+%0A            
  bygroup
@@ -1513,16 +1513,33 @@
 int_mul%7C
+%22%0A             r%22
 int_rshi
@@ -1564,33 +1564,16 @@
 int_xor%7C
-%22%0A             r%22
 int_eq%7Ci
@@ -1592,16 +1592,33 @@
 %7Cint_gt%7C
+%22%0A             r%22
 int_le%7Ci
@@ -1678,33 +1678,16 @@
 loordiv%7C
-%22%0A             r%22
 uint_ge%7C
@@ -2068,16 +2068,33 @@
 item_gc%7C
+%22%0A             r%22
 getarray
@@ -2119,33 +2119,16 @@
 tem_raw%7C
-%22%0A             r%22
 getfield
@@ -2148,16 +2148,33 @@
 ield_gc%7C
+%22%0A             r%22
 getfield
@@ -2383,24 +2383,41 @@
 uard_isnull%7C
+%22%0A             r%22
 guard_nonnul
@@ -2468,16 +2468,33 @@
 verflow%7C
+%22%0A             r%22
 guard_no
@@ -2545,16 +2545,29 @@
 dated)%22,
+%0A            
  Name.Bu

Fix coding style and add a file header.