Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here's a small script I wrote for finding the total numbers of occurrence for different source code elements in ActionScript 3 code (this is written in Python simply because I'm familiar with it, while Perl would probably be better suited for a regex-heavy script like this):</p> <pre><code>#!/usr/bin/python import sys, os, re # might want to improve on the regexes used here codeElements = { 'package':{ 'regex':re.compile('^\s*[(private|public|static)\s]*package\s+([A-Za-z0-9_.]+)\s*', re.MULTILINE), 'numFound':0 }, 'class':{ 'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal|(\[Bindable\]))\s]*class\s', re.MULTILINE), 'numFound':0 }, 'interface':{ 'regex':re.compile('^\s*[(private|public|static|dynamic|final|internal)\s]*interface\s', re.MULTILINE), 'numFound':0 }, 'function':{ 'regex':re.compile('^\s*[(private|public|static|protected|internal|final|override)\s]*function\s', re.MULTILINE), 'numFound':0 }, 'member variable':{ 'regex':re.compile('^\s*[(private|public|static|protected|internal|(\[Bindable\]))\s]*var\s+([A-Za-z0-9_]+)(\s*\\:\s*([A-Za-z0-9_]+))*\s*', re.MULTILINE), 'numFound':0 }, 'todo note':{ 'regex':re.compile('[*\s/][Tt][Oo]\s?[Dd][Oo][\s\-:_/]', re.MULTILINE), 'numFound':0 } } totalLinesOfCode = 0 filePaths = [] for i in range(1,len(sys.argv)): if os.path.exists(sys.argv[i]): filePaths.append(sys.argv[i]) for filePath in filePaths: thisFile = open(filePath,'r') thisFileContents = thisFile.read() thisFile.close() totalLinesOfCode = totalLinesOfCode + len(thisFileContents.splitlines()) for codeElementName in codeElements: matchSubStrList = codeElements[codeElementName]['regex'].findall(thisFileContents) codeElements[codeElementName]['numFound'] = codeElements[codeElementName]['numFound'] + len(matchSubStrList) for codeElementName in codeElements: print str(codeElements[codeElementName]['numFound']) + ' instances of element "'+codeElementName+'" found' print '---' print str(totalLinesOfCode) + ' total lines of code' print '' </code></pre> <p>Pass paths to all of the source code files in your project as arguments for this script to get it to process all of them and report the totals.</p> <p>A command like this:</p> <pre><code>find /path/to/project/root/ -name "*.as" -or -name "*.mxml" | xargs /path/to/script </code></pre> <p>Will output something like this:</p> <pre><code>1589 instances of element "function" found 147 instances of element "package" found 58 instances of element "todo note" found 13 instances of element "interface" found 2033 instances of element "member variable" found 156 instances of element "class" found --- 40822 total lines of code </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload