feat: add extended language validators and fix tokenizer crash bugs
Expand nimcheck with validators and tokenizers for C, C++, C#, Go, Rust, Ruby, CSS, SQL, Markdown, Dockerfile, Makefile, Kotlin, Lua, Swift, TypeScript, and XML. Register all flavors in the validator factory and improve auto-detection scoring for the new languages. Fix infinite tokenizer loops that caused OOM kills: closeBracket now advances position, finishTokenizeStep guards stalled tokenization, and Jinja/JS tokenizers no longer double-advance on brackets. Fix block-balance false positives in Lua (for/do) and Ruby (postfix unless), SQL trailing-comma detection across whitespace, and Makefile tab literals in test fixtures.
This commit is contained in:
+79
@@ -0,0 +1,79 @@
|
||||
import Foundation
|
||||
|
||||
// Unicode comment: 你好世界 🌍🚀
|
||||
|
||||
// Unicode string literals
|
||||
let unicode = "こんにちは世界"
|
||||
print(unicode)
|
||||
|
||||
// Null byte in string
|
||||
let nullStr = "hello\0world"
|
||||
print("Null-str length: \(nullStr.count)")
|
||||
|
||||
// Deeply nested optionals
|
||||
let deep: Int????? = 42
|
||||
if let l1 = deep,
|
||||
let l2 = l1,
|
||||
let l3 = l2,
|
||||
let l4 = l3 {
|
||||
print("Deep optional: \(l4)")
|
||||
}
|
||||
|
||||
// Very long string
|
||||
let longStr = String(repeating: "x", count: 10000)
|
||||
print("Long string length: \(longStr.count)")
|
||||
|
||||
// BOM bytes
|
||||
let bom = Data([0xEF, 0xBB, 0xBF, 0x48, 0x69])
|
||||
print(String(data: bom, encoding: .utf8) ?? "")
|
||||
|
||||
// Deep closure nesting
|
||||
let f1: (Int) -> (Int) -> (Int) -> (Int) -> Int = { x in
|
||||
{ y in
|
||||
{ z in
|
||||
{ w in x + y + z + w }
|
||||
}
|
||||
}
|
||||
}
|
||||
print("Nested closures: \(f1(1)(2)(3)(4))")
|
||||
|
||||
// Deep dictionary nesting
|
||||
let deepDict: [String: Any] = [
|
||||
"a": [
|
||||
"b": [
|
||||
"c": [
|
||||
"d": [
|
||||
"e": "deep"
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
]
|
||||
if let a = deepDict["a"] as? [String: Any],
|
||||
let b = a["b"] as? [String: Any],
|
||||
let c = b["c"] as? [String: Any],
|
||||
let d = c["d"] as? [String: Any],
|
||||
let e = d["e"] as? String {
|
||||
print("Deep dict: \(e)")
|
||||
}
|
||||
|
||||
// Deep error nesting
|
||||
enum AppError: Error {
|
||||
case inner(String)
|
||||
case middle(String, Error)
|
||||
case outer(String, Error)
|
||||
}
|
||||
|
||||
do {
|
||||
do {
|
||||
do {
|
||||
throw AppError.inner("oops")
|
||||
} catch {
|
||||
throw AppError.middle("wrapped", error)
|
||||
}
|
||||
} catch {
|
||||
throw AppError.outer("re-wrapped", error)
|
||||
}
|
||||
} catch {
|
||||
print("Nested error: \(error)")
|
||||
}
|
||||
Vendored
+39
@@ -0,0 +1,39 @@
|
||||
import Foundation
|
||||
|
||||
struct Broken {
|
||||
let x: Int
|
||||
let name: String
|
||||
}
|
||||
|
||||
class BadRepo {
|
||||
private var items: [Int: String] = [:]
|
||||
|
||||
func add(key: Int, item: String) {
|
||||
items[key] = item
|
||||
}
|
||||
|
||||
func show() {
|
||||
print("hello")
|
||||
let x = 5
|
||||
print(x)
|
||||
}
|
||||
}
|
||||
|
||||
let s = "unclosed string
|
||||
print(s)
|
||||
|
||||
let x = 5
|
||||
if x > 0 {
|
||||
print("positive")
|
||||
|
||||
func missingReturn() -> Int {
|
||||
let a = 5
|
||||
}
|
||||
|
||||
let list = [1, 2, 3
|
||||
print(list)
|
||||
|
||||
func badFunction() {
|
||||
let y = 5
|
||||
print(y)
|
||||
}
|
||||
Vendored
+50
@@ -0,0 +1,50 @@
|
||||
import Foundation
|
||||
|
||||
struct Person: Codable {
|
||||
let id: Int
|
||||
let name: String
|
||||
let email: String
|
||||
let active: Bool
|
||||
|
||||
init(id: Int, name: String, email: String, active: Bool = true) {
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.active = active
|
||||
}
|
||||
}
|
||||
|
||||
class Repository<T> {
|
||||
private var items: [Int: T] = [:]
|
||||
|
||||
func add(key: Int, item: T) {
|
||||
items[key] = item
|
||||
}
|
||||
|
||||
func find(key: Int) -> T? {
|
||||
return items[key]
|
||||
}
|
||||
|
||||
func getAll() -> [T] {
|
||||
return Array(items.values)
|
||||
}
|
||||
}
|
||||
|
||||
func add(_ a: Int, _ b: Int) -> Int {
|
||||
return a + b
|
||||
}
|
||||
|
||||
enum Result<T> {
|
||||
case success(T)
|
||||
case failure(Error)
|
||||
}
|
||||
|
||||
let repo = Repository<Person>()
|
||||
repo.add(key: 1, item: Person(id: 1, name: "Alice", email: "alice@example.com"))
|
||||
repo.add(key: 2, item: Person(id: 2, name: "Bob", email: "bob@example.com"))
|
||||
|
||||
for person in repo.getAll() {
|
||||
print("\(person.name) <\(person.email)>")
|
||||
}
|
||||
|
||||
print("3 + 4 = \(add(3, 4))")
|
||||
Reference in New Issue
Block a user