rust-code-analysis
rust-code-analysis copied to clipboard
Compute metrics differently according to parsers
Actually metrics are computed equally for each parser through the metrics function contained in spaces.rs file. This approach though doesn't allow to customize parsers.
To overcome the problem above, it would be helpful to split up parsers in two great classes:
- Metric parsers. They contain a
metricfunction that allows only determined metrics to be computed - Non-metric parsers. They do other things, but they do not compute metrics. For now we can consider them like metric parsers but without the methods to compute metrics
Possible structure for the metric parsers
let parser = CppParser::new(...);
// This function sets the list of metrics to be computed for the CppParser.
// Returns an error if the ones specified aren't available for the CppParser
parser.set_metrics(...).unwrap();
// Compute the metrics
parser.compute_metrics().unwrap();
Advantages
- Each parser computes only the metrics related to the structure of its language (i.e. For the HTML language,
loc, but notnombecause there aren't functions or closures in it) - A user can choose the metrics to be computed through the
set_metricsfunction - This new design can be useful for other features other than metrics
Disdvantages
- Refactor lots of code
- Implementing this new kind of design could introduce further issues
This new approach needs to take into account also the dump of the chosen metrics in different formats