//! The parser. use crate::node::element::tag::{Tag, Type}; use crate::node::Attributes; mod error; mod reader; pub use self::error::Error; #[doc(hidden)] pub use self::reader::Reader; /// A parser. pub struct Parser<'l> { reader: Reader<'l>, } /// An event. #[derive(Debug)] pub enum Event<'l> { /// An error. Error(Error), /// A tag. Tag(&'l str, Type, Attributes), /// A text. Text(&'l str), /// A comment. Comment(&'l str), /// A declaration. Declaration(&'l str), /// An instruction. Instruction(&'l str), } /// A result. pub type Result = std::result::Result; macro_rules! raise( ($parser:expr, $($argument:tt)*) => ( return Some(Event::Error(Error::new($parser.reader.position(), format!($($argument)*)))) ); ); impl<'l> Parser<'l> { /// Create a parser. #[inline] pub fn new(content: &'l str) -> Self { Parser { reader: Reader::new(content), } } fn next_angle(&mut self) -> Option> { let content: String = self.reader.peek_many().take(4).collect(); if content.is_empty() { None } else if content.starts_with("