From 6b471061157ee1873d7ac4f3e30cd501d27dcb5a Mon Sep 17 00:00:00 2001 From: cel 🌸 Date: Sat, 29 Jun 2024 17:06:08 +0100 Subject: WIP: stream parsing --- src/element.rs | 12 ++++++------ src/reader.rs | 45 +++++++++++++++++++++++++++++++++++++++------ 2 files changed, 45 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/element.rs b/src/element.rs index 4dcb616..35d73a3 100644 --- a/src/element.rs +++ b/src/element.rs @@ -9,7 +9,7 @@ pub struct Namespace { namespace: String, } -// names are qualified, they contain the namespace +// names are qualified, they contain a reference to the namespace (held within the reader/writer) pub struct Name { namespace: String, name: String, @@ -22,27 +22,27 @@ pub enum Node { // should this be a trait? pub struct Element { - name: Name, + pub name: Name, // namespace: Name, // each element once created contains the qualified namespace information for that element // the name contains the qualified namespace so this is unnecessary // namespace: String, // hashmap of explicit namespace declarations on the element itself only // possibly not needed as can be calculated at write time depending on context and qualified namespace, and for reading, element validity and namespaces are kept track of by the reader. - namespaces: HashMap, String>, + pub namespace_decl: HashMap, String>, // attributes can be in a different namespace than the element. how to make sure they are valid? // maybe include the namespace instead of or with the prefix // you can calculate the prefix from the namespaced name and the current writer context // you can validate the prefix and calculate the namespace from the current reader context // this results in readers and writers being able to return qualification errors as they aren't able to create elements until every part is qualified. - attributes: HashMap, - children: Option>, + pub attributes: HashMap, + pub children: Option>, } // example of deriving an element: // #[derive(XMLWrite, XMLRead)] -// #[peanuts(namespace = "jabber:client", namespace:stream = "http://etherx.jabber.org/streams", name = "stream:stream")] +// #[peanuts(xmlns = "jabber:client", xmlns:stream = "http://etherx.jabber.org/streams", prefix = "stream")] // pub struct Stream { // from: JID, // id: String, diff --git a/src/reader.rs b/src/reader.rs index 2785c88..b0d21db 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1,6 +1,6 @@ use futures::Stream; use nom::Err; -use std::str; +use std::{collections::BTreeMap, str}; use tokio::io::AsyncBufReadExt; use crate::{ @@ -30,8 +30,8 @@ impl Reader where R: AsyncBufReadExt + Unpin, { - /// reads entire next prolog, element, or misc - pub async fn read<'s>(&'s mut self) -> Result, Error> { + /// could resursively read and include namespace tree with values to be shadowed within new local context + async fn read_recursive(&mut self, namespaces: BTreeMap, String>) -> Result { let element; let len; loop { @@ -45,15 +45,48 @@ where } Err(e) => match e { Err::Incomplete(_) => (), - e => return Err(Error::ParseError(input.to_owned())), + e => return Err::(Error::ParseError(input.to_owned())), }, } } - self.inner.consume(len); - // Ok(element) + let final; + match element { + crate::xml::Element::Empty(e) => { + let final = Element { + + } + }, + crate::xml::Element::NotEmpty(_, _, _) => todo!(), + } + + self.inner.consume(len); todo!() } + /// reads entire next prolog, element, or misc + // pub async fn read>(&mut self) -> Result { + // let element; + // let len; + // loop { + // let buf = self.inner.fill_buf().await?; + // let input = str::from_utf8(buf)?; + // match crate::xml::element(input) { + // Ok((rest, e)) => { + // element = e; + // len = buf.len() - rest.len(); + // break; + // } + // Err(e) => match e { + // Err::Incomplete(_) => (), + // e => return Err::(Error::ParseError(input.to_owned())), + // }, + // } + // } + // self.inner.consume(len); + + // // Ok(element) + // todo!() + // } // pub async fn read_start(&self) -> Result, Error> { // todo!() // } -- cgit