forked from bmabey/gherkin-pygments-lexer
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRakefile
49 lines (39 loc) · 1.67 KB
/
Rakefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
class SyntaxGenerator
def generate
require 'yaml'
require 'erb'
require 'cucumber'
feature_keywords_array = []
scenario_keywords_array = []
examples_keywords_array = []
step_keywords_array = []
Cucumber::LANGUAGES.each do |lang, words|
feature_keywords_array << words.delete('feature').split(/\|/) rescue nil
scenario_keywords_array << words.delete('scenario').split(/\|/) rescue nil
scenario_keywords_array << words.delete('scenario_outline').split(/\|/) rescue nil
scenario_keywords_array << words.delete('background').split(/\|/) rescue nil
examples_keywords_array << words.delete('examples').split(/\|/) rescue nil
step_keywords_array << keywords(lang, words)
end
feature_keywords = feature_keywords_array.flatten.compact.sort.reverse.uniq.join('|')
scenario_keywords = scenario_keywords_array.flatten.compact.sort.reverse.uniq.join('|')
examples_keywords = examples_keywords_array.flatten.compact.sort.reverse.uniq.join('|')
step_keywords = step_keywords_array.flatten.compact.sort.reverse.uniq.join('|')
template = ERB.new(IO.read(File.dirname(__FILE__) + '/lexer.erb.py'))
syntax = template.result(binding)
syntax_file = File.dirname(__FILE__) + '/gherkin_lexer/__init__.py'
File.open(syntax_file, "w") do |io|
io.write(syntax)
end
end
def keywords(lang, words)
space = words['space_after_keyword'] ? '\s+' : ''
%w{given when then and but}.map do |key|
words[key].split(/\|/).map{|w| "#{w}#{space}"}
end
end
end
desc 'Generate Gherkin lexer for all languages supported by Cucumber'
task :generate do
SyntaxGenerator.new.generate
end