Skip to main content

form_of

Function form_of 

Source
pub fn form_of(node: &NodeRef<'_, Flm>) -> Option<Form>
Expand description

Returns the form of the annotation node (a node of an annotator’s command, or a cut part of one), read from the opening delimiter that its argument’s group recorded: [ makes a comment, and { or no delimiter at all (the passage closed by \endphf) a highlight.

Every lowering rule of the element, on every backend, reads the form with this function, and so does the element’s ApartFromText aspect. Returns None when node has no argument named text holding a group, which never happens for a node of the element.

§Examples

use std::sync::Arc;
use flm_core::core::registry::{PackageEntry, RegistryBuilder, RegistryInputs};
use flm_core::lang::{parse_fragment, FlmSource, ParseOptions};
use flm_core::model::doc::FragmentLayout;
use flm_core::stdlib::features::annotations::{form_of, AnnotationsConfig, Annotator, Form};
use flm_core::stdlib::{add_features, StdlibConfig};

let config = AnnotationsConfig::new().annotator(Annotator::new("phf").initials("PhF"));
let mut builder = RegistryBuilder::new();
builder.use_package(add_features(PackageEntry::new("std"), StdlibConfig::new().annotations(config)));
builder.use_package(flm_core::math_passthrough::package());
let registry = builder.build(&RegistryInputs::new())?;
let source = Arc::new(FlmSource::new(r"\phf{a} \phf[b] \phf c\endphf"));
let fragment = parse_fragment(registry.lang(), source, FragmentLayout::Inline, &ParseOptions::default())?;
let forms: Vec<_> = fragment
    .tree()
    .root()
    .descendants()
    .filter(|node| node.name() == Some("phf"))
    .filter_map(|node| form_of(&node))
    .collect();
assert_eq!(forms, [Form::Highlight, Form::Comment, Form::Highlight]);