Skip to content

Commit e488d3e

Browse files
committed
Do Continue early
1 parent 16a024f commit e488d3e

File tree

2 files changed

+26
-29
lines changed

2 files changed

+26
-29
lines changed

python/gherkin-python.razor

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -206,19 +206,22 @@ class @(Model.ParserClassName):
206206
token = self.read_token(context)
207207
token.detach()
208208
queue.append(token)
209-
210-
if @foreach(var tokenType in lookAheadHint.ExpectedTokens) {<text>self.@MatchToken(tokenType)</text>}:
209+
@foreach(var tokenType in lookAheadHint.ExpectedTokens) {
210+
<text>
211+
if self.@MatchToken(tokenType):
211212
match = True
212-
break
213-
214-
if not any(
215-
(@foreach(var tokenType in lookAheadHint.Skip) {
216-
<text>
217-
self.@MatchToken(tokenType),</text>}
213+
break</text>
214+
}
218215

219-
)
220-
):
221-
break
216+
@foreach(var tokenType in lookAheadHint.Skip) {
217+
<text>
218+
if self.@MatchToken(tokenType):
219+
continue</text>
220+
}
221+
@if(lookAheadHint.Skip.Length == 0) {
222+
<text>
223+
break</text>
224+
}
222225

223226
context.token_queue.extend(queue)
224227

python/gherkin/parser.py

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3350,15 +3350,12 @@ def lookahead_0(self, context: ParserContext, currentToken: Token) -> bool:
33503350
match = True
33513351
break
33523352

3353-
if not any(
3354-
(
3355-
self.match_Empty(context, token),
3356-
self.match_Comment(context, token),
3357-
self.match_TagLine(context, token),
3358-
)
3359-
):
3360-
break
3361-
3353+
if self.match_Empty(context, token):
3354+
continue
3355+
if self.match_Comment(context, token):
3356+
continue
3357+
if self.match_TagLine(context, token):
3358+
continue
33623359
context.token_queue.extend(queue)
33633360

33643361
return match
@@ -3377,15 +3374,12 @@ def lookahead_1(self, context: ParserContext, currentToken: Token) -> bool:
33773374
match = True
33783375
break
33793376

3380-
if not any(
3381-
(
3382-
self.match_Empty(context, token),
3383-
self.match_Comment(context, token),
3384-
self.match_TagLine(context, token),
3385-
)
3386-
):
3387-
break
3388-
3377+
if self.match_Empty(context, token):
3378+
continue
3379+
if self.match_Comment(context, token):
3380+
continue
3381+
if self.match_TagLine(context, token):
3382+
continue
33893383
context.token_queue.extend(queue)
33903384

33913385
return match

0 commit comments

Comments
 (0)