| 105 | if group.delimiter() != Delimiter::Parenthesis { |
| 106 | return Err("concat! must use parentheses".to_string()); |
| 107 | } |
| 108 | let mut paths = Vec::new(); |
| 109 | let mut item = TokenStream::new(); |
| 110 | for token in group.stream() { |
| 111 | if matches!(&token, TokenTree::Punct(p) if p.as_char() == ',') { |
| 112 | if item.is_empty() { |
| 113 | return Err("concat! contains empty item".to_string()); |
| 114 | } |
| 115 | paths.extend(parse_input(item)?); |
| 116 | item = TokenStream::new(); |
| 117 | } else { |
| 118 | item.extend([token]); |
| 119 | } |
| 120 | } |
| 121 | if !item.is_empty() { |
| 122 | paths.extend(parse_input(item)?); |
| 123 | } |
| 124 | if paths.is_empty() { |
| 125 | return Err("concat! needs at least one source".to_string()); |
| 126 | } |
| 127 | Ok(paths) |
| 128 | } |
| 129 | |
| 130 | fn parse_include_str(group: &Group) -> Result<String, String> { |
| 131 | if group.delimiter() != Delimiter::Parenthesis { |
| 132 | return Err("include_str! must use parentheses".to_string()); |
| 133 | } |
| 134 | let inner: Vec<TokenTree> = group.stream().into_iter().collect(); |
| 135 | match inner.as_slice() { |
| 136 | [TokenTree::Literal(lit)] => parse_string_literal(&lit.to_string()), |
| 137 | _ => Err("include_str! must contain exactly one string literal".to_string()), |
| 138 | } |
| 139 | } |
| 140 | |
| 141 | fn parse_string_literal(raw: &str) -> Result<String, String> { |
| 142 | if raw.len() < 2 || !raw.starts_with('"') || !raw.ends_with('"') { |
| 143 | return Err("expected string literal".to_string()); |
| 144 | } |
| 145 | let s = &raw[1..raw.len() - 1]; |