Skip to content

Commit affde2e

Browse files
committed
vacuum
1 parent a27bfd2 commit affde2e

12 files changed

Lines changed: 66 additions & 11 deletions

File tree

Sources/Compiler/Compiler.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ extension CompilerWithSource: StmtSyntaxVisitor {
268268
mutating func visit(_ stmt: SavepointStmtSyntax) -> (Statement, Diagnostics)? { nil }
269269

270270
mutating func visit(_ stmt: ReleaseStmtSyntax) -> (Statement, Diagnostics)? { nil }
271+
272+
mutating func visit(_ stmt: VacuumStmtSyntax) -> (Statement, Diagnostics)? { nil }
271273
}
272274

273275
/// Used to validate whether a statement syntax is valid for use in migrations
@@ -295,6 +297,7 @@ struct IsValidForMigrations: StmtSyntaxVisitor {
295297
func visit(_ stmt: RollbackStmtSyntax) -> Bool { false }
296298
func visit(_ stmt: SavepointStmtSyntax) -> Bool { false }
297299
func visit(_ stmt: ReleaseStmtSyntax) -> Bool { false }
300+
func visit(_ stmt: VacuumStmtSyntax) -> Bool { true }
298301
}
299302

300303
/// Used to validate whether a statement syntax is valid for use in queries
@@ -322,6 +325,7 @@ struct IsValidForQueries: StmtSyntaxVisitor {
322325
func visit(_ stmt: RollbackStmtSyntax) -> Bool { false }
323326
func visit(_ stmt: SavepointStmtSyntax) -> Bool { false }
324327
func visit(_ stmt: ReleaseStmtSyntax) -> Bool { false }
328+
func visit(_ stmt: VacuumStmtSyntax) -> Bool { false }
325329
}
326330

327331
// Mainly used in tests, since they are usually a mix of migrations and queries
@@ -349,4 +353,5 @@ struct IsAlwaysValid: StmtSyntaxVisitor {
349353
func visit(_ stmt: RollbackStmtSyntax) -> Bool { true }
350354
func visit(_ stmt: SavepointStmtSyntax) -> Bool { true }
351355
func visit(_ stmt: ReleaseStmtSyntax) -> Bool { true }
356+
func visit(_ stmt: VacuumStmtSyntax) -> Bool { true }
352357
}

Sources/Compiler/Gen/Rewriter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -174,4 +174,6 @@ extension Rewriter: StmtSyntaxVisitor {
174174
func visit(_ stmt: SavepointStmtSyntax) -> [Range<Substring.Index>] { [] }
175175

176176
func visit(_ stmt: ReleaseStmtSyntax) -> [Range<Substring.Index>] { [] }
177+
178+
func visit(_ stmt: VacuumStmtSyntax) -> [Range<Substring.Index>] { [] }
177179
}

Sources/Compiler/Parse/Lexer.swift

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ struct Lexer {
9595
}
9696

9797
switch (current, peek) {
98-
case ("*", "/"): return consumeDouble(of: .starForwardSlash)
9998
case ("<", "<"): return consumeDouble(of: .shiftLeft)
10099
case ("<", "="): return consumeDouble(of: .lte)
101100
case (">", ">"): return consumeDouble(of: .shiftRight)

Sources/Compiler/Parse/Parsers.swift

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,8 @@ enum Parsers {
107107
return release(state: &state)
108108
case (.rollback, _):
109109
return rollback(state: &state)
110+
case (.vacuum, _):
111+
return vacuum(state: &state)
110112
case (.semiColon, _), (.eof, _):
111113
state.skip()
112114
return EmptyStmtSyntax(id: state.nextId(), location: state.current.location)
@@ -176,6 +178,18 @@ enum Parsers {
176178
)
177179
}
178180

181+
static func vacuum(state: inout ParserState) -> VacuumStmtSyntax {
182+
let start = state.take()
183+
let schema = state.current.kind.isSymbol ? identifier(state: &state) : nil
184+
let fileName = state.take(if: .into) ? identifier(state: &state) : nil
185+
return VacuumStmtSyntax(
186+
id: state.nextId(),
187+
location: state.location(from: start),
188+
schema: schema,
189+
fileName: fileName
190+
)
191+
}
192+
179193
static func insertStmt(state: inout ParserState) throws -> InsertStmtSyntax {
180194
let start = state.current
181195
let with = try take(if: .with, state: &state, parse: with)

Sources/Compiler/Parse/Token.swift

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -364,10 +364,6 @@ struct Token {
364364
case gt
365365
case gte
366366

367-
// Comments
368-
case forwardSlashStar
369-
case starForwardSlash
370-
371367
case eof
372368

373369
init(word: Substring) {
@@ -573,8 +569,6 @@ struct Token {
573569
case .lte: "<="
574570
case .gt: ">"
575571
case .gte: ">="
576-
case .forwardSlashStar: "/*"
577-
case .starForwardSlash: "*/"
578572
case .eof: "EOF"
579573
}
580574
}

Sources/Compiler/Sema/CardinalityInferrer.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,8 @@ extension CardinalityInferrer: StmtSyntaxVisitor {
159159
mutating func visit(_ stmt: SavepointStmtSyntax) -> Cardinality { .many }
160160

161161
mutating func visit(_ stmt: ReleaseStmtSyntax) -> Cardinality { .many }
162+
163+
mutating func visit(_ stmt: VacuumStmtSyntax) -> Cardinality { .many }
162164
}
163165

164166
/// We need to look for a `primaryKey = value`. This can get complicated since

Sources/Compiler/Sema/StmtTypeChecker.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -427,6 +427,10 @@ extension StmtTypeChecker: StmtSyntaxVisitor {
427427
mutating func visit(_ stmt: RollbackStmtSyntax) -> ResultColumns {
428428
return .empty
429429
}
430+
431+
mutating func visit(_ stmt: VacuumStmtSyntax) -> ResultColumns {
432+
return .empty
433+
}
430434
}
431435

432436
extension StmtTypeChecker {

Sources/Compiler/Syntax/Statements/StmtSyntax.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,5 @@ protocol StmtSyntaxVisitor {
3636
mutating func visit(_ stmt: RollbackStmtSyntax) -> StmtOutput
3737
mutating func visit(_ stmt: SavepointStmtSyntax) -> StmtOutput
3838
mutating func visit(_ stmt: ReleaseStmtSyntax) -> StmtOutput
39+
mutating func visit(_ stmt: VacuumStmtSyntax) -> StmtOutput
3940
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
//
2+
// VacuumStmtSyntax.swift
3+
// Feather
4+
//
5+
// Created by Wes Wickwire on 6/14/25.
6+
//
7+
8+
struct VacuumStmtSyntax: StmtSyntax {
9+
let id: SyntaxId
10+
let location: SourceLocation
11+
let schema: IdentifierSyntax?
12+
let fileName: IdentifierSyntax?
13+
14+
func accept<V>(visitor: inout V) -> V.StmtOutput where V : StmtSyntaxVisitor {
15+
visitor.visit(self)
16+
}
17+
}

Tests/CompilerTests/LexerTests.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,9 @@ class LexerTests: XCTestCase {
3232
}
3333

3434
func testOperators() throws {
35-
let tokens = tokens(of: "*/ /* << <= >> >= || == != <> -> ->> * . ( ) , + - / % < > & | ^ ~")
35+
let tokens = tokens(of: "<< <= >> >= || == != <> -> ->> * . ( ) , + - / % < > & | ^ ~")
3636

3737
XCTAssertEqual(tokens, [
38-
.starForwardSlash,
39-
.forwardSlashStar,
4038
.shiftLeft,
4139
.lte,
4240
.shiftRight,

0 commit comments

Comments
 (0)