From 3d7fd4c84718e9f014c454e30b5d144d3b95898c Mon Sep 17 00:00:00 2001 From: quephird Date: Sun, 17 Mar 2024 14:02:22 -0700 Subject: [PATCH] LoopType enum only has two cases now since there is no difference between `for` and `while` loops regarding resolving of `break`s and `continue`s. --- slox/Resolver.swift | 7 +++---- slox/ResolverError.swift | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/slox/Resolver.swift b/slox/Resolver.swift index c8c32b5..5a7ec58 100644 --- a/slox/Resolver.swift +++ b/slox/Resolver.swift @@ -22,8 +22,7 @@ struct Resolver { private enum LoopType { case none - case `while` - case `for` + case loop } private var scopeStack: [[String: Bool]] = [] @@ -256,7 +255,7 @@ struct Resolver { mutating private func handleWhile(conditionExpr: Expression, bodyStmt: Statement) throws -> ResolvedStatement { let previousLoopType = currentLoopType - currentLoopType = .while + currentLoopType = .loop defer { currentLoopType = previousLoopType } @@ -272,7 +271,7 @@ struct Resolver { incrementExpr: Expression?, bodyStmt: Statement) throws -> ResolvedStatement { let previousLoopType = currentLoopType - currentLoopType = .for + currentLoopType = .loop defer { currentLoopType = previousLoopType } diff --git a/slox/ResolverError.swift b/slox/ResolverError.swift index d3eca92..63de6da 100644 --- a/slox/ResolverError.swift +++ b/slox/ResolverError.swift @@ -46,7 +46,7 @@ enum ResolverError: CustomStringConvertible, Equatable, LocalizedError { case .cannotBreakOutsideLoop: return "Can only `break` from inside a `while` or `for` loop" case .cannotContinueOutsideLoop: - return "Can only `continue` while inside a loop" + return "Can only `continue` from inside a `while` or `for` loop" } } }