Option to track usage/coverage of NMODL grammar rules from Bison specification
In order to check the NMODL language spec coverage, we would like to know which of the grammar rules are used today in all of the existing models (e.g. ModelDB).
One idea was if we could simply find "bison code coverage" but it doesn't seem like there is such an option: https://stackoverflow.com/questions/73775577/coverage-of-rules-files-generated-by-bison
Another we are considering is to simply add a function call / macro to this job. For example, we could add:
| all model
{
TRACK_NMODL_PARSER(scanner.loc, 1, "all model", ...)
$1->emplace_back_node($2);
$$ = $1;
}
| all local_statement
{
TRACK_NMODL_PARSER(scanner.loc, 2, "all local_statement", ...)
$1->emplace_back_node($2);
$$ = $1;
}
| all define
{
TRACK_NMODL_PARSER(scanner.loc, 3, "all define", ...)
$1->emplace_back_node($2);
$$ = $1;
}
TRACK_NMODL_PARSER then can do some formatted printing of this information to stdout.
We will then run nmodl parser binary (build/bin/nmodl_parser) on all ModelDB+NEURON+BBP models and do some stats of the output log. For example:
- Which of the rules are missing from the usage?
- What is the frequency of certain constructs? (e.g. higher-level blocks like KINETIC)
- Which of the mod files to find a given grammar rule?
Note:
TRACK_NMODL_PARSERcould be enabled only when necessary i.e. it should beno-opin normal build.
WIP branch I created for this is pramodk/nmodl-parser-tracing.
Here are the rules from nmodl.yy that are not used in ModelDB models:
| all MODEL_LEVEL INTEGER_PTR declare
| step_block
| plot_declaration
step_block : all
step_block_body : all
stepped_statement : all
number_list : all
| "+" NUMBER (number rule)
| DEFINEDVAR (integer rule)
| independent_block_body SWEEP independent_definition
| name "[" integer "]" FROM number TO number optional_start units abs_tolerance (dependent_definition rule)
* All for PLOT declaration
plot_declaration : PLOT plot_variable_list VS name optional_index
plot_variable_list : name optional_index
optional_index :
* Terminal, Discrete and Partial block
| terminal_block
| discrete_block
| partial_block
* Rule in optional_statement_list:
| optional_statement_list LINE_COMMENT
* FOR_ALL Statement
| forall_statement
| conductance
| sens
| RESET
| match_block
| partial_equation
* Not sure about below but may be ints are treated as float and hence not covered?
| integer_expression "*" integer_expression
| integer_expression "/" integer_expression
* In primary (could be just ignored)
| primary "/" term
In term: seems like function call is not used
| function_call
In optional_increment:
| BY integer_expression
* FORALL Statement
forall_statement : FORALL1 NAME_PTR statement_list "}"
All of the rules:
* partial_equation
* first_last
In if_solution_error:
| IFERROR statement_list "}"
In optional_solvefor:
| solvefor
* Whole solvefor rule
* terminal_block
* In watch_statement
| watch_statement "," watch
* In watch_expression
| function_call
| watch_expression "/" watch_expression
| watch_expression "^" watch_expression
* Whole rules sens and sens_list
*
* Whole rules: match_block, match_list, match, match_name
* In factor_definition
| NAME_PTR "=" unit "-" GT unit
* In neuron_statement
| neuron_statement SECTION section_var_list
* In electrode_current_var_list
| electrode_current_var_list "," NAME_PTR
* Whole section_var_list
* Whole optional_threadsafe_var_list :
| threadsafe_var_list
Some false positives
Not in ModelDB models but it’s in BBP models or known optimisations:
conductance : CONDUCTANCE Name
| CONDUCTANCE Name USEION NAME_PTR
bbcore_pointer_var_list
| neuron_statement BBCOREPOINTER bbcore_pointer_var_list
| neuron_statement REPRESENTS ONTOLOGY_ID
* In ontology
| REPRESENTS ONTOLOGY_ID
| all LINE_COMMENT
* discrete_block - we know from Michael how to use
* Michael has provided example of below via DISCRETE block:
| NAME_PTR "@" integer
| NAME_PTR "@" integer "[" integer_expression "]"
With respect to integer rules, take a look at https://github.com/nrnhines/glu3d/blob/master/glu3d.mod
We should look at https://github.com/neuronsimulator/nrn/issues/1957 Some of those items are already covered.