gherkin 1.0.2-java → 1.0.3-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (76) hide show
  1. data/.gitattributes +1 -0
  2. data/History.txt +18 -0
  3. data/README.rdoc +4 -1
  4. data/Rakefile +4 -2
  5. data/VERSION.yml +1 -1
  6. data/bin/gherkin +1 -1
  7. data/dotnet/.gitignore +13 -0
  8. data/features/feature_parser.feature +22 -2
  9. data/features/native_lexer.feature +1 -1
  10. data/features/parser_with_native_lexer.feature +1 -1
  11. data/features/step_definitions/gherkin_steps.rb +2 -6
  12. data/features/step_definitions/pretty_printer_steps.rb +2 -3
  13. data/features/steps_parser.feature +1 -1
  14. data/gherkin.gemspec +40 -13
  15. data/java/Gherkin.iml +2 -4
  16. data/java/build.xml +3 -0
  17. data/java/src/gherkin/FixJava.java +6 -3
  18. data/java/src/gherkin/I18nLexer.java +48 -0
  19. data/java/src/gherkin/Listener.java +3 -1
  20. data/java/src/gherkin/Main.java +17 -0
  21. data/java/src/gherkin/Parser.java +9 -3
  22. data/java/src/gherkin/formatter/Argument.java +39 -0
  23. data/java/src/gherkin/formatter/ArgumentFormat.java +17 -0
  24. data/java/src/gherkin/formatter/Colors.java +7 -0
  25. data/java/src/gherkin/formatter/Formatter.java +15 -0
  26. data/java/src/gherkin/formatter/PrettyFormatter.java +219 -0
  27. data/java/src/gherkin/parser/StateMachineReader.java +8 -3
  28. data/java/test/gherkin/formatter/ArgumentTest.java +17 -0
  29. data/lib/gherkin/csharp_lexer.rb +15 -0
  30. data/lib/gherkin/format/argument.rb +35 -0
  31. data/lib/gherkin/format/monochrome_format.rb +9 -0
  32. data/lib/gherkin/i18n.rb +22 -0
  33. data/lib/gherkin/i18n.yml +34 -20
  34. data/lib/gherkin/i18n_lexer.rb +57 -13
  35. data/lib/gherkin/lexer.rb +9 -18
  36. data/lib/gherkin/parser.rb +3 -3
  37. data/lib/gherkin/parser/meta.txt +5 -4
  38. data/lib/gherkin/parser/root.txt +11 -9
  39. data/lib/gherkin/parser/steps.txt +4 -3
  40. data/lib/gherkin/rb_parser.rb +13 -5
  41. data/lib/gherkin/tools/colors.rb +119 -0
  42. data/lib/gherkin/tools/files.rb +6 -1
  43. data/lib/gherkin/tools/pretty_listener.rb +115 -23
  44. data/ragel/lexer.c.rl.erb +67 -51
  45. data/ragel/lexer.csharp.rl.erb +240 -0
  46. data/ragel/lexer.java.rl.erb +27 -18
  47. data/ragel/lexer.rb.rl.erb +17 -17
  48. data/ragel/lexer_common.rl.erb +8 -8
  49. data/spec/gherkin/c_lexer_spec.rb +4 -4
  50. data/spec/gherkin/csharp_lexer_spec.rb +20 -0
  51. data/spec/gherkin/fixtures/comments_in_table.feature +9 -0
  52. data/spec/gherkin/fixtures/complex.feature +2 -0
  53. data/spec/gherkin/fixtures/dos_line_endings.feature +45 -0
  54. data/spec/gherkin/fixtures/i18n_fr.feature +1 -0
  55. data/spec/gherkin/fixtures/i18n_no.feature +1 -0
  56. data/spec/gherkin/fixtures/i18n_zh-CN.feature +1 -0
  57. data/spec/gherkin/format/argument_spec.rb +28 -0
  58. data/spec/gherkin/i18n_lexer_spec.rb +4 -4
  59. data/spec/gherkin/i18n_spec.rb +31 -23
  60. data/spec/gherkin/java_lexer_spec.rb +4 -3
  61. data/spec/gherkin/parser_spec.rb +5 -0
  62. data/spec/gherkin/rb_lexer_spec.rb +4 -2
  63. data/spec/gherkin/sexp_recorder.rb +1 -1
  64. data/spec/gherkin/shared/lexer_spec.rb +169 -60
  65. data/spec/gherkin/shared/py_string_spec.rb +6 -0
  66. data/spec/gherkin/shared/row_spec.rb +107 -0
  67. data/spec/gherkin/shared/tags_spec.rb +1 -1
  68. data/spec/gherkin/tools/colors_spec.rb +19 -0
  69. data/spec/gherkin/tools/pretty_listener_spec.rb +147 -0
  70. data/spec/spec_helper.rb +31 -7
  71. data/tasks/compile.rake +81 -7
  72. data/tasks/ragel_task.rb +6 -4
  73. data/tasks/rspec.rake +2 -2
  74. metadata +86 -26
  75. data/lib/gherkin/java_lexer.rb +0 -10
  76. data/spec/gherkin/shared/table_spec.rb +0 -97
@@ -0,0 +1 @@
1
+ spec/gherkin/fixtures/dos_line_endings.feature -crlf
@@ -1,3 +1,21 @@
1
+ == In Git
2
+
3
+ == Bugfixes
4
+ * The C lexer correctly instantiates a new array for each table, instead of reusing the old one. (Aslak Hellesøy)
5
+ * Emit keywords with space instead of stripping (< keywords are emmitted without space) (Aslak Hellesøy)
6
+ * gherkin reformat now prints comments, and does it with proper indentation (Aslak Hellesøy)
7
+ * .NET resource files are now automatically copied into the .dll (#46 Aslak Hellesøy)
8
+
9
+ == New features
10
+ * The Pure Java implementation now has a simple main method that pretty prints a feature. (#39 Aslak Hellesøy)
11
+ * Writing code generated i18n syntax highlighters for Gherkin is a lot easier thanks to several convenience methods in Gherkin::I18n. (Aslak Hellesøy)
12
+ * .NET (C#) port (#36, #37 Attila Sztupak)
13
+ * Tables parsed and sent by row rather than by table. (Mike Sassak)
14
+
15
+ == Changed features
16
+ * Switced to ISO 639-1 (language) and ISO 3166 alpha-2 (region - if applicable). Applies to Catalan,
17
+ Swedish, Welsh, Romanian and Serbian. (Aslak Hellesøy)
18
+
1
19
  == 1.0.2 (2009-12-30)
2
20
 
3
21
  == Bugfixes
@@ -9,6 +9,9 @@ Fast Gherkin lexer and parser based on Ragel. Gherkin is two things:
9
9
 
10
10
  rake clean spec cucumber
11
11
 
12
+ If the RL_LANG environment variable is set, only the parsers for the languages specified there will be built.
13
+ E.g. in Bash, export RL_LANG="en,fr,no". This can be quite helpful when modifying the Ragel grammar.
14
+
12
15
  == Release process
13
16
 
14
17
  * Run "rake clean spec cucumber" for each platform (1.8.6, 1.8.7, 1.9, jruby) to make sure all is green.
@@ -17,7 +20,7 @@ rake clean spec cucumber
17
20
  * rake clean jar compile
18
21
  * rake gemspec
19
22
  * git commit -a -m "Release vX.Y.Z"
20
- * rake release
23
+ * rake gemcutter:release
21
24
  * ./nativegems.sh
22
25
  * gem push pkg/... (for each native gem)
23
26
 
data/Rakefile CHANGED
@@ -15,10 +15,12 @@ begin
15
15
  gem.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Hellesøy"]
16
16
  gem.executables = ["gherkin"]
17
17
  gem.add_dependency "trollop", ">= 1.15"
18
- gem.add_development_dependency "rspec", ">= 1.2.9"
19
- gem.add_development_dependency "cucumber", ">= 0.5.1"
18
+ gem.add_development_dependency "rspec", ">= 1.3.0"
19
+ gem.add_development_dependency "cucumber", ">= 0.6.2"
20
20
  gem.add_development_dependency "rake-compiler", ">= 0.7.0" unless defined?(JRUBY_VERSION)
21
+ gem.add_development_dependency "albacore", ">= 0.1.0"
21
22
 
23
+ gem.files -= FileList['dotnet/**/*']
22
24
  case ENV['PLATFORM']
23
25
  when 'java'
24
26
  gem.platform = 'java'
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 2
3
+ :patch: 3
4
4
  :major: 1
@@ -2,4 +2,4 @@
2
2
  $:.unshift(File.dirname(__FILE__) + '/../lib') unless $:.include?(File.dirname(__FILE__) + '/../lib')
3
3
 
4
4
  require 'gherkin/cli/main'
5
- Gherkin::Cli::Main.run(ARGV)
5
+ Gherkin::Cli::Main.run(ARGV)
@@ -0,0 +1,13 @@
1
+ *.user
2
+ *.suo
3
+ bin
4
+ obj
5
+ Gherkin/StateMachine/meta.txt
6
+ Gherkin/StateMachine/root.txt
7
+ Gherkin/StateMachine/steps.txt
8
+ Gherkin/Lexer/*.cs
9
+ *.sln.cache
10
+ _ReSharper*
11
+ Gherkin.sln.proj
12
+ *.pidb
13
+ *.userprefs
@@ -6,7 +6,7 @@ Feature: Gherkin Feature lexer
6
6
  make all the syntax decisions for me
7
7
 
8
8
  Background:
9
- Given a "en", "ruby" "root" parser
9
+ Given a "ruby" "root" parser
10
10
 
11
11
  Scenario: Correctly formed feature
12
12
  Given the following text is parsed:
@@ -92,7 +92,7 @@ Feature: Gherkin Feature lexer
92
92
  """
93
93
  Then there should be parse errors on lines 5, 10 and 12
94
94
 
95
- Scenario: Tables
95
+ Scenario: Malformed Tables
96
96
  Given the following text is parsed:
97
97
  """
98
98
  Feature: Antiques Roadshow
@@ -115,6 +115,26 @@ Feature: Gherkin Feature lexer
115
115
  """
116
116
  Then there should be parse errors on lines 10 and 17
117
117
 
118
+ Scenario: Well-formed Tables
119
+ Given the following text is parsed:
120
+ """
121
+ Feature: Row-by-row
122
+
123
+ Scenario: Tables with comments!
124
+ Given I can now comment out a row:
125
+ | Key | Value |
126
+ # | Yes | No |
127
+ # | Good | Bad |
128
+ | Good | Evil |
129
+ Then I am pleased by these things:
130
+ | Raindrops | Roses |
131
+ # | Whiskers | Kittens |
132
+ | Bright Copper | Kettles |
133
+ # | Warm woolen | Mittens |
134
+ | Also Oban | And Hendricks |
135
+ """
136
+ Then there should be no parse errors
137
+
118
138
  Scenario: Multiline keyword descriptions
119
139
  Given the following text is parsed:
120
140
  """
@@ -1,7 +1,7 @@
1
1
  Feature: Native (C/Java) Lexer
2
2
 
3
3
  Background:
4
- Given a "en", "native" "root" parser
4
+ Given a "native" "root" parser
5
5
 
6
6
  Scenario: Parsing an empty feature
7
7
  Given the following text is parsed:
@@ -5,7 +5,7 @@ Feature: Gherkin Feature lexer/parser
5
5
  make all the syntax decisions for me
6
6
 
7
7
  Background:
8
- Given a "en", "native" "root" parser
8
+ Given a "native" "root" parser
9
9
 
10
10
  Scenario: Correctly formed feature
11
11
  When the following text is parsed:
@@ -1,10 +1,6 @@
1
- Given /^a "([^\"]*)", "([^\"]*)" "([^\"]*)" parser$/ do |i18n_language, impl, parser_name|
1
+ Given /^a "([^\"]*)" "([^\"]*)" parser$/ do |ruby_or_native, parser_name|
2
2
  parser = Gherkin::Parser.new(@listener, false, parser_name)
3
- programming_language = {
4
- 'ruby' => 'rb',
5
- 'native' => (defined?(JRUBY_VERSION) ? 'java' : 'c')
6
- }[impl]
7
- @lexer = Gherkin::Lexer.send(programming_language)[i18n_language].new(parser)
3
+ @lexer = Gherkin::I18nLexer.new(parser, ruby_or_native == "ruby")
8
4
  end
9
5
 
10
6
  Given "the following text is parsed:" do |text|
@@ -31,13 +31,12 @@ When /^I parse the prettified representation of each of them$/ do
31
31
  pretty1 = nil
32
32
  pretty2 = nil
33
33
  begin
34
- # announce "========== #{feature}:"
35
34
  pretty1 = pretty(IO.read(feature))
36
35
  pretty2 = pretty(pretty1)
37
36
  pretty2.should == pretty1
38
37
  rescue Spec::Expectations::ExpectationNotMetError => e
39
- File.open("p1.feature", "w") {|io| io.write(pretty1)}
40
- File.open("p2.feature", "w") {|io| io.write(pretty2)}
38
+ File.open("p1.feature", "wb") {|io| io.write(pretty1)}
39
+ File.open("p2.feature", "wb") {|io| io.write(pretty2)}
41
40
  announce "========== #{feature}:"
42
41
  if(e.message =~ /(@@.*)/m)
43
42
  announce $1
@@ -4,7 +4,7 @@ Feature: Gherkin Steps parser
4
4
  I want a steps parser to make writing compound steps easier
5
5
 
6
6
  Background:
7
- Given a "en", "ruby" "steps" parser
7
+ Given a "ruby" "steps" parser
8
8
 
9
9
  Scenario: Parsing steps
10
10
  Given the following text is parsed:
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gherkin}
8
- s.version = "1.0.2"
8
+ s.version = "1.0.3"
9
9
  s.platform = %q{java}
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
12
12
  s.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Helles\303\270y"]
13
- s.date = %q{2009-12-30}
13
+ s.date = %q{2010-03-30}
14
14
  s.default_executable = %q{gherkin}
15
15
  s.description = %q{A fast Gherkin lexer/parser based on the Ragel State Machine Compiler.}
16
16
  s.email = %q{cukes@googlegroups.com}
@@ -20,7 +20,8 @@ Gem::Specification.new do |s|
20
20
  "README.rdoc"
21
21
  ]
22
22
  s.files = [
23
- ".gitignore",
23
+ ".gitattributes",
24
+ ".gitignore",
24
25
  ".mailmap",
25
26
  "History.txt",
26
27
  "LICENSE",
@@ -29,6 +30,7 @@ Gem::Specification.new do |s|
29
30
  "VERSION.yml",
30
31
  "bin/gherkin",
31
32
  "cucumber.yml",
33
+ "dotnet/.gitignore",
32
34
  "features/feature_parser.feature",
33
35
  "features/native_lexer.feature",
34
36
  "features/parser_with_native_lexer.feature",
@@ -42,23 +44,33 @@ Gem::Specification.new do |s|
42
44
  "java/Gherkin.iml",
43
45
  "java/build.xml",
44
46
  "java/src/gherkin/FixJava.java",
47
+ "java/src/gherkin/I18nLexer.java",
45
48
  "java/src/gherkin/Lexer.java",
46
49
  "java/src/gherkin/LexingError.java",
47
50
  "java/src/gherkin/Listener.java",
51
+ "java/src/gherkin/Main.java",
48
52
  "java/src/gherkin/ParseError.java",
49
53
  "java/src/gherkin/Parser.java",
54
+ "java/src/gherkin/formatter/Argument.java",
55
+ "java/src/gherkin/formatter/ArgumentFormat.java",
56
+ "java/src/gherkin/formatter/Colors.java",
57
+ "java/src/gherkin/formatter/Formatter.java",
58
+ "java/src/gherkin/formatter/PrettyFormatter.java",
50
59
  "java/src/gherkin/lexer/.gitignore",
51
60
  "java/src/gherkin/parser/StateMachineReader.java",
61
+ "java/test/gherkin/formatter/ArgumentTest.java",
52
62
  "lib/.gitignore",
53
63
  "lib/gherkin.jar",
54
64
  "lib/gherkin.rb",
55
65
  "lib/gherkin/c_lexer.rb",
56
66
  "lib/gherkin/cli/main.rb",
57
67
  "lib/gherkin/core_ext/array.rb",
68
+ "lib/gherkin/csharp_lexer.rb",
69
+ "lib/gherkin/format/argument.rb",
70
+ "lib/gherkin/format/monochrome_format.rb",
58
71
  "lib/gherkin/i18n.rb",
59
72
  "lib/gherkin/i18n.yml",
60
73
  "lib/gherkin/i18n_lexer.rb",
61
- "lib/gherkin/java_lexer.rb",
62
74
  "lib/gherkin/lexer.rb",
63
75
  "lib/gherkin/parser.rb",
64
76
  "lib/gherkin/parser/meta.txt",
@@ -69,6 +81,7 @@ Gem::Specification.new do |s|
69
81
  "lib/gherkin/rb_lexer/README.rdoc",
70
82
  "lib/gherkin/rb_parser.rb",
71
83
  "lib/gherkin/tools.rb",
84
+ "lib/gherkin/tools/colors.rb",
72
85
  "lib/gherkin/tools/files.rb",
73
86
  "lib/gherkin/tools/pretty_listener.rb",
74
87
  "lib/gherkin/tools/reformat.rb",
@@ -77,18 +90,23 @@ Gem::Specification.new do |s|
77
90
  "nativegems.sh",
78
91
  "ragel/i18n/.gitignore",
79
92
  "ragel/lexer.c.rl.erb",
93
+ "ragel/lexer.csharp.rl.erb",
80
94
  "ragel/lexer.java.rl.erb",
81
95
  "ragel/lexer.rb.rl.erb",
82
96
  "ragel/lexer_common.rl.erb",
83
97
  "spec/gherkin/c_lexer_spec.rb",
98
+ "spec/gherkin/csharp_lexer_spec.rb",
84
99
  "spec/gherkin/fixtures/1.feature",
100
+ "spec/gherkin/fixtures/comments_in_table.feature",
85
101
  "spec/gherkin/fixtures/complex.feature",
102
+ "spec/gherkin/fixtures/dos_line_endings.feature",
86
103
  "spec/gherkin/fixtures/i18n_fr.feature",
87
104
  "spec/gherkin/fixtures/i18n_no.feature",
88
105
  "spec/gherkin/fixtures/i18n_zh-CN.feature",
89
106
  "spec/gherkin/fixtures/simple.feature",
90
107
  "spec/gherkin/fixtures/simple_with_comments.feature",
91
108
  "spec/gherkin/fixtures/simple_with_tags.feature",
109
+ "spec/gherkin/format/argument_spec.rb",
92
110
  "spec/gherkin/i18n_lexer_spec.rb",
93
111
  "spec/gherkin/i18n_spec.rb",
94
112
  "spec/gherkin/java_lexer_spec.rb",
@@ -97,8 +115,10 @@ Gem::Specification.new do |s|
97
115
  "spec/gherkin/sexp_recorder.rb",
98
116
  "spec/gherkin/shared/lexer_spec.rb",
99
117
  "spec/gherkin/shared/py_string_spec.rb",
100
- "spec/gherkin/shared/table_spec.rb",
118
+ "spec/gherkin/shared/row_spec.rb",
101
119
  "spec/gherkin/shared/tags_spec.rb",
120
+ "spec/gherkin/tools/colors_spec.rb",
121
+ "spec/gherkin/tools/pretty_listener_spec.rb",
102
122
  "spec/spec_helper.rb",
103
123
  "tasks/bench.rake",
104
124
  "tasks/bench/feature_builder.rb",
@@ -113,10 +133,12 @@ Gem::Specification.new do |s|
113
133
  s.homepage = %q{http://github.com/aslakhellesoy/gherkin}
114
134
  s.rdoc_options = ["--charset=UTF-8"]
115
135
  s.require_paths = ["lib"]
116
- s.rubygems_version = %q{1.3.5}
136
+ s.rubygems_version = %q{1.3.6}
117
137
  s.summary = %q{Fast Gherkin lexer/parser}
118
138
  s.test_files = [
119
139
  "spec/gherkin/c_lexer_spec.rb",
140
+ "spec/gherkin/csharp_lexer_spec.rb",
141
+ "spec/gherkin/format/argument_spec.rb",
120
142
  "spec/gherkin/i18n_lexer_spec.rb",
121
143
  "spec/gherkin/i18n_spec.rb",
122
144
  "spec/gherkin/java_lexer_spec.rb",
@@ -125,8 +147,10 @@ Gem::Specification.new do |s|
125
147
  "spec/gherkin/sexp_recorder.rb",
126
148
  "spec/gherkin/shared/lexer_spec.rb",
127
149
  "spec/gherkin/shared/py_string_spec.rb",
128
- "spec/gherkin/shared/table_spec.rb",
150
+ "spec/gherkin/shared/row_spec.rb",
129
151
  "spec/gherkin/shared/tags_spec.rb",
152
+ "spec/gherkin/tools/colors_spec.rb",
153
+ "spec/gherkin/tools/pretty_listener_spec.rb",
130
154
  "spec/spec_helper.rb"
131
155
  ]
132
156
 
@@ -136,20 +160,23 @@ Gem::Specification.new do |s|
136
160
 
137
161
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
138
162
  s.add_runtime_dependency(%q<trollop>, [">= 1.15"])
139
- s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
140
- s.add_development_dependency(%q<cucumber>, [">= 0.5.1"])
163
+ s.add_development_dependency(%q<rspec>, [">= 1.3.0"])
164
+ s.add_development_dependency(%q<cucumber>, [">= 0.6.2"])
141
165
  s.add_development_dependency(%q<rake-compiler>, [">= 0.7.0"])
166
+ s.add_development_dependency(%q<albacore>, [">= 0.1.0"])
142
167
  else
143
168
  s.add_dependency(%q<trollop>, [">= 1.15"])
144
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
145
- s.add_dependency(%q<cucumber>, [">= 0.5.1"])
169
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
170
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
146
171
  s.add_dependency(%q<rake-compiler>, [">= 0.7.0"])
172
+ s.add_dependency(%q<albacore>, [">= 0.1.0"])
147
173
  end
148
174
  else
149
175
  s.add_dependency(%q<trollop>, [">= 1.15"])
150
- s.add_dependency(%q<rspec>, [">= 1.2.9"])
151
- s.add_dependency(%q<cucumber>, [">= 0.5.1"])
176
+ s.add_dependency(%q<rspec>, [">= 1.3.0"])
177
+ s.add_dependency(%q<cucumber>, [">= 0.6.2"])
152
178
  s.add_dependency(%q<rake-compiler>, [">= 0.7.0"])
179
+ s.add_dependency(%q<albacore>, [">= 0.1.0"])
153
180
  end
154
181
  end
155
182
 
@@ -1,24 +1,22 @@
1
1
  <?xml version="1.0" encoding="UTF-8"?>
2
- <module relativePaths="true" type="JAVA_MODULE" version="4">
2
+ <module type="JAVA_MODULE" version="4">
3
3
  <component name="NewModuleRootManager" inherit-compiler-output="true">
4
4
  <exclude-output />
5
5
  <content url="file://$MODULE_DIR$">
6
6
  <sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
7
7
  <sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" />
8
- <excludeFolder url="file://$MODULE_DIR$/target" />
9
8
  </content>
10
9
  <orderEntry type="inheritedJdk" />
11
10
  <orderEntry type="sourceFolder" forTests="false" />
12
11
  <orderEntry type="module-library" scope="TEST">
13
12
  <library>
14
13
  <CLASSES>
15
- <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.6.jar!/" />
14
+ <root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.7.jar!/" />
16
15
  </CLASSES>
17
16
  <JAVADOC />
18
17
  <SOURCES />
19
18
  </library>
20
19
  </orderEntry>
21
- <orderEntry type="library" scope="TEST" name="Mockito" level="application" />
22
20
  </component>
23
21
  </module>
24
22
 
@@ -8,6 +8,9 @@
8
8
  <jar destfile="${basedir}/../lib/gherkin.jar">
9
9
  <fileset dir="${basedir}/target/classes" />
10
10
  <fileset dir="${basedir}/../lib" includes="gherkin/parser/*.txt" />
11
+ <manifest>
12
+ <attribute name="Main-Class" value="gherkin.Main" />
13
+ </manifest>
11
14
  </jar>
12
15
  </target>
13
16
  </project>
@@ -17,14 +17,17 @@ public class FixJava {
17
17
  return sb.toString();
18
18
  }
19
19
 
20
- public static String readResourceAsString(String filePath) throws IOException {
21
- Reader machine = new InputStreamReader(FixJava.class.getResourceAsStream(filePath));
20
+ public static String readResource(String filePath) throws IOException {
21
+ Reader reader = new InputStreamReader(FixJava.class.getResourceAsStream(filePath));
22
+ return readReader(reader);
23
+ }
22
24
 
25
+ public static String readReader(Reader reader) throws IOException {
23
26
  final char[] buffer = new char[0x10000];
24
27
  StringBuilder sb = new StringBuilder();
25
28
  int read;
26
29
  do {
27
- read = machine.read(buffer, 0, buffer.length);
30
+ read = reader.read(buffer, 0, buffer.length);
28
31
  if (read > 0) {
29
32
  sb.append(buffer, 0, read);
30
33
  }
@@ -0,0 +1,48 @@
1
+ package gherkin;
2
+
3
+ import java.util.regex.Matcher;
4
+ import java.util.regex.Pattern;
5
+
6
+ public class I18nLexer implements Lexer {
7
+ private static final Pattern LANGUAGE_PATTERN = Pattern.compile("language\\s*:\\s*(.*)");
8
+ private final Listener listener;
9
+ private String i18nLanguage;
10
+
11
+ public I18nLexer(Listener listener) {
12
+ this.listener = listener;
13
+ }
14
+
15
+ /**
16
+ * @return the i18n language code from the previous scanned source.
17
+ */
18
+ public String getI18nLanguage() {
19
+ return i18nLanguage;
20
+ }
21
+
22
+ public void scan(CharSequence source) {
23
+ createDelegate(source).scan(source);
24
+ }
25
+
26
+ private Lexer createDelegate(CharSequence source) {
27
+ i18nLanguage = lang(source);
28
+ String i18nLanguage = this.i18nLanguage.replaceAll("[\\s-]", "").toLowerCase();
29
+ String i18nLexerClassName = i18nLanguage.substring(0,1).toUpperCase() + i18nLanguage.substring(1);
30
+ String qualifiedI18nLexerClassName = "gherkin.lexer." + i18nLexerClassName;
31
+ try {
32
+ Class<?> delegateClass = Class.forName(qualifiedI18nLexerClassName);
33
+ return (Lexer) delegateClass.getConstructor(Listener.class).newInstance(listener);
34
+ } catch (Exception e) {
35
+ throw new RuntimeException("Couldn't load lexer class: " + qualifiedI18nLexerClassName, e);
36
+ }
37
+ }
38
+
39
+ private String lang(CharSequence source) {
40
+ String lineOne = source.toString().split("\\n")[0];
41
+ Matcher matcher = LANGUAGE_PATTERN.matcher(lineOne);
42
+ if(matcher.find()) {
43
+ return matcher.group(1);
44
+ } else {
45
+ return "en";
46
+ }
47
+ }
48
+ }