diff options
Diffstat (limited to 'src/parser/conversion')
| -rw-r--r-- | src/parser/conversion/block.rs | 13 | ||||
| -rw-r--r-- | src/parser/conversion/inline.rs | 38 |
2 files changed, 48 insertions, 3 deletions
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<Rule>) -> Result<Option<c::StructuralSubElement>, 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::<e::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<Rule>) -> e::Title { ]) } + +fn convert_paragraph(pair: Pair<Rule>) -> Result<e::Paragraph, Error> { + let children = pair.into_inner().map(convert_inline).collect::<Result<_,_>>()?; + Ok(e::Paragraph::with_children(children)) +} + + fn convert_target(pair: Pair<Rule>) -> Result<e::Target, Error> { 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<Rule>) -> Result<c::TextOrInlineElement, Error> { + 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<Rule>) -> Result<e::Reference, Error> { + 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)) +} |
