update python code to deal with bang comments everywhere
This commit is contained in:
parent
66462026bb
commit
4cbaa1c438
@ -132,37 +132,34 @@ which looks like this:
|
||||
pattern = (
|
||||
r'([^\047"/\000-\040]+)|((?:(?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]'
|
||||
r'|\r?\n|\r)[^\047\\\r\n]*)*\047)|(?:"[^"\\\r\n]*(?:\\(?:[^\r\n]'
|
||||
r'|\r?\n|\r)[^"\\\r\n]*)*"))[^\047"/\000-\040]*)|((?:/\*![^*]*\*'
|
||||
r'+(?:[^/*][^*]*\*+)*/)[^\047"/\000-\040]*)|(?<=[(,=:\[!&|?{};\r'
|
||||
r'\n])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*'
|
||||
r'|\r?\n|\r)[^"\\\r\n]*)*"))[^\047"/\000-\040]*)|(?<=[(,=:\[!&|?'
|
||||
r'{};\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*'
|
||||
r'][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\0'
|
||||
r'14\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)*((?:/('
|
||||
r'?![\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:'
|
||||
r'\\[^\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\01'
|
||||
r'3\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?'
|
||||
r':(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*('
|
||||
r'?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|'
|
||||
r'}-]))?|(?<=[\000-#%-,./:-@\[-^`{-~-]return)(?:[\000-\011\013\0'
|
||||
r'14\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?'
|
||||
r'://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/)))*((?:/(?![\r\n/*])[^/\\\[\r\n]*'
|
||||
r'(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\])'
|
||||
r')[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:'
|
||||
r'[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*'
|
||||
r'\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[^\000-!#%&(*,'
|
||||
r'./:-@\[\\^`{|~])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*'
|
||||
r']*\*+(?:[^/*][^*]*\*+)*/))*(?:((?:(?://[^\r\n]*)?[\r\n]))(?:['
|
||||
r'\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*'
|
||||
r'+)*/))*)+(?=[^\000-\040"#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#'
|
||||
r'%-,./:-@\[-^`{-~-])((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=[^\000-#%-,./:-@\[-^`{-~-])'
|
||||
r'|(?<=\+)((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?'
|
||||
r':[^/*][^*]*\*+)*/)))+(?=\+)|(?<=-)((?:[\000-\011\013\014\016-'
|
||||
r'\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=-)|(?:[\000'
|
||||
r'-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/'
|
||||
r'))+|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040'
|
||||
r']|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+'
|
||||
r'14\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)*((?:/(?![\r'
|
||||
r'\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r'
|
||||
r'\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014'
|
||||
r'\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r'
|
||||
r'\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:'
|
||||
r'[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[\00'
|
||||
r'0-#%-,./:-@\[-^`{-~-]return)(?:[\000-\011\013\014\016-\040]|(?'
|
||||
r':/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*((?:/(?![\r\n/*])[^/\\\[\r\n'
|
||||
r']*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*'
|
||||
r'\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014\016-\040]|(?:/\*['
|
||||
r'^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:['
|
||||
r'\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)'
|
||||
r')*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[^\000-!#%&(*,./:-@\['
|
||||
r'\\^`{|~])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*'
|
||||
r'][^*]*\*+)*/))*(?:((?:(?://[^\r\n]*)?[\r\n]))(?:[\000-\011\013'
|
||||
r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000'
|
||||
r'-\040"#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#%-,./:-@\[-^`{-~-]'
|
||||
r')((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*'
|
||||
r'\*+)*/)))+(?=[^\000-#%-,./:-@\[-^`{-~-])|(?<=\+)((?:[\000-\011'
|
||||
r'\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=\+)'
|
||||
r'|(?<=-)((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*]'
|
||||
r'[^*]*\*+)*/)))+(?=-)|(?:[\000-\011\013\014\016-\040]|(?:/\*[^*'
|
||||
r']*\*+(?:[^/*][^*]*\*+)*/))+|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\0'
|
||||
r'00-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*'
|
||||
r')+'
|
||||
)
|
||||
|
||||
|
||||
|
198
rjsmin.py
198
rjsmin.py
@ -120,7 +120,6 @@ def _make_jsmin(python_only=False):
|
||||
nospecial, charclass, nospecial
|
||||
)
|
||||
space = r'(?:%s|%s)' % (space_chars, space_comment)
|
||||
space_nobang = r'(?:%s|%s)' % (space_chars, space_comment_nobang)
|
||||
newline = r'(?:%s?[\r\n])' % line_comment
|
||||
|
||||
def fix_charclass(result):
|
||||
@ -200,7 +199,7 @@ def _make_jsmin(python_only=False):
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+' # 3
|
||||
r'(?=%(post_regex_off)s))?'
|
||||
r'|(?<=%(preregex2)s)'
|
||||
r'%(space)s*(?:%(newline)s%(space)s)*'
|
||||
r'%(space)s*'
|
||||
r'(%(regex)s)' # 4
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+' # 5
|
||||
r'(?=%(post_regex_off)s))?'
|
||||
@ -245,29 +244,38 @@ def _make_jsmin(python_only=False):
|
||||
|
||||
r'(%(dull)s+)' # 0
|
||||
r'|(%(strings)s%(dull)s*)' # 1
|
||||
r'|(%(bang_comment)s%(dull)s*)' # 2
|
||||
r'|(?<=%(preregex1)s)'
|
||||
r'%(space)s*(?:%(newline)s%(space)s*)*'
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)*)' # 2
|
||||
r'(%(regex)s)' # 3
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+' # 4
|
||||
r'(?=%(post_regex_off)s))?'
|
||||
r'|(?<=%(preregex2)s)'
|
||||
r'%(space)s*(?:%(newline)s%(space)s)*'
|
||||
r'(%(regex)s)' # 5
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+' # 6
|
||||
r'(%(space)s*)' # 5
|
||||
r'(%(regex)s)' # 6
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+' # 7
|
||||
r'(?=%(post_regex_off)s))?'
|
||||
r'|(?<=%(id_literal_close)s)'
|
||||
r'%(space)s*(?:(%(newline)s)%(space)s*)+' # 7
|
||||
r'(%(space)s*(?:%(newline)s%(space)s*)+)' # 8
|
||||
r'(?=%(id_literal_open)s)'
|
||||
r'|(?<=%(id_literal)s)(%(space)s)+(?=%(id_literal)s)' # 8
|
||||
r'|(?<=\+)(%(space)s)+(?=\+)' # 9
|
||||
r'|(?<=-)(%(space)s)+(?=-)' # 10
|
||||
r'|%(space)s+'
|
||||
r'|(?:%(newline)s%(space)s*)+'
|
||||
) % dict(locals(), space=space_nobang)).sub
|
||||
r'|(?<=%(id_literal)s)(%(space)s+)(?=%(id_literal)s)' # 9
|
||||
r'|(?<=\+)(%(space)s+)(?=\+)' # 10
|
||||
r'|(?<=-)(%(space)s+)(?=-)' # 11
|
||||
r'|(%(space)s+)' # 12
|
||||
r'|((?:%(newline)s%(space)s*)+)' # 13
|
||||
) % locals()).sub
|
||||
|
||||
# print space_sub_banged.__self__.pattern
|
||||
|
||||
keep = _re.compile((
|
||||
# noqa pylint: disable = C0330
|
||||
|
||||
r'%(space_chars)s+|%(space_comment_nobang)s+|%(newline)s+'
|
||||
r'|(%(bang_comment)s+)'
|
||||
) % locals()).sub
|
||||
keeper = lambda m: m.groups()[0] or ''
|
||||
|
||||
# print keep.__self__.pattern
|
||||
|
||||
def space_subber_banged(match):
|
||||
""" Substitution callback """
|
||||
# pylint: disable = R0911
|
||||
@ -277,22 +285,26 @@ def _make_jsmin(python_only=False):
|
||||
return groups[0]
|
||||
elif groups[1]:
|
||||
return groups[1]
|
||||
elif groups[2]:
|
||||
return groups[2]
|
||||
elif groups[3]:
|
||||
if groups[4]:
|
||||
return groups[3] + '\n'
|
||||
return groups[3]
|
||||
elif groups[5]:
|
||||
if groups[6]:
|
||||
return groups[5] + '\n'
|
||||
return groups[5]
|
||||
elif groups[7]:
|
||||
return '\n'
|
||||
elif groups[8] or groups[9] or groups[10]:
|
||||
return ' '
|
||||
return "%s%s%s%s" % (
|
||||
keep(keeper, groups[2]),
|
||||
groups[3],
|
||||
keep(keeper, groups[4] or ''),
|
||||
groups[4] and '\n' or '',
|
||||
)
|
||||
elif groups[6]:
|
||||
return "%s%s%s%s" % (
|
||||
keep(keeper, groups[5]),
|
||||
groups[6],
|
||||
keep(keeper, groups[7] or ''),
|
||||
groups[7] and '\n' or '',
|
||||
)
|
||||
elif groups[8]:
|
||||
return keep(keeper, groups[8]) + '\n'
|
||||
elif groups[9] or groups[10] or groups[11]:
|
||||
return keep(keeper, groups[9] or groups[10] or groups[11]) or ' '
|
||||
else:
|
||||
return ''
|
||||
return keep(keeper, groups[12] or groups[13])
|
||||
|
||||
def jsmin(script, keep_bang_comments=False): # pylint: disable = W0621
|
||||
r"""
|
||||
@ -368,25 +380,24 @@ def jsmin_for_posers(script, keep_bang_comments=False):
|
||||
r'\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:'
|
||||
r'[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[\00'
|
||||
r'0-#%-,./:-@\[-^`{-~-]return)(?:[\000-\011\013\014\016-\040]|(?'
|
||||
r':/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])'
|
||||
r'(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+'
|
||||
r')*/)))*((?:/(?![\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^'
|
||||
r'\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:'
|
||||
r'[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/'
|
||||
r'))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]'
|
||||
r'|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?'
|
||||
r'\]|}-]))?|(?<=[^\000-!#%&(*,./:-@\[\\^`{|~])(?:[\000-\011\013'
|
||||
r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:((?:(?:/'
|
||||
r'/[^\r\n]*)?[\r\n]))(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*'
|
||||
r'\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000-\040"#%-\047)*,./:-@\\-^`'
|
||||
r'|-~])|(?<=[^\000-#%-,./:-@\[-^`{-~-])((?:[\000-\011\013\014\01'
|
||||
r'6-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=[^\000-#%-,./:'
|
||||
r'-@\[-^`{-~-])|(?<=\+)((?:[\000-\011\013\014\016-\040]|(?:/\*[^'
|
||||
r'*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=\+)|(?<=-)((?:[\000-\011\013\0'
|
||||
r'14\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=-)|(?:[\0'
|
||||
r'00-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))+'
|
||||
r'|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|('
|
||||
r'?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+'
|
||||
r':/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*((?:/(?![\r\n/*])[^/\\\[\r\n'
|
||||
r']*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*'
|
||||
r'\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014\016-\040]|(?:/\*['
|
||||
r'^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:['
|
||||
r'\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)'
|
||||
r')*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[^\000-!#%&(*,./:-@\['
|
||||
r'\\^`{|~])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*'
|
||||
r'][^*]*\*+)*/))*(?:((?:(?://[^\r\n]*)?[\r\n]))(?:[\000-\011\013'
|
||||
r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000'
|
||||
r'-\040"#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#%-,./:-@\[-^`{-~-]'
|
||||
r')((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*'
|
||||
r'\*+)*/)))+(?=[^\000-#%-,./:-@\[-^`{-~-])|(?<=\+)((?:[\000-\011'
|
||||
r'\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=\+)'
|
||||
r'|(?<=-)((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*]'
|
||||
r'[^*]*\*+)*/)))+(?=-)|(?:[\000-\011\013\014\016-\040]|(?:/\*[^*'
|
||||
r']*\*+(?:[^/*][^*]*\*+)*/))+|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\0'
|
||||
r'00-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*'
|
||||
r')+'
|
||||
)
|
||||
|
||||
def subber(match):
|
||||
@ -409,55 +420,66 @@ def jsmin_for_posers(script, keep_bang_comments=False):
|
||||
rex = (
|
||||
r'([^\047"/\000-\040]+)|((?:(?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]'
|
||||
r'|\r?\n|\r)[^\047\\\r\n]*)*\047)|(?:"[^"\\\r\n]*(?:\\(?:[^\r\n]'
|
||||
r'|\r?\n|\r)[^"\\\r\n]*)*"))[^\047"/\000-\040]*)|((?:/\*![^*]*\*'
|
||||
r'+(?:[^/*][^*]*\*+)*/)[^\047"/\000-\040]*)|(?<=[(,=:\[!&|?{};\r'
|
||||
r'\n])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*'
|
||||
r'][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\0'
|
||||
r'14\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)*((?:/('
|
||||
r'?![\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:'
|
||||
r'\\[^\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\01'
|
||||
r'3\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?'
|
||||
r':(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*('
|
||||
r'?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|'
|
||||
r'}-]))?|(?<=[\000-#%-,./:-@\[-^`{-~-]return)(?:[\000-\011\013\0'
|
||||
r'14\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?'
|
||||
r'://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/)))*((?:/(?![\r\n/*])[^/\\\[\r\n]*'
|
||||
r'(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\])'
|
||||
r')[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:'
|
||||
r'[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*'
|
||||
r'\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[^\000-!#%&(*,'
|
||||
r'./:-@\[\\^`{|~])(?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*'
|
||||
r']*\*+(?:[^/*][^*]*\*+)*/))*(?:((?:(?://[^\r\n]*)?[\r\n]))(?:['
|
||||
r'\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*'
|
||||
r'+)*/))*)+(?=[^\000-\040"#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#'
|
||||
r'%-,./:-@\[-^`{-~-])((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!'
|
||||
r')[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=[^\000-#%-,./:-@\[-^`{-~-])'
|
||||
r'|(?<=\+)((?:[\000-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?'
|
||||
r':[^/*][^*]*\*+)*/)))+(?=\+)|(?<=-)((?:[\000-\011\013\014\016-'
|
||||
r'\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=-)|(?:[\000'
|
||||
r'-\011\013\014\016-\040]|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/'
|
||||
r'))+|(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040'
|
||||
r']|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+'
|
||||
r'|\r?\n|\r)[^"\\\r\n]*)*"))[^\047"/\000-\040]*)|(?<=[(,=:\[!&|?'
|
||||
r'{};\r\n])((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/'
|
||||
r'*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-\011\013'
|
||||
r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)*)((?:/(?!'
|
||||
r'[\r\n/*])[^/\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^'
|
||||
r'\r\n][^\\\]\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\013\01'
|
||||
r'4\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^'
|
||||
r'\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+('
|
||||
r'?:[^/*][^*]*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=['
|
||||
r'\000-#%-,./:-@\[-^`{-~-]return)((?:[\000-\011\013\014\016-\040'
|
||||
r']|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)((?:/(?![\r\n/*])[^/'
|
||||
r'\\\[\r\n]*(?:(?:\\[^\r\n]|(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]'
|
||||
r'\r\n]*)*\]))[^/\\\[\r\n]*)*/))((?:[\000-\011\013\014\016-\040]'
|
||||
r'|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r'
|
||||
r'\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]'
|
||||
r'*\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))?|(?<=[^\000-!#%&(*'
|
||||
r',./:-@\[\\^`{|~])((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*'
|
||||
r'\*+(?:[^/*][^*]*\*+)*/))*(?:(?:(?://[^\r\n]*)?[\r\n])(?:[\000-'
|
||||
r'\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))*)+)'
|
||||
r'(?=[^\000-\040"#%-\047)*,./:-@\\-^`|-~])|(?<=[^\000-#%-,./:-@'
|
||||
r'\[-^`{-~-])((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:['
|
||||
r'^/*][^*]*\*+)*/))+)(?=[^\000-#%-,./:-@\[-^`{-~-])|(?<=\+)((?:['
|
||||
r'\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)'
|
||||
r')+)(?=\+)|(?<=-)((?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*'
|
||||
r'+(?:[^/*][^*]*\*+)*/))+)(?=-)|((?:[\000-\011\013\014\016-\040]'
|
||||
r'|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))+)|((?:(?:(?://[^\r\n]*)?['
|
||||
r'\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^'
|
||||
r'*]*\*+)*/))*)+)'
|
||||
)
|
||||
|
||||
keep = _re.compile((
|
||||
r'[\000-\011\013\014\016-\040]+|(?:/\*(?!!)[^*]*\*+(?:[^/*][^*]*'
|
||||
r'\*+)*/)+|(?:(?://[^\r\n]*)?[\r\n])+|((?:/\*![^*]*\*+(?:[^/*][^'
|
||||
r'*]*\*+)*/)+)'
|
||||
) % locals()).sub
|
||||
keeper = lambda m: m.groups()[0] or ''
|
||||
|
||||
def subber(match):
|
||||
""" Substitution callback """
|
||||
groups = match.groups()
|
||||
return (
|
||||
groups[0] or
|
||||
groups[1] or
|
||||
groups[2] or
|
||||
(groups[4] and (groups[3] + '\n')) or
|
||||
groups[3] or
|
||||
(groups[6] and (groups[5] + '\n')) or
|
||||
groups[5] or
|
||||
(groups[7] and '\n') or
|
||||
(groups[8] and ' ') or
|
||||
(groups[9] and ' ') or
|
||||
(groups[10] and ' ') or
|
||||
''
|
||||
(groups[3] and "%s%s%s%s" % (
|
||||
keep(keeper, groups[2]),
|
||||
groups[3],
|
||||
keep(keeper, groups[4] or ''),
|
||||
groups[4] and '\n' or '',
|
||||
)) or
|
||||
(groups[6] and "%s%s%s%s" % (
|
||||
keep(keeper, groups[5]),
|
||||
groups[6],
|
||||
keep(keeper, groups[7] or ''),
|
||||
groups[7] and '\n' or '',
|
||||
)) or
|
||||
(groups[8] and keep(keeper, groups[8] + '\n')) or
|
||||
(groups[9] and keep(keeper, groups[9]) or ' ') or
|
||||
(groups[10] and keep(keeper, groups[10]) or ' ') or
|
||||
(groups[11] and keep(keeper, groups[11]) or ' ') or
|
||||
keep(keeper, groups[12] or groups[13])
|
||||
)
|
||||
|
||||
return _re.sub(rex, subber, '\n%s\n' % script).strip()
|
||||
|
Loading…
Reference in New Issue
Block a user