use ast::{ForeignItem, ForeignItemKind, FunctionRetTy};
use ast::GenericParam;
use ast::{Ident, ImplItem, IsAuto, Item, ItemKind};
-use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind, UintTy};
+use ast::{Label, Lifetime, LifetimeDef, Lit, LitKind};
use ast::Local;
use ast::MacStmtStyle;
use ast::{Mac, Mac_, MacDelimiter};
use codemap::{self, CodeMap, Spanned, respan};
use syntax_pos::{self, Span, MultiSpan, BytePos, FileName, DUMMY_SP};
use errors::{self, Applicability, DiagnosticBuilder};
-use parse::{self, classify, token};
-use parse::common::SeqSep;
+use parse::{self, SeqSep, classify, token};
use parse::lexer::TokenAndSpan;
use parse::lexer::comments::{doc_comment_style, strip_doc_comment_decoration};
use parse::{new_sub_parser_from_file, ParseSess, Directory, DirectoryOwnership};
use std::slice;
bitflags! {
- pub struct Restrictions: u8 {
+ struct Restrictions: u8 {
const STMT_EXPR = 1 << 0;
const NO_STRUCT_LITERAL = 1 << 1;
}
}
#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum SemiColonMode {
+enum SemiColonMode {
Break,
Ignore,
}
#[derive(Clone, Copy, Debug, PartialEq)]
-pub enum BlockMode {
+enum BlockMode {
Break,
Ignore,
}
/// the span of the current token:
pub span: Span,
/// the span of the previous token:
- pub meta_var_span: Option<Span>,
+ meta_var_span: Option<Span>,
pub prev_span: Span,
/// the previous token kind
prev_token_kind: PrevTokenKind,
- pub restrictions: Restrictions,
+ restrictions: Restrictions,
/// Used to determine the path to externally loaded source files
- pub directory: Directory<'a>,
+ crate directory: Directory<'a>,
/// Whether to parse sub-modules in other files.
pub recurse_into_file_modules: bool,
/// 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.
pub root_module_name: Option<String>,
- pub expected_tokens: Vec<TokenType>,
+ crate expected_tokens: Vec<TokenType>,
token_cursor: TokenCursor,
- pub desugar_doc_comments: bool,
+ desugar_doc_comments: bool,
/// Whether we should configure out of line modules as we parse.
pub cfg_mods: bool,
}
}
#[derive(PartialEq, Eq, Clone)]
-pub enum TokenType {
+crate enum TokenType {
Token(token::Token),
Keyword(keywords::Keyword),
Operator,
impl TokenType {
fn to_string(&self) -> String {
match *self {
- TokenType::Token(ref t) => format!("`{}`", Parser::token_to_string(t)),
+ TokenType::Token(ref t) => format!("`{}`", pprust::token_to_string(t)),
TokenType::Keyword(kw) => format!("`{}`", kw.name()),
TokenType::Operator => "an operator".to_string(),
TokenType::Lifetime => "lifetime".to_string(),
/// Information about the path to a module.
pub struct ModulePath {
- pub name: String,
- pub path_exists: bool,
+ name: String,
+ path_exists: bool,
pub result: Result<ModulePathSuccess, Error>,
}
warn: bool,
}
-pub struct ModulePathError {
- pub err_msg: String,
- pub help_msg: String,
-}
-
pub enum Error {
FileNotFoundForModule {
mod_name: String,
}
impl Error {
- pub fn span_err<S: Into<MultiSpan>>(self,
+ fn span_err<S: Into<MultiSpan>>(self,
sp: S,
handler: &errors::Handler) -> DiagnosticBuilder {
match self {
}
#[derive(Debug)]
-pub enum LhsExpr {
+enum LhsExpr {
NotYetParsed,
AttributesParsed(ThinVec<Attribute>),
AlreadyParsed(P<Expr>),
next
}
- /// Convert a token to a string using self's reader
- pub fn token_to_string(token: &token::Token) -> String {
- pprust::token_to_string(token)
- }
-
/// Convert the current token to a string using self's reader
pub fn this_token_to_string(&self) -> String {
- Parser::token_to_string(&self.token)
+ pprust::token_to_string(&self.token)
}
- pub fn token_descr(&self) -> Option<&'static str> {
+ fn token_descr(&self) -> Option<&'static str> {
Some(match &self.token {
t if t.is_special_ident() => "reserved identifier",
t if t.is_used_keyword() => "keyword",
})
}
- pub fn this_token_descr(&self) -> String {
+ fn this_token_descr(&self) -> String {
if let Some(prefix) = self.token_descr() {
format!("{} `{}`", prefix, self.this_token_to_string())
} else {
}
}
- pub fn unexpected_last<T>(&self, t: &token::Token) -> PResult<'a, T> {
- let token_str = Parser::token_to_string(t);
+ fn unexpected_last<T>(&self, t: &token::Token) -> PResult<'a, T> {
+ let token_str = pprust::token_to_string(t);
Err(self.span_fatal(self.prev_span, &format!("unexpected token: `{}`", token_str)))
}
- pub fn unexpected<T>(&mut self) -> PResult<'a, T> {
+ crate fn unexpected<T>(&mut self) -> PResult<'a, T> {
match self.expect_one_of(&[], &[]) {
Err(e) => Err(e),
Ok(_) => unreachable!(),
self.bump();
Ok(())
} else {
- let token_str = Parser::token_to_string(t);
+ let token_str = pprust::token_to_string(t);
let this_token_str = self.this_token_to_string();
let mut err = self.fatal(&format!("expected `{}`, found `{}`",
token_str,
/// 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 expect_one_of(&mut self,
+ fn expect_one_of(&mut self,
edible: &[token::Token],
inedible: &[token::Token]) -> PResult<'a, ()>{
fn tokens_to_string(tokens: &[TokenType]) -> String {
err
}
- pub fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
+ fn parse_ident(&mut self) -> PResult<'a, ast::Ident> {
self.parse_ident_common(true)
}
///
/// This method will automatically add `tok` to `expected_tokens` if `tok` is not
/// encountered.
- pub fn check(&mut self, tok: &token::Token) -> bool {
+ fn check(&mut self, tok: &token::Token) -> bool {
let is_present = self.token == *tok;
if !is_present { self.expected_tokens.push(TokenType::Token(tok.clone())); }
is_present
is_present
}
- pub fn check_keyword(&mut self, kw: keywords::Keyword) -> bool {
+ fn check_keyword(&mut self, kw: keywords::Keyword) -> bool {
self.expected_tokens.push(TokenType::Keyword(kw));
self.token.is_keyword(kw)
}
}
}
- pub fn eat_keyword_noexpect(&mut self, kw: keywords::Keyword) -> bool {
+ fn eat_keyword_noexpect(&mut self, kw: keywords::Keyword) -> bool {
if self.token.is_keyword(kw) {
self.bump();
true
/// If the given word is not a keyword, signal an error.
/// If the next token is not the given word, signal an error.
/// Otherwise, eat it.
- pub fn expect_keyword(&mut self, kw: keywords::Keyword) -> PResult<'a, ()> {
+ fn expect_keyword(&mut self, kw: keywords::Keyword) -> PResult<'a, ()> {
if !self.eat_keyword(kw) {
self.unexpected()
} else {
}
}
- pub fn expect_no_suffix(&self, sp: Span, kind: &str, suffix: Option<ast::Name>) {
+ fn expect_no_suffix(&self, sp: Span, kind: &str, suffix: Option<ast::Name>) {
match suffix {
None => {/* everything ok */}
Some(suf) => {
/// Expect and consume a GT. if a >> is seen, replace it
/// with a single > and continue. If a GT is not seen,
/// signal an error.
- pub fn expect_gt(&mut self) -> PResult<'a, ()> {
+ fn expect_gt(&mut self) -> PResult<'a, ()> {
self.expected_tokens.push(TokenType::Token(token::Gt));
match self.token {
token::Gt => {
}
}
- pub fn parse_seq_to_before_gt_or_return<T, F>(&mut self,
- sep: Option<token::Token>,
- mut f: F)
- -> PResult<'a, (Vec<T>, bool)>
- where F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
- {
- let mut v = Vec::new();
- // This loop works by alternating back and forth between parsing types
- // and commas. For example, given a string `A, B,>`, the parser would
- // first parse `A`, then a comma, then `B`, then a comma. After that it
- // would encounter a `>` and stop. This lets the parser handle trailing
- // commas in generic parameters, because it can stop either after
- // parsing a type or after parsing a comma.
- for i in 0.. {
- if self.check(&token::Gt)
- || self.token == token::BinOp(token::Shr)
- || self.token == token::Ge
- || self.token == token::BinOpEq(token::Shr) {
- break;
- }
-
- if i % 2 == 0 {
- match f(self)? {
- Some(result) => v.push(result),
- None => return Ok((v, true))
- }
- } else {
- if let Some(t) = sep.as_ref() {
- self.expect(t)?;
- }
-
- }
- }
- return Ok((v, false));
- }
-
- /// Parse a sequence bracketed by '<' and '>', stopping
- /// before the '>'.
- pub fn parse_seq_to_before_gt<T, F>(&mut self,
- sep: Option<token::Token>,
- mut f: F)
- -> PResult<'a, Vec<T>> where
- F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
- {
- let (result, returned) = self.parse_seq_to_before_gt_or_return(sep,
- |p| Ok(Some(f(p)?)))?;
- assert!(!returned);
- return Ok(result);
- }
-
- pub fn parse_seq_to_gt<T, F>(&mut self,
- sep: Option<token::Token>,
- f: F)
- -> PResult<'a, Vec<T>> where
- F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
- {
- let v = self.parse_seq_to_before_gt(sep, f)?;
- self.expect_gt()?;
- return Ok(v);
- }
-
- pub fn parse_seq_to_gt_or_return<T, F>(&mut self,
- sep: Option<token::Token>,
- f: F)
- -> PResult<'a, (Vec<T>, bool)> where
- F: FnMut(&mut Parser<'a>) -> PResult<'a, Option<T>>,
- {
- let (v, returned) = self.parse_seq_to_before_gt_or_return(sep, f)?;
- if !returned {
- self.expect_gt()?;
- }
- return Ok((v, returned));
- }
-
/// Eat and discard tokens until one of `kets` is encountered. Respects token trees,
/// passes through any errors encountered. Used for error recovery.
- pub fn eat_to_tokens(&mut self, kets: &[&token::Token]) {
+ fn eat_to_tokens(&mut self, kets: &[&token::Token]) {
let handler = self.diagnostic();
if let Err(ref mut err) = self.parse_seq_to_before_tokens(kets,
/// Parse 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_end<T, F>(&mut self,
+ crate fn parse_seq_to_end<T, F>(&mut self,
ket: &token::Token,
sep: SeqSep,
f: F)
/// Parse a sequence, not 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,
+ fn parse_seq_to_before_end<T, F>(&mut self,
ket: &token::Token,
sep: SeqSep,
f: F)
/// Parse a sequence, including the closing delimiter. The function
/// f must consume tokens until reaching the next separator or
/// closing bracket.
- pub fn parse_unspanned_seq<T, F>(&mut self,
+ fn parse_unspanned_seq<T, F>(&mut self,
bra: &token::Token,
ket: &token::Token,
sep: SeqSep,
Ok(result)
}
- // NB: Do not use this function unless you actually plan to place the
- // spanned list in the AST.
- pub fn parse_seq<T, F>(&mut self,
- bra: &token::Token,
- ket: &token::Token,
- sep: SeqSep,
- f: F)
- -> PResult<'a, Spanned<Vec<T>>> where
- F: FnMut(&mut Parser<'a>) -> PResult<'a, T>,
- {
- let lo = self.span;
- self.expect(bra)?;
- let result = self.parse_seq_to_before_end(ket, sep, f)?;
- let hi = self.span;
- self.bump();
- Ok(respan(lo.to(hi), result))
- }
-
/// Advance the parser by one token
pub fn bump(&mut self) {
if self.prev_token_kind == PrevTokenKind::Eof {
/// Advance the parser using provided token as a next one. Use this when
/// consuming a part of a token. For example a single `<` from `<<`.
- pub fn bump_with(&mut self, next: token::Token, span: Span) {
+ fn bump_with(&mut self, next: token::Token, span: Span) {
self.prev_span = self.span.with_hi(span.lo());
// It would be incorrect to record the kind of the current token, but
// fortunately for tokens currently using `bump_with`, the
pub fn fatal(&self, m: &str) -> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(self.span, m)
}
- pub fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
+ fn span_fatal<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_fatal(sp, m)
}
- pub fn span_fatal_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
+ fn span_fatal_err<S: Into<MultiSpan>>(&self, sp: S, err: Error) -> DiagnosticBuilder<'a> {
err.span_err(sp, self.diagnostic())
}
- pub fn span_fatal_help<S: Into<MultiSpan>>(&self,
+ fn span_fatal_help<S: Into<MultiSpan>>(&self,
sp: S,
m: &str,
help: &str) -> DiagnosticBuilder<'a> {
err.help(help);
err
}
- pub fn bug(&self, m: &str) -> ! {
+ fn bug(&self, m: &str) -> ! {
self.sess.span_diagnostic.span_bug(self.span, m)
}
- pub fn warn(&self, m: &str) {
- self.sess.span_diagnostic.span_warn(self.span, m)
- }
- pub fn span_warn<S: Into<MultiSpan>>(&self, sp: S, m: &str) {
- self.sess.span_diagnostic.span_warn(sp, m)
- }
- pub fn span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) {
+ fn span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) {
self.sess.span_diagnostic.span_err(sp, m)
}
- pub fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
+ fn struct_span_err<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> DiagnosticBuilder<'a> {
self.sess.span_diagnostic.struct_span_err(sp, m)
}
- pub fn span_err_help<S: Into<MultiSpan>>(&self, sp: S, m: &str, h: &str) {
- let mut err = self.sess.span_diagnostic.mut_span_err(sp, m);
- err.help(h);
- err.emit();
- }
- pub fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> ! {
+ crate fn span_bug<S: Into<MultiSpan>>(&self, sp: S, m: &str) -> ! {
self.sess.span_diagnostic.span_bug(sp, m)
}
- pub fn abort_if_errors(&self) {
+ crate fn abort_if_errors(&self) {
self.sess.span_diagnostic.abort_if_errors();
}
self.sess.span_diagnostic.cancel(err)
}
- pub fn diagnostic(&self) -> &'a errors::Handler {
+ crate fn diagnostic(&self) -> &'a errors::Handler {
&self.sess.span_diagnostic
}
/// Is the current token one of the keywords that signals a bare function
/// type?
- pub fn token_is_bare_fn_keyword(&mut self) -> bool {
+ fn token_is_bare_fn_keyword(&mut self) -> bool {
self.check_keyword(keywords::Fn) ||
self.check_keyword(keywords::Unsafe) ||
self.check_keyword(keywords::Extern) && self.is_extern_non_path()
}
/// parse a TyKind::BareFn type:
- pub fn parse_ty_bare_fn(&mut self, generic_params: Vec<GenericParam>)
+ fn parse_ty_bare_fn(&mut self, generic_params: Vec<GenericParam>)
-> PResult<'a, TyKind> {
/*
return Ok(TyKind::Rptr(opt_lifetime, MutTy { ty: ty, mutbl: mutbl }));
}
- pub fn parse_ptr(&mut self) -> PResult<'a, MutTy> {
+ fn parse_ptr(&mut self) -> PResult<'a, MutTy> {
let mutbl = if self.eat_keyword(keywords::Mut) {
Mutability::Mutable
} else if self.eat_keyword(keywords::Const) {
/// This version of parse arg doesn't necessarily require
/// identifier names.
- pub fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
+ fn parse_arg_general(&mut self, require_name: bool) -> PResult<'a, Arg> {
maybe_whole!(self, NtArg, |x| x);
let (pat, ty) = if require_name || self.is_named_argument() {
}
/// Parse a single function argument
- pub fn parse_arg(&mut self) -> PResult<'a, Arg> {
+ crate fn parse_arg(&mut self) -> PResult<'a, Arg> {
self.parse_arg_general(true)
}
/// Parse an argument in a lambda header e.g. |arg, arg|
- pub fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
+ fn parse_fn_block_arg(&mut self) -> PResult<'a, Arg> {
let pat = self.parse_pat()?;
let t = if self.eat(&token::Colon) {
self.parse_ty()?
})
}
- pub fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option<P<ast::Expr>>> {
+ fn maybe_parse_fixed_length_of_vec(&mut self) -> PResult<'a, Option<P<ast::Expr>>> {
if self.eat(&token::Semi) {
Ok(Some(self.parse_expr()?))
} else {
}
/// Matches token_lit = LIT_INTEGER | ...
- pub fn parse_lit_token(&mut self) -> PResult<'a, LitKind> {
+ fn parse_lit_token(&mut self) -> PResult<'a, LitKind> {
let out = match self.token {
token::Interpolated(ref nt) => match nt.0 {
token::NtExpr(ref v) | token::NtLiteral(ref v) => match v.node {
}
/// Matches lit = true | false | token_lit
- pub fn parse_lit(&mut self) -> PResult<'a, Lit> {
+ crate fn parse_lit(&mut self) -> PResult<'a, Lit> {
let lo = self.span;
let lit = if self.eat_keyword(keywords::True) {
LitKind::Bool(true)
}
/// matches '-' lit | lit (cf. ast_validation::AstValidator::check_expr_within_pat)
- pub fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> {
+ crate fn parse_literal_maybe_minus(&mut self) -> PResult<'a, P<Expr>> {
maybe_whole_expr!(self);
let minus_lo = self.span;
}
}
- pub fn parse_path_segment_ident(&mut self) -> PResult<'a, ast::Ident> {
+ fn parse_path_segment_ident(&mut self) -> PResult<'a, ast::Ident> {
match self.token {
token::Ident(ident, _) if self.token.is_path_segment_keyword() => {
let span = self.span;
/// `a::b::C::<D>` (with disambiguator)
/// `Fn(Args)` (without disambiguator)
/// `Fn::(Args)` (with disambiguator)
- pub fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
+ crate fn parse_path(&mut self, style: PathStyle) -> PResult<'a, ast::Path> {
self.parse_path_common(style, true)
}
- pub fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool)
+ crate fn parse_path_common(&mut self, style: PathStyle, enable_warning: bool)
-> PResult<'a, ast::Path> {
maybe_whole!(self, NtPath, |path| {
if style == PathStyle::Mod &&
})
}
- pub fn check_lifetime(&mut self) -> bool {
+ crate fn check_lifetime(&mut self) -> bool {
self.expected_tokens.push(TokenType::Lifetime);
self.token.is_lifetime()
}
/// Parse single lifetime 'a or panic.
- pub fn expect_lifetime(&mut self) -> Lifetime {
+ crate fn expect_lifetime(&mut self) -> Lifetime {
if let Some(ident) = self.token.lifetime() {
let span = self.span;
self.bump();
}
}
- pub fn parse_field_name(&mut self) -> PResult<'a, Ident> {
+ fn parse_field_name(&mut self) -> PResult<'a, Ident> {
if let token::Literal(token::Integer(name), None) = self.token {
self.bump();
Ok(Ident::new(name, self.prev_span))
}
/// Parse ident (COLON expr)?
- pub fn parse_field(&mut self) -> PResult<'a, Field> {
+ fn parse_field(&mut self) -> PResult<'a, Field> {
let attrs = self.parse_outer_attributes()?;
let lo = self.span;
})
}
- pub fn mk_expr(&mut self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
+ fn mk_expr(&mut self, span: Span, node: ExprKind, attrs: ThinVec<Attribute>) -> P<Expr> {
P(Expr { node, span, attrs, id: ast::DUMMY_NODE_ID })
}
- pub fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
+ fn mk_unary(&mut self, unop: ast::UnOp, expr: P<Expr>) -> ast::ExprKind {
ExprKind::Unary(unop, expr)
}
- pub fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
+ fn mk_binary(&mut self, binop: ast::BinOp, lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
ExprKind::Binary(binop, lhs, rhs)
}
- pub fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
+ fn mk_call(&mut self, f: P<Expr>, args: Vec<P<Expr>>) -> ast::ExprKind {
ExprKind::Call(f, args)
}
- pub fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
+ fn mk_index(&mut self, expr: P<Expr>, idx: P<Expr>) -> ast::ExprKind {
ExprKind::Index(expr, idx)
}
- pub fn mk_range(&mut self,
+ fn mk_range(&mut self,
start: Option<P<Expr>>,
end: Option<P<Expr>>,
limits: RangeLimits)
}
}
- pub fn mk_assign_op(&mut self, binop: ast::BinOp,
+ fn mk_assign_op(&mut self, binop: ast::BinOp,
lhs: P<Expr>, rhs: P<Expr>) -> ast::ExprKind {
ExprKind::AssignOp(binop, lhs, rhs)
}
- pub fn mk_mac_expr(&mut self, span: Span, m: Mac_, attrs: ThinVec<Attribute>) -> P<Expr> {
+ fn mk_mac_expr(&mut self, span: Span, m: Mac_, attrs: ThinVec<Attribute>) -> P<Expr> {
P(Expr {
id: ast::DUMMY_NODE_ID,
node: ExprKind::Mac(codemap::Spanned {node: m, span: span}),
})
}
- pub fn mk_lit_u32(&mut self, i: u32, attrs: ThinVec<Attribute>) -> P<Expr> {
- let span = &self.span;
- let lv_lit = P(codemap::Spanned {
- node: LitKind::Int(i as u128, ast::LitIntType::Unsigned(UintTy::U32)),
- span: *span
- });
-
- P(Expr {
- id: ast::DUMMY_NODE_ID,
- node: ExprKind::Lit(lv_lit),
- span: *span,
- attrs,
- })
- }
-
fn expect_delimited_token_tree(&mut self) -> PResult<'a, (MacDelimiter, ThinTokenStream)> {
let delim = match self.token {
token::OpenDelim(delim) => delim,
}
/// Parse a block or unsafe block
- pub fn parse_block_expr(&mut self, opt_label: Option<Label>,
+ fn parse_block_expr(&mut self, opt_label: Option<Label>,
lo: Span, blk_mode: BlockCheckMode,
outer_attrs: ThinVec<Attribute>)
-> PResult<'a, P<Expr>> {
}
/// parse a.b or a(13) or a[4] or just a
- pub fn parse_dot_or_call_expr(&mut self,
+ fn parse_dot_or_call_expr(&mut self,
already_parsed_attrs: Option<ThinVec<Attribute>>)
-> PResult<'a, P<Expr>> {
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
self.parse_dot_or_call_expr_with(b, span, attrs)
}
- pub fn parse_dot_or_call_expr_with(&mut self,
+ fn parse_dot_or_call_expr_with(&mut self,
e0: P<Expr>,
lo: Span,
mut attrs: ThinVec<Attribute>)
return Ok(e);
}
- pub fn process_potential_macro_variable(&mut self) {
+ crate fn process_potential_macro_variable(&mut self) {
let (token, span) = match self.token {
token::Dollar if self.span.ctxt() != syntax_pos::hygiene::SyntaxContext::empty() &&
self.look_ahead(1, |t| t.is_ident()) => {
}
/// parse a single token tree from the input.
- pub fn parse_token_tree(&mut self) -> TokenTree {
+ crate fn parse_token_tree(&mut self) -> TokenTree {
match self.token {
token::OpenDelim(..) => {
let frame = mem::replace(&mut self.token_cursor.frame,
}
/// Parse a prefix-unary-operator expr
- pub fn parse_prefix_expr(&mut self,
+ fn parse_prefix_expr(&mut self,
already_parsed_attrs: Option<ThinVec<Attribute>>)
-> PResult<'a, P<Expr>> {
let attrs = self.parse_or_use_outer_attributes(already_parsed_attrs)?;
///
/// This parses an expression accounting for associativity and precedence of the operators in
/// the expression.
- pub fn parse_assoc_expr(&mut self,
+ fn parse_assoc_expr(&mut self,
already_parsed_attrs: Option<ThinVec<Attribute>>)
-> PResult<'a, P<Expr>> {
self.parse_assoc_expr_with(0, already_parsed_attrs.into())
}
/// Parse an associative expression with operators of at least `min_prec` precedence
- pub fn parse_assoc_expr_with(&mut self,
+ fn parse_assoc_expr_with(&mut self,
min_prec: usize,
lhs: LhsExpr)
-> PResult<'a, P<Expr>> {
}
/// Parse an 'if' or 'if let' expression ('if' token already eaten)
- pub fn parse_if_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
+ fn parse_if_expr(&mut self, attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
if self.check_keyword(keywords::Let) {
return self.parse_if_let_expr(attrs);
}
}
/// Parse an 'if let' expression ('if' token already eaten)
- pub fn parse_if_let_expr(&mut self, attrs: ThinVec<Attribute>)
+ fn parse_if_let_expr(&mut self, attrs: ThinVec<Attribute>)
-> PResult<'a, P<Expr>> {
let lo = self.prev_span;
self.expect_keyword(keywords::Let)?;
}
// `move |args| expr`
- pub fn parse_lambda_expr(&mut self,
+ fn parse_lambda_expr(&mut self,
attrs: ThinVec<Attribute>)
-> PResult<'a, P<Expr>>
{
}
// `else` token already eaten
- pub fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> {
+ fn parse_else_expr(&mut self) -> PResult<'a, P<Expr>> {
if self.eat_keyword(keywords::If) {
return self.parse_if_expr(ThinVec::new());
} else {
}
/// Parse a 'for' .. 'in' expression ('for' token already eaten)
- pub fn parse_for_expr(&mut self, opt_label: Option<Label>,
+ fn parse_for_expr(&mut self, opt_label: Option<Label>,
span_lo: Span,
mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
// Parse: `for <src_pat> in <src_expr> <src_loop_block>`
}
/// Parse a 'while' or 'while let' expression ('while' token already eaten)
- pub fn parse_while_expr(&mut self, opt_label: Option<Label>,
+ fn parse_while_expr(&mut self, opt_label: Option<Label>,
span_lo: Span,
mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
if self.token.is_keyword(keywords::Let) {
}
/// Parse a 'while let' expression ('while' token already eaten)
- pub fn parse_while_let_expr(&mut self, opt_label: Option<Label>,
+ fn parse_while_let_expr(&mut self, opt_label: Option<Label>,
span_lo: Span,
mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
self.expect_keyword(keywords::Let)?;
}
// parse `loop {...}`, `loop` token already eaten
- pub fn parse_loop_expr(&mut self, opt_label: Option<Label>,
+ fn parse_loop_expr(&mut self, opt_label: Option<Label>,
span_lo: Span,
mut attrs: ThinVec<Attribute>) -> PResult<'a, P<Expr>> {
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
}
/// Parse a `do catch {...}` expression (`do catch` token already eaten)
- pub fn parse_catch_expr(&mut self, span_lo: Span, mut attrs: ThinVec<Attribute>)
+ fn parse_catch_expr(&mut self, span_lo: Span, mut attrs: ThinVec<Attribute>)
-> PResult<'a, P<Expr>>
{
let (iattrs, body) = self.parse_inner_attrs_and_block()?;
return Ok(self.mk_expr(lo.to(hi), ExprKind::Match(discriminant, arms), attrs));
}
- pub fn parse_arm(&mut self) -> PResult<'a, Arm> {
+ crate fn parse_arm(&mut self) -> PResult<'a, Arm> {
maybe_whole!(self, NtArm, |x| x);
let attrs = self.parse_outer_attributes()?;
/// Evaluate the closure with restrictions in place.
///
/// After the closure is evaluated, restrictions are reset.
- pub fn with_res<F, T>(&mut self, r: Restrictions, f: F) -> T
+ fn with_res<F, T>(&mut self, r: Restrictions, f: F) -> T
where F: FnOnce(&mut Self) -> T
{
let old = self.restrictions;
}
/// Parse an expression, subject to the given restrictions
- pub fn parse_expr_res(&mut self, r: Restrictions,
+ fn parse_expr_res(&mut self, r: Restrictions,
already_parsed_attrs: Option<ThinVec<Attribute>>)
-> PResult<'a, P<Expr>> {
self.with_res(r, |this| this.parse_assoc_expr(already_parsed_attrs))
/// A wrapper around `parse_pat` with some special error handling for the
/// "top-level" patterns in a match arm, `for` loop, `let`, &c. (in contast
/// to subpatterns within such).
- pub fn parse_top_level_pat(&mut self) -> PResult<'a, P<Pat>> {
+ fn parse_top_level_pat(&mut self) -> PResult<'a, P<Pat>> {
let pat = self.parse_pat()?;
if self.token == token::Comma {
// An unexpected comma after a top-level pattern is a clue that the
}
/// Parse a block. No inner attrs are allowed.
- pub fn parse_block(&mut self) -> PResult<'a, P<Block>> {
+ crate fn parse_block(&mut self) -> PResult<'a, P<Block>> {
maybe_whole!(self, NtBlock, |x| x);
let lo = self.span;
}
/// Parse a statement, including the trailing semicolon.
- pub fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> {
+ crate fn parse_full_stmt(&mut self, macro_legacy_warnings: bool) -> PResult<'a, Option<Stmt>> {
// skip looking for a trailing semicolon when we have an interpolated statement
maybe_whole!(self, NtStmt, |x| Some(x));
/// Parses (possibly empty) list of lifetime and type parameters, possibly including
/// trailing comma and erroneous trailing attributes.
- pub fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> {
+ crate fn parse_generic_params(&mut self) -> PResult<'a, Vec<ast::GenericParam>> {
let mut params = Vec::new();
let mut seen_ty_param = false;
loop {
/// matches generics = ( ) | ( < > ) | ( < typaramseq ( , )? > ) | ( < lifetimes ( , )? > )
/// | ( < lifetimes , typaramseq ( , )? > )
/// where typaramseq = ( typaram ) | ( typaram , typaramseq )
- pub fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
+ fn parse_generics(&mut self) -> PResult<'a, ast::Generics> {
maybe_whole!(self, NtGenerics, |x| x);
let span_lo = self.span;
/// ```ignore (only-for-syntax-highlight)
/// where T : Trait<U, V> + 'b, 'a : 'b
/// ```
- pub fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
+ fn parse_where_clause(&mut self) -> PResult<'a, WhereClause> {
maybe_whole!(self, NtWhereClause, |x| x);
let mut where_clause = WhereClause {
}
/// Parse the argument list and result type of a function declaration
- pub fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P<FnDecl>> {
+ fn parse_fn_decl(&mut self, allow_variadic: bool) -> PResult<'a, P<FnDecl>> {
let (args, variadic) = self.parse_fn_args(true, allow_variadic)?;
let ret_ty = self.parse_ret_ty(true)?;
}
/// true if we are looking at `const ID`, false for things like `const fn` etc
- pub fn is_const_item(&mut self) -> bool {
+ fn is_const_item(&mut self) -> bool {
self.token.is_keyword(keywords::Const) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Fn)) &&
!self.look_ahead(1, |t| t.is_keyword(keywords::Unsafe))
/// - `const unsafe fn`
/// - `extern fn`
/// - etc
- pub fn parse_fn_front_matter(&mut self) -> PResult<'a, (Spanned<Constness>, Unsafety, Abi)> {
+ fn parse_fn_front_matter(&mut self) -> PResult<'a, (Spanned<Constness>, Unsafety, Abi)> {
let is_const_fn = self.eat_keyword(keywords::Const);
let const_span = self.prev_span;
let unsafety = self.parse_unsafety();
}
/// Parse an impl item.
- pub fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, ImplItem> {
+ crate fn parse_impl_item(&mut self, at_end: &mut bool) -> PResult<'a, ImplItem> {
maybe_whole!(self, NtImplItem, |x| x);
let attrs = self.parse_outer_attributes()?;
let (mut item, tokens) = self.collect_tokens(|this| {
}
}
- pub fn parse_record_struct_body(&mut self) -> PResult<'a, Vec<StructField>> {
+ fn parse_record_struct_body(&mut self) -> PResult<'a, Vec<StructField>> {
let mut fields = Vec::new();
if self.eat(&token::OpenDelim(token::Brace)) {
while self.token != token::CloseDelim(token::Brace) {
Ok(fields)
}
- pub fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<StructField>> {
+ fn parse_tuple_struct_body(&mut self) -> PResult<'a, Vec<StructField>> {
// This is the case where we find `struct Foo<T>(T) where T: Copy;`
// Unit like structs are handled in parse_item_struct function
let fields = self.parse_unspanned_seq(
}
/// Parse a structure field declaration
- pub fn parse_single_struct_field(&mut self,
+ fn parse_single_struct_field(&mut self,
lo: Span,
vis: Visibility,
attrs: Vec<Attribute> )
}
/// Parse a foreign item.
- pub fn parse_foreign_item(&mut self) -> PResult<'a, Option<ForeignItem>> {
+ crate fn parse_foreign_item(&mut self) -> PResult<'a, Option<ForeignItem>> {
maybe_whole!(self, NtForeignItem, |ni| Some(ni));
let attrs = self.parse_outer_attributes()?;
})
}
- pub fn parse_optional_str(&mut self) -> Option<(Symbol, ast::StrStyle, Option<ast::Name>)> {
+ fn parse_optional_str(&mut self) -> Option<(Symbol, ast::StrStyle, Option<ast::Name>)> {
let ret = match self.token {
token::Literal(token::Str_(s), suf) => (s, ast::StrStyle::Cooked, suf),
token::Literal(token::StrRaw(s, n), suf) => (s, ast::StrStyle::Raw(n), suf),