Make TokenTextRange
private
This commit is contained in:
parent
27bf62b70e
commit
489ae7a800
@ -155,7 +155,7 @@ pub fn expand_hypothetical(
|
||||
mbe::token_tree_to_syntax_node(&hypothetical_expansion.value, fragment_kind).ok()?;
|
||||
|
||||
let token_id = macro_def.map_id_down(token_id);
|
||||
let range = tmap_2.range_by_token(token_id)?.by_kind(token_to_map.kind())?;
|
||||
let range = tmap_2.range_by_token(token_id, token_to_map.kind())?;
|
||||
let token = node.syntax_node().covering_element(range).into_token()?;
|
||||
Some((node.syntax_node(), token))
|
||||
}
|
||||
|
@ -154,7 +154,7 @@ impl HygieneInfo {
|
||||
},
|
||||
};
|
||||
|
||||
let range = token_map.range_by_token(token_id)?.by_kind(SyntaxKind::IDENT)?;
|
||||
let range = token_map.range_by_token(token_id, SyntaxKind::IDENT)?;
|
||||
Some((tt.with_value(range + tt.value), origin))
|
||||
}
|
||||
}
|
||||
|
@ -329,7 +329,7 @@ impl ExpansionInfo {
|
||||
let token_id = self.macro_arg.1.token_by_range(range)?;
|
||||
let token_id = self.macro_def.map_id_down(token_id);
|
||||
|
||||
let range = self.exp_map.range_by_token(token_id)?.by_kind(token.value.kind())?;
|
||||
let range = self.exp_map.range_by_token(token_id, token.value.kind())?;
|
||||
|
||||
let token = self.expanded.value.covering_element(range).into_token()?;
|
||||
|
||||
@ -354,7 +354,7 @@ impl ExpansionInfo {
|
||||
},
|
||||
};
|
||||
|
||||
let range = token_map.range_by_token(token_id)?.by_kind(token.value.kind())?;
|
||||
let range = token_map.range_by_token(token_id, token.value.kind())?;
|
||||
let token =
|
||||
tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
|
||||
Some((tt.with_value(token), origin))
|
||||
|
@ -58,9 +58,8 @@ macro_rules! foobar {
|
||||
let (node, token_map) = token_tree_to_syntax_node(&expanded, FragmentKind::Items).unwrap();
|
||||
let content = node.syntax_node().to_string();
|
||||
|
||||
let get_text = |id, kind| -> String {
|
||||
content[token_map.range_by_token(id).unwrap().by_kind(kind).unwrap()].to_string()
|
||||
};
|
||||
let get_text =
|
||||
|id, kind| -> String { content[token_map.range_by_token(id, kind).unwrap()].to_string() };
|
||||
|
||||
assert_eq!(expanded.token_trees.len(), 4);
|
||||
// {($e:ident) => { fn $e() {} }}
|
||||
|
@ -2,13 +2,13 @@ use parser::{SyntaxKind, T};
|
||||
use syntax::{TextRange, TextSize};
|
||||
|
||||
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
|
||||
pub enum TokenTextRange {
|
||||
enum TokenTextRange {
|
||||
Token(TextRange),
|
||||
Delimiter(TextRange),
|
||||
}
|
||||
|
||||
impl TokenTextRange {
|
||||
pub fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> {
|
||||
fn by_kind(self, kind: SyntaxKind) -> Option<TextRange> {
|
||||
match self {
|
||||
TokenTextRange::Token(it) => Some(it),
|
||||
TokenTextRange::Delimiter(it) => match kind {
|
||||
@ -42,9 +42,9 @@ impl TokenMap {
|
||||
Some(token_id)
|
||||
}
|
||||
|
||||
pub fn range_by_token(&self, token_id: tt::TokenId) -> Option<TokenTextRange> {
|
||||
pub fn range_by_token(&self, token_id: tt::TokenId, kind: SyntaxKind) -> Option<TextRange> {
|
||||
let &(_, range) = self.entries.iter().find(|(tid, _)| *tid == token_id)?;
|
||||
Some(range)
|
||||
range.by_kind(kind)
|
||||
}
|
||||
|
||||
pub(crate) fn shrink_to_fit(&mut self) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user