ObjectiveCParser performs a static analysis on Objective-C code to calculate the metric lines of code per method. The result is written to a *.csv file. ObjectiveCParser is a python script, which uses a generated antlr4 parser for the given Objective-C language grammar from antlr-grammars-v4.
Please star this repository, if you found the project helpful :)
Make sure python3 (including pip3) is installed. Install antlr4, which enables parsing source code.
pip3 install antlr4-python3-runtime
pip3 install antlr4-tools
git clone https://github.com/alschmut/ObjectiveCParser.git
python3 src/main/ProjectParser.py /path/to/MyObjectiveCProject
This generates a *.csv
file with the below structure:
path | method_loc |
---|---|
/path/to/MyFile.m/someMethod | 1 |
/path/to/MyFile.m/anotherMethod | 5 |
I can reccommend using the Open-Source tool CodeCharta, which visualises metrics with a 3D city. Just follow the below steps:
npm i -g codecharta-analysis
ccsh csvimport -d=";" -o MyObjectiveCProject.cc.json MyObjectiveCProject.csv
- Open the CodeCharta Web Demo and import the generated
MyObjectiveCProject.cc.json
file
- Find the <new_language> grammar on antlr-grammars-v4
- Create a new folder
<new_language>
insidesrc/main/antlrParser/
- Copy paste all
.g4
files like Parser, Lexer or UnicodeClasses into the <new_language> folder - Execute
antlr4 -Dlanguage=Python3 *.g4
inside your <new_language> folder. This generates some Python3 classes and other files
- Create a new file
<new_language>ListenerExtended.py
insidesrc/main/antlrParser/ExtendedListener/
- Create a new class which just looks similar to the other existing classes like
ObjcParserListenerExtended
and extend the BaseListener class - Override the language specific
enter...()
functions. To find out which functions to override, have a look at the hierarchical grammar definition inside<your_language>Parser.g4
. Then store the obtained values inside the predefined BaseListener class.
Create another function inside the src/main/antlrParser/LanguageParser.py
like below. Replace the placeholder with your generated/created classes.
def parse_<your_language>_file(self, input_stream: InputStream):
lexer = <your_generated_lexer>(input_stream)
stream = CommonTokenStream(lexer)
parser = <your_generated_parser>(stream)
tree = parser.<your_top_level_grammar_node>()
listener = <your_expanded_listener>()
return self.walk(listener, tree)
Inside src/main/antlrParser/Lanague.py
an enum with all supported programming languages is stored. Add your language name with its file-extension
The LanguageParser.parse_file()
function calls the appropriate parsing function for each language. Add yours with another if-statement checking the file extension