@@ -97,13 +97,83 @@ enum Parsers {
9797 state. diagnostics. add ( . unexpectedToken( of: state. current. kind, at: state. location) )
9898 return EmptyStmtSyntax ( id: state. nextId ( ) , location: state. current. location)
9999 }
100+ case ( . begin, _) :
101+ return begin ( state: & state)
102+ case ( . commit, _) , ( . end, _) :
103+ return commit ( state: & state)
104+ case ( . savepoint, _) :
105+ return savepoint ( state: & state)
106+ case ( . release, _) :
107+ return release ( state: & state)
108+ case ( . rollback, _) :
109+ return rollback ( state: & state)
100110 case ( . semiColon, _) , ( . eof, _) :
101111 state. skip ( )
102112 return EmptyStmtSyntax ( id: state. nextId ( ) , location: state. current. location)
103113 default :
104- state. diagnostics. add ( . unexpectedToken( of: state. current. kind, at: state. location) )
105- return EmptyStmtSyntax ( id: state. nextId ( ) , location: state. current. location)
114+ let token = state. take ( )
115+ state. diagnostics. add ( . unexpectedToken( of: token. kind, at: token. location) )
116+ return EmptyStmtSyntax ( id: state. nextId ( ) , location: token. location)
117+ }
118+ }
119+
120+ static func begin( state: inout ParserState ) -> BeginStmtSyntax {
121+ let start = state. take ( )
122+
123+ let kind : BeginStmtSyntax . Kind ? = if state. take ( if: . deferred) {
124+ . deferred
125+ } else if state. take ( if: . immediate) {
126+ . immediate
127+ } else if state. take ( if: . exclusive) {
128+ . exclusive
129+ } else {
130+ nil
131+ }
132+
133+ state. skip ( if: . transaction)
134+ return BeginStmtSyntax ( id: state. nextId ( ) , location: state. location ( from: start) , kind: kind)
135+ }
136+
137+ static func commit( state: inout ParserState ) -> CommitStmtSyntax {
138+ let start = state. take ( )
139+ state. skip ( if: . transaction)
140+ return CommitStmtSyntax ( id: state. nextId ( ) , location: state. location ( from: start) )
141+ }
142+
143+ static func savepoint( state: inout ParserState ) -> SavepointStmtSyntax {
144+ let start = state. take ( )
145+ let name = identifier ( state: & state)
146+ return SavepointStmtSyntax (
147+ id: state. nextId ( ) ,
148+ location: state. location ( from: start) ,
149+ name: name
150+ )
151+ }
152+
153+ static func release( state: inout ParserState ) -> ReleaseStmtSyntax {
154+ let start = state. take ( )
155+ let name = identifier ( state: & state)
156+ return ReleaseStmtSyntax (
157+ id: state. nextId ( ) ,
158+ location: state. location ( from: start) ,
159+ name: name
160+ )
161+ }
162+
163+ static func rollback( state: inout ParserState ) -> RollbackStmtSyntax {
164+ let start = state. take ( )
165+ let savepoint : IdentifierSyntax ?
166+ if state. take ( if: . to) {
167+ state. skip ( if: . savepoint)
168+ savepoint = identifier ( state: & state)
169+ } else {
170+ savepoint = nil
106171 }
172+ return RollbackStmtSyntax (
173+ id: state. nextId ( ) ,
174+ location: state. location ( from: start) ,
175+ savepoint: savepoint
176+ )
107177 }
108178
109179 static func insertStmt( state: inout ParserState ) throws -> InsertStmtSyntax {
0 commit comments