from StringIO import StringIO
+
def jsmin(js):
ins = StringIO(js)
outs = StringIO()
str = str[1:]
return str
+
def isAlphanum(c):
"""return true if the character is a letter, digit, underscore,
dollar sign, or non-ASCII character.
"""
- return ((c >= 'a' and c <= 'z') or (c >= '0' and c <= '9') or
- (c >= 'A' and c <= 'Z') or c == '_' or c == '$' or c == '\\' or (c is not None and ord(c) > 126));
+ return (c >= 'a' and c <= 'z') or (c >= 'A' and c <= 'Z') \
+ or (c >= '0' and c <= '9') or c == '_' or c == '$' or c == '\\' \
+ or (c is not None and ord(c) > 126)
+
class UnterminatedComment(Exception):
pass
+
class UnterminatedStringLiteral(Exception):
pass
+
class UnterminatedRegularExpression(Exception):
pass
+
class JavascriptMinify(object):
def _outA(self):
self.outstream.write(self.theA)
+
def _outB(self):
self.outstream.write(self.theB)
c = self.instream.read(1)
if c >= ' ' or c == '\n':
return c
- if c == '': # EOF
+ if c == '': # EOF
return '\000'
if c == '\r':
return '\n'
self._outA()
self.theA = self._get()
-
if action <= 3:
self.theB = self._next()
if self.theB == '/' and (self.theA == '(' or self.theA == ',' or
self._outA()
self.theB = self._next()
-
def _jsmin(self):
"""Copy the input to the output, deleting the characters which are
insignificant to JavaScript. Comments will be removed. Tabs will be
if __name__ == '__main__':
import sys
jsm = JavascriptMinify()
- jsm.minify(sys.stdin, sys.stdout)
\ No newline at end of file
+ jsm.minify(sys.stdin, sys.stdout)