aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPhilipp A2018-12-28 16:40:44 +0100
committerPhilipp A2018-12-28 16:40:44 +0100
commit8b16dfaa7cad8cb8a666fcc75a63861b37925d69 (patch)
treed2d6bb815a73f2dd2b1db79b442473bd4c440b34 /src
parent447ecb7945e091e52218d50a701e82f29ad6663d (diff)
downloadrust-rst-8b16dfaa7cad8cb8a666fcc75a63861b37925d69.tar.bz2
Add From<&str> for ID and AT
Diffstat (limited to 'src')
-rw-r--r--src/document_tree/attribute_types.rs12
-rw-r--r--src/parser/conversion/inline.rs22
2 files changed, 20 insertions, 14 deletions
diff --git a/src/document_tree/attribute_types.rs b/src/document_tree/attribute_types.rs
index dc245b5..ba631d9 100644
--- a/src/document_tree/attribute_types.rs
+++ b/src/document_tree/attribute_types.rs
@@ -51,6 +51,18 @@ impl FromStr for AlignHV {
}
}
+impl From<&str> for ID {
+ fn from(s: &str) -> Self {
+ ID(s.to_owned().replace(' ', "-"))
+ }
+}
+
+impl From<&str> for NameToken {
+ fn from(s: &str) -> Self {
+ NameToken(s.to_owned())
+ }
+}
+
impl FromStr for Measure {
type Err = Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
diff --git a/src/parser/conversion/inline.rs b/src/parser/conversion/inline.rs
index d857bfe..1697a06 100644
--- a/src/parser/conversion/inline.rs
+++ b/src/parser/conversion/inline.rs
@@ -5,7 +5,6 @@ use crate::document_tree::{
ExtraAttributes,
elements as e,
element_categories as c,
- attribute_types::{ID,NameToken},
extra_attributes as a,
};
@@ -25,26 +24,21 @@ pub fn convert_inline(pair: Pair<Rule>) -> Result<c::TextOrInlineElement, Error>
fn convert_reference(pair: Pair<Rule>) -> Result<e::Reference, Error> {
let mut name = None;
- let mut uri = None;
- let mut id = None;
- let mut name_tokens = vec![];
+ let /*mut*/ refuri = None;
+ let mut refid = None;
+ let /*mut*/ refname = vec![];
let concrete = pair.into_inner().next().unwrap();
match concrete.as_rule() {
Rule::reference_target => {
let rt_inner = concrete.into_inner().next().unwrap(); // reference_target_uq or target_name_qu
- //TODO: abstract away
- id = Some( ID(rt_inner.as_str().to_owned().replace(' ', "-")));
- name = Some(NameToken(rt_inner.as_str().to_owned()));
+ refid = Some(rt_inner.as_str().into());
+ name = Some(rt_inner.as_str().into());
},
Rule::reference_explicit => unimplemented!("explicit reference"),
Rule::reference_auto => unimplemented!("auto reference"),
_ => unreachable!(),
};
- let extra = a::Reference {
- name: name,
- refuri: uri,
- refid: id,
- refname: name_tokens,
- };
- Ok(e::Reference::with_extra(extra))
+ Ok(e::Reference::with_extra(
+ a::Reference { name, refuri, refid, refname }
+ ))
}