WIP: stream parsing
This commit is contained in:
parent
1f0103cbec
commit
6b47106115
|
@ -9,7 +9,7 @@ pub struct Namespace {
|
||||||
namespace: String,
|
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 {
|
pub struct Name {
|
||||||
namespace: String,
|
namespace: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
@ -22,27 +22,27 @@ pub enum Node {
|
||||||
|
|
||||||
// should this be a trait?
|
// should this be a trait?
|
||||||
pub struct Element {
|
pub struct Element {
|
||||||
name: Name,
|
pub name: Name,
|
||||||
// namespace: Name,
|
// namespace: Name,
|
||||||
// each element once created contains the qualified namespace information for that element
|
// each element once created contains the qualified namespace information for that element
|
||||||
// the name contains the qualified namespace so this is unnecessary
|
// the name contains the qualified namespace so this is unnecessary
|
||||||
// namespace: String,
|
// namespace: String,
|
||||||
// hashmap of explicit namespace declarations on the element itself only
|
// 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.
|
// 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<Option<String>, String>,
|
pub namespace_decl: HashMap<Option<String>, String>,
|
||||||
// attributes can be in a different namespace than the element. how to make sure they are valid?
|
// 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
|
// 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 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
|
// 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.
|
// 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<Name, String>,
|
pub attributes: HashMap<Name, String>,
|
||||||
children: Option<Vec<Node>>,
|
pub children: Option<Vec<Node>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
// example of deriving an element:
|
// example of deriving an element:
|
||||||
|
|
||||||
// #[derive(XMLWrite, XMLRead)]
|
// #[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 {
|
// pub struct Stream {
|
||||||
// from: JID,
|
// from: JID,
|
||||||
// id: String,
|
// id: String,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
use futures::Stream;
|
use futures::Stream;
|
||||||
use nom::Err;
|
use nom::Err;
|
||||||
use std::str;
|
use std::{collections::BTreeMap, str};
|
||||||
use tokio::io::AsyncBufReadExt;
|
use tokio::io::AsyncBufReadExt;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -30,8 +30,8 @@ impl<R> Reader<R>
|
||||||
where
|
where
|
||||||
R: AsyncBufReadExt + Unpin,
|
R: AsyncBufReadExt + Unpin,
|
||||||
{
|
{
|
||||||
/// reads entire next prolog, element, or misc
|
/// could resursively read and include namespace tree with values to be shadowed within new local context
|
||||||
pub async fn read<'s>(&'s mut self) -> Result<crate::xml::Element<'s>, Error> {
|
async fn read_recursive(&mut self, namespaces: BTreeMap<Option<String>, String>) -> Result<Element, Error> {
|
||||||
let element;
|
let element;
|
||||||
let len;
|
let len;
|
||||||
loop {
|
loop {
|
||||||
|
@ -45,15 +45,48 @@ where
|
||||||
}
|
}
|
||||||
Err(e) => match e {
|
Err(e) => match e {
|
||||||
Err::Incomplete(_) => (),
|
Err::Incomplete(_) => (),
|
||||||
e => return Err(Error::ParseError(input.to_owned())),
|
e => return Err::<E, Error>(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!()
|
todo!()
|
||||||
}
|
}
|
||||||
|
/// reads entire next prolog, element, or misc
|
||||||
|
// pub async fn read<E: From<Element>>(&mut self) -> Result<E, Error> {
|
||||||
|
// 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::<E, Error>(Error::ParseError(input.to_owned())),
|
||||||
|
// },
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// self.inner.consume(len);
|
||||||
|
|
||||||
|
// // Ok(element)
|
||||||
|
// todo!()
|
||||||
|
// }
|
||||||
// pub async fn read_start(&self) -> Result<impl From<Element>, Error> {
|
// pub async fn read_start(&self) -> Result<impl From<Element>, Error> {
|
||||||
// todo!()
|
// todo!()
|
||||||
// }
|
// }
|
||||||
|
|
Loading…
Reference in New Issue