From d067cee68744691f3aebd939befc9837247e639c Mon Sep 17 00:00:00 2001 From: Philipp A Date: Sun, 2 Dec 2018 17:22:51 +0100 Subject: First bit of inlines parsing --- src/parser/conversion/block.rs | 13 ++++++++++--- src/parser/conversion/inline.rs | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) create mode 100644 src/parser/conversion/inline.rs (limited to 'src/parser/conversion') diff --git a/src/parser/conversion/block.rs b/src/parser/conversion/block.rs index 0b638e7..5a92ed6 100644 --- a/src/parser/conversion/block.rs +++ b/src/parser/conversion/block.rs @@ -13,20 +13,20 @@ use crate::parser::{ pest_rst::Rule, pair_ext_parse::PairExt, }; -use super::ConversionError; +use super::inline::convert_inline; pub fn convert_ssubel(pair: Pair) -> Result, Error> { // TODO: This is just a proof of concep. Keep closely to DTD in final version! Ok(Some(match pair.as_rule() { Rule::title => convert_title(pair).into(), - Rule::paragraph => e::Paragraph::with_children(vec![pair.as_str().into()]).into(), + Rule::paragraph => convert_paragraph(pair)?.into(), Rule::target => convert_target(pair)?.into(), Rule::substitution_def => convert_substitution_def(pair)?.into(), Rule::admonition_gen => convert_admonition_gen(pair)?.into(), Rule::image => convert_image::(pair)?.into(), Rule::EOI => return Ok(None), - rule => return Err(ConversionError::UnknownRuleError { rule }.into()), + rule => panic!("unknown rule {:?}", rule), })) } @@ -47,6 +47,13 @@ fn convert_title(pair: Pair) -> e::Title { ]) } + +fn convert_paragraph(pair: Pair) -> Result { + let children = pair.into_inner().map(convert_inline).collect::>()?; + Ok(e::Paragraph::with_children(children)) +} + + fn convert_target(pair: Pair) -> Result { let mut attrs = a::Target { anonymous: false, diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs new file mode 100644 index 0000000..0b6f659 --- /dev/null +++ b/src/parser/conversion/inline.rs @@ -0,0 +1,38 @@ +use failure::Error; +use pest::iterators::Pair; + +use crate::document_tree::{ + ExtraAttributes, + elements as e, + element_categories as c, +// attribute_types::ID, + extra_attributes as a, +}; + +use crate::parser::{ + pest_rst::Rule, +// pair_ext_parse::PairExt, +}; + + +pub fn convert_inline(pair: Pair) -> Result { + Ok(match pair.as_rule() { + Rule::str => pair.as_str().into(), + Rule::reference => convert_reference(pair)?.into(), + rule => panic!("unknown rule {:?}", rule), + }) +} + +fn convert_reference(pair: Pair) -> Result { + let name = None; + let uri = None; + let id = None; + let name_tokens = vec![]; + let extra = a::Reference { + name: name, + refuri: uri, + refid: id, + refname: name_tokens, + }; + Ok(e::Reference::with_extra(extra)) +} -- cgit v1.2.3