Skip to content

Commit

Permalink
make mbe::TokenTree private to module
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Sep 22, 2019
1 parent 9835697 commit 81fe857
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
44 changes: 22 additions & 22 deletions src/libsyntax/ext/mbe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,14 @@ use rustc_data_structures::sync::Lrc;
/// Contains the sub-token-trees of a "delimited" token tree, such as the contents of `(`. Note
/// that the delimiter itself might be `NoDelim`.
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
crate struct Delimited {
crate delim: token::DelimToken,
crate tts: Vec<TokenTree>,
struct Delimited {
delim: token::DelimToken,
tts: Vec<TokenTree>,
}

impl Delimited {
/// Returns a `self::TokenTree` with a `Span` corresponding to the opening delimiter.
crate fn open_tt(&self, span: Span) -> TokenTree {
fn open_tt(&self, span: Span) -> TokenTree {
let open_span = if span.is_dummy() {
span
} else {
Expand All @@ -37,7 +37,7 @@ impl Delimited {
}

/// Returns a `self::TokenTree` with a `Span` corresponding to the closing delimiter.
crate fn close_tt(&self, span: Span) -> TokenTree {
fn close_tt(&self, span: Span) -> TokenTree {
let close_span = if span.is_dummy() {
span
} else {
Expand All @@ -48,33 +48,33 @@ impl Delimited {
}

#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug)]
crate struct SequenceRepetition {
struct SequenceRepetition {
/// The sequence of token trees
crate tts: Vec<TokenTree>,
tts: Vec<TokenTree>,
/// The optional separator
crate separator: Option<Token>,
separator: Option<Token>,
/// Whether the sequence can be repeated zero (*), or one or more times (+)
crate kleene: KleeneToken,
kleene: KleeneToken,
/// The number of `Match`s that appear in the sequence (and subsequences)
crate num_captures: usize,
num_captures: usize,
}

#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Debug, Copy)]
crate struct KleeneToken {
crate span: Span,
crate op: KleeneOp,
struct KleeneToken {
span: Span,
op: KleeneOp,
}

impl KleeneToken {
crate fn new(op: KleeneOp, span: Span) -> KleeneToken {
fn new(op: KleeneOp, span: Span) -> KleeneToken {
KleeneToken { span, op }
}
}

/// A Kleene-style [repetition operator](http://en.wikipedia.org/wiki/Kleene_star)
/// for token sequences.
#[derive(Clone, PartialEq, RustcEncodable, RustcDecodable, Hash, Debug, Copy)]
crate enum KleeneOp {
enum KleeneOp {
/// Kleene star (`*`) for zero or more repetitions
ZeroOrMore,
/// Kleene plus (`+`) for one or more repetitions
Expand All @@ -86,7 +86,7 @@ crate enum KleeneOp {
/// Similar to `tokenstream::TokenTree`, except that `$i`, `$i:ident`, and `$(...)`
/// are "first-class" token trees. Useful for parsing macros.
#[derive(Debug, Clone, PartialEq, RustcEncodable, RustcDecodable)]
crate enum TokenTree {
enum TokenTree {
Token(Token),
Delimited(DelimSpan, Lrc<Delimited>),
/// A kleene-style repetition sequence
Expand All @@ -103,7 +103,7 @@ crate enum TokenTree {

impl TokenTree {
/// Return the number of tokens in the tree.
crate fn len(&self) -> usize {
fn len(&self) -> usize {
match *self {
TokenTree::Delimited(_, ref delimed) => match delimed.delim {
token::NoDelim => delimed.tts.len(),
Expand All @@ -115,23 +115,23 @@ impl TokenTree {
}

/// Returns `true` if the given token tree is delimited.
crate fn is_delimited(&self) -> bool {
fn is_delimited(&self) -> bool {
match *self {
TokenTree::Delimited(..) => true,
_ => false,
}
}

/// Returns `true` if the given token tree is a token of the given kind.
crate fn is_token(&self, expected_kind: &TokenKind) -> bool {
fn is_token(&self, expected_kind: &TokenKind) -> bool {
match self {
TokenTree::Token(Token { kind: actual_kind, .. }) => actual_kind == expected_kind,
_ => false,
}
}

/// Gets the `index`-th sub-token-tree. This only makes sense for delimited trees and sequences.
crate fn get_tt(&self, index: usize) -> TokenTree {
fn get_tt(&self, index: usize) -> TokenTree {
match (self, index) {
(&TokenTree::Delimited(_, ref delimed), _) if delimed.delim == token::NoDelim => {
delimed.tts[index].clone()
Expand All @@ -151,7 +151,7 @@ impl TokenTree {
}

/// Retrieves the `TokenTree`'s span.
crate fn span(&self) -> Span {
fn span(&self) -> Span {
match *self {
TokenTree::Token(Token { span, .. })
| TokenTree::MetaVar(span, _)
Expand All @@ -160,7 +160,7 @@ impl TokenTree {
}
}

crate fn token(kind: TokenKind, span: Span) -> TokenTree {
fn token(kind: TokenKind, span: Span) -> TokenTree {
TokenTree::Token(Token::new(kind, span))
}
}
2 changes: 1 addition & 1 deletion src/libsyntax/ext/mbe/macro_check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ struct MacroState<'a> {
/// - `node_id` is used to emit lints
/// - `span` is used when no spans are available
/// - `lhses` and `rhses` should have the same length and represent the macro definition
crate fn check_meta_variables(
pub(super) fn check_meta_variables(
sess: &ParseSess,
node_id: NodeId,
span: Span,
Expand Down
4 changes: 2 additions & 2 deletions src/libsyntax/ext/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ crate enum ParseResult<T> {
crate type NamedParseResult = ParseResult<FxHashMap<Ident, NamedMatch>>;

/// Count how many metavars are named in the given matcher `ms`.
crate fn count_names(ms: &[TokenTree]) -> usize {
pub(super) fn count_names(ms: &[TokenTree]) -> usize {
ms.iter().fold(0, |count, elt| {
count + match *elt {
TokenTree::Sequence(_, ref seq) => seq.num_captures,
Expand Down Expand Up @@ -648,7 +648,7 @@ fn inner_parse_loop<'root, 'tt>(
/// - `directory`: Information about the file locations (needed for the black-box parser)
/// - `recurse_into_modules`: Whether or not to recurse into modules (needed for the black-box
/// parser)
crate fn parse(
pub(super) fn parse(
sess: &ParseSess,
tts: TokenStream,
ms: &[TokenTree],
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/ext/mbe/quoted.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::iter::Peekable;
/// # Returns
///
/// A collection of `self::TokenTree`. There may also be some errors emitted to `sess`.
crate fn parse(
pub(super) fn parse(
input: tokenstream::TokenStream,
expect_matchers: bool,
sess: &ParseSess,
Expand Down

0 comments on commit 81fe857

Please sign in to comment.