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 ParseSesstoken: Token

The current token.

token_spacing: Spacing

The spacing for the current token

prev_token: Token

The previous token.

capture_cfg: boollast_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

Matches attribute = # ! [ meta_item ]. inner_parse_policy prescribes how to handle inner attributes.

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.

Parses cfg_attr(pred, attr_item_list) where attr_item_list is comma-delimited.

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)? ;

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.

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.

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.

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.

Parses an expression.

Parses an expression, forcing tokens to be collected

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.

Matches '-' lit | lit (cf. ast_validation::AstValidator::check_expr_within_pat). Keep this in sync with Token::can_begin_literal_maybe_minus.

Parses a source module as a crate. This is the main entry point for the parser.

Parses the contents of a module (inner attributes followed by module items).

Parses a foreign item (one in an extern { ... } block).

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.

Parse a non-terminal (e.g. MBE :pat or :ident).

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.

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.

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.

Parses a statement, including the trailing semicolon.

Parses a type.

Expects and consumes the token t. Signals an error if the next token is not t.

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.

Consumes a token ‘tok’ if it exists. Returns whether the given token was present.

If the next token is the given keyword, eats it and returns true. Otherwise, returns false. An expectation is also added for diagnostics purposes.

Advance the parser by one token.

Look-ahead dist tokens of self.token and get access to that token there. When dist == 0 then the current token is looked at.

Parses a stream of tokens into a list of TokenTrees, up to EOF.

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.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Executes the destructor for this type. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Performs the conversion.

Should always be Self

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.