File tree Expand file tree Collapse file tree 2 files changed +18
-12
lines changed
Expand file tree Collapse file tree 2 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 11
2+ from bpython .line import LazyReCompile
23from bpython .formatter import BPythonFormatter
34from bpython ._py3compat import PythonLexer
45from bpython .config import Struct , loadini , default_config_path
@@ -62,17 +63,21 @@ def fs_from_match(d):
6263 atts ['bold' ] = True
6364 return fmtstr (d ['string' ], ** atts )
6465
66+
67+ peel_off_string_re = LazyReCompile (
68+ r"""(?P<colormarker>\x01
69+ (?P<fg>[krgybmcwdKRGYBMCWD]?)
70+ (?P<bg>[krgybmcwdKRGYBMCWDI]?)?)
71+ (?P<bold>\x02?)
72+ \x03
73+ (?P<string>[^\x04]*)
74+ \x04
75+ (?P<rest>.*)
76+ """ , re .VERBOSE | re .DOTALL )
77+
78+
6579def peel_off_string (s ):
66- p = r"""(?P<colormarker>\x01
67- (?P<fg>[krgybmcwdKRGYBMCWD]?)
68- (?P<bg>[krgybmcwdKRGYBMCWDI]?)?)
69- (?P<bold>\x02?)
70- \x03
71- (?P<string>[^\x04]*)
72- \x04
73- (?P<rest>.*)
74- """
75- m = re .match (p , s , re .VERBOSE | re .DOTALL )
80+ m = peel_off_string_re .match (s )
7681 assert m , repr (s )
7782 d = m .groupdict ()
7883 rest = d ['rest' ]
Original file line number Diff line number Diff line change 1010
1111class LazyReCompile (object ):
1212
13- def __init__ (self , regex ):
13+ def __init__ (self , regex , flags = 0 ):
1414 self .regex = regex
15+ self .flags = flags
1516 self .compiled = None
1617
1718 def compile_regex (method ):
1819 def _impl (self , * args , ** kwargs ):
1920 if self .compiled is None :
20- self .compiled = re .compile (self .regex )
21+ self .compiled = re .compile (self .regex , self . flags )
2122 return method (self , * args , ** kwargs )
2223 return _impl
2324
You can’t perform that action at this time.
0 commit comments