diff options
| author | Philipp A | 2018-12-08 00:43:20 +0100 |
|---|---|---|
| committer | Philipp A | 2018-12-08 00:43:20 +0100 |
| commit | 96b5685ef6e74d2be4f43b96e3862abdfc0fcb0d (patch) | |
| tree | 0850a35aad640b111dc6321f6b5eb9d5d81ddc93 | |
| parent | eb416cc02b1ec8dbd3073dc6e2c0f80ae53dab9e (diff) | |
| download | rust-rst-96b5685ef6e74d2be4f43b96e3862abdfc0fcb0d.tar.bz2 | |
some todos
| -rw-r--r-- | src/document_tree/attribute_types.rs | 2 | ||||
| -rw-r--r-- | src/document_tree/element_types.rs | 2 | ||||
| -rw-r--r-- | src/document_tree/elements.rs | 2 | ||||
| -rw-r--r-- | src/document_tree/extra_attributes.rs | 2 | ||||
| -rw-r--r-- | src/parser/conversion/block.rs | 15 | ||||
| -rw-r--r-- | src/parser/conversion/inline.rs | 2 | ||||
| -rw-r--r-- | src/parser/pair_ext_parse.rs | 11 | ||||
| -rw-r--r-- | src/parser/tests.rs | 4 | ||||
| -rw-r--r-- | src/rst.pest | 2 |
9 files changed, 26 insertions, 16 deletions
diff --git a/src/document_tree/attribute_types.rs b/src/document_tree/attribute_types.rs index 8f7dac5..dc245b5 100644 --- a/src/document_tree/attribute_types.rs +++ b/src/document_tree/attribute_types.rs @@ -83,6 +83,4 @@ mod test { let _c: Measure = ".5in".parse().unwrap(); let _d: Measure = "1.pc".parse().unwrap(); } - - // TODO: Test parsing measures } diff --git a/src/document_tree/element_types.rs b/src/document_tree/element_types.rs index 9ac90e2..429573e 100644 --- a/src/document_tree/element_types.rs +++ b/src/document_tree/element_types.rs @@ -49,7 +49,7 @@ // Citation { backrefs: Vec<ID> }, // SystemMessage { backrefs: Vec<ID>, level: usize, line: usize, type_: NameToken }, // Figure { align: AlignH, width: usize }, -// Table, //TODO +// Table, //TODO: Table // // //body sub elements // ListItem, diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs index 638d44b..e1f0245 100644 --- a/src/document_tree/elements.rs +++ b/src/document_tree/elements.rs @@ -201,7 +201,7 @@ impl_elems!( (Citation, SubFootnote; +) (SystemMessage, BodyElement; +) (Figure, SubFigure; +) - (Table; +) //TODO + (Table; +) //TODO: Table //body sub elements (ListItem, BodyElement) diff --git a/src/document_tree/extra_attributes.rs b/src/document_tree/extra_attributes.rs index 1799e4f..58a1e94 100644 --- a/src/document_tree/extra_attributes.rs +++ b/src/document_tree/extra_attributes.rs @@ -69,7 +69,7 @@ impl_extra!(Footnote { backrefs: Vec<ID>, auto: bool }); impl_extra!(Citation { backrefs: Vec<ID> }); impl_extra!(SystemMessage { backrefs: Vec<ID>, level: Option<usize>, line: Option<usize>, type_: Option<NameToken> }); impl_extra!(Figure { align: Option<AlignH>, width: Option<usize> }); -impl_extra!(Table {}); //TODO +impl_extra!(Table {}); //TODO: Table impl_extra!(OptionArgument { delimiter: Option<String> }); diff --git a/src/parser/conversion/block.rs b/src/parser/conversion/block.rs index 280aff3..eba50b1 100644 --- a/src/parser/conversion/block.rs +++ b/src/parser/conversion/block.rs @@ -17,7 +17,7 @@ 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! + // TODO: This is just a proof of concept. Keep closely to DTD in final version! Ok(Some(match pair.as_rule() { Rule::title => convert_title(pair).into(), Rule::paragraph => convert_paragraph(pair)?.into(), @@ -62,7 +62,7 @@ fn convert_target(pair: Pair<Rule>) -> Result<e::Target, Error> { for p in pair.into_inner() { match p.as_rule() { Rule::target_name_uq | Rule::target_name_qu => { - //TODO: abstract + //TODO: abstract away attrs.refid = Some( ID(p.as_str().to_owned().replace(' ', "-"))); attrs.refname.push(NameToken(p.as_str().to_owned())); }, @@ -103,7 +103,7 @@ fn convert_image<I>(pair: Pair<Rule>) -> Result<I, Error> where I: Element + Ext "alt" => image.extra_mut().alt = Some(opt_val.as_str().to_owned()), "height" => image.extra_mut().height = Some(opt_val.parse()?), "width" => image.extra_mut().width = Some(opt_val.parse()?), - "scale" => image.extra_mut().scale = Some(opt_val.parse()?), // TODO: can end with % + "scale" => image.extra_mut().scale = Some(parse_scale(&opt_val)?), "align" => image.extra_mut().align = Some(opt_val.parse()?), "target" => image.extra_mut().target = Some(opt_val.parse()?), name => bail!("Unknown Image option {}", name), @@ -113,6 +113,15 @@ fn convert_image<I>(pair: Pair<Rule>) -> Result<I, Error> where I: Element + Ext Ok(image) } +fn parse_scale(pair: &Pair<Rule>) -> Result<u8, Error> { + let input = if pair.as_str().chars().rev().next() == Some('%') { &pair.as_str()[..pair.as_str().len()-1] } else { pair.as_str() }; + use pest::error::{Error,ErrorVariant}; + Ok(input.parse().map_err(|e: std::num::ParseIntError| { + let var: ErrorVariant<Rule> = ErrorVariant::CustomError { message: e.to_string() }; + Error::new_from_span(var, pair.as_span()) + })?) +} + fn convert_admonition_gen(pair: Pair<Rule>) -> Result<c::BodyElement, Error> { let mut iter = pair.into_inner(); let typ = iter.next().unwrap().as_str(); diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs index d0aa524..d857bfe 100644 --- a/src/parser/conversion/inline.rs +++ b/src/parser/conversion/inline.rs @@ -32,7 +32,7 @@ fn convert_reference(pair: Pair<Rule>) -> Result<e::Reference, Error> { match concrete.as_rule() { Rule::reference_target => { let rt_inner = concrete.into_inner().next().unwrap(); // reference_target_uq or target_name_qu - //TODO: abstract + //TODO: abstract away id = Some( ID(rt_inner.as_str().to_owned().replace(' ', "-"))); name = Some(NameToken(rt_inner.as_str().to_owned())); }, diff --git a/src/parser/pair_ext_parse.rs b/src/parser/pair_ext_parse.rs index 2ce642a..c7d2d45 100644 --- a/src/parser/pair_ext_parse.rs +++ b/src/parser/pair_ext_parse.rs @@ -1,5 +1,6 @@ use std::str::FromStr; +use pest::Span; use pest::iterators::Pair; use pest::error::{Error,ErrorVariant}; @@ -10,9 +11,11 @@ pub trait PairExt<R> where R: pest::RuleType { impl<'l, R> PairExt<R> for Pair<'l, R> where R: pest::RuleType { fn parse<T, E>(&self) -> Result<T, Error<R>> where T: FromStr<Err = E>, E: ToString { - self.as_str().parse().map_err(|e: T::Err| { - let var: ErrorVariant<R> = ErrorVariant::CustomError { message: e.to_string() }; - Error::new_from_span(var, self.as_span()) - }) + self.as_str().parse().map_err(|e| to_parse_error(self.as_span(), &e)) } } + +pub(crate) fn to_parse_error<E, R>(span: Span, e: &E) -> Error<R> where E: ToString, R: pest::RuleType { + let var: ErrorVariant<R> = ErrorVariant::CustomError { message: e.to_string() }; + Error::new_from_span(var, span) +} diff --git a/src/parser/tests.rs b/src/parser/tests.rs index 331f87b..3ebc952 100644 --- a/src/parser/tests.rs +++ b/src/parser/tests.rs @@ -108,8 +108,8 @@ fn admonitions() { }; } -// TODO: substitutions -// TODO: images +// TODO: test substitutions +// TODO: test images #[allow(clippy::cyclomatic_complexity)] #[test] diff --git a/src/rst.pest b/src/rst.pest index 7b99b5c..595fd76 100644 --- a/src/rst.pest +++ b/src/rst.pest @@ -41,7 +41,7 @@ hanging_block = _{ // Substitution definition. A block type substitution_def = { ".." ~ PUSH(" "+) ~ "|" ~ substitution_name ~ "|" ~ " "+ ~ inline_dirblock ~ DROP } substitution_name = { !" " ~ (!(" "|"|") ~ ANY)+ ~ (" "+ ~ (!(" "|"|") ~ ANY)+)* } -inline_dirblock = _{ image } // TODO: | replace +inline_dirblock = _{ image } // TODO: implement “replace” and so on // Target. A block type target = { target_qu | target_uq } |
