(&'r mut self, mathml: Element<'c>)
| 2163 | } |
| 2164 | |
| 2165 | pub fn match_pattern<T:TreeOrString<'c, 'm, T>>(&'r mut self, mathml: Element<'c>) -> Result<T> { |
| 2166 | // debug!("Looking for a match for: \n{}", mml_to_string(&mathml)); |
| 2167 | let tag_name = mathml.name().local_part(); |
| 2168 | let rules = &self.speech_rules.rules; |
| 2169 | |
| 2170 | // start with priority rules that apply to any node (should be a very small number) |
| 2171 | if let Some(rule_vector) = rules.get("!*") { |
| 2172 | if let Some(result) = self.find_match(rule_vector, mathml)? { |
| 2173 | return Ok(result); // found a match |
| 2174 | } |
| 2175 | } |
| 2176 | |
| 2177 | if let Some(rule_vector) = rules.get(tag_name) { |
| 2178 | if let Some(result) = self.find_match(rule_vector, mathml)? { |
| 2179 | return Ok(result); // found a match |
| 2180 | } |
| 2181 | } |
| 2182 | |
| 2183 | // no rules for specific element, fall back to rules for "*" which *should* be present in all rule files as fallback |
| 2184 | if let Some(rule_vector) = rules.get("*") { |
| 2185 | if let Some(result) = self.find_match(rule_vector, mathml)? { |
| 2186 | return Ok(result); // found a match |
| 2187 | } |
| 2188 | } |
| 2189 | |
| 2190 | // no rules matched -- poorly written rule file -- let flow through to default error |
| 2191 | // report error message with file name |
| 2192 | let mut file_name = "unknown"; |
| 2193 | let speech_manager = self.speech_rules.pref_manager.borrow(); |
| 2194 | if let Some(path) = &speech_manager.get_rule_file(&self.speech_rules.name)[0] { |
| 2195 | file_name= path.to_str().unwrap(); |
| 2196 | } |
| 2197 | // FIX: handle error appropriately |
| 2198 | bail!("\nNo match found!\nMissing patterns in {} for MathML.\n{}", file_name, mml_to_string(&mathml)); |
| 2199 | } |
| 2200 | |
| 2201 | fn find_match<T:TreeOrString<'c, 'm, T>>(&'r mut self, rule_vector: &[Box<SpeechPattern>], mathml: Element<'c>) -> Result<Option<T>> { |
| 2202 | for pattern in rule_vector { |
nothing calls this directly
no test coverage detected