lexers.py
24 lines
| 944 B
| text/x-python
|
PythonLexer
/ converters / lexers.py
|
r7912 | #----------------------------------------------------------------------------- | ||
# Imports | ||||
#----------------------------------------------------------------------------- | ||||
from pygments.lexers import PythonLexer, BashLexer | ||||
from pygments.lexer import bygroups, using | ||||
|
r8748 | from pygments.token import Keyword, Operator, Text | ||
|
r7912 | |||
#----------------------------------------------------------------------------- | ||||
# Classes | ||||
#----------------------------------------------------------------------------- | ||||
class IPythonLexer(PythonLexer): | ||||
name = 'IPython' | ||||
aliases = ['ip', 'ipython'] | ||||
filenames = ['*.ipy'] | ||||
tokens = PythonLexer.tokens.copy() | ||||
tokens['root'] = [ | ||||
|
r8749 | (r'(\%+)(\w+)\s+(\.*)(\n)', bygroups(Operator, Keyword, | ||
using(BashLexer), Text)), | ||||
|
r7912 | (r'(\%+)(\w+)\b', bygroups(Operator, Keyword)), | ||
(r'^(!)(.+)(\n)', bygroups(Operator, using(BashLexer), Text)), | ||||
] + tokens['root'] | ||||