Refactor Parsers and Parser States

Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
This commit is contained in:
Will Hawkins
2026-03-10 03:56:18 -04:00
parent 7c7416fa64
commit 3188b52965
12 changed files with 223 additions and 381 deletions
+14 -2
View File
@@ -15,7 +15,13 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
public struct Scope<T>: CustomStringConvertible {
public struct Scope<T>: CustomStringConvertible, Sequence {
public typealias Element = T
public typealias Iterator = Dictionary<Identifier, T>.Values.Iterator
public func makeIterator() -> Iterator {
self.symbols.values.makeIterator()
}
var symbols: [Identifier: T] = Dictionary()
public init() {}
@@ -45,7 +51,7 @@ public struct Scope<T>: CustomStringConvertible {
}
}
public struct Scopes<T>: CustomStringConvertible {
public struct Scopes<T>: CustomStringConvertible, Sequence {
var scopes: [Scope<T>] = Array()
public init() {}
@@ -117,6 +123,12 @@ public struct Scopes<T>: CustomStringConvertible {
return .Error(Error(withMessage: "Cannot find \(identifier) in lexical scope."))
}
public typealias Element = T
public typealias Iterator = Dictionary<Identifier, T>.Values.Iterator
public func makeIterator() -> Iterator {
scopes.last?.makeIterator() ?? Scope<T>().makeIterator()
}
public var count: Int {
scopes.count
}