annotate jsmin.py @ 93:817aa2851339 default tip

Added a very simple index.html.
author Atul Varma <varmaa@toolness.com>
date Fri, 23 May 2008 03:50:44 -0700
parents 9d9d8c76d52d
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
26
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
1 #!/usr/bin/python
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
2
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
3 # This code is original from jsmin by Douglas Crockford, it was translated to
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
4 # Python by Baruch Even. The original code had the following copyright and
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
5 # license.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
6 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
7 # /* jsmin.c
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
8 # 2007-05-22
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
9 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
10 # Copyright (c) 2002 Douglas Crockford (www.crockford.com)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
11 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
12 # Permission is hereby granted, free of charge, to any person obtaining a copy of
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
13 # this software and associated documentation files (the "Software"), to deal in
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
14 # the Software without restriction, including without limitation the rights to
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
15 # use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
16 # of the Software, and to permit persons to whom the Software is furnished to do
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
17 # so, subject to the following conditions:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
18 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
19 # The above copyright notice and this permission notice shall be included in all
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
20 # copies or substantial portions of the Software.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
21 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
22 # The Software shall be used for Good, not Evil.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
23 #
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
24 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
25 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
26 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
27 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
28 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
29 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
30 # SOFTWARE.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
31 # */
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
32
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
33 from StringIO import StringIO
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
34
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
35 def jsmin(js):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
36 ins = StringIO(js)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
37 outs = StringIO()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
38 JavascriptMinify().minify(ins, outs)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
39 str = outs.getvalue()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
40 if len(str) > 0 and str[0] == '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
41 str = str[1:]
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
42 return str
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
43
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
44 def isAlphanum(c):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
45 """return true if the character is a letter, digit, underscore,
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
46 dollar sign, or non-ASCII character.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
47 """
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
48 return ((c >= 'a' and c <= 'z') or (c >= '0' and c <= '9') or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
49 (c >= 'A' and c <= 'Z') or c == '_' or c == '$' or c == '\\' or (c is not None and ord(c) > 126));
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
50
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
51 class UnterminatedComment(Exception):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
52 pass
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
53
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
54 class UnterminatedStringLiteral(Exception):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
55 pass
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
56
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
57 class UnterminatedRegularExpression(Exception):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
58 pass
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
59
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
60 class JavascriptMinify(object):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
61
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
62 def _outA(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
63 self.outstream.write(self.theA)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
64 def _outB(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
65 self.outstream.write(self.theB)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
66
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
67 def _get(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
68 """return the next character from stdin. Watch out for lookahead. If
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
69 the character is a control character, translate it to a space or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
70 linefeed.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
71 """
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
72 c = self.theLookahead
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
73 self.theLookahead = None
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
74 if c == None:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
75 c = self.instream.read(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
76 if c >= ' ' or c == '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
77 return c
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
78 if c == '': # EOF
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
79 return '\000'
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
80 if c == '\r':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
81 return '\n'
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
82 return ' '
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
83
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
84 def _peek(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
85 self.theLookahead = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
86 return self.theLookahead
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
87
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
88 def _next(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
89 """get the next character, excluding comments. peek() is used to see
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
90 if a '/' is followed by a '/' or '*'.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
91 """
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
92 c = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
93 if c == '/':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
94 p = self._peek()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
95 if p == '/':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
96 c = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
97 while c > '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
98 c = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
99 return c
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
100 if p == '*':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
101 c = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
102 while 1:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
103 c = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
104 if c == '*':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
105 if self._peek() == '/':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
106 self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
107 return ' '
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
108 if c == '\000':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
109 raise UnterminatedComment()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
110
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
111 return c
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
112
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
113 def _action(self, action):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
114 """do something! What you do is determined by the argument:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
115 1 Output A. Copy B to A. Get the next B.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
116 2 Copy B to A. Get the next B. (Delete A).
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
117 3 Get the next B. (Delete B).
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
118 action treats a string as a single character. Wow!
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
119 action recognizes a regular expression if it is preceded by ( or , or =.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
120 """
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
121 if action <= 1:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
122 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
123
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
124 if action <= 2:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
125 self.theA = self.theB
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
126 if self.theA == "'" or self.theA == '"':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
127 while 1:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
128 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
129 self.theA = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
130 if self.theA == self.theB:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
131 break
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
132 if self.theA <= '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
133 raise UnterminatedStringLiteral()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
134 if self.theA == '\\':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
135 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
136 self.theA = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
137
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
138
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
139 if action <= 3:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
140 self.theB = self._next()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
141 if self.theB == '/' and (self.theA == '(' or self.theA == ',' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
142 self.theA == '=' or self.theA == ':' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
143 self.theA == '[' or self.theA == '?' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
144 self.theA == '!' or self.theA == '&' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
145 self.theA == '|' or self.theA == ';' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
146 self.theA == '{' or self.theA == '}' or
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
147 self.theA == '\n'):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
148 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
149 self._outB()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
150 while 1:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
151 self.theA = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
152 if self.theA == '/':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
153 break
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
154 elif self.theA == '\\':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
155 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
156 self.theA = self._get()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
157 elif self.theA <= '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
158 raise UnterminatedRegularExpression()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
159 self._outA()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
160 self.theB = self._next()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
161
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
162
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
163 def _jsmin(self):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
164 """Copy the input to the output, deleting the characters which are
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
165 insignificant to JavaScript. Comments will be removed. Tabs will be
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
166 replaced with spaces. Carriage returns will be replaced with linefeeds.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
167 Most spaces and linefeeds will be removed.
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
168 """
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
169 self.theA = '\n'
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
170 self._action(3)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
171
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
172 while self.theA != '\000':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
173 if self.theA == ' ':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
174 if isAlphanum(self.theB):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
175 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
176 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
177 self._action(2)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
178 elif self.theA == '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
179 if self.theB in ['{', '[', '(', '+', '-']:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
180 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
181 elif self.theB == ' ':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
182 self._action(3)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
183 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
184 if isAlphanum(self.theB):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
185 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
186 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
187 self._action(2)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
188 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
189 if self.theB == ' ':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
190 if isAlphanum(self.theA):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
191 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
192 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
193 self._action(3)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
194 elif self.theB == '\n':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
195 if self.theA in ['}', ']', ')', '+', '-', '"', '\'']:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
196 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
197 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
198 if isAlphanum(self.theA):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
199 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
200 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
201 self._action(3)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
202 else:
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
203 self._action(1)
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
204
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
205 def minify(self, instream, outstream):
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
206 self.instream = instream
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
207 self.outstream = outstream
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
208 self.theA = '\n'
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
209 self.theB = None
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
210 self.theLookahead = None
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
211
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
212 self._jsmin()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
213 self.instream.close()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
214
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
215 if __name__ == '__main__':
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
216 import sys
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
217 jsm = JavascriptMinify()
9d9d8c76d52d Added jsmin.py, although I've removed the comment from the SConstruct to use packer b/c it doesn't actually reduce the size of troll.js (nor does minify).
Atul Varma <varmaa@toolness.com>
parents:
diff changeset
218 jsm.minify(sys.stdin, sys.stdout)