use Punctuated
@@ -4,6 +4,7 @@ use std::fs;
use proc_macro2::{Ident, Span};
use quote::format_ident;
use syn::parse::{Parse, ParseStream};
+use syn::punctuated::Punctuated;
use syn::{Expr, LitBool, LitStr, Token};
use syn::{ExprArray, Type};
@@ -52,27 +53,11 @@ impl Parse for QueryMacroInput {
let _ = input.parse::<syn::token::Eq>()?;
if key == "source" {
- let mut fragments: Vec<LitStr> = Vec::new();
- 'source_parser: while !input.is_empty() {
- if input.lookahead1().peek(LitStr) {
- fragments.push(input.parse()?);
- if input.lookahead1().peek(Token![+]) {
- let _ = input.parse::<Token![+]>();
- } else {
- break 'source_parser;
- }
- } else {
- break 'source_parser;
- }
- }
- if fragments.len() == 0 {
- return Err(syn::Error::new_spanned(key, "no source given"));
- }
- query_src = Some((
- QuerySrc::String(fragments.iter().map(LitStr::value).collect()),
- input.span(),
- ));
-
+ let query_str = Punctuated::<LitStr, Token![+]>::parse_separated_nonempty(input)?
+ .iter()
+ .map(LitStr::value)
+ .collect();
+ query_src = Some((QuerySrc::String(query_str), input.span()));
} else if key == "source_file" {
let lit_str = input.parse::<LitStr>()?;
query_src = Some((QuerySrc::File(lit_str.value()), lit_str.span()));
