Struct rustc_ap_rustc_parse::parser::Parser [−][src]
pub struct Parser<'a> { pub sess: &'a ParseSess, pub token: Token, pub token_spacing: Spacing, pub prev_token: Token, pub capture_cfg: bool, pub last_type_ascription: Option<(Span, bool)>, // some fields omitted }
Fields
sess: &'a ParseSess
token: Token
The current token.
token_spacing: Spacing
The spacing for the current token
prev_token: Token
The previous token.
capture_cfg: bool
last_type_ascription: Option<(Span, bool)>
Span pointing at the :
for the last type ascription the parser has seen, and whether it
looked like it could have been a mistyped path or literal Option:Some(42)
).
Implementations
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_attribute(
&mut self,
inner_parse_policy: InnerAttrPolicy<'_>
) -> PResult<'a, Attribute>
[src]
pub fn parse_attribute(
&mut self,
inner_parse_policy: InnerAttrPolicy<'_>
) -> PResult<'a, Attribute>
[src]Matches attribute = # ! [ meta_item ]
.
inner_parse_policy
prescribes how to handle inner attributes.
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, AttrItem>
[src]
pub fn parse_attr_item(&mut self, capture_tokens: bool) -> PResult<'a, AttrItem>
[src]Parses an inner part of an attribute (the path and following tokens).
The tokens must be either a delimited token stream, or empty token stream,
or the “legacy” key-value form.
PATH (
TOKEN_STREAM )
PATH [
TOKEN_STREAM ]
PATH {
TOKEN_STREAM }
PATH
PATH =
UNSUFFIXED_LIT
The delimiters or =
are still put into the resulting token stream.
pub fn parse_cfg_attr(
&mut self
) -> PResult<'a, (MetaItem, Vec<(AttrItem, Span)>)>
[src]
pub fn parse_cfg_attr(
&mut self
) -> PResult<'a, (MetaItem, Vec<(AttrItem, Span)>)>
[src]Parses cfg_attr(pred, attr_item_list)
where attr_item_list
is comma-delimited.
pub fn parse_meta_item(&mut self) -> PResult<'a, MetaItem>
[src]
pub fn parse_meta_item(&mut self) -> PResult<'a, MetaItem>
[src]Matches the following grammar (per RFC 1559).
meta_item : PATH ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ; meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn collect_tokens_trailing_token<R: AstLike>(
&mut self,
attrs: AttrWrapper,
force_collect: ForceCollect,
f: impl FnOnce(&mut Self, Vec<Attribute>) -> PResult<'a, (R, TrailingToken)>
) -> PResult<'a, R>
[src]
pub fn collect_tokens_trailing_token<R: AstLike>(
&mut self,
attrs: AttrWrapper,
force_collect: ForceCollect,
f: impl FnOnce(&mut Self, Vec<Attribute>) -> PResult<'a, (R, TrailingToken)>
) -> PResult<'a, R>
[src]Records all tokens consumed by the provided callback,
including the current token. These tokens are collected
into a LazyTokenStream
, and returned along with the result
of the callback.
Note: If your callback consumes an opening delimiter
(including the case where you call collect_tokens
when the current token is an opening delimeter),
you must also consume the corresponding closing delimiter.
That is, you can consume
something ([{ }])
or ([{}])
, but not ([{}]
This restriction shouldn’t be an issue in practice, since this function is used to record the tokens for a parsed AST item, which always has matching delimiters.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn struct_span_err<S: Into<MultiSpan>>(
&self,
sp: S,
m: &str
) -> DiagnosticBuilder<'a>
[src]
&self,
sp: S,
m: &str
) -> DiagnosticBuilder<'a>
pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> !
[src]
pub fn maybe_suggest_struct_literal(
&mut self,
lo: Span,
s: BlockCheckMode
) -> Option<PResult<'a, P<Block>>>
[src]
&mut self,
lo: Span,
s: BlockCheckMode
) -> Option<PResult<'a, P<Block>>>
pub fn maybe_annotate_with_ascription(
&mut self,
err: &mut DiagnosticBuilder<'_>,
maybe_expected_semicolon: bool
)
[src]
&mut self,
err: &mut DiagnosticBuilder<'_>,
maybe_expected_semicolon: bool
)
pub fn handle_ambiguous_unbraced_const_arg(
&mut self,
args: &mut Vec<AngleBracketedArg>
) -> PResult<'a, bool>
[src]
pub fn handle_ambiguous_unbraced_const_arg(
&mut self,
args: &mut Vec<AngleBracketedArg>
) -> PResult<'a, bool>
[src]Handle encountering a symbol in a generic argument list that is not a ,
or >
. In this
case, we emit an error and try to suggest enclosing a const argument in braces if it looks
like the user has forgotten them.
pub fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, P<Expr>>
[src]
pub fn handle_unambiguous_unbraced_const_arg(&mut self) -> PResult<'a, P<Expr>>
[src]Attempt to parse a generic const argument that has not been enclosed in braces. There are a limited number of expressions that are permitted without being encoded in braces:
- Literals.
- Single-segment paths (i.e. standalone generic const parameters). All other expressions that can be parsed will emit an error suggesting the expression be wrapped in braces.
pub fn recover_const_arg(
&mut self,
start: Span,
err: DiagnosticBuilder<'a>
) -> PResult<'a, GenericArg>
[src]
pub fn recover_const_arg(
&mut self,
start: Span,
err: DiagnosticBuilder<'a>
) -> PResult<'a, GenericArg>
[src]Try to recover from possible generic const argument without {
and }
.
When encountering code like foo::< bar + 3 >
or foo::< bar - baz >
we suggest
foo::<{ bar + 3 }>
and foo::<{ bar - baz }>
, respectively. We only provide a suggestion
if we think that that the resulting expression would be well formed.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>
[src]
pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>
[src]Parses an expression.
pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>>
[src]
pub fn parse_expr_force_collect(&mut self) -> PResult<'a, P<Expr>>
[src]Parses an expression, forcing tokens to be collected
pub fn parse_anon_const_expr(&mut self) -> PResult<'a, AnonConst>
[src]
pub fn parse_str_lit(&mut self) -> Result<StrLit, Option<Lit>>
[src]
pub fn parse_str_lit(&mut self) -> Result<StrLit, Option<Lit>>
[src]Returns a string literal if the next token is a string literal.
In case of error returns Some(lit)
if the next token is a literal with a wrong kind,
and returns None
if the next token is not literal at all.
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>>
[src]
pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>>
[src]Matches '-' lit | lit
(cf. ast_validation::AstValidator::check_expr_within_pat
).
Keep this in sync with Token::can_begin_literal_maybe_minus
.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate>
[src]
pub fn parse_crate_mod(&mut self) -> PResult<'a, Crate>
[src]Parses a source module as a crate. This is the main entry point for the parser.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_item(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<P<Item>>>
[src]
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<P<Item>>>
pub fn parse_impl_item(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<AssocItem>>>>
[src]
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<AssocItem>>>>
pub fn parse_trait_item(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<AssocItem>>>>
[src]
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<AssocItem>>>>
pub fn parse_foreign_item(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<ForeignItem>>>>
[src]
pub fn parse_foreign_item(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Option<P<ForeignItem>>>>
[src]Parses a foreign item (one in an extern { ... }
block).
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool
[src]
pub fn nonterminal_may_begin_with(kind: NonterminalKind, token: &Token) -> bool
[src]Checks whether a non-terminal may begin with a particular token.
Returning false
is a stability guarantee that such a matcher will never begin with that
token. Be conservative (return true) if not sure.
pub fn parse_nonterminal(
&mut self,
kind: NonterminalKind
) -> PResult<'a, Nonterminal>
[src]
pub fn parse_nonterminal(
&mut self,
kind: NonterminalKind
) -> PResult<'a, Nonterminal>
[src]Parse a non-terminal (e.g. MBE :pat
or :ident
).
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_pat_no_top_alt(
&mut self,
expected: Option<&'static str>
) -> PResult<'a, P<Pat>>
[src]
pub fn parse_pat_no_top_alt(
&mut self,
expected: Option<&'static str>
) -> PResult<'a, P<Pat>>
[src]Parses a pattern.
Corresponds to pat<no_top_alt>
in RFC 2535 and does not admit or-patterns
at the top level. Used when parsing the parameters of lambda expressions,
functions, function pointers, and pat
macro fragments.
pub fn parse_pat_allow_top_alt(
&mut self,
expected: Option<&'static str>,
rc: RecoverComma
) -> PResult<'a, P<Pat>>
[src]
pub fn parse_pat_allow_top_alt(
&mut self,
expected: Option<&'static str>,
rc: RecoverComma
) -> PResult<'a, P<Pat>>
[src]Parses a pattern.
Corresponds to top_pat
in RFC 2535 and allows or-pattern at the top level.
Used for parsing patterns in all cases when pat<no_top_alt>
is not used.
Note that after the FCP in https://github.com/rust-lang/rust/issues/81415, a leading vert is allowed in nested or-patterns, too. This allows us to simplify the grammar somewhat.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn parse_stmt(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Stmt>>
[src]
pub fn parse_stmt(
&mut self,
force_collect: ForceCollect
) -> PResult<'a, Option<Stmt>>
[src]Parses a statement. This stops just before trailing semicolons on everything but items.
e.g., a StmtKind::Semi
parses to a StmtKind::Expr
, leaving the trailing ;
unconsumed.
pub fn parse_full_stmt(
&mut self,
recover: AttemptLocalParseRecovery
) -> PResult<'a, Option<Stmt>>
[src]
pub fn parse_full_stmt(
&mut self,
recover: AttemptLocalParseRecovery
) -> PResult<'a, Option<Stmt>>
[src]Parses a statement, including the trailing semicolon.
impl<'a> Parser<'a>
[src]
impl<'a> Parser<'a>
[src]pub fn new(
sess: &'a ParseSess,
tokens: TokenStream,
desugar_doc_comments: bool,
subparser_name: Option<&'static str>
) -> Self
[src]
sess: &'a ParseSess,
tokens: TokenStream,
desugar_doc_comments: bool,
subparser_name: Option<&'static str>
) -> Self
pub fn unexpected<T>(&mut self) -> PResult<'a, T>
[src]
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, bool>
[src]
pub fn expect(&mut self, t: &TokenKind) -> PResult<'a, bool>
[src]Expects and consumes the token t
. Signals an error if the next token is not t
.
pub fn expect_one_of(
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind]
) -> PResult<'a, bool>
[src]
pub fn expect_one_of(
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind]
) -> PResult<'a, bool>
[src]Expect next token to be edible or inedible token. If edible, then consume it; if inedible, then return without consuming anything. Signal a fatal error if next token is unexpected.
pub fn parse_ident(&mut self) -> PResult<'a, Ident>
[src]
pub fn eat(&mut self, tok: &TokenKind) -> bool
[src]
pub fn eat(&mut self, tok: &TokenKind) -> bool
[src]Consumes a token ‘tok’ if it exists. Returns whether the given token was present.
pub fn eat_keyword(&mut self, kw: Symbol) -> bool
[src]
pub fn eat_keyword(&mut self, kw: Symbol) -> bool
[src]If the next token is the given keyword, eats it and returns true
.
Otherwise, returns false
. An expectation is also added for diagnostics purposes.
pub fn look_ahead<R>(&self, dist: usize, looker: impl FnOnce(&Token) -> R) -> R
[src]
pub fn look_ahead<R>(&self, dist: usize, looker: impl FnOnce(&Token) -> R) -> R
[src]Look-ahead dist
tokens of self.token
and get access to that token there.
When dist == 0
then the current token is looked at.
pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec<TokenTree>>
[src]
pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec<TokenTree>>
[src]Parses a stream of tokens into a list of TokenTree
s, up to EOF.
pub fn parse_tokens(&mut self) -> TokenStream
[src]
pub fn parse_visibility(
&mut self,
fbt: FollowedByType
) -> PResult<'a, Visibility>
[src]
pub fn parse_visibility(
&mut self,
fbt: FollowedByType
) -> PResult<'a, Visibility>
[src]Parses pub
, pub(crate)
and pub(in path)
plus shortcuts crate
for pub(crate)
,
pub(self)
for pub(in self)
and pub(super)
for pub(in super)
.
If the following element can’t be a tuple (i.e., it’s a function definition), then
it’s not a tuple struct field), and the contents within the parentheses isn’t valid,
so emit a proper diagnostic.
pub fn collect_tokens_no_attrs<R: AstLike>(
&mut self,
f: impl FnOnce(&mut Self) -> PResult<'a, R>
) -> PResult<'a, R>
[src]
&mut self,
f: impl FnOnce(&mut Self) -> PResult<'a, R>
) -> PResult<'a, R>
pub fn clear_expected_tokens(&mut self)
[src]
Trait Implementations
Auto Trait Implementations
impl<'a> !RefUnwindSafe for Parser<'a>
impl<'a> !Send for Parser<'a>
impl<'a> !Sync for Parser<'a>
impl<'a> Unpin for Parser<'a>
impl<'a> !UnwindSafe for Parser<'a>
Blanket Implementations
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]pub fn borrow_mut(&mut self) -> &mut T
[src]
pub fn borrow_mut(&mut self) -> &mut T
[src]Mutably borrows from an owned value. Read more
impl<T> Instrument for T
[src]
impl<T> Instrument for T
[src]fn instrument(self, span: Span) -> Instrumented<Self>
[src]
fn instrument(self, span: Span) -> Instrumented<Self>
[src]Instruments this type with the provided Span
, returning an
Instrumented
wrapper. Read more
fn in_current_span(self) -> Instrumented<Self>
[src]
fn in_current_span(self) -> Instrumented<Self>
[src]impl<T> MaybeResult<T> for T
[src]
impl<T> MaybeResult<T> for T
[src]impl<T> Same<T> for T
impl<T> Same<T> for T
type Output = T
type Output = T
Should always be Self
impl<T> ToOwned for T where
T: Clone,
[src]
impl<T> ToOwned for T where
T: Clone,
[src]type Owned = T
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn to_owned(&self) -> T
[src]Creates owned data from borrowed data, usually by cloning. Read more
pub fn clone_into(&self, target: &mut T)
[src]
pub fn clone_into(&self, target: &mut T)
[src]🔬 This is a nightly-only experimental API. (toowned_clone_into
)
recently added
Uses borrowed data to replace owned data, usually by cloning. Read more
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
pub fn vzip(self) -> V
impl<'a, T> Captures<'a> for T where
T: ?Sized,
[src]
T: ?Sized,