##// END OF EJS Templates
Simplify control flow with nesting....
Simplify control flow with nesting. These two branches were mutually exclusive and naturally structured as if { if ... else ... }, rather than two conjunctive clauses.

File last commit:

r8789:e0bdc672
r8807:5ac86eea
Show More
lexers.py
38 lines | 1.5 KiB | text/x-python | PythonLexer
David Warde-Farley
Introduce standard structure from coding guidelines in converters/.
r8789 """A custom pygments lexer for IPython code cells.
Informs The pygments highlighting library of the quirks of IPython's superset
of Python -- magic commands, !shell commands, etc.
"""
#-----------------------------------------------------------------------------
# Copyright (c) 2012, the IPython Development Team.
#
# Distributed under the terms of the Modified BSD License.
#
# The full license is in the file COPYING.txt, distributed with this software.
#-----------------------------------------------------------------------------
MinRK
add IPython lexer for pygments
r7912 #-----------------------------------------------------------------------------
# Imports
#-----------------------------------------------------------------------------
David Warde-Farley
Introduce standard structure from coding guidelines in converters/.
r8789 # Third-party imports
MinRK
add IPython lexer for pygments
r7912 from pygments.lexers import PythonLexer, BashLexer
from pygments.lexer import bygroups, using
David Warde-Farley
Unused imports.
r8748 from pygments.token import Keyword, Operator, Text
MinRK
add IPython lexer for pygments
r7912
#-----------------------------------------------------------------------------
# Classes
#-----------------------------------------------------------------------------
class IPythonLexer(PythonLexer):
name = 'IPython'
aliases = ['ip', 'ipython']
filenames = ['*.ipy']
tokens = PythonLexer.tokens.copy()
tokens['root'] = [
David Warde-Farley
PEP8-ify rest of the repository.
r8749 (r'(\%+)(\w+)\s+(\.*)(\n)', bygroups(Operator, Keyword,
using(BashLexer), Text)),
MinRK
add IPython lexer for pygments
r7912 (r'(\%+)(\w+)\b', bygroups(Operator, Keyword)),
(r'^(!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)),
] + tokens['root']