Plain text compare not yet working because the text is quoted from the sexp.

This commit is contained in:
Tom Alexander
2023-04-22 17:58:16 -04:00
parent 8072430265
commit b3e182d7fe
3 changed files with 120 additions and 35 deletions

View File

@@ -60,5 +60,9 @@ pub use lesser_element::Planning;
pub use lesser_element::SrcBlock;
pub use lesser_element::TableCell;
pub use lesser_element::VerseBlock;
pub use object::Object;
pub use object::PlainText;
pub use object::RegularLink;
pub use object::TextMarkup;
pub use source::Source;
type Context<'r, 's> = &'r parser_context::ContextTree<'r, 's>;

View File

@@ -27,9 +27,9 @@ pub enum Token<'s> {
#[derive(Debug)]
pub struct TextWithProperties<'s> {
#[allow(dead_code)]
text: &'s str,
pub text: &'s str,
#[allow(dead_code)]
properties: Vec<Token<'s>>,
pub properties: Vec<Token<'s>>,
}
impl<'s> Token<'s> {
@@ -47,6 +47,13 @@ impl<'s> Token<'s> {
}?)
}
pub fn as_text<'p>(&'p self) -> Result<&'p TextWithProperties<'s>, Box<dyn std::error::Error>> {
Ok(match self {
Token::TextWithProperties(body) => Ok(body),
_ => Err(format!("wrong token type {:?}", self)),
}?)
}
pub fn as_map<'p>(
&'p self,
) -> Result<HashMap<&'s str, &'p Token<'s>>, Box<dyn std::error::Error>> {