Skip to content

Commit

Permalink
push TokenTree::parse down
Browse files Browse the repository at this point in the history
  • Loading branch information
matklad committed Sep 22, 2019
1 parent 9fd75f5 commit 9835697
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 16 deletions.
15 changes: 14 additions & 1 deletion src/libsyntax/ext/mbe/macro_rules.rs
Expand Up @@ -8,7 +8,7 @@ use crate::ext::mbe;
use crate::ext::mbe::macro_check;
use crate::ext::mbe::macro_parser::{parse, parse_failure_msg};
use crate::ext::mbe::macro_parser::{Error, Failure, Success};
use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq};
use crate::ext::mbe::macro_parser::{MatchedNonterminal, MatchedSeq, NamedParseResult};
use crate::ext::mbe::transcribe::transcribe;
use crate::feature_gate::Features;
use crate::parse::parser::Parser;
Expand Down Expand Up @@ -1171,3 +1171,16 @@ fn quoted_tt_to_string(tt: &mbe::TokenTree) -> String {
),
}
}

impl TokenTree {
/// Use this token tree as a matcher to parse given tts.
fn parse(cx: &ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream)
-> NamedParseResult {
// `None` is because we're not interpolating
let directory = Directory {
path: Cow::from(cx.current_expansion.module.directory.as_path()),
ownership: cx.current_expansion.directory_ownership,
};
parse(cx.parse_sess(), tts, mtch, Some(directory), true)
}
}
15 changes: 0 additions & 15 deletions src/libsyntax/tokenstream.rs
Expand Up @@ -13,9 +13,6 @@
//! and a borrowed `TokenStream` is sufficient to build an owned `TokenStream` without taking
//! ownership of the original.

use crate::ext::base;
use crate::ext::mbe::{self, macro_parser};
use crate::parse::Directory;
use crate::parse::token::{self, DelimToken, Token, TokenKind};
use crate::print::pprust;

Expand All @@ -26,7 +23,6 @@ use rustc_data_structures::sync::Lrc;
use rustc_serialize::{Decoder, Decodable, Encoder, Encodable};
use smallvec::{SmallVec, smallvec};

use std::borrow::Cow;
use std::{fmt, iter, mem};

#[cfg(test)]
Expand Down Expand Up @@ -63,17 +59,6 @@ where
{}

impl TokenTree {
/// Use this token tree as a matcher to parse given tts.
crate fn parse(cx: &base::ExtCtxt<'_>, mtch: &[mbe::TokenTree], tts: TokenStream)
-> macro_parser::NamedParseResult {
// `None` is because we're not interpolating
let directory = Directory {
path: Cow::from(cx.current_expansion.module.directory.as_path()),
ownership: cx.current_expansion.directory_ownership,
};
macro_parser::parse(cx.parse_sess(), tts, mtch, Some(directory), true)
}

/// Checks if this TokenTree is equal to the other, regardless of span information.
pub fn eq_unspanned(&self, other: &TokenTree) -> bool {
match (self, other) {
Expand Down

0 comments on commit 9835697

Please sign in to comment.