Skip to main content

make_with

Function make_with 

Source
pub fn make_with(options: &XmlOptions) -> Tabnas
Expand description

Build an XML parser with caller options: the engine, then this plugin, the make(options) of the canonical plugin (new Tabnas().use(Xml, options)) and the Make(options) of the Go port.

The parser reads a source from a reader a window at a time (Tabnas::parse_reader, admin ADR-30) rather than whole: its tokens are the xmltag matcher’s and the engine’s own, and the matcher reads the source only through the lexer’s window, reading it on where a construct runs past the window’s end, so the parser declares lex.window. The option is set here, on the parser this crate makes whole, and not in xml or plugin, which other grammars install beneath matchers of their own (feed) and embed mode installs on a jsonic parser.

Infallible for every option but one: the grammar documents are fixed literals, so any other failure here is a bug in this crate rather than anything a caller did.

§Panics

When options.embed is true. The engine carries no grammar of its own, so embed mode has no jsonic document to embed XML in, and a parser built anyway would parse every document to nothing. For embed mode, install plugin on a jsonic parser (tabnas_jsonic::make()) instead.

let parser = tabnas_xml::make_with(&tabnas_xml::XmlOptions {
    strict_entities: false,
    ..Default::default()
});
assert_eq!(
    parser.parse("<a>&nope;</a>")?.to_string(),
    r#"{"name":"a","localName":"a","attributes":{},"children":["&nope;"]}"#
);