Ejemplo n.º 1
0
class IPythonPTLexer(Lexer):
    """
    Wrapper around PythonLexer and BashLexer.
    """
    def __init__(self):
        self.python_lexer = PygmentsLexer(Python3Lexer if PY3 else PythonLexer)
        self.shell_lexer = PygmentsLexer(BashLexer)

    def lex_document(self, cli, document):
        if document.text.startswith('!'):
            return self.shell_lexer.lex_document(cli, document)
        else:
            return self.python_lexer.lex_document(cli, document)
Ejemplo n.º 2
0
class IPythonPTLexer(Lexer):
    """
    Wrapper around PythonLexer and BashLexer.
    """
    def __init__(self):
        self.python_lexer = PygmentsLexer(Python3Lexer if PY3 else PythonLexer)
        self.shell_lexer = PygmentsLexer(BashLexer)

    def lex_document(self, cli, document):
        if document.text.startswith('!'):
            return self.shell_lexer.lex_document(cli, document)
        else:
            return self.python_lexer.lex_document(cli, document)
Ejemplo n.º 3
0
class PdbLexer(Lexer):
    def __init__(self):
        self.python_lexer = PygmentsLexer(PythonLexer)

    def lex_document(self, cli, document):
        parts = document.text.split(None, 1)
        first_word = parts[0] if parts else ''

        # When the first word is a PDB command:
        if first_word in shortcuts.keys() or first_word in commands_with_help.keys():
            # PDB:
            if cli.is_done:
                tokens = [
                    (Token.PdbCommand, ' %s ' % first_word),
                    (Token, ' '),
                    (Token, parts[1] if len(parts) > 1 else ''),
                ]
            else:
                tokens = [(Token.Text, document.text)]

            token_lines = list(split_lines(tokens))
            def get_line(lineno):
                return token_lines[lineno]
            return get_line

        # Otherwise, highlight as Python code.
        else:
            return self.python_lexer.lex_document(cli, document)
Ejemplo n.º 4
0
class PdbLexer(Lexer):
    def __init__(self):
        self.python_lexer = PygmentsLexer(PythonLexer)

    def lex_document(self, cli, document):
        parts = document.text.split(None, 1)
        first_word = parts[0] if parts else ''

        # When the first word is a PDB command:
        if first_word in shortcuts.keys(
        ) or first_word in commands_with_help.keys():
            # PDB:
            if cli.is_done:
                tokens = [
                    (Token.PdbCommand, ' %s ' % first_word),
                    (Token, ' '),
                    (Token, parts[1] if len(parts) > 1 else ''),
                ]
            else:
                tokens = [(Token.Text, document.text)]

            token_lines = list(split_lines(tokens))

            def get_line(lineno):
                return token_lines[lineno]

            return get_line

        # Otherwise, highlight as Python code.
        else:
            return self.python_lexer.lex_document(cli, document)