Skip to content

Commit c39c630

Browse files
committed
Match SQLDelights query definition
1 parent b26b365 commit c39c630

3 files changed

Lines changed: 13 additions & 21 deletions

File tree

Sources/Compiler/Parse/Parsers.swift

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ enum Parsers {
7070
return try updateStmt(state: &state)
7171
case (.delete, _):
7272
return try deleteStmt(state: &state)
73-
case (.define, _):
73+
case (.identifier, _):
7474
return try definition(state: &state)
7575
case (.pragma, _):
7676
return try pragma(state: &state)
@@ -180,7 +180,7 @@ enum Parsers {
180180

181181
static func vacuum(state: inout ParserState) -> VacuumStmtSyntax {
182182
let start = state.take()
183-
let schema = state.current.kind.isSymbol ? identifier(state: &state) : nil
183+
let schema = state.current.kind.isIdentifier ? identifier(state: &state) : nil
184184
let fileName = state.take(if: .into) ? identifier(state: &state) : nil
185185
return VacuumStmtSyntax(
186186
id: state.nextId(),
@@ -400,7 +400,7 @@ enum Parsers {
400400
schema = nil
401401
}
402402

403-
let name = state.current.kind.isSymbol ? identifier(state: &state) : nil
403+
let name = state.current.kind.isIdentifier ? identifier(state: &state) : nil
404404
return ReindexStmtSyntax(
405405
id: state.nextId(),
406406
schemaName: schema,
@@ -1461,7 +1461,7 @@ enum Parsers {
14611461
} else {
14621462
let name = identifier(state: &state)
14631463

1464-
let type = state.current.kind.isSymbol && state.current.kind != .unindexed
1464+
let type = state.current.kind.isIdentifier && state.current.kind != .unindexed
14651465
? typeName(state: &state, doNotConsumeWords: ["UNINDEXED"])
14661466
: nil
14671467

@@ -1504,7 +1504,7 @@ enum Parsers {
15041504
repeat {
15051505
let column = try columnDef(state: &state)
15061506
columns[column.name] = column
1507-
} while state.take(if: .comma) && state.current.kind.isSymbol
1507+
} while state.take(if: .comma) && state.current.kind.isIdentifier
15081508

15091509
return columns
15101510
}
@@ -2302,10 +2302,8 @@ enum Parsers {
23022302
}
23032303
}
23042304

2305-
/// This is a custom thing, `DEFINE QUERY ...`
2305+
/// This is a custom thing, `queryName(input: Name): ...`
23062306
static func definition(state: inout ParserState) throws -> StmtSyntax {
2307-
let define = state.take(.define)
2308-
state.skip(.query)
23092307
let name = identifier(state: &state)
23102308

23112309
let params: [Substring: IdentifierSyntax]? = take(if: .openParen, state: &state) { state in
@@ -2321,7 +2319,7 @@ enum Parsers {
23212319
}
23222320
}
23232321

2324-
state.skip(.as)
2322+
state.skip(.colon)
23252323
let stmt = try stmt(state: &state)
23262324

23272325
return QueryDefinitionStmtSyntax(
@@ -2330,7 +2328,7 @@ enum Parsers {
23302328
input: params?["input"],
23312329
output: params?["output"],
23322330
statement: stmt,
2333-
location: define.location.spanning(state.current.location)
2331+
location: name.location.spanning(state.current.location)
23342332
)
23352333
}
23362334

Sources/Compiler/Parse/Token.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,6 @@ struct Token {
4646
.default,
4747
.deferrable,
4848
.deferred,
49-
// DEFINE is our own keyword, this may need to get removed and be
50-
// treated as an identifier later but will cross that bridge when
51-
// i get to it.
52-
.define,
5349
.delete,
5450
.desc,
5551
.detach,
@@ -214,7 +210,6 @@ struct Token {
214210
case `default`
215211
case deferrable
216212
case deferred
217-
case define
218213
case delete
219214
case desc
220215
case detach
@@ -376,7 +371,7 @@ struct Token {
376371
}
377372
}
378373

379-
var isSymbol: Bool {
374+
var isIdentifier: Bool {
380375
if case .identifier = self { return true }
381376
return false
382377
}
@@ -425,7 +420,6 @@ struct Token {
425420
case .default: "DEFAULT"
426421
case .deferrable: "DEFERRABLE"
427422
case .deferred: "DEFERRED"
428-
case .define: "DEFINE"
429423
case .delete: "DELETE"
430424
case .desc: "DESC"
431425
case .detach: "DETACH"

Tests/CompilerTests/Parser/ParseDefinition.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@
33
-- CHECK: NAME fetchUser
44
-- CHECK: STATEMENT
55
-- CHECK: ...
6-
DEFINE QUERY fetchUser AS
6+
fetchUser:
77
SELECT * FROM user WHERE id = ?;
88

99
-- CHECK: QUERY_DEFINITION_STMT_SYNTAX
1010
-- CHECK: NAME insertUser
1111
-- CHECK: STATEMENT
1212
-- CHECK: ...
13-
DEFINE QUERY insertUser AS
13+
insertUser:
1414
INSERT INTO user (id, name) VALUES (1, 'Joe');
1515

1616
-- CHECK: QUERY_DEFINITION_STMT_SYNTAX
1717
-- CHECK: NAME fetchUser
1818
-- CHECK: OUTPUT FetchedUser
1919
-- CHECK: STATEMENT
2020
-- CHECK: ...
21-
DEFINE QUERY fetchUser(output: FetchedUser) AS
21+
fetchUser(output: FetchedUser):
2222
SELECT * FROM user WHERE id = ?;
2323

2424
-- CHECK: QUERY_DEFINITION_STMT_SYNTAX
@@ -27,5 +27,5 @@ SELECT * FROM user WHERE id = ?;
2727
-- CHECK: OUTPUT FetchedUser
2828
-- CHECK: STATEMENT
2929
-- CHECK: ...
30-
DEFINE QUERY fetchUser(input: TheBestInput, output: FetchedUser) AS
30+
fetchUser(input: TheBestInput, output: FetchedUser):
3131
SELECT * FROM user WHERE id = ?;

0 commit comments

Comments
 (0)