pub struct Parser { /* private fields */ }Expand description
Parses a document as it arrives, a piece at a time, into the tree
parse_with would build from the whole: the same for any way of
cutting the input up, with the same spans and errors when asked for.
Each Parser::feed tokenizes and builds as far as the input allows,
keeping only what it can’t decide yet (an unfinished tag, a character
reference cut short, a CR that might be half a CRLF) for the next
piece; Parser::finish reads the end of the input and hands back the
document. The pieces are &str, so one can’t end inside a character:
decoding bytes, and finding the encoding, comes first, and is the
encoding crate’s.
use parsec::{Options, Parser};
let mut parser = Parser::new(Options::default());
for piece in ["<p>He", "llo, <b>wor", "ld</b>"] {
parser.feed(piece);
}
let doc = parser.finish().unwrap();
assert_eq!(doc.text(doc.root()), "Hello, world");Implementations§
Source§impl Parser
impl Parser
Sourcepub fn new(options: Options) -> Parser
pub fn new(options: Options) -> Parser
A parser for a whole document, as parse_with parses one.
Sourcepub fn fragment(ns: Ns, context: &str, options: Options) -> Parser
pub fn fragment(ns: Ns, context: &str, options: Options) -> Parser
A parser for the contents of an element named context in
namespace ns, as parse_fragment_with parses them.
Sourcepub fn finish(self) -> Result<Document, ParseError>
pub fn finish(self) -> Result<Document, ParseError>
The end of the input: the document, or why there’s none, as
parse_with gives them. A budget counts the time spent in
Parser::feed and here, not the time between.