Skip to content

Commit 26ee361

Browse files
jneenjneen
andauthored
Fix the broken Gherkin spec on main, and refactor STEP_REGEX (#2226)
* fix the spec for gherkin to specify that the whitespace is not part of the keyword * eliminate Gherkin.step_regex in favour of a pre-computed one from the Rake task * uniq gherkin keywords --------- Co-authored-by: jneen <jneen@jneen.net>
1 parent f8609f2 commit 26ee361

File tree

4 files changed

+40
-32
lines changed

4 files changed

+40
-32
lines changed

lib/rouge/lexers/gherkin.rb

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ def self.detect?(text)
2121
require_relative 'gherkin/keywords'
2222
end
2323

24-
def self.step_regex
25-
# in Gherkin's config, keywords that end in < don't
26-
# need word boundaries at the ends - all others do.
27-
@step_regex ||= Regexp.new(
28-
KEYWORDS[:step].map do |w|
29-
if w.end_with? '<'
30-
Regexp.escape(w.chop)
31-
elsif w.end_with?(' ')
32-
Regexp.escape(w)
33-
else
34-
"#{Regexp.escape(w)}\\b"
35-
end
36-
end.join('|')
37-
)
38-
end
39-
4024
rest_of_line = /.*?(?=[#\n])/
4125

4226
state :basic do
@@ -74,9 +58,10 @@ def self.step_regex
7458

7559
state :has_examples do
7660
mixin :has_scenarios
77-
rule Gherkin.step_regex, Name::Function do
61+
rule Gherkin::STEP_REGEX do
7862
token Name::Function
79-
reset_stack; push :step
63+
reset_stack
64+
push :step
8065
end
8166
end
8267

0 commit comments

Comments
 (0)