s/MetaVarExpr::Length/MetaVarExpr::Len/
This commit is contained in:
parent
6a19a87097
commit
fa5964fa91
3 changed files with 8 additions and 8 deletions
|
@ -23,7 +23,7 @@ pub(crate) enum MetaVarExpr {
|
||||||
|
|
||||||
/// The length of the repetition at a particular depth, where 0 is the inner-most
|
/// The length of the repetition at a particular depth, where 0 is the inner-most
|
||||||
/// repetition. The `usize` is the depth.
|
/// repetition. The `usize` is the depth.
|
||||||
Length(usize),
|
Len(usize),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl MetaVarExpr {
|
impl MetaVarExpr {
|
||||||
|
@ -48,13 +48,13 @@ impl MetaVarExpr {
|
||||||
MetaVarExpr::Ignore(parse_ident(&mut iter, psess, ident.span)?)
|
MetaVarExpr::Ignore(parse_ident(&mut iter, psess, ident.span)?)
|
||||||
}
|
}
|
||||||
"index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
|
"index" => MetaVarExpr::Index(parse_depth(&mut iter, psess, ident.span)?),
|
||||||
"length" => MetaVarExpr::Length(parse_depth(&mut iter, psess, ident.span)?),
|
"len" => MetaVarExpr::Len(parse_depth(&mut iter, psess, ident.span)?),
|
||||||
_ => {
|
_ => {
|
||||||
let err_msg = "unrecognized meta-variable expression";
|
let err_msg = "unrecognized meta-variable expression";
|
||||||
let mut err = psess.dcx.struct_span_err(ident.span, err_msg);
|
let mut err = psess.dcx.struct_span_err(ident.span, err_msg);
|
||||||
err.span_suggestion(
|
err.span_suggestion(
|
||||||
ident.span,
|
ident.span,
|
||||||
"supported expressions are count, ignore, index and length",
|
"supported expressions are count, ignore, index and len",
|
||||||
"",
|
"",
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
|
@ -68,7 +68,7 @@ impl MetaVarExpr {
|
||||||
pub(crate) fn ident(&self) -> Option<Ident> {
|
pub(crate) fn ident(&self) -> Option<Ident> {
|
||||||
match *self {
|
match *self {
|
||||||
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
|
MetaVarExpr::Count(ident, _) | MetaVarExpr::Ignore(ident) => Some(ident),
|
||||||
MetaVarExpr::Index(..) | MetaVarExpr::Length(..) => None,
|
MetaVarExpr::Index(..) | MetaVarExpr::Len(..) => None,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -111,7 +111,7 @@ fn parse_count<'psess>(
|
||||||
Ok(MetaVarExpr::Count(ident, depth))
|
Ok(MetaVarExpr::Count(ident, depth))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Parses the depth used by index(depth) and length(depth).
|
/// Parses the depth used by index(depth) and len(depth).
|
||||||
fn parse_depth<'psess>(
|
fn parse_depth<'psess>(
|
||||||
iter: &mut RefTokenTreeCursor<'_>,
|
iter: &mut RefTokenTreeCursor<'_>,
|
||||||
psess: &'psess ParseSess,
|
psess: &'psess ParseSess,
|
||||||
|
|
|
@ -357,7 +357,7 @@ fn parse_sep_and_kleene_op<'a>(
|
||||||
|
|
||||||
// `$$` or a meta-variable is the lhs of a macro but shouldn't.
|
// `$$` or a meta-variable is the lhs of a macro but shouldn't.
|
||||||
//
|
//
|
||||||
// For example, `macro_rules! foo { ( ${length()} ) => {} }`
|
// For example, `macro_rules! foo { ( ${len()} ) => {} }`
|
||||||
fn span_dollar_dollar_or_metavar_in_the_lhs_err(sess: &Session, token: &Token) {
|
fn span_dollar_dollar_or_metavar_in_the_lhs_err(sess: &Session, token: &Token) {
|
||||||
sess.dcx()
|
sess.dcx()
|
||||||
.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
|
.span_err(token.span, format!("unexpected token: {}", pprust::token_to_string(token)));
|
||||||
|
|
|
@ -675,14 +675,14 @@ fn transcribe_metavar_expr<'a>(
|
||||||
}
|
}
|
||||||
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "index")),
|
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "index")),
|
||||||
},
|
},
|
||||||
MetaVarExpr::Length(depth) => match repeats.iter().nth_back(depth) {
|
MetaVarExpr::Len(depth) => match repeats.iter().nth_back(depth) {
|
||||||
Some((_, length)) => {
|
Some((_, length)) => {
|
||||||
result.push(TokenTree::token_alone(
|
result.push(TokenTree::token_alone(
|
||||||
TokenKind::lit(token::Integer, sym::integer(*length), None),
|
TokenKind::lit(token::Integer, sym::integer(*length), None),
|
||||||
visited_span(),
|
visited_span(),
|
||||||
));
|
));
|
||||||
}
|
}
|
||||||
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "length")),
|
None => return Err(out_of_bounds_err(cx, repeats.len(), sp.entire(), "len")),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue