MCPcopy Index your code
hub / github.com/prompt-toolkit/ptpython / PtpythonLexer

Class PtpythonLexer

src/ptpython/lexer.py:14–30  ·  view source on GitHub ↗

Lexer for ptpython input. If the input starts with an exclamation mark, use a Bash lexer, otherwise, use a Python 3 lexer.

Source from the content-addressed store, hash-verified

12
13
14class PtpythonLexer(Lexer):
15 """
16 Lexer for ptpython input.
17
18 If the input starts with an exclamation mark, use a Bash lexer, otherwise,
19 use a Python 3 lexer.
20 """
21
22 def __init__(self, python_lexer: Lexer | None = None) -> None:
23 self.python_lexer = python_lexer or PygmentsLexer(PythonLexer)
24 self.system_lexer = PygmentsLexer(BashLexer)
25
26 def lex_document(self, document: Document) -> Callable[[int], StyleAndTextTuples]:
27 if document.text.startswith("!"):
28 return self.system_lexer.lex_document(document)
29
30 return self.python_lexer.lex_document(document)

Callers 1

__init__Method · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected