pub struct Parser<'a> {
pub sess: &'a ParseSess,
pub token: Token,
pub span: Span,
pub prev_span: Span,
pub recurse_into_file_modules: bool,
pub root_module_name: Option<String>,
pub cfg_mods: bool,
// some fields omitted
}
the span of the current token:
Whether to parse sub-modules in other files.
Name of the root module this parser originated from. If None
, then the
name is not known. This does not change while the parser is descending
into modules, and sub-parsers have new values for this name.
Whether we should configure out of line modules as we parse.
Convert the current token to a string using self's reader
Expect and consume the token t. Signal 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.
Consume token 'tok' if it exists. Returns true if the given
token was present, false otherwise.
If the next token is the given keyword, eat it and return
true. Otherwise, return false.
Parse a sequence, including the closing delimiter. The function
f must consume tokens until reaching the next separator or
closing bracket.
Parse a sequence, not including the closing delimiter. The function
f must consume tokens until reaching the next separator or
closing bracket.
Advance the parser by one token
Parse the items in a trait declaration
Parses simple paths.
path = [::] segment+
segment = ident | ident[::]<args> | ident[::](args) [-> type]
a::b::C<D>
(without disambiguator)
a::b::C::<D>
(with disambiguator)
Fn(Args)
(without disambiguator)
Fn::(Args)
(with disambiguator)
Like parse_path
, but also supports parsing Word
meta items into paths for back-compat.
This is used when parsing derive macro paths in #[derive]
attributes.
Parse an async move {...}
expression
Parse 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.
Parse a block. No inner attrs are allowed.
Parse 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,
it's not a tuple struct field) and the contents within the parens
isn't valid, emit a proper diagnostic.
Returns either a path to a module, or .
Parses a source module as a crate. This is the main
entry point for the parser.
Matches attribute = # ! [ meta_item ]
If permit_inner is true, then a leading !
indicates an inner
attribute
Per RFC#1559, matches the following grammar:
meta_item : IDENT ( '=' UNSUFFIXED_LIT | '(' meta_item_inner? ')' )? ;
meta_item_inner : (meta_item | UNSUFFIXED_LIT) (',' meta_item_inner)? ;
Performs copy-assignment from source
. Read more
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
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Immutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (get_type_id
)
this method will likely be replaced by an associated static
Mutably borrows from an owned value. Read more
🔬 This is a nightly-only experimental API. (try_from
)
The type returned in the event of a conversion error.
🔬 This is a nightly-only experimental API. (try_from
)
Create an error for a missing method specialization. Defaults to panicking with type, trait & method names. S
is the encoder/decoder state type, T
is the type being encoded/decoded, and the arguments are the names of the trait and method that should've been overridden. Read more