OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # | 2 # |
3 # Copyright 2011 - 2013 | 3 # Copyright 2011 - 2013 |
4 # Andr\xe9 Malo or his licensors, as applicable | 4 # Andr\xe9 Malo or his licensors, as applicable |
5 # | 5 # |
6 # Licensed under the Apache License, Version 2.0 (the "License"); | 6 # Licensed under the Apache License, Version 2.0 (the "License"); |
7 # you may not use this file except in compliance with the License. | 7 # you may not use this file except in compliance with the License. |
8 # You may obtain a copy of the License at | 8 # You may obtain a copy of the License at |
9 # | 9 # |
10 # http://www.apache.org/licenses/LICENSE-2.0 | 10 # http://www.apache.org/licenses/LICENSE-2.0 |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 except NameError: | 92 except NameError: |
93 xrange = range # pylint: disable = W0622 | 93 xrange = range # pylint: disable = W0622 |
94 | 94 |
95 space_chars = r'[\000-\011\013\014\016-\040]' | 95 space_chars = r'[\000-\011\013\014\016-\040]' |
96 | 96 |
97 line_comment = r'(?://[^\r\n]*)' | 97 line_comment = r'(?://[^\r\n]*)' |
98 space_comment = r'(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)' | 98 space_comment = r'(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)' |
99 string1 = \ | 99 string1 = \ |
100 r'(?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^\047\\\r\n]*)*\047)' | 100 r'(?:\047[^\047\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^\047\\\r\n]*)*\047)' |
101 string2 = r'(?:"[^"\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^"\\\r\n]*)*")' | 101 string2 = r'(?:"[^"\\\r\n]*(?:\\(?:[^\r\n]|\r?\n|\r)[^"\\\r\n]*)*")' |
102 strings = r'(?:%s|%s)' % (string1, string2) | 102 string3 = r'(?:`(?:[^`\\]|\\.)*`)' |
| 103 strings = r'(?:%s|%s|%s)' % (string1, string2, string3) |
103 | 104 |
104 charclass = r'(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\])' | 105 charclass = r'(?:\[[^\\\]\r\n]*(?:\\[^\r\n][^\\\]\r\n]*)*\])' |
105 nospecial = r'[^/\\\[\r\n]' | 106 nospecial = r'[^/\\\[\r\n]' |
106 regex = r'(?:/(?![\r\n/*])%s*(?:(?:\\[^\r\n]|%s)%s*)*/)' % ( | 107 regex = r'(?:/(?![\r\n/*])%s*(?:(?:\\[^\r\n]|%s)%s*)*/)' % ( |
107 nospecial, charclass, nospecial) | 108 nospecial, charclass, nospecial) |
108 space = r'(?:%s|%s)' % (space_chars, space_comment) | 109 space = r'(?:%s|%s)' % (space_chars, space_comment) |
109 newline = r'(?:%s?[\r\n])' % line_comment | 110 newline = r'(?:%s?[\r\n])' % line_comment |
110 | 111 |
111 def fix_charclass(result): | 112 def fix_charclass(result): |
112 """ Fixup string of chars to fit into a regex char class """ | 113 """ Fixup string of chars to fit into a regex char class """ |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 return r'[%s]' % fix_charclass(result) | 156 return r'[%s]' % fix_charclass(result) |
156 | 157 |
157 not_id_literal = not_id_literal_(r'[a-zA-Z0-9_$]') | 158 not_id_literal = not_id_literal_(r'[a-zA-Z0-9_$]') |
158 preregex1 = r'[(,=:\[!&|?{};\r\n]' | 159 preregex1 = r'[(,=:\[!&|?{};\r\n]' |
159 preregex2 = r'%(not_id_literal)sreturn' % locals() | 160 preregex2 = r'%(not_id_literal)sreturn' % locals() |
160 | 161 |
161 id_literal = id_literal_(r'[a-zA-Z0-9_$]') | 162 id_literal = id_literal_(r'[a-zA-Z0-9_$]') |
162 id_literal_open = id_literal_(r'[a-zA-Z0-9_${\[(!+-]') | 163 id_literal_open = id_literal_(r'[a-zA-Z0-9_${\[(!+-]') |
163 id_literal_close = id_literal_(r'[a-zA-Z0-9_$}\])"\047+-]') | 164 id_literal_close = id_literal_(r'[a-zA-Z0-9_$}\])"\047+-]') |
164 | 165 |
165 dull = r'[^\047"/\000-\040]' | 166 dull = r'[^\047"`/\000-\040]' |
166 | 167 |
167 space_sub = _re.compile(( | 168 space_sub = _re.compile(( |
168 r'(%(dull)s+)' | 169 r'(%(dull)s+)' |
169 r'|(%(strings)s%(dull)s*)' | 170 r'|(%(strings)s%(dull)s*)' |
170 r'|(?<=%(preregex1)s)' | 171 r'|(?<=%(preregex1)s)' |
171 r'%(space)s*(?:%(newline)s%(space)s*)*' | 172 r'%(space)s*(?:%(newline)s%(space)s*)*' |
172 r'(%(regex)s%(dull)s*)' | 173 r'(%(regex)s%(dull)s*)' |
173 r'|(?<=%(preregex2)s)' | 174 r'|(?<=%(preregex2)s)' |
174 r'%(space)s*(?:%(newline)s%(space)s)*' | 175 r'%(space)s*(?:%(newline)s%(space)s)*' |
175 r'(%(regex)s%(dull)s*)' | 176 r'(%(regex)s%(dull)s*)' |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
286 r'\*+(?:[^/*][^*]*\*+)*/)))+(?=\+)|(?<=-)((?:[\000-\011\013\014\016-' | 287 r'\*+(?:[^/*][^*]*\*+)*/)))+(?=\+)|(?<=-)((?:[\000-\011\013\014\016-' |
287 r'\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=-)|(?:[\000-\011\013' | 288 r'\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/)))+(?=-)|(?:[\000-\011\013' |
288 r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))+|(?:(?:(?://[^' | 289 r'\014\016-\040]|(?:/\*[^*]*\*+(?:[^/*][^*]*\*+)*/))+|(?:(?:(?://[^' |
289 r'\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^' | 290 r'\r\n]*)?[\r\n])(?:[\000-\011\013\014\016-\040]|(?:/\*[^*]*\*+(?:[^' |
290 r'/*][^*]*\*+)*/))*)+', subber, '\n%s\n' % script).strip() | 291 r'/*][^*]*\*+)*/))*)+', subber, '\n%s\n' % script).strip() |
291 | 292 |
292 | 293 |
293 if __name__ == '__main__': | 294 if __name__ == '__main__': |
294 import sys as _sys | 295 import sys as _sys |
295 _sys.stdout.write(jsmin(_sys.stdin.read())) | 296 _sys.stdout.write(jsmin(_sys.stdin.read())) |
OLD | NEW |