@@ -205,27 +205,27 @@ enum Parsers {
205205 let name = identifier ( state: & state)
206206
207207 let isFunctionCall : Bool
208- let value : ExprSyntax
208+ let value : PragmaStmt . Value ?
209209 switch state. current. kind {
210210 case . openParen:
211211 isFunctionCall = true
212212 // The parens could technically get parsed by the `expr` but
213213 // then the expr type would technically be different.
214214 value = parens ( state: & state) { state in
215- expr ( state: & state)
215+ pragmaValue ( state: & state)
216216 }
217217 case . equal:
218218 isFunctionCall = false
219219 state. skip ( )
220- value = expr ( state: & state)
220+ value = pragmaValue ( state: & state)
221221 default :
222222 state. diagnostics. add ( . unexpectedToken(
223223 of: state. current. kind,
224224 expectedAnyOf: . equal, . openParen,
225225 at: state. current. range
226226 ) )
227227 // Still try to parse the value
228- value = expr ( state: & state)
228+ value = pragmaValue ( state: & state)
229229 isFunctionCall = false
230230 }
231231
@@ -239,6 +239,42 @@ enum Parsers {
239239 )
240240 }
241241
242+ /// https://www.sqlite.org/pragma.html
243+ static func pragmaValue( state: inout ParserState ) -> PragmaStmt . Value ? {
244+ switch state. current. kind {
245+ case . yes:
246+ state. skip ( )
247+ return . yes
248+ case . no:
249+ state. skip ( )
250+ return . no
251+ case . true :
252+ state. skip ( )
253+ return . true
254+ case . false :
255+ state. skip ( )
256+ return . false
257+ case . int( let value) :
258+ let token = state. take ( )
259+ if value == 0 {
260+ return . zero
261+ } else if value == 1 {
262+ return . one
263+ } else {
264+ state. diagnostics. add ( . init( " Expected 1 or 0 " , at: token. range) )
265+ return nil
266+ }
267+ case . on:
268+ state. skip ( )
269+ return . on
270+ case . off:
271+ state. skip ( )
272+ return . off
273+ default :
274+ return nil
275+ }
276+ }
277+
242278 /// https://www.sqlite.org/syntax/upsert-clause.html
243279 static func upsertClause(
244280 state: inout ParserState
@@ -391,7 +427,7 @@ enum Parsers {
391427 state. consume ( . from)
392428 let table = qualifiedTableName ( state: & state)
393429 let whereExpr = state. take ( if: . where) ? expr ( state: & state) : nil
394- let returningClause = state. take ( if : . returning) ? returningClause ( state: & state) : nil
430+ let returningClause = state. current . kind == . returning ? returningClause ( state: & state) : nil
395431 return DeleteStmtSyntax (
396432 id: state. nextId ( ) ,
397433 cte: cte,
0 commit comments