Python pygments.lexers.python.PythonLexer() Examples
The following are 23
code examples of pygments.lexers.python.PythonLexer().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygments.lexers.python
, or try the search function
.
Example #1
Source File: inputhook.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 6 votes |
def main(): # Create user interface. hello_world_window() # Enable threading in GTK. (Otherwise, GTK will keep the GIL.) gtk.gdk.threads_init() # Read input from the command line, using an event loop with this hook. # We use `patch_stdout`, because clicking the button will print something; # and that should print nicely 'above' the input line. with patch_stdout(): session = PromptSession( "Python >>> ", inputhook=inputhook, lexer=PygmentsLexer(PythonLexer) ) result = session.prompt() print("You said: %s" % result)
Example #2
Source File: templates.py From komodo-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #3
Source File: templates.py From syntax-highlighting with GNU Affero General Public License v3.0 | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #4
Source File: parsers.py From syntax-highlighting with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #5
Source File: templates.py From android_universal with MIT License | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #6
Source File: parsers.py From android_universal with MIT License | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #7
Source File: templates.py From diaphora with GNU Affero General Public License v3.0 | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #8
Source File: parsers.py From diaphora with GNU Affero General Public License v3.0 | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #9
Source File: templates.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #10
Source File: parsers.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #11
Source File: templates.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #12
Source File: parsers.py From Carnets with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #13
Source File: terminal.py From ward with MIT License | 5 votes |
def output_why_test_failed(self, test_result: TestResult): err = test_result.error if isinstance(err, TestFailure): src_lines, line_num = inspect.getsourcelines(test_result.test.fn) # TODO: Only include lines up to where the failure occurs if src_lines[-1].strip() == "": src_lines = src_lines[:-1] gutter_width = len(str(len(src_lines) + line_num)) def gutter(i): offset_line_num = i + line_num rv = f"{str(offset_line_num):>{gutter_width}}" if offset_line_num == err.error_line: return colored(f"{rv} ! ", color="red") else: return lightblack(f"{rv} | ") if err.operator in Comparison: src = "".join(src_lines) src = highlight(src, PythonLexer(), TerminalFormatter()) src = f"".join( [gutter(i) + l for i, l in enumerate(src.splitlines(keepends=True))] ) print(indent(src, DOUBLE_INDENT)) if err.operator == Comparison.Equals: self.print_failure_equals(err) else: self.print_traceback(err) print(Style.RESET_ALL)
Example #14
Source File: tokenizer.py From bigcode-tools with MIT License | 5 votes |
def __init__(self, **kwargs): super(Python2Tokenizer, self).__init__(**kwargs) self._lexer = PythonLexer()
Example #15
Source File: parsers.py From komodo-wakatime with BSD 3-Clause "New" or "Revised" License | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #16
Source File: pygments-tokens.py From python-prompt-toolkit with BSD 3-Clause "New" or "Revised" License | 5 votes |
def main(): # Printing a manually constructed list of (Token, text) tuples. text = [ (Token.Keyword, "print"), (Token.Punctuation, "("), (Token.Literal.String.Double, '"'), (Token.Literal.String.Double, "hello"), (Token.Literal.String.Double, '"'), (Token.Punctuation, ")"), (Token.Text, "\n"), ] print_formatted_text(PygmentsTokens(text)) # Printing the output of a pygments lexer. tokens = list(pygments.lex('print("Hello")', lexer=PythonLexer())) print_formatted_text(PygmentsTokens(tokens)) # With a custom style. style = Style.from_dict( { "pygments.keyword": "underline", "pygments.literal.string": "bg:#00ff00 #ffffff", } ) print_formatted_text(PygmentsTokens(tokens), style=style)
Example #17
Source File: templates.py From pygments with BSD 2-Clause "Simplified" License | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #18
Source File: parsers.py From pygments with BSD 2-Clause "Simplified" License | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #19
Source File: templates.py From pySINDy with MIT License | 5 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value
Example #20
Source File: parsers.py From pigaios with GNU General Public License v3.0 | 5 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #21
Source File: terminalwriter.py From pytest with MIT License | 5 votes |
def _highlight(self, source: str) -> str: """Highlight the given source code if we have markup support.""" if not self.hasmarkup or not self.code_highlight: return source try: from pygments.formatters.terminal import TerminalFormatter from pygments.lexers.python import PythonLexer from pygments import highlight except ImportError: return source else: highlighted = highlight( source, PythonLexer(), TerminalFormatter(bg="dark") ) # type: str return highlighted
Example #22
Source File: parsers.py From pySINDy with MIT License | 4 votes |
def __init__(self, **options): super(AntlrPythonLexer, self).__init__(PythonLexer, AntlrLexer, **options)
Example #23
Source File: templates.py From pigaios with GNU General Public License v3.0 | 4 votes |
def get_tokens_unprocessed(self, text): pylexer = PythonLexer(**self.options) for pos, type_, value in pylexer.get_tokens_unprocessed(text): if type_ == Token.Error and value == '$': type_ = Comment.Preproc yield pos, type_, value