[−][src]Struct syntax::parse::parser::Parser
Fields
sess: &'a ParseSess
token: Token
The current normalized token.
"Normalized" means that some interpolated tokens
($i: ident
and $l: lifetime
meta-variables) are replaced
with non-interpolated identifier and lifetime tokens they refer to.
Perhaps the normalized / non-normalized setup can be simplified somehow.
prev_span: Span
Span of the previous non-normalized token.
recurse_into_file_modules: bool
true
to parse sub-modules in other files.
root_module_name: Option<String>
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.
cfg_mods: bool
true
we should configure out of line modules as we parse.
Methods
impl<'a> Parser<'a>
[src]
pub fn new(
sess: &'a ParseSess,
tokens: TokenStream,
directory: Option<Directory<'a>>,
recurse_into_file_modules: bool,
desugar_doc_comments: bool,
subparser_name: Option<&'static str>
) -> Self
[src]
sess: &'a ParseSess,
tokens: TokenStream,
directory: Option<Directory<'a>>,
recurse_into_file_modules: bool,
desugar_doc_comments: bool,
subparser_name: Option<&'static str>
) -> Self
pub fn this_token_to_string(&self) -> String
[src]
Converts the current token to a string using self
's reader.
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]
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind]
) -> PResult<'a, bool>
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]
Consumes a token 'tok' if it exists. Returns whether the given token was present.
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
.
pub fn parse_seq_to_end<T, F>(
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: F
) -> PResult<'a, Vec<T>> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
[src]
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: F
) -> PResult<'a, Vec<T>> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
Parses a sequence, including the closing delimiter. The function
f
must consume tokens until reaching the next separator or
closing bracket.
pub fn parse_seq_to_before_end<T, F>(
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: F
) -> PResult<'a, (Vec<T>, bool)> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
[src]
&mut self,
ket: &TokenKind,
sep: SeqSep,
f: F
) -> PResult<'a, (Vec<T>, bool)> where
F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
Parses a sequence, not including the closing delimiter. The function
f
must consume tokens until reaching the next separator or
closing bracket.
pub fn bump(&mut self)
[src]
Advance the parser by one token
pub fn look_ahead<R, F>(&self, dist: usize, f: F) -> R where
F: FnOnce(&Token) -> R,
[src]
F: FnOnce(&Token) -> R,
pub fn parse_trait_item(&mut self, at_end: &mut bool) -> PResult<'a, TraitItem>
[src]
Parses the items in a trait declaration.
pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>>
[src]
Parses a type.
pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path>
[src]
Parses simple paths.
path = [::] segment+
segment = ident | ident[::]<args> | ident[::](args) [-> type]
Examples
a::b::C<D>
(without disambiguator)
a::b::C::<D>
(with disambiguator)
Fn(Args)
(without disambiguator)
Fn::(Args)
(with disambiguator)
pub fn parse_path_allowing_meta(
&mut self,
style: PathStyle
) -> PResult<'a, Path>
[src]
&mut self,
style: PathStyle
) -> PResult<'a, Path>
Like parse_path
, but also supports parsing Word
meta items into paths for
backwards-compatibility. This is used when parsing derive macro paths in #[derive]
attributes.
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_async_block(
&mut self,
attrs: ThinVec<Attribute>
) -> PResult<'a, P<Expr>>
[src]
&mut self,
attrs: ThinVec<Attribute>
) -> PResult<'a, P<Expr>>
Parses an async move {...}
expression.
pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>
[src]
Parses an expression.
pub fn parse_pat(
&mut self,
expected: Option<&'static str>
) -> PResult<'a, P<Pat>>
[src]
&mut self,
expected: Option<&'static str>
) -> PResult<'a, P<Pat>>
Parses a pattern.
pub fn parse_stmt(&mut self) -> PResult<'a, Option<Stmt>>
[src]
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.
pub fn parse_block(&mut self) -> PResult<'a, P<Block>>
[src]
Parses a block. No inner attributes are allowed.
pub fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, ImplItem>
[src]
Parses an impl item.
pub fn parse_visibility(
&mut self,
can_take_tuple: bool
) -> PResult<'a, Visibility>
[src]
&mut self,
can_take_tuple: bool
) -> PResult<'a, Visibility>
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 submod_path_from_attr(
attrs: &[Attribute],
dir_path: &Path
) -> Option<PathBuf>
[src]
attrs: &[Attribute],
dir_path: &Path
) -> Option<PathBuf>
pub fn default_submod_path(
id: Ident,
relative: Option<Ident>,
dir_path: &Path,
source_map: &SourceMap
) -> ModulePath
[src]
id: Ident,
relative: Option<Ident>,
dir_path: &Path,
source_map: &SourceMap
) -> ModulePath
Returns a path to a module.
pub fn parse_item(&mut self) -> PResult<'a, Option<P<Item>>>
[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.
pub fn parse_optional_str(&mut self) -> Option<(Symbol, StrStyle, Option<Name>)>
[src]
pub fn parse_str(&mut self) -> PResult<'a, (Symbol, StrStyle)>
[src]
impl<'a> Parser<'a>
[src]
pub fn parse_attribute(&mut self, permit_inner: bool) -> PResult<'a, Attribute>
[src]
Matches attribute = # ! [ meta_item ]
If permit_inner is true, then a leading !
indicates an inner
attribute
pub fn parse_meta_item(&mut self) -> PResult<'a, MetaItem>
[src]
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)? ;
impl<'a> Parser<'a>
[src]
pub fn fatal(&self, m: &str) -> DiagnosticBuilder<'a>
[src]
pub fn span_fatal<S: Into<MultiSpan>>(
&self,
sp: S,
m: &str
) -> DiagnosticBuilder<'a>
[src]
&self,
sp: S,
m: &str
) -> DiagnosticBuilder<'a>
pub fn span_fatal_err<S: Into<MultiSpan>>(
&self,
sp: S,
err: Error
) -> DiagnosticBuilder<'a>
[src]
&self,
sp: S,
err: Error
) -> DiagnosticBuilder<'a>
pub fn bug(&self, m: &str) -> !
[src]
pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str)
[src]
pub fn expected_one_of_not_found(
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind]
) -> PResult<'a, bool>
[src]
&mut self,
edible: &[TokenKind],
inedible: &[TokenKind]
) -> PResult<'a, bool>
pub fn unexpected_try_recover(&mut self, t: &TokenKind) -> PResult<'a, bool>
[src]
Create a DiagnosticBuilder
for an unexpected token t
and try to recover if it is a
closing delimiter.
impl<'a> Parser<'a>
[src]
pub fn parse_ast_fragment(
&mut self,
kind: AstFragmentKind,
macro_legacy_warnings: bool
) -> PResult<'a, AstFragment>
[src]
&mut self,
kind: AstFragmentKind,
macro_legacy_warnings: bool
) -> PResult<'a, AstFragment>
pub fn ensure_complete_parse(
&mut self,
macro_path: &Path,
kind_name: &str,
span: Span
)
[src]
&mut self,
macro_path: &Path,
kind_name: &str,
span: Span
)
Trait Implementations
impl<'a> Clone for Parser<'a>
[src]
fn clone(&self) -> Parser<'a>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl<'a> Drop for Parser<'a>
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<E> SpecializationError for E
[src]
default fn not_found<S, T>(
trait_name: &'static str,
method_name: &'static str
) -> E where
T: ?Sized,
[src]
trait_name: &'static str,
method_name: &'static str
) -> E where
T: ?Sized,
impl<T> Send for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Sync for T where
T: ?Sized,
[src]
T: ?Sized,