Skip to content

Commit 3f5c6a4

Browse files
authored
Merge pull request #2 from marcdejonge/add-allow-headers
Fixes some clippy warnings
2 parents ed122d8 + ab4c757 commit 3f5c6a4

File tree

6 files changed

+23
-25
lines changed

6 files changed

+23
-25
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[package]
22
name = "nom-parse-macros"
33
description = "Procedural macros for generating parser functions for the nom libary"
4-
version = "0.4.0"
4+
version = "0.4.1"
55
license = "MIT/Apache-2.0"
66
keywords = ["nom", "parser", "parsable"]
77
categories = ["parsing"]

examples/extra_where_clause.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,9 @@ where
1818
{
1919
move |mut input: I| {
2020
let mut array = [T::default(); D];
21-
for ix in 0..D {
22-
let (rest, _) = prefix.parse(input)?;
23-
let (rest, value) = T::parse(rest)?;
24-
input = rest;
25-
array[ix] = value;
21+
for val in &mut array {
22+
(input, _) = prefix.parse(input)?;
23+
(input, *val) = T::parse(input)?;
2624
}
2725
Ok((input, array))
2826
}

src/fields.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ impl Fields {
149149
.collect()
150150
}
151151

152+
#[allow(clippy::collapsible_else_if)]
152153
pub fn create_instance_expr(&self, variant_name: Option<&Ident>) -> TokenStream {
153154
let creation_names = self.get_creation_names();
154155

src/lib.rs

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
//! don't need a ton of use statements in your code. But there are also a couple of special cases:
1818
//!
1919
//! - `{}` or `()` will be replaced with a [`nom_parse_trait::ParseFrom::parse`] call for the
20-
//! corresponding field. This is useful when you are using types that have implemented the
21-
//! `ParseFrom` trait already.
20+
//! corresponding field. This is useful when you are using types that have implemented the
21+
//! `ParseFrom` trait already.
2222
//! - Strings, bytes strings and characters will be translated to match the input verbatim using
23-
//! the [`nom::bytes::complete::tag`] function.
23+
//! the [`nom::bytes::complete::tag`] function.
2424
//!
2525
//! # Input types that are supported
2626
//!
@@ -34,13 +34,13 @@
3434
//! # Known limitations
3535
//!
3636
//! - When your try to use a custom parser combinator, the nom function parser will try to change
37-
//! all parameters to be nom parsers. This is useful in many cases, but when you need to pass in
38-
//! a normal string for example, it won't work. In these cases, you can define a separate function
39-
//! to wrap the call. I'm not sure how to fix that right now, but I'm open to suggestions.
37+
//! all parameters to be nom parsers. This is useful in many cases, but when you need to pass in
38+
//! a normal string for example, it won't work. In these cases, you can define a separate function
39+
//! to wrap the call. I'm not sure how to fix that right now, but I'm open to suggestions.
4040
//!
4141
//! - Since the generated input type is very generic, all functions that you want to use in the
42-
//! nom expression should also be very generic. In the future I might add a way to specify if you
43-
//! want to generate a specific input type, but for now it's not possible.
42+
//! nom expression should also be very generic. In the future I might add a way to specify if you
43+
//! want to generate a specific input type, but for now it's not possible.
4444
4545
extern crate proc_macro;
4646
mod fields;
@@ -146,7 +146,6 @@ use quote::ToTokens;
146146
/// end: [N; D],
147147
/// }
148148
/// ```
149-
150149
#[proc_macro_attribute]
151150
pub fn parse_from(attrs: TokenStream, object: TokenStream) -> TokenStream {
152151
let parse_format = syn::parse_macro_input!(attrs as ParseFormat);

src/nom_packages.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ fn parse_call(call: &mut ExprCall) -> Result<()> {
216216
if ident == "tuple" || ident == "alt" {
217217
let args = call.args.clone();
218218
if args.len() != 1 {
219-
call.args = Punctuated::from(Punctuated::new());
219+
call.args = Punctuated::new();
220220
call.args.push(Expr::Tuple(ExprTuple {
221221
attrs: vec![],
222222
paren_token: Default::default(),
@@ -228,7 +228,7 @@ fn parse_call(call: &mut ExprCall) -> Result<()> {
228228
update_nom_expression(arg)?;
229229
}
230230
// Nom functions without parameters should not be called, but referenced directly
231-
} else if parameters.len() == 0 {
231+
} else if parameters.is_empty() {
232232
if ident != "fail" {
233233
return Err(syn::Error::new_spanned(
234234
call.func.clone(),

src/parser_generator.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,8 @@ impl ToTokens for ParserGenerator {
5454

5555
tokens.extend(object.to_token_stream());
5656

57-
let (mapping_names, mappings): (Vec<_>, Vec<_>) = variants
58-
.iter()
59-
.map(|variant| generate_variant(variant))
60-
.unzip();
57+
let (mapping_names, mappings): (Vec<_>, Vec<_>) =
58+
variants.iter().map(generate_variant).unzip();
6159

6260
generate_parser(
6361
tokens,
@@ -78,7 +76,7 @@ impl ToTokens for ParserGenerator {
7876

7977
fn generate_variant(variant: &ParsedVariant) -> (Ident, TokenStream) {
8078
let mapping_name = Ident::new(
81-
&format!("map_{}", variant.name.to_string().to_lowercase()),
79+
&format!("parse_{}", variant.name.to_string().to_lowercase()),
8280
Span::call_site(),
8381
);
8482
let format_expr = variant.format.to_token_stream();
@@ -113,14 +111,16 @@ fn generate_parser(
113111
token_stream: &mut TokenStream,
114112
name: &Ident,
115113
generics: &Generics,
116-
extra_where_clauses: &Vec<WherePredicate>,
114+
extra_where_clauses: &[WherePredicate],
117115
content: impl ToTokens,
118116
) {
119117
let (_, type_generics, _) = generics.split_for_impl();
120-
let parser_generics = parser_generics(&generics, extra_where_clauses);
118+
let parser_generics = parser_generics(generics, extra_where_clauses);
121119
let (impl_generics, _, where_statement) = parser_generics.split_for_impl();
122120

123121
token_stream.extend(quote! {
122+
#[automatically_derived]
123+
#[allow(unused)]
124124
impl #impl_generics nom_parse_trait::ParseFrom<I, E> for #name #type_generics
125125
#where_statement
126126
{
@@ -134,7 +134,7 @@ fn generate_parser(
134134
});
135135
}
136136

137-
fn parser_generics(generics: &Generics, extra_where_clauses: &Vec<WherePredicate>) -> Generics {
137+
fn parser_generics(generics: &Generics, extra_where_clauses: &[WherePredicate]) -> Generics {
138138
let mut generics = generics.clone();
139139

140140
// If there are no generics, start a new one

0 commit comments

Comments
 (0)