diff --git a/src/ast.rs b/src/ast.rs index f025cb5..74c9421 100644 --- a/src/ast.rs +++ b/src/ast.rs @@ -193,51 +193,12 @@ pub enum Expr { Op(Op, Vec>), } -impl Default for Expr { - fn default() -> Self { - Self::Op(Op::Tuple, vec![]) - } -} - -impl Expr { - pub fn anno(self, annotation: A) -> Anno, A> { - Anno(self, annotation) - } - - pub fn and_do(self, annotation: A, other: Anno, A>) -> Self { - let Self::Op(Op::Do, mut exprs) = self else { - return Self::Op(Op::Do, vec![self.anno(annotation), other]); - }; - let Anno(Self::Op(Op::Do, mut other), _) = other else { - exprs.push(other); - return Self::Op(Op::Do, exprs); - }; - exprs.append(&mut other); - Self::Op(Op::Do, exprs) - } - - pub fn is_place(&self) -> bool { - matches!( - self, - Self::Id(_) | Self::Op(Op::Index, _) | Self::Op(Op::Dot, _) | Self::Op(Op::Deref, _) - ) - } - - #[allow(clippy::type_complexity)] - pub fn as_slice(&self) -> Option<(Op, &[Anno, A>])> { - match self { - Expr::Op(op, args) => Some((*op, args.as_slice())), - _ => None, - } - } -} - #[derive(Clone, Copy, Debug, PartialEq, Eq)] pub enum Op { // -- true operators Do, // Expr ; Expr As, // Expr as Expr - Macro, // macro Expr => Expr + Macro, // macro { (Pat => Expr)* } Block, // { Expr } Array, // [ Expr,* ] ArRep, // [ Expr ; Expr ] @@ -305,6 +266,45 @@ pub enum Op { OrSet, // Expr |= Expr } +impl Default for Expr { + fn default() -> Self { + Self::Op(Op::Tuple, vec![]) + } +} + +impl Expr { + pub fn anno(self, annotation: A) -> Anno, A> { + Anno(self, annotation) + } + + pub fn and_do(self, annotation: A, other: Anno, A>) -> Self { + let Self::Op(Op::Do, mut exprs) = self else { + return Self::Op(Op::Do, vec![self.anno(annotation), other]); + }; + let Anno(Self::Op(Op::Do, mut other), _) = other else { + exprs.push(other); + return Self::Op(Op::Do, exprs); + }; + exprs.append(&mut other); + Self::Op(Op::Do, exprs) + } + + pub fn is_place(&self) -> bool { + matches!( + self, + Self::Id(_) | Self::Op(Op::Index, _) | Self::Op(Op::Dot, _) | Self::Op(Op::Deref, _) + ) + } + + #[allow(clippy::type_complexity)] + pub fn as_slice(&self) -> Option<(Op, &[Anno, A>])> { + match self { + Expr::Op(op, args) => Some((*op, args.as_slice())), + _ => None, + } + } +} + use crate::{fmt::FmtAdapter, span::Span}; use std::{fmt::Display, format_args as fmt};