gherkin 0.0.3-universal-java-1.5 → 0.0.4-universal-java-1.5

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore CHANGED
@@ -3,6 +3,5 @@
3
3
  coverage
4
4
  rdoc
5
5
  pkg
6
- *.dot
7
- *.png
8
- *.so
6
+ ext
7
+ tmp
@@ -17,6 +17,25 @@ rake spec cucumber
17
17
 
18
18
  rake clobber
19
19
 
20
+ == Release process
21
+
22
+ Run just "rake" for each platform (1.8.6, 1.8.7, 1.9, jruby) to make sure all is green.
23
+
24
+ 1) Bump version in the VERSION file
25
+ 2) rake gemspec
26
+ 3) Commit everything
27
+ 4) rake release
28
+ 5) ./nativegems.sh
29
+ 6) gem push pkg/... (for each native gem)
30
+
31
+ TODO: Also build windows gem with dll using rake-compiler. MinGW gem can be done on OS X/Linux, but
32
+ the one for the old Ruby one-click installers must be built with Visual Studio/nmake.
33
+
34
+ == Build windows gems on OS X
35
+
36
+ * http://www.copiousfreetime.org/articles/2008/10/12/building-gems-for-windows.html
37
+ * rake-compiler docs
38
+
20
39
  == Notes
21
40
 
22
41
  Ragel supports Ruby, but it's much slower than C. The ruby target will be used for development.
data/Rakefile CHANGED
@@ -4,9 +4,6 @@ require 'rubygems'
4
4
  require 'rake'
5
5
  require 'rake/clean'
6
6
 
7
- JRUBY = defined?(JRUBY_VERSION)
8
- WINDOWS = Config::CONFIG['host_os'] =~ /mswin|mingw/
9
-
10
7
  begin
11
8
  require 'jeweler'
12
9
  Jeweler::Tasks.new do |gem|
@@ -18,22 +15,26 @@ begin
18
15
  gem.authors = ["Mike Sassak", "Gregory Hnatiuk", "Aslak Hellesøy"]
19
16
  gem.executables = ["gherkin"]
20
17
  gem.add_development_dependency "rspec", "1.2.9"
21
- gem.add_development_dependency "cucumber"
18
+ gem.add_development_dependency "cucumber", "0.4.4"
19
+ gem.add_development_dependency "rake-compiler", "0.6.0" unless defined?(JRUBY_VERSION)
22
20
 
23
- # Jeweler only includes files in git by default. Add the generated ones.
24
- gem.files += FileList['lib/gherkin/rb_lexer/*.rb']
25
-
26
- if(JRUBY)
27
- gem.platform = Gem::Platform::CURRENT
21
+ case ENV['PLATFORM']
22
+ when 'universal-java-1.5'
23
+ gem.platform = 'universal-java-1.5'
28
24
  gem.files += FileList['lib/gherkin.jar']
29
25
  gem.extensions = []
30
- elsif(WINDOWS)
31
- gem.platform = Gem::Platform::CURRENT
32
- gem.files += FileList['lib/gherkin_lexer.dll']
26
+ when 'i386-mswin32'
27
+ gem.platform = 'i386-mswin32'
28
+ gem.files += FileList['lib/*.so']
29
+ gem.extensions = []
30
+ when 'i386-mingw32'
31
+ gem.platform = 'i386-mingw32'
32
+ gem.files += FileList['lib/*.so']
33
33
  gem.extensions = []
34
34
  else
35
- gem.files += FileList['ext/gherkin_lexer/*.{c,h}']
36
- gem.extensions = 'ext/gherkin_lexer/extconf.rb'
35
+ gem.files += FileList['lib/gherkin/rb_lexer/*.rb']
36
+ gem.files += FileList['ext/**/*.c']
37
+ gem.extensions = FileList['ext/**/extconf.rb']
37
38
  end
38
39
 
39
40
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
@@ -45,4 +46,4 @@ end
45
46
 
46
47
  Dir['tasks/**/*.rake'].each { |rake| load rake }
47
48
 
48
- task :default => [:spec, :cucumber]
49
+ task :default => [:jar, :compile, :spec, :cucumber]
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :minor: 0
3
- :patch: 3
3
+ :patch: 4
4
4
  :major: 0
@@ -6,5 +6,5 @@ require 'gherkin/tools/pretty_printer'
6
6
 
7
7
  listener = Gherkin::Tools::PrettyPrinter.new(STDOUT)
8
8
  parser = Gherkin::Parser.new(listener, true) # We could skip the parser here, if we don't want to verify well-formedness
9
- lexer = Gherkin::Lexer['en'].new(parser)
10
- lexer.scan(IO.read(ARGV[0]))
9
+ lexer = Gherkin::I18nLexer.new(parser)
10
+ lexer.scan(IO.read(ARGV[0]))
@@ -6,6 +6,9 @@ Feature: Pretty printer
6
6
  Given I have Cucumber's home dir defined in CUCUMBER_HOME
7
7
  When I find all of the .feature files
8
8
  And I parse the prettified representation of each of them
9
- # Of course, we don't really want all those errors, but these are the current ones.
9
+ # Of course, we don't really want any errors. The last
10
+ # two files that were not identical are written to p1.feature
11
+ # and p2.feature. Do a diff -u p1.feature p2.feature
12
+ #
10
13
  Then the following files should have errors:
11
- | Path | Error |
14
+ | Path | Error |
@@ -1,4 +1,5 @@
1
1
  require 'stringio'
2
+ require 'gherkin'
2
3
  require 'gherkin/tools/pretty_printer'
3
4
 
4
5
  module PrettyPlease
@@ -27,12 +28,16 @@ end
27
28
  When /^I parse the prettified representation of each of them$/ do
28
29
  @errors = [['Path', 'Error']]
29
30
  @features.each do |feature|
31
+ pretty1 = nil
32
+ pretty2 = nil
30
33
  begin
34
+ # announce "========== #{feature}:"
31
35
  pretty1 = pretty(IO.read(feature))
32
36
  pretty2 = pretty(pretty1)
33
-
34
37
  pretty2.should == pretty1
35
38
  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)}
36
41
  announce "========== #{feature}:"
37
42
  if(e.message =~ /(@@.*)/m)
38
43
  announce $1
@@ -5,12 +5,12 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{gherkin}
8
- s.version = "0.0.3"
8
+ s.version = "0.0.4"
9
9
  s.platform = %q{universal-java-1.5}
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-11-25}
13
+ s.date = %q{2009-11-28}
14
14
  s.default_executable = %q{gherkin}
15
15
  s.description = %q{A fast Gherkin lexer in Ragel}
16
16
  s.email = %q{cukes@googlegroups.com}
@@ -27,8 +27,6 @@ Gem::Specification.new do |s|
27
27
  "VERSION.yml",
28
28
  "bin/gherkin",
29
29
  "cucumber.yml",
30
- "ext/gherkin_lexer/.gitignore",
31
- "ext/gherkin_lexer/extconf.rb",
32
30
  "features/feature_parser.feature",
33
31
  "features/native_lexer.feature",
34
32
  "features/parser_with_native_lexer.feature",
@@ -53,6 +51,7 @@ Gem::Specification.new do |s|
53
51
  "lib/gherkin.jar",
54
52
  "lib/gherkin.rb",
55
53
  "lib/gherkin/c_lexer.rb",
54
+ "lib/gherkin/core_ext/array.rb",
56
55
  "lib/gherkin/i18n.yml",
57
56
  "lib/gherkin/i18n_lexer.rb",
58
57
  "lib/gherkin/java_lexer.rb",
@@ -64,54 +63,16 @@ Gem::Specification.new do |s|
64
63
  "lib/gherkin/rb_lexer.rb",
65
64
  "lib/gherkin/rb_lexer/.gitignore",
66
65
  "lib/gherkin/rb_lexer/README.rdoc",
67
- "lib/gherkin/rb_lexer/ar.rb",
68
- "lib/gherkin/rb_lexer/bg.rb",
69
- "lib/gherkin/rb_lexer/cat.rb",
70
- "lib/gherkin/rb_lexer/cs.rb",
71
- "lib/gherkin/rb_lexer/cy.rb",
72
- "lib/gherkin/rb_lexer/da.rb",
73
- "lib/gherkin/rb_lexer/de.rb",
74
- "lib/gherkin/rb_lexer/en-au.rb",
75
- "lib/gherkin/rb_lexer/en-lol.rb",
76
- "lib/gherkin/rb_lexer/en-tx.rb",
77
- "lib/gherkin/rb_lexer/en.rb",
78
- "lib/gherkin/rb_lexer/es.rb",
79
- "lib/gherkin/rb_lexer/et.rb",
80
- "lib/gherkin/rb_lexer/fi.rb",
81
- "lib/gherkin/rb_lexer/fr.rb",
82
- "lib/gherkin/rb_lexer/he.rb",
83
- "lib/gherkin/rb_lexer/hr.rb",
84
- "lib/gherkin/rb_lexer/hu.rb",
85
- "lib/gherkin/rb_lexer/id.rb",
86
- "lib/gherkin/rb_lexer/it.rb",
87
- "lib/gherkin/rb_lexer/ja.rb",
88
- "lib/gherkin/rb_lexer/ko.rb",
89
- "lib/gherkin/rb_lexer/lt.rb",
90
- "lib/gherkin/rb_lexer/lv.rb",
91
- "lib/gherkin/rb_lexer/nl.rb",
92
- "lib/gherkin/rb_lexer/no.rb",
93
- "lib/gherkin/rb_lexer/pl.rb",
94
- "lib/gherkin/rb_lexer/pt.rb",
95
- "lib/gherkin/rb_lexer/ro.rb",
96
- "lib/gherkin/rb_lexer/ro2.rb",
97
- "lib/gherkin/rb_lexer/ru.rb",
98
- "lib/gherkin/rb_lexer/se.rb",
99
- "lib/gherkin/rb_lexer/sk.rb",
100
- "lib/gherkin/rb_lexer/sr-Latn.rb",
101
- "lib/gherkin/rb_lexer/sr.rb",
102
- "lib/gherkin/rb_lexer/tr.rb",
103
- "lib/gherkin/rb_lexer/uz.rb",
104
- "lib/gherkin/rb_lexer/vi.rb",
105
- "lib/gherkin/rb_lexer/zh-CN.rb",
106
- "lib/gherkin/rb_lexer/zh-TW.rb",
107
66
  "lib/gherkin/rb_parser.rb",
108
67
  "lib/gherkin/tools/pretty_printer.rb",
68
+ "nativegems.sh",
109
69
  "ragel/i18n/.gitignore",
110
70
  "ragel/lexer.c.rl.erb",
111
71
  "ragel/lexer.java.rl.erb",
112
72
  "ragel/lexer.rb.rl.erb",
113
73
  "ragel/lexer_common.rl.erb",
114
74
  "spec/gherkin/c_lexer_spec.rb",
75
+ "spec/gherkin/fixtures/1.feature",
115
76
  "spec/gherkin/fixtures/complex.feature",
116
77
  "spec/gherkin/fixtures/i18n_fr.feature",
117
78
  "spec/gherkin/fixtures/i18n_no.feature",
@@ -133,9 +94,9 @@ Gem::Specification.new do |s|
133
94
  "tasks/bench/feature_builder.rb",
134
95
  "tasks/bench/generated/.gitignore",
135
96
  "tasks/bench/null_listener.rb",
97
+ "tasks/compile.rake",
136
98
  "tasks/cucumber.rake",
137
- "tasks/ext.rake",
138
- "tasks/ragel.rake",
99
+ "tasks/ragel_task.rb",
139
100
  "tasks/rdoc.rake",
140
101
  "tasks/rspec.rake"
141
102
  ]
@@ -145,8 +106,7 @@ Gem::Specification.new do |s|
145
106
  s.rubygems_version = %q{1.3.5}
146
107
  s.summary = %q{Fast Gherkin lexer}
147
108
  s.test_files = [
148
- "spec/spec_helper.rb",
149
- "spec/gherkin/c_lexer_spec.rb",
109
+ "spec/gherkin/c_lexer_spec.rb",
150
110
  "spec/gherkin/i18n_spec.rb",
151
111
  "spec/gherkin/java_lexer_spec.rb",
152
112
  "spec/gherkin/parser_spec.rb",
@@ -155,7 +115,8 @@ Gem::Specification.new do |s|
155
115
  "spec/gherkin/shared/lexer_spec.rb",
156
116
  "spec/gherkin/shared/py_string_spec.rb",
157
117
  "spec/gherkin/shared/table_spec.rb",
158
- "spec/gherkin/shared/tags_spec.rb"
118
+ "spec/gherkin/shared/tags_spec.rb",
119
+ "spec/spec_helper.rb"
159
120
  ]
160
121
 
161
122
  if s.respond_to? :specification_version then
@@ -164,14 +125,17 @@ Gem::Specification.new do |s|
164
125
 
165
126
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
166
127
  s.add_development_dependency(%q<rspec>, ["= 1.2.9"])
167
- s.add_development_dependency(%q<cucumber>, [">= 0"])
128
+ s.add_development_dependency(%q<cucumber>, ["= 0.4.4"])
129
+ s.add_development_dependency(%q<rake-compiler>, ["= 0.6.0"])
168
130
  else
169
131
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
170
- s.add_dependency(%q<cucumber>, [">= 0"])
132
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
133
+ s.add_dependency(%q<rake-compiler>, ["= 0.6.0"])
171
134
  end
172
135
  else
173
136
  s.add_dependency(%q<rspec>, ["= 1.2.9"])
174
- s.add_dependency(%q<cucumber>, [">= 0"])
137
+ s.add_dependency(%q<cucumber>, ["= 0.4.4"])
138
+ s.add_dependency(%q<rake-compiler>, ["= 0.6.0"])
175
139
  end
176
140
  end
177
141
 
@@ -1,2 +1,4 @@
1
- gherkin_lexer.bundle
2
- gherkin.jar
1
+ *.bundle
2
+ *.dll
3
+ *.so
4
+ *.jar
@@ -1,9 +1,9 @@
1
- require 'gherkin_lexer'
2
-
3
1
  module Gherkin
4
2
  module CLexer
5
3
  def self.[](i18n_language)
6
- i18n_lexer_class_name = i18n_language.gsub(/[\s-]/, '').capitalize
4
+ name = i18n_language.gsub(/[\s-]/, '')
5
+ require "gherkin_lexer_#{name}"
6
+ i18n_lexer_class_name = name.capitalize
7
7
  const_get(i18n_lexer_class_name)
8
8
  end
9
9
  end
@@ -0,0 +1,5 @@
1
+ class Array
2
+ def utf8_pack(fmt)
3
+ (RUBY_VERSION =~ /^1\.9/) ? pack(fmt).force_encoding("UTF-8") : pack(fmt)
4
+ end
5
+ end
@@ -6,20 +6,21 @@ module Gherkin
6
6
  class << self
7
7
  def [](i18n_lang)
8
8
  begin
9
+ # Uncomment the line below (during development) to force use of Ruby lexer
10
+ # return rb[i18n_lang]
11
+
9
12
  if defined?(JRUBY_VERSION)
10
13
  java[i18n_lang]
11
14
  else
12
15
  begin
13
16
  c[i18n_lang]
14
- rescue NameError => e
17
+ rescue NameError, LoadError => e
15
18
  warn("WARNING: #{e.message}. Reverting to Ruby lexer")
16
19
  rb[i18n_lang]
17
- rescue LoadError
18
- rb[i18n_lang]
19
20
  end
20
21
  end
21
- rescue LoadError
22
- raise I18nLexerNotFound, "No lexer was found for #{i18n_lang}. Supported languages are listed in gherkin/i18n.yml."
22
+ rescue LoadError => e
23
+ raise I18nLexerNotFound, "No lexer was found for #{i18n_lang} (#{e.message}). Supported languages are listed in gherkin/i18n.yml."
23
24
  end
24
25
  end
25
26
 
@@ -1,8 +1,9 @@
1
1
  module Gherkin
2
2
  module RbLexer
3
3
  def self.[](i18n_language)
4
- require "gherkin/rb_lexer/#{i18n_language}"
5
- i18n_lexer_class_name = i18n_language.gsub(/[\s-]/, '').capitalize
4
+ name = i18n_language.gsub(/[\s-]/, '')
5
+ require "gherkin/rb_lexer/#{name}"
6
+ i18n_lexer_class_name = name.capitalize
6
7
  const_get(i18n_lexer_class_name)
7
8
  end
8
9
  end
@@ -1,3 +1,4 @@
1
+ # encoding: utf-8
1
2
  module Gherkin
2
3
  module Tools
3
4
  class PrettyPrinter
@@ -53,9 +54,7 @@ module Gherkin
53
54
  end
54
55
 
55
56
  def py_string(string, line)
56
- @io.puts ' """'
57
- @io.puts string.gsub(/^/, ' ')
58
- @io.puts ' """'
57
+ @io.puts " \"\"\"\n" + string.gsub(START, ' ') + "\n \"\"\""
59
58
  end
60
59
 
61
60
  def syntax_error(state, event, legal_events, line)
@@ -63,10 +62,17 @@ module Gherkin
63
62
  end
64
63
 
65
64
  private
65
+ if(RUBY_VERSION =~ /^1\.9/)
66
+ START = /#{"^".encode('UTF-8')}/
67
+ NL = Regexp.new("\n".encode('UTF-8'))
68
+ else
69
+ START = /^/
70
+ NL = /\n/n
71
+ end
66
72
 
67
73
  def indent(string, indentation)
68
74
  indent = ""
69
- string.split(/\n/n).map do |l|
75
+ string.split(NL).map do |l|
70
76
  s = "#{indent}#{l}"
71
77
  indent = indentation
72
78
  s
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+ # Builds gems for all supported platforms
3
+ rake gemspec build PLATFORM=universal-java-1.5
4
+ rake cross compile gemspec build PLATFORM=i386-mswin32 RUBY_CC_VERSION=1.8.6
5
+ rake gemspec build PLATFORM=i386-mingw32 RUBY_CC_VERSION=1.8.6
@@ -5,6 +5,19 @@
5
5
  #include <stddef.h>
6
6
  #endif
7
7
 
8
+ #ifdef HAVE_RUBY_RE_H
9
+ #include <ruby/re.h>
10
+ #endif
11
+
12
+ #ifdef HAVE_RUBY_ENCODING_H
13
+ #include <ruby/encoding.h>
14
+ #define ENCODED_STR_NEW(ptr, len) \
15
+ rb_enc_str_new(ptr, len, rb_utf8_encoding());
16
+ #else
17
+ #define ENCODED_STR_NEW(ptr, len) \
18
+ rb_str_new(ptr, len);
19
+ #endif
20
+
8
21
  #ifndef RSTRING_PTR
9
22
  #define RSTRING_PTR(s) (RSTRING(s)->ptr)
10
23
  #endif
@@ -115,10 +128,12 @@ static VALUE rb_eGherkinLexerError;
115
128
 
116
129
  action store_comment_content {
117
130
  STORE_ATTR(comment)
131
+ lexer->mark = 0;
118
132
  }
119
133
 
120
134
  action store_tag_content {
121
135
  STORE_ATTR(tag)
136
+ lexer->mark = 0;
122
137
  }
123
138
 
124
139
  action inc_line_number {
@@ -160,7 +175,7 @@ static VALUE rb_eGherkinLexerError;
160
175
 
161
176
  action store_cell_content {
162
177
  VALUE con = Qnil;
163
- con = rb_str_new(PTR_TO(content_start), LEN(content_start, p));
178
+ con = ENCODED_STR_NEW(PTR_TO(content_start), LEN(content_start, p));
164
179
  rb_funcall(con, rb_intern("strip!"), 0);
165
180
 
166
181
  rb_ary_push(current_row, con);
@@ -217,7 +232,7 @@ static VALUE rb_eGherkinLexerError;
217
232
  }
218
233
  }
219
234
 
220
- include lexer_common "lexer_common.<%= i18n_language %>.rl";
235
+ include lexer_common "lexer_common.<%= @i18n %>.rl";
221
236
 
222
237
  }%%
223
238
 
@@ -251,8 +266,8 @@ store_kw_con(VALUE listener, const char * event_name,
251
266
  int current_line)
252
267
  {
253
268
  VALUE con = Qnil, kw = Qnil;
254
- kw = rb_str_new(keyword_at, keyword_length);
255
- con = rb_str_new(at, length);
269
+ kw = ENCODED_STR_NEW(keyword_at, keyword_length);
270
+ con = ENCODED_STR_NEW(at, length);
256
271
  con = multiline_strip(con);
257
272
  rb_funcall(con, rb_intern("strip!"), 0);
258
273
  rb_funcall(kw, rb_intern("strip!"), 0);
@@ -264,7 +279,7 @@ store_attr(VALUE listener, const char * attr_type,
264
279
  const char * at, size_t length,
265
280
  int line)
266
281
  {
267
- VALUE val = rb_str_new(at, length);
282
+ VALUE val = ENCODED_STR_NEW(at, length);
268
283
  rb_funcall(listener, rb_intern(attr_type), 2, val, INT2FIX(line));
269
284
  }
270
285
 
@@ -274,8 +289,8 @@ store_pystring_content(VALUE listener,
274
289
  const char *at, size_t length,
275
290
  int current_line)
276
291
  {
277
- VALUE con = rb_str_new(at, length);
278
- // Gherkin will crash gracefully if the string representation of start_col pushes the pattern past 64 characters
292
+ VALUE con = ENCODED_STR_NEW(at, length);
293
+ // Gherkin will crash gracefully if the string representation of start_col pushes the pattern past 32 characters
279
294
  char pat[32];
280
295
  snprintf(pat, 32, "^ {0,%d}", start_col);
281
296
  VALUE re = rb_reg_regcomp(rb_str_new2(pat));
@@ -331,9 +346,10 @@ static VALUE CLexer_scan(VALUE self, VALUE input)
331
346
  lexer_state *lexer = NULL;
332
347
  DATA_GET(self, lexer_state, lexer);
333
348
 
334
- rb_str_append(input, rb_str_new2("\n%_FEATURE_END_%"));
335
- char *data = RSTRING_PTR(input);
336
- long len = RSTRING_LEN(input);
349
+ VALUE input_copy = rb_str_dup(input);
350
+ rb_str_append(input_copy, rb_str_new2("\n%_FEATURE_END_%"));
351
+ char *data = RSTRING_PTR(input_copy);
352
+ long len = RSTRING_LEN(input_copy);
337
353
 
338
354
  if (len == 0) {
339
355
  rb_raise(rb_eGherkinLexerError, "No content to lex.");
@@ -371,14 +387,14 @@ static VALUE CLexer_scan(VALUE self, VALUE input)
371
387
  }
372
388
  }
373
389
 
374
- void Init_gherkin_lexer()
390
+ void Init_gherkin_lexer_<%= @i18n %>()
375
391
  {
376
392
  mGherkin = rb_define_module("Gherkin");
377
393
  mLexer = rb_const_get(mGherkin, rb_intern("Lexer"));
378
394
  rb_eGherkinLexerError = rb_const_get(mLexer, rb_intern("LexingError"));
379
395
 
380
396
  mCLexer = rb_define_module_under(mGherkin, "CLexer");
381
- cI18nLexer = rb_define_class_under(mCLexer, "En", rb_cObject);
397
+ cI18nLexer = rb_define_class_under(mCLexer, "<%= @i18n.capitalize %>", rb_cObject);
382
398
  rb_define_alloc_func(cI18nLexer, CLexer_alloc);
383
399
  rb_define_method(cI18nLexer, "initialize", CLexer_init, 1);
384
400
  rb_define_method(cI18nLexer, "scan", CLexer_scan, 1);