fast_regexp 0.5.0-aarch64-linux → 0.6.1-aarch64-linux
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +19 -6
- data/lib/fast_regexp/3.3/fast_regexp.so +0 -0
- data/lib/fast_regexp/3.4/fast_regexp.so +0 -0
- data/lib/fast_regexp/4.0/fast_regexp.so +0 -0
- data/lib/fast_regexp/version.rb +1 -1
- data/lib/fast_regexp.rb +47 -16
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9e8f43c5d2a9aa1903943558c35ab6a46b15df0b752c652f6442bd6a328bce7c
|
|
4
|
+
data.tar.gz: 666effbf46f4db06dbc5b644c88202daac203e7c167cf060cbb5d1f2e63d66a5
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 38ca3692c0b727e5003acca7e24031b73c19fd2957bfbe715dae5c5edd2065fa93ba9e665d2f6cebbc721513957c25193c5c5ca3125e6be59bbc236244fefe52
|
|
7
|
+
data.tar.gz: '040688216ab69d2ab613548b3dab2b798e90a776c2cff4d107ddc9f4208943b0439cb8d8124128dcb6015b81a316eae4cf8f8cc49d44bdcf5a7126c6b6216146'
|
data/README.md
CHANGED
|
@@ -5,12 +5,10 @@
|
|
|
5
5
|
|
|
6
6
|
Fast, drop-in regex for Ruby — backed by [rust/regex](https://docs.rs/regex/latest/regex/) with transparent fallback to the stdlib `::Regexp` engine for features rust/regex doesn't support (lookaround, backreferences, possessive quantifiers, etc.).
|
|
7
7
|
|
|
8
|
-
You get rust/regex's speed
|
|
8
|
+
You get rust/regex's speed on the common path, and a single uniform API (`Fast::Regexp`, `Fast::Regexp::MatchData`) regardless of which engine actually ran underneath.
|
|
9
9
|
|
|
10
10
|
## Installation
|
|
11
11
|
|
|
12
|
-
Install [Rust](https://www.rust-lang.org/) via [rustup](https://rustup.rs/) or in any other way.
|
|
13
|
-
|
|
14
12
|
Add as a dependency:
|
|
15
13
|
|
|
16
14
|
```ruby
|
|
@@ -21,6 +19,14 @@ gem "fast_regexp"
|
|
|
21
19
|
gem install fast_regexp
|
|
22
20
|
```
|
|
23
21
|
|
|
22
|
+
Precompiled native gems are published for **arm64-darwin**, **x86_64-linux**,
|
|
23
|
+
and **aarch64-linux** against Ruby **3.3**, **3.4**, and **4.0** — no Rust
|
|
24
|
+
toolchain required on those platforms.
|
|
25
|
+
|
|
26
|
+
On any other platform/Ruby combo, Bundler/RubyGems falls back to the source
|
|
27
|
+
gem and compiles the extension at install time. That path needs
|
|
28
|
+
[Rust](https://www.rust-lang.org/) (install via [rustup](https://rustup.rs/)).
|
|
29
|
+
|
|
24
30
|
Include in your code:
|
|
25
31
|
|
|
26
32
|
```ruby
|
|
@@ -155,6 +161,14 @@ slow.match?("foobar") # => true
|
|
|
155
161
|
/ `#stdlib` accessors. Replacement templates use rust/regex syntax (`$1`,
|
|
156
162
|
`${name}`, `$$`) on both paths; the stdlib fallback translates them for you.
|
|
157
163
|
|
|
164
|
+
You can force a specific engine via the `backend:` kwarg:
|
|
165
|
+
|
|
166
|
+
```ruby
|
|
167
|
+
Fast::Regexp.new('\w+', backend: :fast) # rust/regex only; raises on unsupported
|
|
168
|
+
Fast::Regexp.new(pat, backend: :stdlib) # skip rust/regex; use ::Regexp directly
|
|
169
|
+
Fast::Regexp.new('\w+', backend: :auto) # default — try rust, fall back on reject
|
|
170
|
+
```
|
|
171
|
+
|
|
158
172
|
> [!NOTE]
|
|
159
173
|
> The fast path is byte-based (rust/regex's `regex::bytes`), so `#=~` returns
|
|
160
174
|
> a *byte* offset. The stdlib fallback path returns the byte offset too, for
|
|
@@ -230,7 +244,7 @@ In-depth docs live under [`docs/`](docs/README.md), organized via the
|
|
|
230
244
|
- **Tutorial:** [Getting started](docs/tutorials/getting-started.md)
|
|
231
245
|
- **How-to:** [Migrate from stdlib `::Regexp`](docs/how-to/migrate-from-stdlib-regexp.md), [Handle unsupported syntax](docs/how-to/handle-unsupported-syntax.md)
|
|
232
246
|
- **Reference:** [`Fast::Regexp`](docs/reference/fast-regexp.md), [`MatchData`](docs/reference/fast-regexp-matchdata.md), [`Set`](docs/reference/fast-regexp-set.md)
|
|
233
|
-
- **Explainers:** [Engine fallback](docs/explainers/engine-fallback.md)
|
|
247
|
+
- **Explainers:** [Engine fallback](docs/explainers/engine-fallback.md)
|
|
234
248
|
|
|
235
249
|
## Development
|
|
236
250
|
|
|
@@ -252,8 +266,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jetpks
|
|
|
252
266
|
huge thanks for the original bindings and the clean magnus integration that
|
|
253
267
|
made this work easy to extend. This fork rebrands the gem, reshapes the
|
|
254
268
|
public API (`Fast::Regexp`, real `MatchData`, `sub`/`gsub`, `===`/`=~`,
|
|
255
|
-
`Regexp`-constructor coercion),
|
|
256
|
-
thread/fiber-friendly matching, and adds transparent fallback to stdlib
|
|
269
|
+
`Regexp`-constructor coercion), and adds transparent fallback to stdlib
|
|
257
270
|
`::Regexp` for patterns rust/regex can't compile.
|
|
258
271
|
|
|
259
272
|
## License
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/fast_regexp/version.rb
CHANGED
data/lib/fast_regexp.rb
CHANGED
|
@@ -6,16 +6,27 @@ module Fast
|
|
|
6
6
|
# Façade over rust/regex with a transparent fallback to stdlib `::Regexp`.
|
|
7
7
|
#
|
|
8
8
|
# `Fast::Regexp.new(pattern)` first tries to compile with rust/regex (fast,
|
|
9
|
-
#
|
|
10
|
-
#
|
|
11
|
-
#
|
|
9
|
+
# byte-based). If the pattern uses features rust/regex does not support
|
|
10
|
+
# (lookaround, backreferences, possessive quantifiers, etc.) we fall back
|
|
11
|
+
# to `::Regexp` so consumers don't have to juggle two libraries.
|
|
12
12
|
class Regexp
|
|
13
|
+
NATIVE_EXTENSIONS = %w[.bundle .so .rb].freeze
|
|
14
|
+
|
|
15
|
+
# Precompiled native gems ship per-ABI subdirs (`fast_regexp/4.0/...`),
|
|
16
|
+
# the source-gem `rake compile` build lands flat (`fast_regexp/...`).
|
|
17
|
+
# Pick whichever exists for the current Ruby ABI, with the per-ABI path
|
|
18
|
+
# winning when both are present.
|
|
19
|
+
def self.locate_native(base, ruby_version: RUBY_VERSION)
|
|
20
|
+
abi = ruby_version[/\d+\.\d+/]
|
|
21
|
+
candidates = [File.join(base, abi, "fast_regexp"), File.join(base, "fast_regexp")]
|
|
22
|
+
candidates.find { |stem| NATIVE_EXTENSIONS.any? { |ext| File.exist?(stem + ext) } }
|
|
23
|
+
end
|
|
13
24
|
end
|
|
14
25
|
end
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
27
|
+
native = Fast::Regexp.locate_native(File.expand_path("fast_regexp", __dir__))
|
|
28
|
+
raise LoadError, "could not locate fast_regexp native extension" unless native
|
|
29
|
+
require native
|
|
19
30
|
|
|
20
31
|
module Fast
|
|
21
32
|
class Regexp
|
|
@@ -34,6 +45,15 @@ module Fast
|
|
|
34
45
|
allocate.tap { |re| re.send(:initialize, translated, original: pattern, **opts) }
|
|
35
46
|
end
|
|
36
47
|
|
|
48
|
+
# Bulk-compile a symbol-keyed hash of patterns. Handy for defining a set
|
|
49
|
+
# of regex constants in one shot:
|
|
50
|
+
#
|
|
51
|
+
# RE = Fast::Regexp.create_many(word: '\w+', num: '\d+').freeze
|
|
52
|
+
# RE[:word].match("hello")
|
|
53
|
+
def create_many(**patterns)
|
|
54
|
+
patterns.transform_values { |pat| new(pat) }
|
|
55
|
+
end
|
|
56
|
+
|
|
37
57
|
private
|
|
38
58
|
|
|
39
59
|
def translate_regexp(regexp)
|
|
@@ -46,11 +66,17 @@ module Fast
|
|
|
46
66
|
|
|
47
67
|
attr_reader :pattern, :backend
|
|
48
68
|
|
|
69
|
+
BACKENDS = %i[auto fast stdlib].freeze
|
|
70
|
+
|
|
49
71
|
# Internal — use `Fast::Regexp.new`. `original` is the unmodified input
|
|
50
72
|
# (String or ::Regexp) so we can build an accurate stdlib fallback.
|
|
51
|
-
|
|
73
|
+
# `backend:` forces a specific engine: `:auto` (default) tries rust/regex
|
|
74
|
+
# and falls back to stdlib, `:fast` raises if rust/regex rejects the
|
|
75
|
+
# pattern, `:stdlib` skips rust/regex entirely.
|
|
76
|
+
def initialize(pattern, original: pattern, backend: :auto, **opts)
|
|
77
|
+
raise ArgumentError, "backend must be one of #{BACKENDS.inspect}" unless BACKENDS.include?(backend)
|
|
52
78
|
@pattern = pattern
|
|
53
|
-
@backend = compile_backend(pattern, original, opts)
|
|
79
|
+
@backend = compile_backend(pattern, original, backend, opts)
|
|
54
80
|
end
|
|
55
81
|
|
|
56
82
|
def fast? = @backend.is_a?(Native)
|
|
@@ -178,17 +204,22 @@ module Fast
|
|
|
178
204
|
count
|
|
179
205
|
end
|
|
180
206
|
|
|
181
|
-
def compile_backend(pattern, original, opts)
|
|
207
|
+
def compile_backend(pattern, original, backend, opts)
|
|
208
|
+
return compile_stdlib(pattern, original) if backend == :stdlib
|
|
182
209
|
Native._native_new(pattern, **opts)
|
|
183
210
|
rescue ArgumentError => e
|
|
211
|
+
raise if backend == :fast
|
|
212
|
+
compile_stdlib(pattern, original, fallback_from: e)
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
def compile_stdlib(pattern, original, fallback_from: nil)
|
|
184
216
|
return original if original.is_a?(::Regexp)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
end
|
|
217
|
+
::Regexp.new(pattern)
|
|
218
|
+
rescue ::RegexpError => e
|
|
219
|
+
# Pattern is malformed in both engines (auto path) — surface the
|
|
220
|
+
# original rust/regex error since it's typically more detailed.
|
|
221
|
+
# Otherwise propagate the stdlib error as-is.
|
|
222
|
+
raise(fallback_from ? ArgumentError.new(fallback_from.message) : e)
|
|
192
223
|
end
|
|
193
224
|
|
|
194
225
|
# Maps positional capture indices to names for the stdlib backend so we
|