From 0e545077c66315bddfc663a0d4f4431637027ad4 Mon Sep 17 00:00:00 2001 From: John Date: Tue, 30 Jul 2024 19:42:28 -0500 Subject: [PATCH] cl-ast: Remove "Continue" struct --- compiler/cl-ast/src/ast.rs | 6 +----- compiler/cl-ast/src/ast_impl.rs | 9 +-------- compiler/cl-ast/src/ast_visitor/fold.rs | 6 +----- compiler/cl-ast/src/ast_visitor/visit.rs | 6 ++---- compiler/cl-interpret/src/interpret.rs | 7 +------ compiler/cl-parser/src/parser.rs | 2 +- compiler/cl-repl/examples/yaml.rs | 9 +++------ 7 files changed, 10 insertions(+), 35 deletions(-) diff --git a/compiler/cl-ast/src/ast.rs b/compiler/cl-ast/src/ast.rs index 18b31cc..1b1b3a0 100644 --- a/compiler/cl-ast/src/ast.rs +++ b/compiler/cl-ast/src/ast.rs @@ -403,7 +403,7 @@ pub enum ExprKind { /// A [Return] expression `return` [`Expr`]? Return(Return), /// A continue expression: `continue` - Continue(Continue), + Continue, } /// An [Assign]ment expression: [`Expr`] ([`ModifyKind`] [`Expr`])\+ @@ -612,7 +612,3 @@ pub struct Break { pub struct Return { pub body: Option>, } - -/// A continue expression: `continue` -#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Hash)] -pub struct Continue; diff --git a/compiler/cl-ast/src/ast_impl.rs b/compiler/cl-ast/src/ast_impl.rs index 543b98b..34c5964 100644 --- a/compiler/cl-ast/src/ast_impl.rs +++ b/compiler/cl-ast/src/ast_impl.rs @@ -453,7 +453,7 @@ mod display { ExprKind::For(v) => v.fmt(f), ExprKind::Break(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 { @@ -784,7 +778,6 @@ mod convert { For => ExprKind::For, Break => ExprKind::Break, Return => ExprKind::Return, - Continue => ExprKind::Continue, } impl From for Literal { bool => Literal::Bool, diff --git a/compiler/cl-ast/src/ast_visitor/fold.rs b/compiler/cl-ast/src/ast_visitor/fold.rs index 20fc7bd..c784348 100644 --- a/compiler/cl-ast/src/ast_visitor/fold.rs +++ b/compiler/cl-ast/src/ast_visitor/fold.rs @@ -376,10 +376,6 @@ pub trait Fold { let Return { body } = r; Return { body: body.map(|e| Box::new(self.fold_expr(*e))) } } - fn fold_continue(&mut self, c: Continue) -> Continue { - let Continue = c; - Continue - } } #[inline] @@ -553,7 +549,7 @@ pub fn or_fold_expr_kind(folder: &mut F, kind: ExprKind) -> Ex ExprKind::For(f) => ExprKind::For(folder.fold_for(f)), ExprKind::Break(b) => ExprKind::Break(folder.fold_break(b)), 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(folder: &mut F, kind: MemberKind) -> MemberKind { diff --git a/compiler/cl-ast/src/ast_visitor/visit.rs b/compiler/cl-ast/src/ast_visitor/visit.rs index 6c60cec..5926cd2 100644 --- a/compiler/cl-ast/src/ast_visitor/visit.rs +++ b/compiler/cl-ast/src/ast_visitor/visit.rs @@ -334,9 +334,7 @@ pub trait Visit<'a>: Sized { self.visit_expr(body) } } - fn visit_continue(&mut self, c: &'a Continue) { - let Continue = c; - } + fn visit_continue(&mut self) {} } 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::Break(b) => visitor.visit_break(b), 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) { diff --git a/compiler/cl-interpret/src/interpret.rs b/compiler/cl-interpret/src/interpret.rs index 75ca6c3..a007ecb 100644 --- a/compiler/cl-interpret/src/interpret.rs +++ b/compiler/cl-interpret/src/interpret.rs @@ -156,7 +156,7 @@ impl Interpret for ExprKind { ExprKind::For(v) => v.interpret(env), ExprKind::Break(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 { - Err(Error::Continue) - } -} impl Interpret for Return { fn interpret(&self, env: &mut Environment) -> IResult { let Self { body } = self; diff --git a/compiler/cl-parser/src/parser.rs b/compiler/cl-parser/src/parser.rs index 0b1ad27..9f66705 100644 --- a/compiler/cl-parser/src/parser.rs +++ b/compiler/cl-parser/src/parser.rs @@ -850,7 +850,7 @@ impl<'t> Parser<'t> { TokenKind::Return => ExprKind::Return(self.parse_return()?), TokenKind::Continue => { self.consume_peeked(); - Continue.into() + ExprKind::Continue } op => { diff --git a/compiler/cl-repl/examples/yaml.rs b/compiler/cl-repl/examples/yaml.rs index cce7153..9425f2a 100644 --- a/compiler/cl-repl/examples/yaml.rs +++ b/compiler/cl-repl/examples/yaml.rs @@ -411,7 +411,9 @@ pub mod yamlify { ExprKind::For(k) => k.yaml(y), ExprKind::Break(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); } } - impl Yamlify for Continue { - fn yaml(&self, y: &mut Yamler) { - y.key("Continue"); - } - } impl Yamlify for Literal { fn yaml(&self, y: &mut Yamler) { y.value(format_args!("\"{self}\""));