Lines Matching +full:input +full:- +full:value

1 // SPDX-License-Identifier: Apache-2.0 OR MIT
18 /// `proc_macro::TokenStream` input of a `proc_macro_attribute`, you do **not**
39 /// - `kind = "..."`
40 /// - `hot`
41 /// - `with(sugar, milk, ...)`, a comma-separated list of ingredients
52 /// pub fn tea(args: TokenStream, input: TokenStream) -> TokenStream {
58 /// kind = Some(meta.value()?.parse()?);
82 /// trailing commas, and producing sensible error messages on unexpected input.
86 /// --> src/main.rs:3:37
107 /// pub fn tea(args: TokenStream, input: TokenStream) -> TokenStream {
124 /// fn parse(&mut self, meta: ParseNestedMeta) -> Result<()> {
126 /// self.kind = Some(meta.value()?.parse()?);
134 pub fn parser(logic: impl FnMut(ParseNestedMeta) -> Result<()>) -> impl Parser<Output = ()> { in parser()
135 |input: ParseStream| { in parser()
136 if input.is_empty() { in parser()
139 parse_nested_meta(input, logic) in parser()
149 /// Refer to usage examples on the following two entry-points:
151 /// - [`Attribute::parse_nested_meta`] if you have an entire `Attribute` to
156 /// - [`syn::meta::parser`] if you are implementing a `proc_macro_attribute`
168 pub input: ParseStream<'a>, field
172 /// Used when parsing `key = "value"` syntax.
174 /// All it does is advance `meta.input` past the `=` sign in the input. You
177 /// use `meta.value()?`.
191 /// let value = meta.value()?; // this parses the `=`
192 /// let s: LitStr = value.parse()?; // this parses `"EarlGrey"`
193 /// if s.value() == "EarlGrey" {
204 pub fn value(&self) -> Result<ParseStream<'a>> { in value() method
205 self.input.parse::<Token![=]>()?; in value()
206 Ok(self.input) in value()
225 /// meta.parse_nested_meta(|meta| { // <---
263 /// parenthesized!(content in meta.input);
275 logic: impl FnMut(ParseNestedMeta) -> Result<()>, in parse_nested_meta()
276 ) -> Result<()> { in parse_nested_meta()
278 parenthesized!(content in self.input); in parse_nested_meta()
293 /// # fn example(attr: &Attribute) -> syn::Result<()> {
311 /// --> src/main.rs:3:26
317 /// More usefully, the second place is if you've already parsed a value but
318 /// have decided not to accept the value:
323 /// # fn example(attr: &Attribute) -> syn::Result<()> {
328 /// let expr: Expr = meta.value()?.parse()?;
348 /// --> src/main.rs:3:7
360 /// # fn example(expr: Expr) -> syn::Result<()> {
375 /// --> src/main.rs:3:14
380 pub fn error(&self, msg: impl Display) -> Error { in error()
382 let end_span = self.input.cursor().prev_span(); in error()
388 input: ParseStream, in parse_nested_meta()
389 mut logic: impl FnMut(ParseNestedMeta) -> Result<()>, in parse_nested_meta()
390 ) -> Result<()> { in parse_nested_meta()
392 let path = input.call(parse_meta_path)?; in parse_nested_meta()
393 logic(ParseNestedMeta { path, input })?; in parse_nested_meta()
394 if input.is_empty() { in parse_nested_meta()
397 input.parse::<Token![,]>()?; in parse_nested_meta()
398 if input.is_empty() { in parse_nested_meta()
405 fn parse_meta_path(input: ParseStream) -> Result<Path> { in parse_meta_path()
407 leading_colon: input.parse()?, in parse_meta_path()
410 if input.peek(Ident::peek_any) { in parse_meta_path()
411 let ident = Ident::parse_any(input)?; in parse_meta_path()
413 } else if input.is_empty() { in parse_meta_path()
414 return Err(input.error("expected nested attribute")); in parse_meta_path()
415 } else if input.peek(Lit) { in parse_meta_path()
416 return Err(input.error("unexpected literal in nested attribute, expected ident")); in parse_meta_path()
418 return Err(input.error("unexpected token in nested attribute, expected ident")); in parse_meta_path()
420 while input.peek(Token![::]) { in parse_meta_path()
421 let punct = input.parse()?; in parse_meta_path()
423 let ident = Ident::parse_any(input)?; in parse_meta_path()