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

Method evaluate

src/xpath_functions.rs:349–390  ·  view source on GitHub ↗

eval function for IsNode errors happen for wrong number/kind of arg

(&self,
                        _context: &context::Evaluation<'_, 'd>,
                        args: Vec<Value<'d>>)

Source from the content-addressed store, hash-verified

347 // eval function for IsNode
348 // errors happen for wrong number/kind of arg
349 fn evaluate<'d>(&self,
350 _context: &context::Evaluation<'_, 'd>,
351 args: Vec<Value<'d>>)
352 -> Result<Value<'d>, Error>
353 {
354
355 let mut args = Args(args);
356 args.exactly(2)?;
357 let kind = args.pop_string()?;
358 // FIX: there is some conflict problem with xpath errors and error-chain
359 // .chain_err(|e| format!("Second arg to is_leaf is not a string: {}", e.to_string()))?;
360 match kind.as_str() {
361 "simple" | "leaf" | "common_fraction" | "2D" | "modified" | "scripted" => (),
362 _ => return Err( Error::Other(format!("Unknown argument value '{}' for IsNode", kind.as_str())) ),
363 };
364
365 let nodes = args.pop_nodeset()?;
366 if nodes.size() == 0 {
367 return Err(Error::Other("Missing argument for IsNode".to_string() ));
368 };
369 return Ok(
370 Value::Boolean(
371 nodes.iter()
372 .all(|node|
373 if let Node::Element(e) = node {
374 match kind.as_str() {
375 "simple" => IsNode::is_simple(e),
376 "leaf" => MATHML_LEAF_NODES.contains(name(&e)),
377 "2D" => IsNode::is_2D(&e),
378 "modified" => MATHML_MODIFIED_NODES.contains(name(&e)),
379 "scripted" => MATHML_SCRIPTED_NODES.contains(name(&e)),
380 "common_fraction" => IsNode::is_common_fraction(e, usize::MAX, usize::MAX),
381 _ => true, // can't happen due to check above
382 }
383 } else {
384 // xpath is something besides an element, so no match
385 false
386 }
387 )
388 )
389 );
390 }
391}
392
393struct ToOrdinal;

Callers

nothing calls this directly

Calls 7

is_simpleFunction · 0.85
nameFunction · 0.85
validate_one_nodeFunction · 0.85
get_text_from_elementFunction · 0.85
as_strMethod · 0.80
lenMethod · 0.80
is_emptyMethod · 0.80

Tested by

no test coverage detected