gherkin 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/History.txt +15 -6
  2. data/README.rdoc +23 -0
  3. data/Rakefile +1 -0
  4. data/VERSION.yml +1 -1
  5. data/features/step_definitions/gherkin_steps.rb +1 -1
  6. data/features/step_definitions/{pretty_printer_steps.rb → pretty_listener_step.rb} +2 -2
  7. data/gherkin.gemspec +24 -35
  8. data/java/Gherkin.iml +8 -14
  9. data/java/src/{gherkin → main/java/gherkin}/lexer/.gitignore +0 -0
  10. data/lib/gherkin.rb +1 -1
  11. data/lib/gherkin/c_lexer.rb +2 -2
  12. data/lib/gherkin/{format → formatter}/argument.rb +1 -1
  13. data/lib/gherkin/{tools → formatter}/colors.rb +1 -1
  14. data/lib/gherkin/{format → formatter}/monochrome_format.rb +1 -1
  15. data/lib/gherkin/{tools → formatter}/pretty_listener.rb +8 -9
  16. data/lib/gherkin/i18n.rb +27 -5
  17. data/lib/gherkin/i18n_lexer.rb +18 -44
  18. data/lib/gherkin/parser/filter_listener.rb +191 -0
  19. data/lib/gherkin/parser/parser.rb +142 -0
  20. data/lib/gherkin/parser/sexp.rb +45 -0
  21. data/lib/gherkin/parser/tag_expression.rb +46 -0
  22. data/lib/gherkin/rb_lexer.rb +2 -2
  23. data/ragel/lexer_common.rl.erb +1 -1
  24. data/spec/gherkin/{format → formatter}/argument_spec.rb +2 -2
  25. data/spec/gherkin/{tools → formatter}/colors_spec.rb +2 -2
  26. data/spec/gherkin/{tools → formatter}/pretty_listener_spec.rb +5 -5
  27. data/spec/gherkin/i18n_lexer_spec.rb +3 -3
  28. data/spec/gherkin/parser/filter_listener_spec.rb +363 -0
  29. data/spec/gherkin/parser/parser_spec.rb +35 -0
  30. data/spec/gherkin/parser/tag_expression_spec.rb +120 -0
  31. data/spec/gherkin/rb_lexer_spec.rb +0 -1
  32. data/spec/gherkin/sexp_recorder.rb +3 -3
  33. data/spec/gherkin/shared/lexer_spec.rb +19 -19
  34. data/spec/gherkin/shared/tags_spec.rb +4 -4
  35. data/tasks/bench.rake +2 -2
  36. data/tasks/compile.rake +1 -1
  37. data/tasks/ragel_task.rb +1 -1
  38. metadata +25 -36
  39. data/java/build.xml +0 -16
  40. data/java/src/gherkin/FixJava.java +0 -37
  41. data/java/src/gherkin/I18nLexer.java +0 -48
  42. data/java/src/gherkin/Lexer.java +0 -5
  43. data/java/src/gherkin/LexingError.java +0 -7
  44. data/java/src/gherkin/Listener.java +0 -29
  45. data/java/src/gherkin/Main.java +0 -17
  46. data/java/src/gherkin/ParseError.java +0 -22
  47. data/java/src/gherkin/Parser.java +0 -191
  48. data/java/src/gherkin/formatter/Argument.java +0 -39
  49. data/java/src/gherkin/formatter/ArgumentFormat.java +0 -17
  50. data/java/src/gherkin/formatter/Colors.java +0 -7
  51. data/java/src/gherkin/formatter/Formatter.java +0 -15
  52. data/java/src/gherkin/formatter/PrettyFormatter.java +0 -219
  53. data/java/src/gherkin/parser/StateMachineReader.java +0 -67
  54. data/java/test/gherkin/formatter/ArgumentTest.java +0 -17
  55. data/lib/gherkin/lexer.rb +0 -35
  56. data/lib/gherkin/parser.rb +0 -19
  57. data/lib/gherkin/rb_parser.rb +0 -125
  58. data/spec/gherkin/parser_spec.rb +0 -33
@@ -1,27 +1,36 @@
1
- == In Git
1
+ == 1.0.4 (2009-04-07)
2
2
 
3
- == Bugfixes
3
+ === New features
4
+ * Pure java releases of Gherkin at http://cukes.info/maven
5
+ * A FilterListener in Ruby that is the last missing piece to plug Gherkin into Cucumber. (Gregory Hnatiuk, Aslak Hellesøy, Matt Wynne, Mike Sassak)
6
+
7
+ === Changed features
8
+ * The Lexer now emits the '@' for tags. (Aslak Hellesøy)
9
+
10
+ == 1.0.3 (2009-03-31)
11
+
12
+ === Bugfixes
4
13
  * The C lexer correctly instantiates a new array for each table, instead of reusing the old one. (Aslak Hellesøy)
5
14
  * Emit keywords with space instead of stripping (< keywords are emmitted without space) (Aslak Hellesøy)
6
15
  * gherkin reformat now prints comments, and does it with proper indentation (Aslak Hellesøy)
7
16
  * .NET resource files are now automatically copied into the .dll (#46 Aslak Hellesøy)
8
17
 
9
- == New features
18
+ === New features
10
19
  * The Pure Java implementation now has a simple main method that pretty prints a feature. (#39 Aslak Hellesøy)
11
20
  * Writing code generated i18n syntax highlighters for Gherkin is a lot easier thanks to several convenience methods in Gherkin::I18n. (Aslak Hellesøy)
12
21
  * .NET (C#) port (#36, #37 Attila Sztupak)
13
22
  * Tables parsed and sent by row rather than by table. (Mike Sassak)
14
23
 
15
- == Changed features
24
+ === Changed features
16
25
  * Switced to ISO 639-1 (language) and ISO 3166 alpha-2 (region - if applicable). Applies to Catalan,
17
26
  Swedish, Welsh, Romanian and Serbian. (Aslak Hellesøy)
18
27
 
19
28
  == 1.0.2 (2009-12-30)
20
29
 
21
- == Bugfixes
30
+ === Bugfixes
22
31
  * Build passes on Ruby 1.9.2 (Aslak Hellesøy)
23
32
 
24
- == New features
33
+ === New features
25
34
  * New command line based on trollop. Commands: reformat, stats. (Aslak Hellesøy)
26
35
  * I18nLexer#scan sets #language to the I18n for the language scanned (Mike Sassak)
27
36
  * I18n#adverbs, brings I18n to parity with Cucumber::Parser::NaturalLanguage (Mike Sassak)
@@ -5,6 +5,20 @@ Fast Gherkin lexer and parser based on Ragel. Gherkin is two things:
5
5
  * The language that has evolved out of the Cucumber project.
6
6
  * This library
7
7
 
8
+ == Generating and building the code
9
+
10
+ You'll need MRI (any version) if you want to build for MRI. To build the Java implementation you'll need JRuby.
11
+ You'll also need Ragel installed and on your PATH.
12
+ Finally you'll need the jeweler gem. (Jeweler will tell you what other gems you need when you run rake)
13
+
14
+ === MRI
15
+
16
+ rake clean compile
17
+
18
+ === Java
19
+
20
+ rake clean jar
21
+
8
22
  == Running RSpec and Cucumber tests
9
23
 
10
24
  rake clean spec cucumber
@@ -23,6 +37,15 @@ E.g. in Bash, export RL_LANG="en,fr,no". This can be quite helpful when modifyin
23
37
  * rake gemcutter:release
24
38
  * ./nativegems.sh
25
39
  * gem push pkg/... (for each native gem)
40
+ * cd java && mvn deploy
41
+
42
+ == Configuring Rake-Compiler for cross compilation
43
+ In order to build Windows binaries (so we can release Windows gems from OS X/Linux) we need to set up rake-compiler.
44
+
45
+ http://github.com/luislavena/rake-compiler/
46
+
47
+ I didn't want to install macports (I'm on homebrew) and I couldn't figure out how to build MinGW myself. I got prebuilt binaries:
48
+ http://crossgcc.rts-software.org/doku.php - just add the bin folder to your PATH
26
49
 
27
50
  == Note on Patches/Pull Requests
28
51
 
data/Rakefile CHANGED
@@ -21,6 +21,7 @@ begin
21
21
  gem.add_development_dependency "albacore", ">= 0.1.0"
22
22
 
23
23
  gem.files -= FileList['dotnet/**/*']
24
+ gem.files -= FileList['java/**/*']
24
25
  case ENV['PLATFORM']
25
26
  when 'java'
26
27
  gem.platform = 'java'
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 1
@@ -1,5 +1,5 @@
1
1
  Given /^a "([^\"]*)" "([^\"]*)" parser$/ do |ruby_or_native, parser_name|
2
- parser = Gherkin::Parser.new(@listener, false, parser_name)
2
+ parser = Gherkin::Parser::Parser.new(@listener, false, parser_name)
3
3
  @lexer = Gherkin::I18nLexer.new(parser, ruby_or_native == "ruby")
4
4
  end
5
5
 
@@ -1,11 +1,11 @@
1
1
  require 'stringio'
2
2
  require 'gherkin'
3
- require 'gherkin/tools/pretty_listener'
3
+ require 'gherkin/formatter/pretty_listener'
4
4
 
5
5
  module PrettyPlease
6
6
  def pretty(source)
7
7
  io = StringIO.new
8
- listener = Gherkin::Tools::PrettyListener.new(io)
8
+ listener = Gherkin::Formatter::PrettyListener.new(io)
9
9
  parser = Gherkin::Parser.new(listener, true)
10
10
  lexer = Gherkin::I18nLexer.new(parser)
11
11
  lexer.scan(source)
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gherkin}
8
- s.version = "1.0.3"
8
+ s.version = "1.0.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Helles\303\270y"]
12
- s.date = %q{2010-03-30}
12
+ s.date = %q{2010-04-07}
13
13
  s.default_executable = %q{gherkin}
14
14
  s.description = %q{A fast Gherkin lexer/parser based on the Ragel State Machine Compiler.}
15
15
  s.email = %q{cukes@googlegroups.com}
@@ -77,45 +77,33 @@ Gem::Specification.new do |s|
77
77
  "features/parser_with_native_lexer.feature",
78
78
  "features/pretty_printer.feature",
79
79
  "features/step_definitions/gherkin_steps.rb",
80
- "features/step_definitions/pretty_printer_steps.rb",
80
+ "features/step_definitions/pretty_listener_step.rb",
81
81
  "features/steps_parser.feature",
82
82
  "features/support/env.rb",
83
83
  "gherkin.gemspec",
84
84
  "java/.gitignore",
85
85
  "java/Gherkin.iml",
86
- "java/build.xml",
87
- "java/src/gherkin/FixJava.java",
88
- "java/src/gherkin/I18nLexer.java",
89
- "java/src/gherkin/Lexer.java",
90
- "java/src/gherkin/LexingError.java",
91
- "java/src/gherkin/Listener.java",
92
- "java/src/gherkin/Main.java",
93
- "java/src/gherkin/ParseError.java",
94
- "java/src/gherkin/Parser.java",
95
- "java/src/gherkin/formatter/Argument.java",
96
- "java/src/gherkin/formatter/ArgumentFormat.java",
97
- "java/src/gherkin/formatter/Colors.java",
98
- "java/src/gherkin/formatter/Formatter.java",
99
- "java/src/gherkin/formatter/PrettyFormatter.java",
100
- "java/src/gherkin/lexer/.gitignore",
101
- "java/src/gherkin/parser/StateMachineReader.java",
102
- "java/test/gherkin/formatter/ArgumentTest.java",
86
+ "java/src/main/java/gherkin/lexer/.gitignore",
103
87
  "lib/.gitignore",
104
88
  "lib/gherkin.rb",
105
89
  "lib/gherkin/c_lexer.rb",
106
90
  "lib/gherkin/cli/main.rb",
107
91
  "lib/gherkin/core_ext/array.rb",
108
92
  "lib/gherkin/csharp_lexer.rb",
109
- "lib/gherkin/format/argument.rb",
110
- "lib/gherkin/format/monochrome_format.rb",
93
+ "lib/gherkin/formatter/argument.rb",
94
+ "lib/gherkin/formatter/colors.rb",
95
+ "lib/gherkin/formatter/monochrome_format.rb",
96
+ "lib/gherkin/formatter/pretty_listener.rb",
111
97
  "lib/gherkin/i18n.rb",
112
98
  "lib/gherkin/i18n.yml",
113
99
  "lib/gherkin/i18n_lexer.rb",
114
- "lib/gherkin/lexer.rb",
115
- "lib/gherkin/parser.rb",
100
+ "lib/gherkin/parser/filter_listener.rb",
116
101
  "lib/gherkin/parser/meta.txt",
102
+ "lib/gherkin/parser/parser.rb",
117
103
  "lib/gherkin/parser/root.txt",
104
+ "lib/gherkin/parser/sexp.rb",
118
105
  "lib/gherkin/parser/steps.txt",
106
+ "lib/gherkin/parser/tag_expression.rb",
119
107
  "lib/gherkin/rb_lexer.rb",
120
108
  "lib/gherkin/rb_lexer/.gitignore",
121
109
  "lib/gherkin/rb_lexer/README.rdoc",
@@ -160,11 +148,8 @@ Gem::Specification.new do |s|
160
148
  "lib/gherkin/rb_lexer/vi.rb",
161
149
  "lib/gherkin/rb_lexer/zhCN.rb",
162
150
  "lib/gherkin/rb_lexer/zhTW.rb",
163
- "lib/gherkin/rb_parser.rb",
164
151
  "lib/gherkin/tools.rb",
165
- "lib/gherkin/tools/colors.rb",
166
152
  "lib/gherkin/tools/files.rb",
167
- "lib/gherkin/tools/pretty_listener.rb",
168
153
  "lib/gherkin/tools/reformat.rb",
169
154
  "lib/gherkin/tools/stats.rb",
170
155
  "lib/gherkin/tools/stats_listener.rb",
@@ -187,19 +172,21 @@ Gem::Specification.new do |s|
187
172
  "spec/gherkin/fixtures/simple.feature",
188
173
  "spec/gherkin/fixtures/simple_with_comments.feature",
189
174
  "spec/gherkin/fixtures/simple_with_tags.feature",
190
- "spec/gherkin/format/argument_spec.rb",
175
+ "spec/gherkin/formatter/argument_spec.rb",
176
+ "spec/gherkin/formatter/colors_spec.rb",
177
+ "spec/gherkin/formatter/pretty_listener_spec.rb",
191
178
  "spec/gherkin/i18n_lexer_spec.rb",
192
179
  "spec/gherkin/i18n_spec.rb",
193
180
  "spec/gherkin/java_lexer_spec.rb",
194
- "spec/gherkin/parser_spec.rb",
181
+ "spec/gherkin/parser/filter_listener_spec.rb",
182
+ "spec/gherkin/parser/parser_spec.rb",
183
+ "spec/gherkin/parser/tag_expression_spec.rb",
195
184
  "spec/gherkin/rb_lexer_spec.rb",
196
185
  "spec/gherkin/sexp_recorder.rb",
197
186
  "spec/gherkin/shared/lexer_spec.rb",
198
187
  "spec/gherkin/shared/py_string_spec.rb",
199
188
  "spec/gherkin/shared/row_spec.rb",
200
189
  "spec/gherkin/shared/tags_spec.rb",
201
- "spec/gherkin/tools/colors_spec.rb",
202
- "spec/gherkin/tools/pretty_listener_spec.rb",
203
190
  "spec/spec_helper.rb",
204
191
  "tasks/bench.rake",
205
192
  "tasks/bench/feature_builder.rb",
@@ -219,19 +206,21 @@ Gem::Specification.new do |s|
219
206
  s.test_files = [
220
207
  "spec/gherkin/c_lexer_spec.rb",
221
208
  "spec/gherkin/csharp_lexer_spec.rb",
222
- "spec/gherkin/format/argument_spec.rb",
209
+ "spec/gherkin/formatter/argument_spec.rb",
210
+ "spec/gherkin/formatter/colors_spec.rb",
211
+ "spec/gherkin/formatter/pretty_listener_spec.rb",
223
212
  "spec/gherkin/i18n_lexer_spec.rb",
224
213
  "spec/gherkin/i18n_spec.rb",
225
214
  "spec/gherkin/java_lexer_spec.rb",
226
- "spec/gherkin/parser_spec.rb",
215
+ "spec/gherkin/parser/filter_listener_spec.rb",
216
+ "spec/gherkin/parser/parser_spec.rb",
217
+ "spec/gherkin/parser/tag_expression_spec.rb",
227
218
  "spec/gherkin/rb_lexer_spec.rb",
228
219
  "spec/gherkin/sexp_recorder.rb",
229
220
  "spec/gherkin/shared/lexer_spec.rb",
230
221
  "spec/gherkin/shared/py_string_spec.rb",
231
222
  "spec/gherkin/shared/row_spec.rb",
232
223
  "spec/gherkin/shared/tags_spec.rb",
233
- "spec/gherkin/tools/colors_spec.rb",
234
- "spec/gherkin/tools/pretty_listener_spec.rb",
235
224
  "spec/spec_helper.rb"
236
225
  ]
237
226
 
@@ -1,22 +1,16 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <module type="JAVA_MODULE" version="4">
3
- <component name="NewModuleRootManager" inherit-compiler-output="true">
4
- <exclude-output />
2
+ <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
+ <component name="NewModuleRootManager" inherit-compiler-output="false">
4
+ <output url="file://$MODULE_DIR$/target/classes" />
5
+ <output-test url="file://$MODULE_DIR$/target/test-classes" />
5
6
  <content url="file://$MODULE_DIR$">
6
- <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
- <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
7
+ <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
+ <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
9
+ <excludeFolder url="file://$MODULE_DIR$/target" />
8
10
  </content>
9
11
  <orderEntry type="inheritedJdk" />
10
12
  <orderEntry type="sourceFolder" forTests="false" />
11
- <orderEntry type="module-library" scope="TEST">
12
- <library>
13
- <CLASSES>
14
- <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.7.jar!/" />
15
- </CLASSES>
16
- <JAVADOC />
17
- <SOURCES />
18
- </library>
19
- </orderEntry>
13
+ <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.8.1" level="project" />
20
14
  </component>
21
15
  </module>
22
16
 
@@ -1,2 +1,2 @@
1
1
  require 'gherkin/i18n_lexer'
2
- require 'gherkin/parser'
2
+ require 'gherkin/parser/parser'
@@ -1,7 +1,7 @@
1
1
  module Gherkin
2
2
  module CLexer
3
- def self.[](i18n_language)
4
- name = i18n_language.gsub(/[\s-]/, '')
3
+ def self.[](i18n_language_name)
4
+ name = i18n_language_name.gsub(/[\s-]/, '')
5
5
  require "gherkin_lexer_#{name}"
6
6
  i18n_lexer_class_name = name.capitalize
7
7
  const_get(i18n_lexer_class_name)
@@ -1,5 +1,5 @@
1
1
  module Gherkin
2
- module Format
2
+ module Formatter
3
3
  class Argument
4
4
  attr_reader :byte_offset, :val
5
5
 
@@ -1,7 +1,7 @@
1
1
  require 'term/ansicolor'
2
2
 
3
3
  module Gherkin
4
- module Tools
4
+ module Formatter
5
5
  # Defines aliases for coloured output. You don't invoke any methods from this
6
6
  # module directly, but you can change the output colours by defining
7
7
  # a <tt>GHERKIN_COLORS</tt> variable in your shell, very much like how you can
@@ -1,5 +1,5 @@
1
1
  module Gherkin
2
- module Format
2
+ module Formatter
3
3
  class MonochromeFormat
4
4
  def format_argument(arg)
5
5
  arg
@@ -1,14 +1,13 @@
1
1
  # encoding: utf-8
2
2
 
3
- require 'gherkin/tools/colors'
4
- require 'gherkin/format/monochrome_format'
3
+ require 'gherkin/formatter/colors'
4
+ require 'gherkin/formatter/monochrome_format'
5
+ require 'gherkin/formatter/argument'
5
6
 
6
7
  module Gherkin
7
- module Tools
8
- # TODO: Rename to Gherkin::Pretty::PrettyReporter - that's what this class *does*
9
- # (The fact that it conforms to the Gherkin Listener interface is secondary)
8
+ module Formatter
10
9
  class PrettyListener
11
- include Gherkin::Tools::Colors
10
+ include Colors
12
11
 
13
12
  class << self
14
13
  def new(io, monochrome=false)
@@ -24,14 +23,14 @@ module Gherkin
24
23
  def initialize(io, monochrome=false)
25
24
  @io = io
26
25
  @monochrome = monochrome
27
- @format = @monochrome ? Format::MonochromeFormat.new : Format::AnsiColorFormat.new
26
+ @format = @monochrome ? MonochromeFormat.new : AnsiColorFormat.new
28
27
  @tags = nil
29
28
  @comments = nil
30
29
  end
31
30
 
32
31
  def tag(name, line)
33
32
  @tags ||= []
34
- @tags << "@#{name}"
33
+ @tags << name
35
34
  end
36
35
 
37
36
  def comment(content, line)
@@ -65,7 +64,7 @@ module Gherkin
65
64
  def step(keyword, name, line, status=nil, arguments=nil, location=nil)
66
65
  flush_table
67
66
  status_param = "#{status}_param" if status
68
- name = Gherkin::Format::Argument.format(name, @format, (arguments || []))
67
+ name = Gherkin::Formatter::Argument.format(name, @format, (arguments || []))
69
68
  #{|arg| status_param ? self.__send__(status_param, arg, @monochrome) : arg} if arguments
70
69
 
71
70
  step = "#{keyword}#{indent(name, ' ')}"
@@ -46,6 +46,33 @@ module Gherkin
46
46
  @keywords['grammar_name'] = @keywords['name'].gsub(/\s/, '')
47
47
  end
48
48
 
49
+ def lexer(listener, force_ruby)
50
+ begin
51
+ if force_ruby
52
+ rb(listener)
53
+ else
54
+ begin
55
+ c(listener)
56
+ rescue NameError, LoadError => e
57
+ warn("WARNING: #{e.message}. Reverting to Ruby lexer.")
58
+ rb(listener)
59
+ end
60
+ end
61
+ rescue LoadError => e
62
+ raise I18nLexerNotFound, "No lexer was found for #{i18n_language_name} (#{e.message}). Supported languages are listed in gherkin/i18n.yml."
63
+ end
64
+ end
65
+
66
+ def c(listener)
67
+ require 'gherkin/c_lexer'
68
+ CLexer[@key].new(listener)
69
+ end
70
+
71
+ def rb(listener)
72
+ require 'gherkin/rb_lexer'
73
+ RbLexer[@key].new(listener)
74
+ end
75
+
49
76
  def sanitized_key
50
77
  @key.gsub(/[\s-]/, '')
51
78
  end
@@ -95,11 +122,6 @@ module Gherkin
95
122
  @keywords[key].split('|').map{|kw| space ? keyword_space(kw) : kw}
96
123
  end
97
124
 
98
- def adverbs
99
- # TODO: looks very similar to #step_keywords. Lose this? Where is it used from?
100
- %w{given when then and but}.map{|keyword| @keywords[keyword].split('|').map{|w| w.gsub(/[\s<']/, '')}}.flatten
101
- end
102
-
103
125
  private
104
126
 
105
127
  def keyword_space(val)
@@ -11,63 +11,37 @@ module Gherkin
11
11
  attr_reader :i18n_language
12
12
 
13
13
  class << self
14
- def new(parser, force_ruby)
14
+ def new(listener, force_ruby)
15
15
  if !force_ruby && defined?(JRUBY_VERSION)
16
16
  require 'gherkin.jar'
17
- Java::Gherkin::I18nLexer.new(parser)
17
+ Java::Gherkin::I18nLexer.new(listener)
18
18
  else
19
19
  super
20
20
  end
21
21
  end
22
+ end
22
23
 
23
- def lexer_class(i18n_lang, force_ruby)
24
- begin
25
- if force_ruby
26
- rb[i18n_lang]
27
- else
28
- begin
29
- c[i18n_lang]
30
- rescue NameError, LoadError => e
31
- warn("WARNING: #{e.message}. Reverting to Ruby lexer.")
32
- rb[i18n_lang]
33
- end
34
- end
35
- rescue LoadError => e
36
- raise I18nLexerNotFound, "No lexer was found for #{i18n_lang} (#{e.message}). Supported languages are listed in gherkin/i18n.yml."
37
- end
38
- end
39
-
40
- def i18n_language(source)
41
- line_one = source.split(/\n/)[0]
42
- match = LANGUAGE_PATTERN.match(line_one)
43
- I18n.get(match ? match[1] : 'en').key
44
- end
24
+ def initialize(listener, force_ruby)
25
+ @listener = listener
26
+ @force_ruby = force_ruby
27
+ end
45
28
 
46
- def c
47
- require 'gherkin/c_lexer'
48
- CLexer
49
- end
29
+ def scan(source)
30
+ create_delegate(source).scan(source)
31
+ end
50
32
 
51
- def csharp
52
- require 'gherkin/csharp_lexer'
53
- CSharpLexer
54
- end
33
+ private
55
34
 
56
- def rb
57
- require 'gherkin/rb_lexer'
58
- RbLexer
59
- end
35
+ def create_delegate(source)
36
+ @i18n_language = lang(source)
37
+ @i18n_language.lexer(@listener, @force_ruby)
60
38
  end
61
39
 
62
- def initialize(parser, force_ruby)
63
- @parser = parser
64
- @force_ruby = force_ruby
40
+ def lang(source)
41
+ line_one = source.split(/\n/)[0]
42
+ match = LANGUAGE_PATTERN.match(line_one)
43
+ I18n.get(match ? match[1] : 'en')
65
44
  end
66
45
 
67
- def scan(source)
68
- @i18n_language = self.class.i18n_language(source)
69
- delegate = self.class.lexer_class(@i18n_language, @force_ruby).new(@parser)
70
- delegate.scan(source)
71
- end
72
46
  end
73
47
  end