File: patch_tb_lexer.py

package info (click to toggle)
python-friendly 0.7.21%2Bgit20230418.fe5d3a2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,268 kB
  • sloc: python: 2,291; makefile: 6
file content (27 lines) | stat: -rw-r--r-- 860 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# Monkeypatching the traceback lexer so that it treats
# "Code block" the same as "File"
from pygments.lexers.python import PythonTracebackLexer
from pygments.lexer import bygroups
from pygments.token import Text, Name, Number, Operator, Generic


PythonTracebackLexer.tokens["root"].insert(
    0,
    # SyntaxError in interactive interpreter can start with this.
    (r"^(?=  Code block \[\d+\], line \d+)", Generic.Traceback, "intb"),
)

PythonTracebackLexer.tokens["intb"].insert(
    0,
    (
        r"^(  Code block )(\[)(\d+)(\])(, line )(\d+)(, in )(.+)(\n)",
        bygroups(Text, Operator, Number, Operator, Text, Number, Text, Name, Text),
    ),
)
PythonTracebackLexer.tokens["intb"].insert(
    1,
    (
        r"^(  Code block )(\[)(\d+)(\])(, line )(\d+)(\n)",
        bygroups(Text, Operator, Number, Operator, Text, Number, Text),
    ),
)