rust-code-analysis icon indicating copy to clipboard operation
rust-code-analysis copied to clipboard

Compute metrics differently according to parsers

Open Luni-4 opened this issue 5 years ago • 1 comments

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 metric function 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 not nom because there aren't functions or closures in it)
  • A user can choose the metrics to be computed through the set_metrics function
  • 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

Luni-4 avatar Nov 18 '20 20:11 Luni-4

This new approach needs to take into account also the dump of the chosen metrics in different formats

Luni-4 avatar Nov 20 '20 09:11 Luni-4