update code format

This commit is contained in:
Marc-Antoine Arnaud
2018-05-23 17:14:53 +02:00
parent 8b3d98d911
commit d63e9d27d8
18 changed files with 1218 additions and 970 deletions

View File

@@ -1,4 +1,3 @@
use proc_macro2::TokenTreeIter;
use proc_macro2::TokenNode::*;
use proc_macro2::Spacing;
@@ -18,13 +17,9 @@ pub struct YaSerdeAttribute {
fn get_value(iter: &mut TokenTreeIter) -> Option<String> {
match (iter.next(), iter.next()) {
(Some(operator), Some(value)) => {
match (operator.kind, value.kind) {
(Op('=', Spacing::Alone), Literal(l)) => {
Some(l.to_string().replace("\"", ""))
},
_ => None,
}
(Some(operator), Some(value)) => match (operator.kind, value.kind) {
(Op('=', Spacing::Alone), Literal(l)) => Some(l.to_string().replace("\"", "")),
_ => None,
},
_ => None,
}
@@ -42,54 +37,48 @@ impl YaSerdeAttribute {
for attr in attrs.iter() {
let mut attr_iter = attr.clone().tts.into_iter();
match attr_iter.next() {
Some(token) => {
match token.kind {
Group(Parenthesis, token_stream) => {
let mut attr_iter = token_stream.into_iter();
Some(token) => match token.kind {
Group(Parenthesis, token_stream) => {
let mut attr_iter = token_stream.into_iter();
while let Some(item) = attr_iter.next() {
match item.kind {
Term(t) => {
match t.as_str() {
"attribute" => {
attribute = true;
},
"namespace" => {
if let Some(namespace) = get_value(&mut attr_iter) {
let splitted : Vec<&str> = namespace.split(": ").collect();
if splitted.len() == 2 {
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
}
if splitted.len() == 1 {
namespaces.insert("".to_owned(), splitted[0].to_owned());
}
}
},
"prefix" => {
prefix = get_value(&mut attr_iter);
while let Some(item) = attr_iter.next() {
match item.kind {
Term(t) => match t.as_str() {
"attribute" => {
attribute = true;
}
"namespace" => {
if let Some(namespace) = get_value(&mut attr_iter) {
let splitted: Vec<&str> = namespace.split(": ").collect();
if splitted.len() == 2 {
namespaces.insert(splitted[0].to_owned(), splitted[1].to_owned());
}
"rename" => {
rename = get_value(&mut attr_iter);
},
"root" => {
root = get_value(&mut attr_iter);
},
"text" => {
text = true;
if splitted.len() == 1 {
namespaces.insert("".to_owned(), splitted[0].to_owned());
}
_ => {},
}
},
}
"prefix" => {
prefix = get_value(&mut attr_iter);
}
"rename" => {
rename = get_value(&mut attr_iter);
}
"root" => {
root = get_value(&mut attr_iter);
}
"text" => {
text = true;
}
_ => {}
}
},
_ => {}
}
},
_ => {},
}
}
_ => {}
},
None => {},
None => {}
}
}