cl-ast: Remove "Continue" struct

This commit is contained in:
John 2024-07-30 19:42:28 -05:00
parent b64cc232f9
commit 0e545077c6
7 changed files with 10 additions and 35 deletions

View File

@ -403,7 +403,7 @@ pub enum ExprKind {
/// A [Return] expression `return` [`Expr`]? /// A [Return] expression `return` [`Expr`]?
Return(Return), Return(Return),
/// A continue expression: `continue` /// A continue expression: `continue`
Continue(Continue), Continue,
} }
/// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+ /// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+
@ -612,7 +612,3 @@ pub struct Break {
pub struct Return { pub struct Return {
pub body: Option<Box<Expr>>, pub body: Option<Box<Expr>>,
} }
/// A continue expression: `continue`
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)]
pub struct Continue;

View File

@ -453,7 +453,7 @@ mod display {
ExprKind::For(v) => v.fmt(f), ExprKind::For(v) => v.fmt(f),
ExprKind::Break(v) => v.fmt(f), ExprKind::Break(v) => v.fmt(f),
ExprKind::Return(v) => v.fmt(f), ExprKind::Return(v) => v.fmt(f),
ExprKind::Continue(_) => "continue".fmt(f), ExprKind::Continue => "continue".fmt(f),
} }
} }
} }
@ -693,12 +693,6 @@ mod display {
} }
} }
} }
impl Display for Continue {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
"continue".fmt(f)
}
}
} }
mod convert { mod convert {
@ -784,7 +778,6 @@ mod convert {
For => ExprKind::For, For => ExprKind::For,
Break => ExprKind::Break, Break => ExprKind::Break,
Return => ExprKind::Return, Return => ExprKind::Return,
Continue => ExprKind::Continue,
} }
impl From for Literal { impl From for Literal {
bool => Literal::Bool, bool => Literal::Bool,

View File

@ -376,10 +376,6 @@ pub trait Fold {
let Return { body } = r; let Return { body } = r;
Return { body: body.map(|e| Box::new(self.fold_expr(*e))) } Return { body: body.map(|e| Box::new(self.fold_expr(*e))) }
} }
fn fold_continue(&mut self, c: Continue) -> Continue {
let Continue = c;
Continue
}
} }
#[inline] #[inline]
@ -553,7 +549,7 @@ pub fn or_fold_expr_kind<F: Fold + ?Sized>(folder: &mut F, kind: ExprKind) -> Ex
ExprKind::For(f) => ExprKind::For(folder.fold_for(f)), ExprKind::For(f) => ExprKind::For(folder.fold_for(f)),
ExprKind::Break(b) => ExprKind::Break(folder.fold_break(b)), ExprKind::Break(b) => ExprKind::Break(folder.fold_break(b)),
ExprKind::Return(r) => ExprKind::Return(folder.fold_return(r)), ExprKind::Return(r) => ExprKind::Return(folder.fold_return(r)),
ExprKind::Continue(c) => ExprKind::Continue(folder.fold_continue(c)), ExprKind::Continue => ExprKind::Continue,
} }
} }
pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind { pub fn or_fold_member_kind<F: Fold + ?Sized>(folder: &mut F, kind: MemberKind) -> MemberKind {

View File

@ -334,9 +334,7 @@ pub trait Visit<'a>: Sized {
self.visit_expr(body) self.visit_expr(body)
} }
} }
fn visit_continue(&mut self, c: &'a Continue) { fn visit_continue(&mut self) {}
let Continue = c;
}
} }
pub fn or_visit_literal<'a, V: Visit<'a>>(visitor: &mut V, l: &'a Literal) { pub fn or_visit_literal<'a, V: Visit<'a>>(visitor: &mut V, l: &'a Literal) {
@ -477,7 +475,7 @@ pub fn or_visit_expr_kind<'a, V: Visit<'a>>(visitor: &mut V, e: &'a ExprKind) {
ExprKind::For(f) => visitor.visit_for(f), ExprKind::For(f) => visitor.visit_for(f),
ExprKind::Break(b) => visitor.visit_break(b), ExprKind::Break(b) => visitor.visit_break(b),
ExprKind::Return(r) => visitor.visit_return(r), ExprKind::Return(r) => visitor.visit_return(r),
ExprKind::Continue(c) => visitor.visit_continue(c), ExprKind::Continue => visitor.visit_continue(),
} }
} }
pub fn or_visit_member_kind<'a, V: Visit<'a>>(visitor: &mut V, kind: &'a MemberKind) { pub fn or_visit_member_kind<'a, V: Visit<'a>>(visitor: &mut V, kind: &'a MemberKind) {

View File

@ -156,7 +156,7 @@ impl Interpret for ExprKind {
ExprKind::For(v) => v.interpret(env), ExprKind::For(v) => v.interpret(env),
ExprKind::Break(v) => v.interpret(env), ExprKind::Break(v) => v.interpret(env),
ExprKind::Return(v) => v.interpret(env), ExprKind::Return(v) => v.interpret(env),
ExprKind::Continue(v) => v.interpret(env), ExprKind::Continue => Err(Error::Continue),
} }
} }
} }
@ -579,11 +579,6 @@ impl Interpret for Else {
} }
} }
} }
impl Interpret for Continue {
fn interpret(&self, _env: &mut Environment) -> IResult<ConValue> {
Err(Error::Continue)
}
}
impl Interpret for Return { impl Interpret for Return {
fn interpret(&self, env: &mut Environment) -> IResult<ConValue> { fn interpret(&self, env: &mut Environment) -> IResult<ConValue> {
let Self { body } = self; let Self { body } = self;

View File

@ -850,7 +850,7 @@ impl<'t> Parser<'t> {
TokenKind::Return => ExprKind::Return(self.parse_return()?), TokenKind::Return => ExprKind::Return(self.parse_return()?),
TokenKind::Continue => { TokenKind::Continue => {
self.consume_peeked(); self.consume_peeked();
Continue.into() ExprKind::Continue
} }
op => { op => {

View File

@ -411,7 +411,9 @@ pub mod yamlify {
ExprKind::For(k) => k.yaml(y), ExprKind::For(k) => k.yaml(y),
ExprKind::Break(k) => k.yaml(y), ExprKind::Break(k) => k.yaml(y),
ExprKind::Return(k) => k.yaml(y), ExprKind::Return(k) => k.yaml(y),
ExprKind::Continue(k) => k.yaml(y), ExprKind::Continue => {
y.key("Continue");
}
} }
} }
} }
@ -579,11 +581,6 @@ pub mod yamlify {
y.key("Return").yaml(body); y.key("Return").yaml(body);
} }
} }
impl Yamlify for Continue {
fn yaml(&self, y: &mut Yamler) {
y.key("Continue");
}
}
impl Yamlify for Literal { impl Yamlify for Literal {
fn yaml(&self, y: &mut Yamler) { fn yaml(&self, y: &mut Yamler) {
y.value(format_args!("\"{self}\"")); y.value(format_args!("\"{self}\""));