[][src]Struct rustc_ap_rustc_parse::parser::Parser

pub struct Parser<'a> {
    pub sess: &'a ParseSess,
    pub token: Token,
    pub prev_span: Span,
    pub recurse_into_file_modules: bool,
    pub root_module_name: Option<String>,
    pub cfg_mods: bool,
    pub last_type_ascription: Option<(Span, bool)>,
    // some fields omitted


sess: &'a ParseSesstoken: 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

The 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.

last_type_ascription: Option<(Span, bool)>


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_attr_item(&mut self) -> 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)>)>

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]

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]

pub fn parse_expr(&mut self) -> PResult<'a, P<Expr>>[src]

Parses an expression.

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]

Matches '-' lit | lit (cf. ast_validation::AstValidator::check_expr_within_pat).

impl<'a> Parser<'a>[src]

pub fn parse_item(&mut self) -> PResult<'a, Option<P<Item>>>[src]

pub fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, AssocItem>[src]

pub fn parse_trait_item(&mut self, at_end: &mut bool) -> PResult<'a, AssocItem>[src]

pub fn parse_foreign_item(
    &mut self,
    extern_sp: Span
) -> PResult<'a, ForeignItem>

Parses a foreign item.

impl<'a> Parser<'a>[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 submod_path_from_attr(
    attrs: &[Attribute],
    dir_path: &Path
) -> Option<PathBuf>

pub fn default_submod_path(
    id: Ident,
    relative: Option<Ident>,
    dir_path: &Path,
    source_map: &SourceMap
) -> ModulePath

Returns a path to a module.

impl<'a> Parser<'a>[src]

pub fn parse_pat(
    &mut self,
    expected: Option<&'static str>
) -> PResult<'a, P<Pat>>

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.

impl<'a> Parser<'a>[src]

pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, Path>[src]

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)

impl<'a> Parser<'a>[src]

pub fn parse_ty(&mut self) -> PResult<'a, P<Ty>>[src]

Parses a type.

pub fn check_lifetime(&mut self) -> bool[src]

pub fn expect_lifetime(&mut self) -> Lifetime[src]

Parses a single lifetime 'a or panics.

impl<'a> Parser<'a>[src]

pub fn struct_span_err<S: Into<MultiSpan>>(
    sp: S,
    m: &str
) -> DiagnosticBuilder<'a>

pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> ![src]

pub fn maybe_annotate_with_ascription(
    &mut self,
    err: &mut DiagnosticBuilder,
    maybe_expected_semicolon: bool

impl<'a> Parser<'a>[src]

pub fn parse_stmt(&mut self) -> 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_block(&mut self) -> PResult<'a, P<Block>>[src]

Parses a block. No inner attributes are allowed.

pub fn parse_full_stmt(
    &mut self,
    macro_legacy_warnings: bool
) -> PResult<'a, Option<Stmt>>

Parses a statement, including the trailing semicolon.

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

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>

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. An expectation is also added for diagnostics purposes.

pub fn bump(&mut self)[src]

Advance the parser by one token.

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 process_potential_macro_variable(&mut self)[src]

pub fn parse_token_tree(&mut self) -> TokenTree[src]

Parses a single token tree from the input.

pub fn parse_all_token_trees(&mut self) -> PResult<'a, Vec<TokenTree>>[src]

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

pub fn parse_tokens(&mut self) -> TokenStream[src]

pub fn parse_visibility(
    &mut self,
    fbt: FollowedByType
) -> 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.

Trait Implementations

impl<'a> Clone for Parser<'a>[src]

impl<'a> Drop for Parser<'a>[src]

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> Any for T where
    T: 'static + ?Sized

impl<T> Borrow<T> for T where
    T: ?Sized

impl<T> BorrowMut<T> for T where
    T: ?Sized

impl<'a, T> Captures<'a> for T where
    T: ?Sized

impl<T> Erased for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 

impl<E> SpecializationError for E[src]

impl<T> ToOwned for T where
    T: Clone

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.