Lines Matching +full:path +full:- +full:parse
5 /// A path at which a named item is exported (e.g. `std::collections::HashMap`).
7 pub struct Path {
13 impl<T> From<T> for Path implementation
17 fn from(segment: T) -> Self { in from()
18 let mut path = Path { in from() localVariable
22 path.segments.push_value(segment.into()); in from()
23 path in from()
27 impl Path { impl
28 /// Determines whether this is a path of length 1 equal to the given
33 /// - the path has no leading colon,
34 /// - the number of path segments is 1,
35 /// - the first path segment has no angle bracketed or parenthesized
36 /// path arguments, and
37 /// - the ident of the first path segment is equal to the given one.
45 /// fn get_serde_meta_item(attr: &Attribute) -> Result<Option<&TokenStream>> {
46 /// if attr.path().is_ident("serde") {
56 pub fn is_ident<I>(&self, ident: &I) -> bool in is_ident()
67 /// If this path consists of a single ident, returns the ident.
69 /// A path is considered an ident if:
71 /// - the path has no leading colon,
72 /// - the number of path segments is 1, and
73 /// - the first path segment has no angle bracketed or parenthesized
74 /// path arguments.
75 pub fn get_ident(&self) -> Option<&Ident> { in get_ident()
86 /// An error if this path is not a single ident, as defined in `get_ident`.
89 pub fn require_ident(&self) -> Result<&Ident> { in require_ident()
94 "expected this path to be an identifier", in require_ident()
101 /// A segment of a path together with any path arguments on that segment.
113 fn from(ident: T) -> Self { in from()
122 /// Angle bracketed or parenthesized arguments of a path segment.
130 /// The `(A, B) -> C` in `Fn(A, B) -> C`.
136 /// The `(A, B) -> C` in `Fn(A, B) -> C`.
142 fn default() -> Self { in default()
148 pub fn is_empty(&self) -> bool { in is_empty()
156 pub fn is_none(&self) -> bool { in is_none()
190 /// Angle bracketed arguments of a path segment: the `<K, V>` in `HashMap<K,
237 /// Arguments of a function path segment: the `(A, B) -> C` in `Fn(A,B) ->
250 /// The explicit Self type in a qualified path: the `T` in `<T as
253 /// The actual path, including the trait and the associated item, is stored
281 use crate::parse::{Parse, ParseStream, Result};
284 impl Parse for Path { implementation
285 fn parse(input: ParseStream) -> Result<Self> { in parse() method
291 impl Parse for GenericArgument {
292 fn parse(input: ParseStream) -> Result<Self> { in parse() method
294 return Ok(GenericArgument::Lifetime(input.parse()?)); in parse()
301 let mut argument: Type = input.parse()?; in parse()
304 Type::Path(mut ty) in parse()
306 && ty.path.leading_colon.is_none() in parse()
307 && ty.path.segments.len() == 1 in parse()
308 && match &ty.path.segments[0].arguments { in parse()
313 if let Some(eq_token) = input.parse::<Option<Token![=]>>()? { in parse()
314 let segment = ty.path.segments.pop().unwrap().into_value(); in parse()
333 ty: input.parse()?, in parse()
339 if let Some(colon_token) = input.parse::<Option<Token![:]>>()? { in parse()
340 let segment = ty.path.segments.pop().unwrap().into_value(); in parse()
355 let value: TypeParamBound = input.parse()?; in parse()
360 let punct: Token![+] = input.parse()?; in parse()
368 argument = Type::Path(ty); in parse()
377 pub(crate) fn const_argument(input: ParseStream) -> Result<Expr> { in const_argument()
381 let lit = input.parse()?; in const_argument()
386 let ident: Ident = input.parse()?; in const_argument()
387 return Ok(Expr::Path(ExprPath { in const_argument()
390 path: Path::from(ident), in const_argument()
397 let block: ExprBlock = input.parse()?; in const_argument()
406 content.parse::<Expr>()?; in const_argument()
416 /// Parse `::<…>` with mandatory leading `::`.
418 /// The ordinary [`Parse`] impl for `AngleBracketedGenericArguments`
422 pub fn parse_turbofish(input: ParseStream) -> Result<Self> { in parse_turbofish()
423 let colon2_token: Token![::] = input.parse()?; in parse_turbofish()
427 fn do_parse(colon2_token: Option<Token![::]>, input: ParseStream) -> Result<Self> { in do_parse()
430 lt_token: input.parse()?, in do_parse()
437 let value: GenericArgument = input.parse()?; in do_parse()
442 let punct: Token![,] = input.parse()?; in do_parse()
447 gt_token: input.parse()?, in do_parse()
453 impl Parse for AngleBracketedGenericArguments {
454 fn parse(input: ParseStream) -> Result<Self> { in parse() method
455 let colon2_token: Option<Token![::]> = input.parse()?; in parse()
461 impl Parse for ParenthesizedGenericArguments {
462 fn parse(input: ParseStream) -> Result<Self> { in parse() method
466 inputs: content.parse_terminated(Type::parse, Token![,])?, in parse()
473 impl Parse for PathSegment {
474 fn parse(input: ParseStream) -> Result<Self> { in parse() method
480 fn parse_helper(input: ParseStream, expr_style: bool) -> Result<Self> { in parse_helper()
493 input.parse()? in parse_helper()
501 arguments: PathArguments::AngleBracketed(input.parse()?), in parse_helper()
509 impl Path { implementation
510 /// Parse a `Path` containing no path arguments on any of its segments.
515 /// use syn::{Path, Result, Token};
516 /// use syn::parse::{Parse, ParseStream};
528 /// path: Path,
531 /// impl Parse for SingleUse {
532 /// fn parse(input: ParseStream) -> Result<Self> {
534 /// use_token: input.parse()?,
535 /// path: input.call(Path::parse_mod_style)?,
541 pub fn parse_mod_style(input: ParseStream) -> Result<Self> { in parse_mod_style()
542 Ok(Path { in parse_mod_style()
543 leading_colon: input.parse()?, in parse_mod_style()
560 let punct = input.parse()?; in parse_mod_style()
564 return Err(input.parse::<Ident>().unwrap_err()); in parse_mod_style()
566 return Err(input.error("expected path segment after `::`")); in parse_mod_style()
573 pub(crate) fn parse_helper(input: ParseStream, expr_style: bool) -> Result<Self> { in parse_helper()
574 let mut path = Path { in parse_helper() localVariable
575 leading_colon: input.parse()?, in parse_helper()
583 Path::parse_rest(input, &mut path, expr_style)?; in parse_helper()
584 Ok(path) in parse_helper()
589 path: &mut Self, in parse_rest()
591 ) -> Result<()> { in parse_rest()
593 let punct: Token![::] = input.parse()?; in parse_rest()
594 path.segments.push_punct(punct); in parse_rest()
596 path.segments.push_value(value); in parse_rest()
601 pub(crate) fn is_mod_style(&self) -> bool { in is_mod_style()
608 pub(crate) fn qpath(input: ParseStream, expr_style: bool) -> Result<(Option<QSelf>, Path)> { in qpath() argument
610 let lt_token: Token![<] = input.parse()?; in qpath()
611 let this: Type = input.parse()?; in qpath()
612 let path = if input.peek(Token![as]) { in qpath() localVariable
613 let as_token: Token![as] = input.parse()?; in qpath()
614 let path: Path = input.parse()?; in qpath() localVariable
615 Some((as_token, path)) in qpath()
619 let gt_token: Token![>] = input.parse()?; in qpath()
620 let colon2_token: Token![::] = input.parse()?; in qpath()
623 let path = PathSegment::parse_helper(input, expr_style)?; in qpath() localVariable
624 rest.push_value(path); in qpath()
628 let punct: Token![::] = input.parse()?; in qpath()
631 let (position, as_token, path) = match path { in qpath()
632 Some((as_token, mut path)) => { in qpath()
633 let pos = path.segments.len(); in qpath()
634 path.segments.push_punct(colon2_token); in qpath()
635 path.segments.extend(rest.into_pairs()); in qpath()
636 (pos, Some(as_token), path) in qpath()
639 let path = Path { in qpath() localVariable
643 (0, None, path) in qpath()
653 Ok((Some(qself), path)) in qpath()
655 let path = Path::parse_helper(input, expr_style)?; in qpath() localVariable
656 Ok((None, path)) in qpath()
674 impl ToTokens for Path { implementation
714 Expr::Path(expr) in to_tokens()
717 && expr.path.get_ident().is_some() => in to_tokens()
824 pub(crate) fn print_path(tokens: &mut TokenStream, qself: &Option<QSelf>, path: &Path) { in print_path() argument
828 path.to_tokens(tokens); in print_path()
835 let pos = cmp::min(qself.position, path.segments.len()); in print_path()
836 let mut segments = path.segments.pairs(); in print_path()
839 path.leading_colon.to_tokens(tokens); in print_path()
851 path.leading_colon.to_tokens(tokens); in print_path()
861 fn span(&self) -> Span { in span()