Skip to content

Commit 370f944

Browse files
committed
Do Continue early
1 parent e488d3e commit 370f944

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

python/gherkin-python.razor

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,9 @@ class @(Model.ParserClassName):
202202
token = None
203203
queue = []
204204
match = False
205-
while True:
205+
# Effectively do-while
206+
continue_lookahead = True
207+
while continue_lookahead:
206208
token = self.read_token(context)
207209
token.detach()
208210
queue.append(token)
@@ -213,15 +215,15 @@ class @(Model.ParserClassName):
213215
break</text>
214216
}
215217

218+
219+
continue_lookahead = False
216220
@foreach(var tokenType in lookAheadHint.Skip) {
217221
<text>
218222
if self.@MatchToken(tokenType):
223+
continue_lookahead = True
219224
continue</text>
220225
}
221-
@if(lookAheadHint.Skip.Length == 0) {
222-
<text>
223-
break</text>
224-
}
226+
225227

226228
context.token_queue.extend(queue)
227229

python/gherkin/parser.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,7 +3341,9 @@ def lookahead_0(self, context: ParserContext, currentToken: Token) -> bool:
33413341
token = None
33423342
queue = []
33433343
match = False
3344-
while True:
3344+
# Effectively do-while
3345+
continue_lookahead = True
3346+
while continue_lookahead:
33453347
token = self.read_token(context)
33463348
token.detach()
33473349
queue.append(token)
@@ -3350,12 +3352,18 @@ def lookahead_0(self, context: ParserContext, currentToken: Token) -> bool:
33503352
match = True
33513353
break
33523354

3355+
continue_lookahead = False
3356+
33533357
if self.match_Empty(context, token):
3358+
continue_lookahead = True
33543359
continue
33553360
if self.match_Comment(context, token):
3361+
continue_lookahead = True
33563362
continue
33573363
if self.match_TagLine(context, token):
3364+
continue_lookahead = True
33583365
continue
3366+
33593367
context.token_queue.extend(queue)
33603368

33613369
return match
@@ -3365,7 +3373,9 @@ def lookahead_1(self, context: ParserContext, currentToken: Token) -> bool:
33653373
token = None
33663374
queue = []
33673375
match = False
3368-
while True:
3376+
# Effectively do-while
3377+
continue_lookahead = True
3378+
while continue_lookahead:
33693379
token = self.read_token(context)
33703380
token.detach()
33713381
queue.append(token)
@@ -3374,12 +3384,18 @@ def lookahead_1(self, context: ParserContext, currentToken: Token) -> bool:
33743384
match = True
33753385
break
33763386

3387+
continue_lookahead = False
3388+
33773389
if self.match_Empty(context, token):
3390+
continue_lookahead = True
33783391
continue
33793392
if self.match_Comment(context, token):
3393+
continue_lookahead = True
33803394
continue
33813395
if self.match_TagLine(context, token):
3396+
continue_lookahead = True
33823397
continue
3398+
33833399
context.token_queue.extend(queue)
33843400

33853401
return match

0 commit comments

Comments
 (0)