242 # counting |
242 # counting |
243 if tok.type == NEWLINE: |
243 if tok.type == NEWLINE: |
244 stats.inc('nloc') |
244 stats.inc('nloc') |
245 elif tok.type == COMMENT: |
245 elif tok.type == COMMENT: |
246 stats.inc('comments') |
246 stats.inc('comments') |
|
247 if tok.line.strip() == tok.text: |
|
248 stats.inc('commentlines') |
247 elif tok.type == EMPTY: |
249 elif tok.type == EMPTY: |
248 if parser.tokenlist[idx - 1].type == token.OP: |
250 if parser.tokenlist[idx - 1].type == token.OP: |
249 stats.inc('nloc') |
251 stats.inc('nloc') |
|
252 elif parser.tokenlist[idx - 1].type == COMMENT: |
|
253 continue |
250 else: |
254 else: |
251 stats.inc('empty') |
255 stats.inc('empty') |
252 elif tok.type == INDENT: |
256 elif tok.type == INDENT: |
253 stats.indent(tok) |
257 stats.indent(tok) |
254 elif tok.type == DEDENT: |
258 elif tok.type == DEDENT: |
259 |
263 |
260 # collect overall statistics |
264 # collect overall statistics |
261 summarize(total, 'lines', parser.lines) |
265 summarize(total, 'lines', parser.lines) |
262 summarize(total, 'bytes', len(text)) |
266 summarize(total, 'bytes', len(text)) |
263 summarize(total, 'comments', stats.getCounter('TOTAL ', 'comments')) |
267 summarize(total, 'comments', stats.getCounter('TOTAL ', 'comments')) |
|
268 summarize(total, 'commentlines', |
|
269 stats.getCounter('TOTAL ', 'commentlines')) |
264 summarize(total, 'empty lines', stats.getCounter('TOTAL ', 'empty')) |
270 summarize(total, 'empty lines', stats.getCounter('TOTAL ', 'empty')) |
265 summarize(total, 'non-commentary lines', |
271 summarize(total, 'non-commentary lines', |
266 stats.getCounter('TOTAL ', 'nloc')) |
272 stats.getCounter('TOTAL ', 'nloc')) |
267 |
273 |
268 return stats |
274 return stats |