Lines Matching refs:parse
17 //! trait to parse these syntax tree data structures from a token stream.
23 //! pointing out the exact token that triggered the failure to parse.
32 //! use syn::parse::{Parse, ParseStream};
50 //! fn parse(input: ParseStream) -> Result<Self> {
53 //! input.parse().map(Item::Struct)
55 //! input.parse().map(Item::Enum)
63 //! fn parse(input: ParseStream) -> Result<Self> {
66 //! struct_token: input.parse()?,
67 //! ident: input.parse()?,
75 //! # fn parse(input: ParseStream) -> Result<Self> {
91 //! # The `syn::parse*` functions
93 //! The [`syn::parse`], [`syn::parse2`], and [`syn::parse_str`] functions serve
98 //! [`syn::parse`]: crate::parse()
139 //! // Can't parse `Punctuated` without knowing whether trailing punctuation
141 //! let path: Punctuated<PathSegment, Token![::]> = syn::parse(tokens)?;
156 //! use syn::parse::Parser;
165 //! let _path = parser.parse(tokens)?;
171 //! let _args = parser.parse(tokens)?;
176 //! let _attrs = parser.parse(tokens)?;
214 fn parse(input: ParseStream) -> Result<Self>;
240 /// - One of [the `syn::parse*` functions][syn-parse]; or
244 /// [syn-parse]: self#the-synparse-functions
297 /// use syn::parse::ParseStream;
321 /// # input.parse()
324 /// # use syn::parse::Parser;
362 /// Triggers an error at the current position of the parse stream.
459 /// parse stream past it.
460 pub fn parse<T: Parse>(&self) -> Result<T> {
461 T::parse(self)
464 /// Calls the given parser function to parse a syntax tree node of type `T`
469 /// The parser below invokes [`Attribute::parse_outer`] to parse a vector of
476 /// use syn::parse::{Parse, ParseStream};
490 /// fn parse(input: ParseStream) -> Result<Self> {
493 /// struct_token: input.parse()?,
494 /// name: input.parse()?,
495 /// semi_token: input.parse()?,
504 /// Looks at the next token in the parse stream to determine whether it
507 /// Does not advance the position of the parse stream.
528 /// use syn::parse::{Parse, ParseStream};
544 /// fn parse(input: ParseStream) -> Result<Self> {
545 /// let trait_token: Token![trait] = input.parse()?;
546 /// let ident: Ident = input.parse()?;
547 /// let mut generics: Generics = input.parse()?;
548 /// let colon_token: Option<Token![:]> = input.parse()?;
553 /// supertraits.push_value(input.parse()?);
557 /// supertraits.push_punct(input.parse()?);
561 /// generics.where_clause = input.parse()?;
581 /// Looks at the second-next token in the parse stream.
588 /// keyword in Rust. We can't use just `peek` and decide to parse a union if
595 /// use syn::parse::{Parse, ParseStream};
606 /// fn parse(input: ParseStream) -> Result<Self> {
608 /// input.parse().map(UnionOrMacro::Union)
610 /// input.parse().map(UnionOrMacro::Macro)
629 /// Looks at the third-next token in the parse stream.
651 /// Parsing continues until the end of this parse stream. The entire content
652 /// of this parse stream must consist of `T` and `P`.
660 /// use syn::parse::{Parse, ParseStream};
675 /// fn parse(input: ParseStream) -> Result<Self> {
678 /// struct_token: input.parse()?,
679 /// ident: input.parse()?,
681 /// fields: content.parse_terminated(Type::parse, Token![,])?,
682 /// semi_token: input.parse()?,
705 /// use syn::parse::{Parse, ParseStream};
715 /// fn parse(input: ParseStream) -> Result<Self> {
716 /// Ok(Self(input.parse()?, input.parse()?))
725 /// fn parse(input: ParseStream) -> Result<Self> {
761 /// use syn::parse::{Parse, ParseStream};
772 /// fn parse(input: ParseStream) -> Result<Self> {
775 /// mod_token: input.parse()?,
776 /// name: input.parse()?,
781 /// items.push(content.parse()?);
800 /// use syn::parse::{Parse, ParseStream};
820 /// fn parse(input: ParseStream) -> Result<Self> {
823 /// input.parse().map(GenericParam::Type)
825 /// input.parse().map(GenericParam::Lifetime)
827 /// input.parse().map(GenericParam::Const)
838 /// Forks a parse stream so that parsing tokens out of either the original
843 /// Forking a parse stream is a cheap fixed amount of work and does not
850 /// # use syn::parse::ParseStream;
854 /// if input.fork().parse::<Expr>().is_ok() {
855 /// return input.parse::<Expr>();
862 /// parse stream. Only use a fork when the amount of work performed against
866 /// unavoidable, use [`parse::discouraged::Speculative`] to advance the
867 /// original stream once the fork's parse is determined to have been
873 /// [`parse::discouraged::Speculative`]: discouraged::Speculative
878 /// The parse implementation shown here parses possibly restricted `pub`
904 /// The parser uses a forked parse stream to check the first token inside of
906 /// work performed against the forked parse stream.
911 /// use syn::parse::{Parse, ParseStream};
925 /// fn parse(input: ParseStream) -> Result<Self> {
926 /// let pub_token: Token![pub] = input.parse()?;
950 /// in_token: Some(content.parse()?),
975 /// Triggers an error at the current position of the parse stream.
981 /// use syn::parse::{Parse, ParseStream};
989 /// fn parse(input: ParseStream) -> Result<Self> {
995 /// expr: input.parse()?,
1007 /// Speculatively parses tokens from this parse stream, advancing the
1019 /// use syn::parse::ParseStream;
1043 /// # input.parse()
1046 /// # use syn::parse::Parser;
1082 /// Returns the `Span` of the next token in the parse stream, or
1083 /// `Span::call_site()` if this parse stream has completely exhausted its
1095 /// parse stream.
1098 /// will affect the state of this parse stream.
1105 /// use syn::parse::{ParseStream, Result};
1136 /// use syn::parse::{Parse, Parser};
1141 /// let _langle: Token![<] = input.parse()?;
1142 /// let ty = recognize_token_stream(syn::Type::parse)(input)?;
1143 /// let _rangle: Token![>] = input.parse()?;
1165 fn parse(input: ParseStream) -> Result<Self> {
1166 input.parse().map(Box::new)
1172 fn parse(input: ParseStream) -> Result<Self> {
1174 Ok(Some(input.parse()?))
1183 fn parse(input: ParseStream) -> Result<Self> {
1190 fn parse(input: ParseStream) -> Result<Self> {
1200 fn parse(input: ParseStream) -> Result<Self> {
1214 fn parse(input: ParseStream) -> Result<Self> {
1224 fn parse(input: ParseStream) -> Result<Self> {
1232 /// Parser that can parse Rust tokens into a particular syntax tree node.
1252 fn parse(self, tokens: proc_macro::TokenStream) -> Result<Self::Output> {
1334 /// use syn::parse::Nothing;
1357 fn parse(_input: ParseStream) -> Result<Self> {