MCPcopy Create free account
hub / github.com/daisy/MathCAT / read_one_definitions_file

Function read_one_definitions_file

src/definitions.rs:224–244  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

222
223use crate::speech::*;
224fn read_one_definitions_file(path: &Path) -> Result<()> {
225 // read in the file contents
226 let definition_file_contents = read_to_string_shim(path)
227 .chain_err(|| format!("trying to read {}", path.to_str().unwrap()))?;
228
229 // callback to do the work of building up the defined vectors/hashmaps (in 'build_values') from YAML
230 let defs_build_fn = |variable_def_list: &Yaml| {
231 // Rule::DefinitionList
232 // debug!("variable_def_list {} is\n{}", yaml_to_type(variable_def_list), yaml_to_string(variable_def_list));
233 let vec = crate::speech::as_vec_checked(variable_def_list)
234 .chain_err(||format!("in file {:?}", path.to_str()))?;
235 for variable_def in vec {
236 build_values(variable_def).chain_err(||format!("in file {:?}", path.to_str()))?;
237 }
238 return Ok(());
239 };
240
241 // Convert the file contents to YAML and call the callback
242 return crate::speech::compile_rule(&definition_file_contents, defs_build_fn)
243 .chain_err(|| format!("In file '{}'", path.to_str().unwrap()));
244}
245
246// Do the work of converting a single YAML def into the vec/hashset
247fn build_values(definition: &Yaml) -> Result<()> {

Callers 1

read_definitions_fileFunction · 0.85

Calls 3

as_vec_checkedFunction · 0.85
build_valuesFunction · 0.85
compile_ruleFunction · 0.85

Tested by

no test coverage detected