| 1 | use craterust-analyzer cargo pastey 0.2.3 crate/::errorrust-analyzer cargo pastey 0.2.3 error/::{Errorrust-analyzer cargo pastey 0.2.3 error/Error#, Resultrust-analyzer cargo pastey 0.2.3 error/Result#}; |
| 2 | use proc_macrorust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro crate/::{token_streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/, Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#, Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Group#, Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#, Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Literal#, Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#}; |
| 3 | use stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/::Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#; |
| 4 | |
| 5 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) enum Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment# { |
| 6 | Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr#), |
| 7 | Apostropherust-analyzer cargo pastey 0.2.3 segment/Segment#Apostrophe#(Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#), |
| 8 | Envrust-analyzer cargo pastey 0.2.3 segment/Segment#Env#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr#), |
| 9 | Modifierrust-analyzer cargo pastey 0.2.3 segment/Segment#Modifier#(Colonrust-analyzer cargo pastey 0.2.3 segment/Colon#, Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Ident#), |
| 10 | Replacerust-analyzer cargo pastey 0.2.3 segment/Segment#Replace#(Colonrust-analyzer cargo pastey 0.2.3 segment/Colon#, Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Group#), |
| 11 | } |
| 12 | |
| 13 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) struct LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr# { |
| 14 | pub valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.: Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#, |
| 15 | pub spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span.: Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, |
| 16 | } |
| 17 | |
| 18 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) struct Colonrust-analyzer cargo pastey 0.2.3 segment/Colon# { |
| 19 | pub spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span.: Spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Span#, |
| 20 | } |
| 21 | |
| 22 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) fn parserust-analyzer cargo pastey 0.2.3 segment/parse().(tokens: &mut Peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/Peekable#<token_streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/::IntoIterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/IntoIter#>) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#<Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#>> { |
| 23 | let mut segments = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 24 | while match tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() { |
| 25 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => false, |
| 26 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct)) => punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'>', |
| 27 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(_) => true, |
| 28 | } { |
| 29 | match tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().() { |
| 30 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Ident#(ident) => { |
| 31 | let mut fragment = ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 32 | if fragment.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().("r#") { |
| 33 | fragment = fragment.split_offrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]split_off().(2); |
| 34 | } |
| 35 | if fragment rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq().==rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq(). rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`PartialEq<&str>`]eq()."env" |
| 36 | && match tokens.peekrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`]peek().() { |
| 37 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct)) => punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'!', |
| 38 | _ => false, |
| 39 | } |
| 40 | { |
| 41 | let bang = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().().unwraprust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]unwrap().(); // `!` |
| 42 | let expect_group = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 43 | let parenthesized = match &expect_group { |
| 44 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group)) |
| 45 | if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Parenthesisrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#Parenthesis# => |
| 46 | { |
| 47 | group |
| 48 | } |
| 49 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(wrong) => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(wrong.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "expected `(`")), |
| 50 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 51 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().( |
| 52 | ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 53 | bang.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), |
| 54 | "expected `(` after `env!`", |
| 55 | )); |
| 56 | } |
| 57 | }; |
| 58 | let mut inner = parenthesized.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().(); |
| 59 | let lit = match inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().() { |
| 60 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Literal#(lit)) => lit, |
| 61 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(wrong) => { |
| 62 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(wrong.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "expected string literal")) |
| 63 | } |
| 64 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 65 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().( |
| 66 | ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 67 | parenthesized.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(), |
| 68 | "expected string literal as argument to env! macro", |
| 69 | )) |
| 70 | } |
| 71 | }; |
| 72 | |
| 73 | segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Envrust-analyzer cargo pastey 0.2.3 segment/Segment#Env#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr# { |
| 74 | valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.: get_literal_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_literal_string_value().(&lit, false, false)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch()., |
| 75 | spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span.: lit.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Literal]span().(), |
| 76 | })); |
| 77 | |
| 78 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unexpected) = inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().() { |
| 79 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().( |
| 80 | unexpected.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), |
| 81 | "unexpected token in env! macro", |
| 82 | )); |
| 83 | } |
| 84 | } else { |
| 85 | segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr# { |
| 86 | valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.: fragment, |
| 87 | spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span.: ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 88 | })); |
| 89 | } |
| 90 | } |
| 91 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Literal#(lit) => { |
| 92 | segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr# { |
| 93 | valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.: lit.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 94 | spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span.: lit.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Literal]span().(), |
| 95 | })); |
| 96 | } |
| 97 | // Note: `_` is always tokenized as an Ident, never a Punct, so there |
| 98 | // is no `'_'` arm here, it would be unreachable dead code. |
| 99 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct) => match punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() { |
| 100 | '\'' => segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Apostropherust-analyzer cargo pastey 0.2.3 segment/Segment#Apostrophe#(punct.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]span().())), |
| 101 | ':' => { |
| 102 | let colon_span = punct.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]span().(); |
| 103 | let colon = Colonrust-analyzer cargo pastey 0.2.3 segment/Colon# { spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span.: colon_span }; |
| 104 | let ident = match tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() { |
| 105 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Ident#(ident)) => ident, |
| 106 | wrong => { |
| 107 | let span = wrong.as_refrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]as_ref().().map_orrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]map_or().(colon_span, TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().); |
| 108 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(span, "expected identifier after `:`")); |
| 109 | } |
| 110 | }; |
| 111 | |
| 112 | if ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."replace" { |
| 113 | let replace = tokens.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().(); |
| 114 | |
| 115 | match replace { |
| 116 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group)) |
| 117 | if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Parenthesisrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#Parenthesis# => |
| 118 | { |
| 119 | segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Replacerust-analyzer cargo pastey 0.2.3 segment/Segment#Replace#(colon, group)); |
| 120 | } |
| 121 | _ => { |
| 122 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().( |
| 123 | colon.spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span., |
| 124 | ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 125 | "expected `(` after replace modifier", |
| 126 | )); |
| 127 | } |
| 128 | } |
| 129 | } else { |
| 130 | segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Modifierrust-analyzer cargo pastey 0.2.3 segment/Segment#Modifier#(colon, ident)); |
| 131 | } |
| 132 | } |
| 133 | '#' => segments.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(LitStrrust-analyzer cargo pastey 0.2.3 segment/LitStr# { |
| 134 | valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.: "#".to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(), |
| 135 | spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span.: punct.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]span().(), |
| 136 | })), |
| 137 | _ => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(punct.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]span().(), "unexpected punct")), |
| 138 | }, |
| 139 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group) => { |
| 140 | if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Nonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#None# { |
| 141 | let mut inner = group.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().().peekablerust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#peekable().(); |
| 142 | let nested = parserust-analyzer cargo pastey 0.2.3 segment/parse().(&mut inner)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 143 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unexpected) = inner.nextrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/adapters/peekable/impl#[`Peekable<I>`][Iterator]next().() { |
| 144 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(unexpected.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "unexpected token")); |
| 145 | } |
| 146 | segments.extendrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][`Extend<T>`]extend().(nested); |
| 147 | } else { |
| 148 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(group.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(), "unexpected token")); |
| 149 | } |
| 150 | } |
| 151 | } |
| 152 | } |
| 153 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(segments) |
| 154 | } |
| 155 | |
| 156 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) fn pasterust-analyzer cargo pastey 0.2.3 segment/paste().(segments: &[Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#]) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 157 | let mut evaluated = Vecrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/Vec#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T>`]new().(); |
| 158 | let mut is_lifetime = false; |
| 159 | |
| 160 | for (i, segment) in segments.iterrust-analyzer cargo core https://github.com/rust-lang/rust/library/core slice/impl#[`[T]`]iter().().enumeraterust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#enumerate().() { |
| 161 | match segment { |
| 162 | Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Stringrust-analyzer cargo pastey 0.2.3 segment/Segment#String#(segment) => { |
| 163 | if segment.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."#" { |
| 164 | if i rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialEq<Self>`]eq().0 { |
| 165 | // Enable Raw mode |
| 166 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().("r#")); |
| 167 | continue; |
| 168 | } |
| 169 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().( |
| 170 | segment.spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span., |
| 171 | "`#` is reserved keyword and it enables the raw mode \ |
| 172 | (i.e. generate Raw Identifiers) and it is only allowed in \ |
| 173 | the beginning like `[< # ... >]`", |
| 174 | )); |
| 175 | } |
| 176 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(segment.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value..clonerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][Clone]clone().()); |
| 177 | } |
| 178 | Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Apostropherust-analyzer cargo pastey 0.2.3 segment/Segment#Apostrophe#(span) => { |
| 179 | if is_lifetime { |
| 180 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(*rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/deref/impl#[`&T`][Deref]deref().span, "unexpected lifetime")); |
| 181 | } |
| 182 | is_lifetime = true; |
| 183 | } |
| 184 | Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Envrust-analyzer cargo pastey 0.2.3 segment/Segment#Env#(var) => { |
| 185 | let resolved = match stdrust-analyzer cargo std https://github.com/rust-lang/rust/library/std crate/::envrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/::varrust-analyzer cargo std https://github.com/rust-lang/rust/library/std env/var().(&var.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.) { |
| 186 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(resolved) => resolved, |
| 187 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(_) => { |
| 188 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().( |
| 189 | var.spanrust-analyzer cargo pastey 0.2.3 segment/LitStr#span., |
| 190 | &formatrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc macros/format!!("no such env var: {:?}", var.valuerust-analyzer cargo pastey 0.2.3 segment/LitStr#value.), |
| 191 | )); |
| 192 | } |
| 193 | }; |
| 194 | let resolved = resolved.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().('-', "_"); |
| 195 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(resolved); |
| 196 | } |
| 197 | Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Modifierrust-analyzer cargo pastey 0.2.3 segment/Segment#Modifier#(colon, ident) => { |
| 198 | let last = match evaluated.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 199 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last) => last, |
| 200 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => { |
| 201 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().(colon.spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span., ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), "unexpected modifier")) |
| 202 | } |
| 203 | }; |
| 204 | match ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() { |
| 205 | "lower" => { |
| 206 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(last.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()); |
| 207 | } |
| 208 | "upper" => { |
| 209 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(last.to_uppercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_uppercase().()); |
| 210 | } |
| 211 | "snake" => { |
| 212 | let mut acc = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 213 | let mut prev = '_'; |
| 214 | for ch in last.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() { |
| 215 | if ch.is_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_uppercase().() && prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'_' { |
| 216 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().('_'); |
| 217 | } |
| 218 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(ch); |
| 219 | prev = ch; |
| 220 | } |
| 221 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(acc.to_lowercaserust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]to_lowercase().()); |
| 222 | } |
| 223 | "camel" | "upper_camel" | "lower_camel" => { |
| 224 | let mut is_lower_camel = ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().().as_strrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]as_str().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[`&A`][`PartialEq<&B>`]eq()."lower_camel"; |
| 225 | let mut acc = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 226 | let mut prev = '_'; |
| 227 | for ch in last.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() { |
| 228 | if ch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'_' { |
| 229 | if prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'_' { |
| 230 | if is_lower_camel { |
| 231 | for chl in ch.to_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_lowercase().() { |
| 232 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chl); |
| 233 | } |
| 234 | is_lower_camel = false; |
| 235 | } else { |
| 236 | for chu in ch.to_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_uppercase().() { |
| 237 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chu); |
| 238 | } |
| 239 | } |
| 240 | } else if prev.is_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_uppercase().() { |
| 241 | for chl in ch.to_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_lowercase().() { |
| 242 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chl); |
| 243 | } |
| 244 | } else { |
| 245 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(ch); |
| 246 | } |
| 247 | } |
| 248 | prev = ch; |
| 249 | } |
| 250 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(acc); |
| 251 | } |
| 252 | "camel_edge" => { |
| 253 | let mut acc = Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::newrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]new().(); |
| 254 | let mut prev = '_'; |
| 255 | for ch in last.charsrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]chars().() { |
| 256 | if ch rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().!=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]ne().'_' { |
| 257 | if prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'_' { |
| 258 | for chu in ch.to_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_uppercase().() { |
| 259 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chu); |
| 260 | } |
| 261 | } else if prev.is_uppercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]is_uppercase().() { |
| 262 | for chl in ch.to_lowercaserust-analyzer cargo core https://github.com/rust-lang/rust/library/core char/methods/impl#[char]to_lowercase().() { |
| 263 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(chl); |
| 264 | } |
| 265 | } else { |
| 266 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(ch); |
| 267 | } |
| 268 | } else if prev rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().'_' { |
| 269 | acc.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]push().(ch); |
| 270 | } |
| 271 | prev = ch; |
| 272 | } |
| 273 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(acc); |
| 274 | } |
| 275 | _ => { |
| 276 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().( |
| 277 | colon.spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span., |
| 278 | ident.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Ident]span().(), |
| 279 | "unsupported modifier", |
| 280 | )); |
| 281 | } |
| 282 | } |
| 283 | } |
| 284 | Segmentrust-analyzer cargo pastey 0.2.3 segment/Segment#::Replacerust-analyzer cargo pastey 0.2.3 segment/Segment#Replace#(colon, group) => { |
| 285 | let mut inner_stream = group.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().(); |
| 286 | let from = inner_stream.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().(); |
| 287 | let punct = inner_stream.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().(); |
| 288 | let to = inner_stream.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().(); |
| 289 | |
| 290 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(unexpected_token) = inner_stream.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().() { |
| 291 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(unexpected_token.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "expected `)`")); |
| 292 | } |
| 293 | |
| 294 | match (from, punct, to) { |
| 295 | (Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(from), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Punctrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Punct#(punct)), Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(to)) |
| 296 | if punct.as_charrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Punct]as_char().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().==rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[char][`PartialEq<Self>`]eq().',' => |
| 297 | { |
| 298 | let last = |
| 299 | match evaluated.poprust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]pop().() { |
| 300 | Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(last) => last, |
| 301 | Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None# => return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::new2rust-analyzer cargo pastey 0.2.3 error/impl#[Error]new2().( |
| 302 | colon.spanrust-analyzer cargo pastey 0.2.3 segment/Colon#span., |
| 303 | group.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(), |
| 304 | "replace modifier requires a preceding value to operate on.", |
| 305 | )), |
| 306 | }; |
| 307 | |
| 308 | let from_str = get_token_tree_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_token_tree_string_value().(&from)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 309 | let to_str = get_token_tree_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_token_tree_string_value().(&to)?rust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/impl#[`Result<T, E>`][Try]branch().; |
| 310 | |
| 311 | let new_ident = last.replacerust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc str/impl#[str]replace().(&from_str, &to_str); |
| 312 | |
| 313 | evaluated.pushrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`]push().(new_ident); |
| 314 | } |
| 315 | _ => { |
| 316 | return Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().( |
| 317 | group.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]span().(), |
| 318 | "expected replace modifier format: `:replace(\"from\", \"to\")`", |
| 319 | )) |
| 320 | } |
| 321 | } |
| 322 | } |
| 323 | } |
| 324 | } |
| 325 | |
| 326 | let mut pasted = evaluated.into_iterrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc vec/impl#[`Vec<T, A>`][IntoIterator]into_iter().().collectrust-analyzer cargo core https://github.com/rust-lang/rust/library/core iter/traits/iterator/Iterator#collect().::<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#>(); |
| 327 | if is_lifetime { |
| 328 | pasted.insertrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]insert().(0, '\''); |
| 329 | } |
| 330 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(pasted) |
| 331 | } |
| 332 | |
| 333 | // The three defensive sub-conditions below can never evaluate to false when called |
| 334 | // from get_literal_string_value with a real proc_macro::Literal, because- |
| 335 | // |
| 336 | // ends_with('"') — the Rust tokenizer rejects unterminated string literals before |
| 337 | // the macro receives them, so starts_with('"') implies ends_with('"'). |
| 338 | // ends_with('\'') — same: the tokenizer rejects unterminated char literals. |
| 339 | // len() >= 2 — impossible once both prefix and suffix chars are confirmed present. |
| 340 | // |
| 341 | // These checks are kept for correctness in case this function is called with an |
| 342 | // arbitrary &str in the future. The false branches are exercised by the |
| 343 | // unit tests below, which call is_quoted_string_or_char directly |
| 344 | // with raw &str values (e.g. "\"abc", "'abc", "\""). |
| 345 | // proc_macro::Literal has no constructor that produces such malformed tokens, so |
| 346 | // the test_helpers.rs (with paste_test macro) path cannot cover these branches. |
| 347 | fn is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().(l_str: &str, parse_char: bool) -> bool { |
| 348 | ((l_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('"') && l_str.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('"')) |
| 349 | || (parse_char && l_str.starts_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]starts_with().('\'') && l_str.ends_withrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]ends_with().('\''))) |
| 350 | && l_str.lenrust-analyzer cargo core https://github.com/rust-lang/rust/library/core str/impl#[str]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().>=rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/impls/impl#[usize][`PartialOrd<Self>`]ge().2 |
| 351 | } |
| 352 | |
| 353 | fn get_literal_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_literal_string_value().(l: &Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Literal#, parse_char: bool, parse_numbers: bool) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 354 | let l_str = l.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().(); |
| 355 | |
| 356 | if is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().(&l_str, parse_char) { |
| 357 | // TODO: maybe handle escape sequences in the string if |
| 358 | // someone has a use case. |
| 359 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#::fromrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`From<&str>`]from().(&l_str[rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().1..rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/range/Range#l_str.lenrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String]len().() rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().-rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub(). rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/arith/impl#[usize][`Sub<Self>`]sub().1]rust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[String][`Index<I>`]index().)) |
| 360 | } else if parse_numbers { |
| 361 | Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(l_str) |
| 362 | } else { |
| 363 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(l.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Literal]span().(), "expected string literal")) |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | pub(craterust-analyzer cargo pastey 0.2.3 crate/) fn get_token_tree_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_token_tree_string_value().(t: &TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#) -> Resultrust-analyzer cargo pastey 0.2.3 error/Result#<Stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/String#> { |
| 368 | match t { |
| 369 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Identrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Ident#(ident) => Okrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Ok#(ident.to_stringrust-analyzer cargo alloc https://github.com/rust-lang/rust/library/alloc string/impl#[T][ToString]to_string().()), |
| 370 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Literalrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Literal#(literal) => get_literal_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_literal_string_value().(literal, true, true), |
| 371 | TokenTreerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#::Grouprust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro TokenTree#Group#(group) if group.delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]delimiter().() rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().==rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq(). rust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Delimiter][`PartialEq<Self>`]eq().Delimiterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#::Nonerust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro Delimiter#None# => { |
| 372 | // Handle interpolated tokens from macro_rules (common in older Rust versions) |
| 373 | let mut inner = group.streamrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[Group]stream().().into_iterrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[TokenStream][IntoIterator]into_iter().(); |
| 374 | if let Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(first) = inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().() { |
| 375 | if inner.nextrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro token_stream/impl#[IntoIter][Iterator]next().().is_nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/impl#[`Option<T>`]is_none().() { |
| 376 | // Single token in the group, recursively process it |
| 377 | return get_token_tree_string_valuerust-analyzer cargo pastey 0.2.3 segment/get_token_tree_string_value().(&first); |
| 378 | } |
| 379 | } |
| 380 | Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(t.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "Expected either Ident, or Literal.")) |
| 381 | } |
| 382 | _ => Errrust-analyzer cargo core https://github.com/rust-lang/rust/library/core result/Result#Err#(Errorrust-analyzer cargo pastey 0.2.3 error/Error#::newrust-analyzer cargo pastey 0.2.3 error/impl#[Error]new().(t.spanrust-analyzer cargo proc_macro https://github.com/rust-lang/rust/library/proc_macro impl#[TokenTree]span().(), "Expected either Ident, or Literal.")), |
| 383 | } |
| 384 | } |
| 385 | |
| 386 | #[cfg(test)] |
| 387 | mod testsrust-analyzer cargo pastey 0.2.3 segment/tests/ { |
| 388 | use superrust-analyzer cargo pastey 0.2.3 segment/::is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().; |
| 389 | |
| 390 | #[testrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/test:] |
| 391 | fn test_is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/tests/test_is_quoted_string_or_char().() { |
| 392 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("\"hello\"", false)); |
| 393 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("abc", false)); |
| 394 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("\"", false)); |
| 395 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("\"abc", false)); |
| 396 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("'a'", true)); |
| 397 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("'abc", true)); |
| 398 | assertrust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/assert!!(!rust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/bit/impl#[bool][Not]not().is_quoted_string_or_charrust-analyzer cargo pastey 0.2.3 segment/is_quoted_string_or_char().("abc", true)); |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | #[cfg(doctest)] |
| 403 | #[doc(hidden)] |
| 404 | mod doc_tests { |
| 405 | /// ```compile_fail |
| 406 | /// use pastey::paste; |
| 407 | /// paste! { fn [<a + b>]() {} } |
| 408 | /// ``` |
| 409 | fn test_unexpected_punct() {} |
| 410 | |
| 411 | /// ```compile_fail |
| 412 | /// use pastey::paste; |
| 413 | /// paste! { fn [<{}>]() {} } |
| 414 | /// ``` |
| 415 | fn test_unexpected_group() {} |
| 416 | |
| 417 | /// ```compile_fail |
| 418 | /// use pastey::paste; |
| 419 | /// paste! { fn [<env! foo>]() {} } |
| 420 | /// ``` |
| 421 | fn test_env_missing_paren() {} |
| 422 | |
| 423 | /// ```compile_fail |
| 424 | /// use pastey::paste; |
| 425 | /// paste! { fn [<env!(foo)>]() {} } |
| 426 | /// ``` |
| 427 | fn test_env_non_literal_arg() {} |
| 428 | |
| 429 | /// ```compile_fail |
| 430 | /// use pastey::paste; |
| 431 | /// paste! { fn [<env!()>]() {} } |
| 432 | /// ``` |
| 433 | fn test_env_empty() {} |
| 434 | |
| 435 | /// ```compile_fail |
| 436 | /// use pastey::paste; |
| 437 | /// paste! { fn [<env!("CARGO_PKG_NAME" "extra")>]() {} } |
| 438 | /// ``` |
| 439 | fn test_env_unexpected_token() {} |
| 440 | |
| 441 | /// ```compile_fail |
| 442 | /// use pastey::paste; |
| 443 | /// paste! { fn [<a:>]() {} } |
| 444 | /// ``` |
| 445 | fn test_no_ident_after_colon() {} |
| 446 | |
| 447 | /// ```compile_fail |
| 448 | /// use pastey::paste; |
| 449 | /// paste! { fn [<a:replace x>]() {} } |
| 450 | /// ``` |
| 451 | fn test_replace_missing_paren() {} |
| 452 | |
| 453 | /// ```compile_fail |
| 454 | /// use pastey::paste; |
| 455 | /// paste! { fn [<a:pillow>]() {} } |
| 456 | /// ``` |
| 457 | fn test_unsupported_modifier() {} |
| 458 | |
| 459 | /// ```compile_fail |
| 460 | /// use pastey::paste; |
| 461 | /// paste! { fn [<a:replace("x","y","z")>]() {} } |
| 462 | /// ``` |
| 463 | fn test_replace_extra_token() {} |
| 464 | |
| 465 | /// ```compile_fail |
| 466 | /// use pastey::paste; |
| 467 | /// paste! { struct [<:replace("H","W")>]; } |
| 468 | /// ``` |
| 469 | fn test_replace_no_preceding_value() {} |
| 470 | |
| 471 | /// ```compile_fail |
| 472 | /// use pastey::paste; |
| 473 | /// paste! { fn [<a:replace(x)>]() {} } |
| 474 | /// ``` |
| 475 | fn test_replace_wrong_format() {} |
| 476 | |
| 477 | /// ```compile_fail |
| 478 | /// use pastey::paste; |
| 479 | /// paste! { struct [<foo # bar>]; } |
| 480 | /// ``` |
| 481 | fn test_raw_mode_wrong_position() {} |
| 482 | |
| 483 | /// ```compile_fail |
| 484 | /// use pastey::paste; |
| 485 | /// paste! { fn [<'a 'b>]() {} } |
| 486 | /// ``` |
| 487 | fn test_unexpected_lifetime() {} |
| 488 | |
| 489 | /// ```compile_fail |
| 490 | /// use pastey::paste; |
| 491 | /// paste! { fn [<env!("THIS_VAR_DOES_NOT_EXIST_XYZ_999")>]() {} } |
| 492 | /// ``` |
| 493 | fn test_no_such_env_var() {} |
| 494 | |
| 495 | /// ```compile_fail |
| 496 | /// use pastey::paste; |
| 497 | /// paste! { fn [<:lower>]() {} } |
| 498 | /// ``` |
| 499 | fn test_modifier_no_preceding_value() {} |
| 500 | |
| 501 | /// ```compile_fail |
| 502 | /// use pastey::paste; |
| 503 | /// paste! { fn [<env!["CARGO_PKG_NAME"]>]() {} } |
| 504 | /// ``` |
| 505 | fn test_env_bracket_group() {} |
| 506 | |
| 507 | /// ```compile_fail |
| 508 | /// use pastey::paste; |
| 509 | /// paste! { struct [<a:replace["x", "y"]>]; } |
| 510 | /// ``` |
| 511 | fn test_replace_bracket_group() {} |
| 512 | |
| 513 | /// ```compile_fail |
| 514 | /// use pastey::paste; |
| 515 | /// macro_rules! m { |
| 516 | /// ($e:expr) => { paste! { fn [<$e foo>]() {} } } |
| 517 | /// } |
| 518 | /// m!(1 > 0); |
| 519 | /// ``` |
| 520 | fn test_none_group_unexpected_token() {} |
| 521 | |
| 522 | /// ```compile_fail |
| 523 | /// use pastey::paste; |
| 524 | /// paste! { struct [<a:replace("x"; "y")>]; } |
| 525 | /// ``` |
| 526 | fn test_replace_wrong_separator() {} |
| 527 | |
| 528 | /// ```compile_fail |
| 529 | /// use pastey::paste; |
| 530 | /// paste! { fn [<env!(42)>]() {} } |
| 531 | /// ``` |
| 532 | fn test_env_numeric_literal() {} |
| 533 | |
| 534 | /// ```compile_fail |
| 535 | /// use pastey::paste; |
| 536 | /// paste! { fn [<env!('a')>]() {} } |
| 537 | /// ``` |
| 538 | fn test_env_char_literal() {} |
| 539 | |
| 540 | /// ```compile_fail |
| 541 | /// use pastey::paste; |
| 542 | /// paste! { struct [<Foo:replace(["x"], "y")>]; } |
| 543 | /// ``` |
| 544 | fn test_replace_from_bracket_group() {} |
| 545 | |
| 546 | /// ```compile_fail |
| 547 | /// use pastey::paste; |
| 548 | /// macro_rules! m { |
| 549 | /// ($from:expr) => { paste! { struct [<Foo:replace($from, "y")>]; } } |
| 550 | /// } |
| 551 | /// m!(x + y); |
| 552 | /// ``` |
| 553 | fn test_replace_from_multi_token_none_group() {} |
| 554 | |
| 555 | /// ```compile_fail |
| 556 | /// use pastey::paste; |
| 557 | /// macro_rules! m { |
| 558 | /// ($to:expr) => { paste! { struct [<Foo:replace("o", $to)>]; } } |
| 559 | /// } |
| 560 | /// m!(x + y); |
| 561 | /// ``` |
| 562 | fn test_replace_to_multi_token_none_group() {} |
| 563 | } |