aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPhilipp A2018-11-19 21:26:38 +0100
committerPhilipp A2018-11-19 21:26:38 +0100
commitde6c16c95806a5d26779c3bc96241dfcab1f18ec (patch)
tree8283ca8371e547a6770180e918d910e2cc3cfc30
parent4272b19a79f786c6121e6c18c5aa4da4a4b2e02a (diff)
downloadrust-rst-de6c16c95806a5d26779c3bc96241dfcab1f18ec.tar.bz2
Make it compile again
-rw-r--r--src/document_tree/element_categories.rs10
-rw-r--r--src/document_tree/elements.rs30
-rw-r--r--src/parser.rs4
-rw-r--r--src/rst.pest2
4 files changed, 24 insertions, 22 deletions
diff --git a/src/document_tree/element_categories.rs b/src/document_tree/element_categories.rs
index bc2e347..3a14b16 100644
--- a/src/document_tree/element_categories.rs
+++ b/src/document_tree/element_categories.rs
@@ -1,5 +1,7 @@
use std::fmt::{self,Debug,Formatter};
+use serde::{Serialize,Serializer};
+
use super::elements::*;
pub trait HasChildren<C> {
@@ -31,6 +33,14 @@ macro_rules! synonymous_enum {( $name:ident { $( $entry:ident ),* } ) => (
}
}
+ impl Serialize for $name {
+ fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
+ match self {
+ $( $name::$entry(ref inner) => inner.serialize(serializer), )*
+ }
+ }
+ }
+
$(
impl Into<$name> for $entry {
fn into(self) -> $name {
diff --git a/src/document_tree/elements.rs b/src/document_tree/elements.rs
index 77efa34..681c52e 100644
--- a/src/document_tree/elements.rs
+++ b/src/document_tree/elements.rs
@@ -2,10 +2,7 @@ use url::Url;
use serde::{
Serialize,
Serializer,
- ser::{
- SerializeSeq,
- SerializeStruct,
- },
+ ser::{SerializeStruct},
};
use super::extra_attributes::{self,ExtraAttributes};
@@ -84,29 +81,24 @@ macro_rules! impl_serialize {
($name: ident, $extra: ident, $childtype: ident) => {
impl Serialize for $name {
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: Serializer {
+ #[allow(unused_mut)]
let mut state = serializer.serialize_struct(stringify!($name), 3)?;
// TODO: common attrs
- impl_serialize_extra!($extra);
- impl_serialize_children!($childtype, self, serializer);
+ impl_cond__! { $extra =>
+
+ }
+ impl_cond__! { $childtype =>
+ state.serialize_field("children", self.children())?;
+ }
state.end()
}
}
};
}
-macro_rules! impl_serialize_extra {
- (__) => {};
- ($name: ident) => {
- // TODO extra_attributes::$name
- };
-}
-
-macro_rules! impl_serialize_children {
- (__, $_: ident, $__: ident) => {};
- ($childtype: ident, $self: ident, $serializer: ident) => {
- use serde::ser::SerializeStruct;
- $serializer.serialize_field("children", $self.children());
- };
+macro_rules! impl_cond__ {
+ (__ => $($b:tt)*) => {};
+ ($thing: ident => $($b:tt)*) => { $($b)* };
}
macro_rules! impl_elem {
diff --git a/src/parser.rs b/src/parser.rs
index fa12b3e..93e2cc1 100644
--- a/src/parser.rs
+++ b/src/parser.rs
@@ -50,11 +50,11 @@ fn convert_ssubel(pair: pest::iterators::Pair<Rule>) -> Result<StructuralSubElem
fn convert_title(pair: pest::iterators::Pair<pest_rst::Rule>) -> Title {
let mut title: Option<&str> = None;
- let mut adornment_char: Option<char> = None;
+ let mut _adornment_char: Option<char> = None;
for p in pair.into_inner() {
match p.as_rule() {
Rule::line => title = Some(p.as_str()),
- Rule::adornments => adornment_char = Some(p.as_str().chars().next().expect("Empty adornment?")),
+ Rule::adornments => _adornment_char = Some(p.as_str().chars().next().expect("Empty adornment?")),
rule => panic!("Unexpected rule in title: {:?}", rule),
};
}
diff --git a/src/rst.pest b/src/rst.pest
index 3d1d3d4..6608203 100644
--- a/src/rst.pest
+++ b/src/rst.pest
@@ -37,7 +37,7 @@ hanging_block = _{
// | plain
}
-// Note. A block type
+// Admonition. A block type
admonition = { ".." ~ PUSH(" "+) ~ admonition_type ~ "::" ~ (blank_line | line) ~ blank_line* ~ admonition_body? ~ DROP }
admonition_type = { "attention" | "caution" | "danger" | "error" | "hint" | "important" | "note" | "tip" | "warning" | "admonition" }