mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 12:29:21 +00:00
minor: cleanup
This commit is contained in:
parent
77bf761203
commit
613609cc5e
3 changed files with 35 additions and 18 deletions
|
@ -6,12 +6,38 @@ use syntax::SmolStr;
|
|||
|
||||
use crate::{tt_iter::TtIter, ParseError};
|
||||
|
||||
pub(crate) fn parse_template(template: &tt::Subtree) -> Result<Vec<Op>, ParseError> {
|
||||
parse_inner(template, Mode::Template).into_iter().collect()
|
||||
}
|
||||
/// Consider
|
||||
///
|
||||
/// ```
|
||||
/// macro_rules! an_macro {
|
||||
/// ($x:expr + $y:expr) => ($y * $x)
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Stuff to the left of `=>` is a [`MetaTemplate`] pattern (which is matched
|
||||
/// with input).
|
||||
///
|
||||
/// Stuff to the right is a [`MetaTemplate`] template which is used to produce
|
||||
/// output.
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct MetaTemplate(pub(crate) Vec<Op>);
|
||||
|
||||
pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result<Vec<Op>, ParseError> {
|
||||
parse_inner(pattern, Mode::Pattern).into_iter().collect()
|
||||
impl MetaTemplate {
|
||||
pub(crate) fn parse_pattern(pattern: &tt::Subtree) -> Result<MetaTemplate, ParseError> {
|
||||
let ops =
|
||||
parse_inner(pattern, Mode::Pattern).into_iter().collect::<Result<_, ParseError>>()?;
|
||||
Ok(MetaTemplate(ops))
|
||||
}
|
||||
|
||||
pub(crate) fn parse_template(template: &tt::Subtree) -> Result<MetaTemplate, ParseError> {
|
||||
let ops =
|
||||
parse_inner(template, Mode::Template).into_iter().collect::<Result<_, ParseError>>()?;
|
||||
Ok(MetaTemplate(ops))
|
||||
}
|
||||
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = &Op> {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
|
@ -36,15 +62,6 @@ pub(crate) enum Separator {
|
|||
Puncts(SmallVec<[tt::Punct; 3]>),
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq)]
|
||||
pub(crate) struct MetaTemplate(pub(crate) Vec<Op>);
|
||||
|
||||
impl MetaTemplate {
|
||||
pub(crate) fn iter(&self) -> impl Iterator<Item = &Op> {
|
||||
self.0.iter()
|
||||
}
|
||||
}
|
||||
|
||||
// Note that when we compare a Separator, we just care about its textual value.
|
||||
impl PartialEq for Separator {
|
||||
fn eq(&self, other: &Separator) -> bool {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue