Skip to content

Commit 3fe9dbe

Browse files
committed
Implement StringScanner for TruffleRuby in pure Ruby
* Fixes #194. * This is a fresh new implementation from scratch, contributed directly to ruby/strscan, under BSD-2-Clause. This was implemented using the strscan tests, specs from ruby/spec and the documentation (https://docs.ruby-lang.org/en/master/StringScanner.html). * lib/strscan.rb now handles the loading for all implementations. * Test on TruffleRuby 33 to ensure it keeps working on older TruffleRuby releases, which do not have the necessary Primitives used by this new implementation.
1 parent 104dd1a commit 3fe9dbe

File tree

8 files changed

+476
-12
lines changed

8 files changed

+476
-12
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ jobs:
2929
- { os: windows-latest , ruby: mingw }
3030
- { os: windows-latest , ruby: mswin }
3131
- { os: ubuntu-latest , ruby: jruby-9.4 }
32+
- { os: ubuntu-latest , ruby: truffleruby-33 }
3233
exclude:
3334
- { os: macos-latest , ruby: 2.4 }
3435
- { os: ubuntu-latest , ruby: 2.5 }

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ if RUBY_ENGINE == "jruby"
3131
ext.target_version = '1.8'
3232
ext.ext_dir = 'ext/jruby'
3333
end
34-
extra_require_path = "ext/jruby/lib"
34+
extra_require_path = "lib"
3535
elsif RUBY_ENGINE == "ruby"
3636
require 'rake/extensiontask'
3737
Rake::ExtensionTask.new("strscan") do |x|

ext/jruby/lib/strscan.rb

Lines changed: 0 additions & 3 deletions
This file was deleted.

ext/strscan/strscan.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2299,6 +2299,4 @@ Init_strscan(void)
22992299
rb_define_method(StringScanner, "fixed_anchor?", strscan_fixed_anchor_p, 0);
23002300

23012301
rb_define_method(StringScanner, "named_captures", strscan_named_captures, 0);
2302-
2303-
rb_require("strscan/strscan");
23042302
}

lib/strscan.rb

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
case RUBY_ENGINE
2+
when 'ruby'
3+
require 'strscan.so'
4+
require_relative 'strscan/strscan'
5+
when 'jruby'
6+
require 'strscan.jar'
7+
JRuby::Util.load_ext('org.jruby.ext.strscan.StringScannerLibrary')
8+
require_relative 'strscan/strscan'
9+
when 'truffleruby'
10+
if RUBY_ENGINE_VERSION.to_i >= 34
11+
require 'strscan/truffleruby_strscan'
12+
require_relative 'strscan/strscan'
13+
else
14+
$LOAD_PATH.delete __dir__
15+
require 'strscan'
16+
end
17+
else
18+
raise "Unknown Ruby: #{RUBY_ENGINE}"
19+
end

0 commit comments

Comments
 (0)