aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive/src
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-08-14 20:47:19 +0200
committerLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2019-08-14 20:54:58 +0200
commit956d52a62d623cd56e212e7de0df135b5aa20d43 (patch)
tree1fb6b97b02a1119e9528a2ef24a3b1ffce9ba19e /askama_derive/src
parenta0997e7108a46e78541b1e4f3fb77d6fd56df901 (diff)
downloadaskama-956d52a62d623cd56e212e7de0df135b5aa20d43.tar.gz
askama-956d52a62d623cd56e212e7de0df135b5aa20d43.tar.bz2
askama-956d52a62d623cd56e212e7de0df135b5aa20d43.zip
Prevent rightward drift in attribute interpretation code
Diffstat (limited to 'askama_derive/src')
-rw-r--r--askama_derive/src/input.rs93
1 files changed, 51 insertions, 42 deletions
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs
index a0cb813..3b65640 100644
--- a/askama_derive/src/input.rs
+++ b/askama_derive/src/input.rs
@@ -54,52 +54,61 @@ impl<'a> TemplateInput<'a> {
let mut ext = None;
let mut syntax = None;
for item in meta_list.nested {
- if let syn::NestedMeta::Meta(syn::Meta::NameValue(ref pair)) = item {
- if pair.path.is_ident("path") {
- if let syn::Lit::Str(ref s) = pair.lit {
- if source.is_some() {
- panic!("must specify 'source' or 'path', not both");
- }
- source = Some(Source::Path(s.value()));
- } else {
- panic!("template path must be string literal");
- }
- } else if pair.path.is_ident("source") {
- if let syn::Lit::Str(ref s) = pair.lit {
- if source.is_some() {
- panic!("must specify 'source' or 'path', not both");
- }
- source = Some(Source::Source(s.value()));
- } else {
- panic!("template source must be string literal");
- }
- } else if pair.path.is_ident("print") {
- if let syn::Lit::Str(ref s) = pair.lit {
- print = s.value().into();
- } else {
- panic!("print value must be string literal");
+ let pair = match item {
+ syn::NestedMeta::Meta(syn::Meta::NameValue(ref pair)) => pair,
+ _ => panic!(
+ "unsupported attribute argument {:?}",
+ item.to_token_stream()
+ ),
+ };
+
+ if pair.path.is_ident("path") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ if source.is_some() {
+ panic!("must specify 'source' or 'path', not both");
}
- } else if pair.path.is_ident("escape") {
- if let syn::Lit::Str(ref s) = pair.lit {
- escaping = Some(s.value());
- } else {
- panic!("escape value must be string literal");
- }
- } else if pair.path.is_ident("ext") {
- if let syn::Lit::Str(ref s) = pair.lit {
- ext = Some(s.value());
- } else {
- panic!("ext value must be string literal");
- }
- } else if pair.path.is_ident("syntax") {
- if let syn::Lit::Str(ref s) = pair.lit {
- syntax = Some(s.value())
- } else {
- panic!("syntax value must be string literal");
+ source = Some(Source::Path(s.value()));
+ } else {
+ panic!("template path must be string literal");
+ }
+ } else if pair.path.is_ident("source") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ if source.is_some() {
+ panic!("must specify 'source' or 'path', not both");
}
+ source = Some(Source::Source(s.value()));
+ } else {
+ panic!("template source must be string literal");
+ }
+ } else if pair.path.is_ident("print") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ print = s.value().into();
+ } else {
+ panic!("print value must be string literal");
+ }
+ } else if pair.path.is_ident("escape") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ escaping = Some(s.value());
+ } else {
+ panic!("escape value must be string literal");
+ }
+ } else if pair.path.is_ident("ext") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ ext = Some(s.value());
+ } else {
+ panic!("ext value must be string literal");
+ }
+ } else if pair.path.is_ident("syntax") {
+ if let syn::Lit::Str(ref s) = pair.lit {
+ syntax = Some(s.value())
} else {
- panic!("unsupported attribute key '{}' found", pair.path.to_token_stream())
+ panic!("syntax value must be string literal");
}
+ } else {
+ panic!(
+ "unsupported attribute key '{}' found",
+ pair.path.to_token_stream()
+ )
}
}