spb/metrika Public
Stata-class statistics, GPU-accelerated by Apple Silicon. Native Swift — no Electron, no Python runtime, no compromises.
Swift 92.4%
HTML 3.3%
R 3%
Shell 1.3%
1//2// ParseError.swift3// Metrika4//5// Author: Simon-Pierre Boucher6// Contact: contact@spboucher.ai7// Copyright © 2026 Simon-Pierre Boucher. All rights reserved.8//910/// Parse failure with the 1-based source column and, where possible, a11/// suggested fix (CLAUDE.md §4: errors must cite column position and12/// suggest fixes via Levenshtein distance on known verbs).13public struct ZQParseError: Error, Equatable, Sendable, CustomStringConvertible {14 public var message: String15 public var column: Int16 public var suggestion: String?1718 public init(message: String, column: Int, suggestion: String? = nil) {19 self.message = message20 self.column = column21 self.suggestion = suggestion22 }2324 public var description: String {25 var text = "parse error at column \(column): \(message)"26 if let suggestion {27 text += "\n did you mean '\(suggestion)'?"28 }29 return text30 }31}3233/// Levenshtein edit distance, used to suggest the closest known verb for34/// an unrecognized command.35public func levenshteinDistance(_ a: String, _ b: String) -> Int {36 let a = Array(a), b = Array(b)37 if a.isEmpty { return b.count }38 if b.isEmpty { return a.count }3940 var previous = Array(0...b.count)41 var current = [Int](repeating: 0, count: b.count + 1)4243 for i in 1...a.count {44 current[0] = i45 for j in 1...b.count {46 let substitution = previous[j - 1] + (a[i - 1] == b[j - 1] ? 0 : 1)47 current[j] = min(previous[j] + 1, current[j - 1] + 1, substitution)48 }49 swap(&previous, ¤t)50 }51 return previous[b.count]52}53