quick_xml/parser/mod.rs
1//! Contains low-level parsers of different XML pieces.
2
3use crate::errors::SyntaxError;
4
5mod comment;
6mod dtd;
7mod element;
8mod pi;
9
10pub use comment::CommentParser;
11pub(crate) use dtd::DtdParser;
12pub use element::ElementParser;
13pub use pi::PiParser;
14
15/// Used to decouple reading of data from data source and parsing XML structure from it.
16/// This is a state preserved between getting chunks of bytes from the reader.
17///
18/// This trait is implemented for every parser that processes piece of XML grammar.
19pub trait Parser {
20 /// Process new data and try to determine end of the parsed thing.
21 ///
22 /// Returns position of the end of thing in `bytes` in case of successful search
23 /// and `None` otherwise.
24 ///
25 /// # Parameters
26 /// - `bytes`: a slice to find the end of a thing.
27 /// Should contain text in ASCII-compatible encoding
28 fn feed(&mut self, bytes: &[u8]) -> Option<usize>;
29
30 /// Returns parse error produced by this parser in case of reaching end of
31 /// input without finding the end of a parsed thing.
32 ///
33 /// # Parameters
34 /// - `content`: the content that was read before EOF. Some parsers may use
35 /// this to provide more specific error messages.
36 fn eof_error(self, content: &[u8]) -> SyntaxError;
37}