oxixml_xml/parser/mod.rs
1//! Contains low-level parsers of different XML pieces.
2//!
3//! These parsers are the incremental state machines that the pull
4//! [`Reader`](crate::reader::Reader) drives while scanning for the end of a
5//! markup construct. Each parser consumes bytes chunk-by-chunk (so that it can
6//! be fed across buffer boundaries) and reports the position at which the
7//! construct it recognizes ends.
8//!
9//! Mirrors the `parser` module of quick-xml 0.41.
10
11use crate::errors::SyntaxError;
12
13mod comment;
14mod dtd;
15mod element;
16mod pi;
17
18pub use comment::CommentParser;
19pub(crate) use dtd::DtdParser;
20pub use element::ElementParser;
21pub use pi::PiParser;
22
23/// Used to decouple reading of data from data source and parsing XML structure from it.
24/// This is a state preserved between getting chunks of bytes from the reader.
25///
26/// This trait is implemented for every parser that processes piece of XML grammar.
27pub trait Parser {
28 /// Process new data and try to determine end of the parsed thing.
29 ///
30 /// Returns position of the end of thing in `bytes` in case of successful search
31 /// and `None` otherwise.
32 ///
33 /// # Parameters
34 /// - `bytes`: a slice to find the end of a thing.
35 /// Should contain text in ASCII-compatible encoding
36 fn feed(&mut self, bytes: &[u8]) -> Option<usize>;
37
38 /// Returns parse error produced by this parser in case of reaching end of
39 /// input without finding the end of a parsed thing.
40 ///
41 /// # Parameters
42 /// - `content`: the content that was read before EOF. Some parsers may use
43 /// this to provide more specific error messages.
44 fn eof_error(self, content: &[u8]) -> SyntaxError;
45}