112 """ |
112 """ |
113 def __init__(self): |
113 def __init__(self): |
114 """ |
114 """ |
115 Constructor |
115 Constructor |
116 """ |
116 """ |
117 self.identifiers = [] # list of identifiers in order of appearance |
117 self.identifiers = [] |
118 self.active = [('TOTAL ', -1, 0)] # stack of active identifiers and indent levels |
118 # list of identifiers in order of appearance |
119 self.counters = {} # counters per identifier |
119 self.active = [('TOTAL ', -1, 0)] |
|
120 # stack of active identifiers and indent levels |
|
121 self.counters = {} |
|
122 # counters per identifier |
120 self.indent_level = 0 |
123 self.indent_level = 0 |
121 |
124 |
122 def indent(self, tok): |
125 def indent(self, tok): |
123 """ |
126 """ |
124 Public method used to increment the indentation level. |
127 Public method used to increment the indentation level. |
130 def dedent(self, tok): |
133 def dedent(self, tok): |
131 """ |
134 """ |
132 Public method used to decrement the indentation level. |
135 Public method used to decrement the indentation level. |
133 |
136 |
134 @param tok the token to be processed (Token) |
137 @param tok the token to be processed (Token) |
|
138 @exception ValueError raised to indicate an invalid indentation level |
135 """ |
139 """ |
136 self.indent_level -= 1 |
140 self.indent_level -= 1 |
137 if self.indent_level < 0: |
141 if self.indent_level < 0: |
138 raise ValueError("INTERNAL ERROR: Negative indent level") |
142 raise ValueError("INTERNAL ERROR: Negative indent level") |
139 |
143 |
256 # collect overall statistics |
260 # collect overall statistics |
257 summarize(total, 'lines', parser.lines) |
261 summarize(total, 'lines', parser.lines) |
258 summarize(total, 'bytes', len(text)) |
262 summarize(total, 'bytes', len(text)) |
259 summarize(total, 'comments', stats.getCounter('TOTAL ', 'comments')) |
263 summarize(total, 'comments', stats.getCounter('TOTAL ', 'comments')) |
260 summarize(total, 'empty lines', stats.getCounter('TOTAL ', 'empty')) |
264 summarize(total, 'empty lines', stats.getCounter('TOTAL ', 'empty')) |
261 summarize(total, 'non-commentary lines', stats.getCounter('TOTAL ', 'nloc')) |
265 summarize(total, 'non-commentary lines', |
|
266 stats.getCounter('TOTAL ', 'nloc')) |
262 |
267 |
263 return stats |
268 return stats |
264 |
269 |
265 |
270 |
266 def main(): |
271 def main(): |
267 """ |
272 """ |
268 Modules main function used when called as a script. |
273 Module main function used when called as a script. |
269 |
274 |
270 This function simply loops over all files given on the commandline |
275 Loop over all files given on the command line and collect the individual |
271 and collects the individual and overall source code statistics. |
276 and overall source code statistics. |
272 """ |
277 """ |
273 import sys |
278 import sys |
274 |
279 |
275 files = sys.argv[1:] |
280 files = sys.argv[1:] |
276 |
281 |