cl-parser: Dedicated parsing logic for patterns!
This commit is contained in:
@@ -586,6 +586,7 @@ pub struct MatchArm(pub Pattern, pub Expr);
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
pub enum Pattern {
|
||||
Name(Sym),
|
||||
Path(Path),
|
||||
Literal(Literal),
|
||||
Rest(Option<Box<Pattern>>),
|
||||
Ref(Mutability, Box<Pattern>),
|
||||
|
||||
@@ -468,6 +468,7 @@ impl Display for Pattern {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
match self {
|
||||
Pattern::Name(sym) => sym.fmt(f),
|
||||
Pattern::Path(path) => path.fmt(f),
|
||||
Pattern::Literal(literal) => literal.fmt(f),
|
||||
Pattern::Rest(Some(name)) => write!(f, "..{name}"),
|
||||
Pattern::Rest(None) => "..".fmt(f),
|
||||
|
||||
@@ -338,6 +338,7 @@ impl WeightOf for Pattern {
|
||||
fn weight_of(&self) -> usize {
|
||||
match self {
|
||||
Pattern::Name(s) => size_of_val(s),
|
||||
Pattern::Path(p) => p.weight_of(),
|
||||
Pattern::Literal(literal) => literal.weight_of(),
|
||||
Pattern::Rest(Some(pattern)) => pattern.weight_of(),
|
||||
Pattern::Rest(None) => 0,
|
||||
|
||||
@@ -253,6 +253,7 @@ pub trait Fold {
|
||||
fn fold_pattern(&mut self, p: Pattern) -> Pattern {
|
||||
match p {
|
||||
Pattern::Name(sym) => Pattern::Name(self.fold_sym(sym)),
|
||||
Pattern::Path(path) => Pattern::Path(self.fold_path(path)),
|
||||
Pattern::Literal(literal) => Pattern::Literal(self.fold_literal(literal)),
|
||||
Pattern::Rest(Some(name)) => Pattern::Rest(Some(self.fold_pattern(*name).into())),
|
||||
Pattern::Rest(None) => Pattern::Rest(None),
|
||||
|
||||
@@ -793,6 +793,7 @@ impl Walk for Pattern {
|
||||
fn children<'a, V: Visit<'a>>(&'a self, v: &mut V) {
|
||||
match self {
|
||||
Pattern::Name(sym) => sym.visit_in(v),
|
||||
Pattern::Path(path) => path.visit_in(v),
|
||||
Pattern::Literal(literal) => literal.visit_in(v),
|
||||
Pattern::Rest(pattern) => pattern.visit_in(v),
|
||||
Pattern::Ref(mutability, pattern) => {
|
||||
|
||||
Reference in New Issue
Block a user