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