pub fn xml(parser: &mut Tabnas, options: &XmlOptions) -> Result<(), PluginError>Expand description
Install the XML grammar on parser: the port of the Xml plugin
function.
In pure mode the parser is reconfigured for XML alone: xml becomes
the start rule, the JSON structural tokens and every non-XML lexer are
switched off, and any jsonic value rules are removed, so the parser
carries the four XML rules whether it started as the bare engine (as
make arranges) or as a jsonic parser. In embed mode, on a jsonic
parser, the jsonic grammar stays and XML elements become values.
Installation is idempotent: an instance that already carries the
xml rule is left alone.
§Errors
Embed mode on a parser whose val rule is not jsonic’s, the bare
engine and the strict-JSON parsers among them, is refused with a
PluginError that starts xml: embed mode needs a jsonic host, and
nothing is installed.
let mut parser = tabnas::Tabnas::new();
tabnas_xml::xml(&mut parser, &tabnas_xml::XmlOptions::default())?;
assert_eq!(
parser.parse("<a x='1'/>")?.to_string(),
r#"{"name":"a","localName":"a","attributes":{"x":"1"},"children":[]}"#
);