fast_regexp 0.5.0-aarch64-linux → 0.6.0-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 +11 -4
- 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 +33 -13
- 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: '039084596a2999534c4e78c9c3fc008ddcf0712a573c93234f4191d9b8e6fd3d'
|
|
4
|
+
data.tar.gz: 8f2629a2a40c5a82c26f73ce9826954bf8de24ab879757c7e672808a3b1edf26
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 415c361fe5761dfcb68d734c970e120189cd2f7770dc8997af51e4572c42ba17f72fa1d04465d3b67d9f191ffc58054b8bff98498a42ff41ad25145ecad0eed1
|
|
7
|
+
data.tar.gz: 2a011e1aa4c1b1c45107fbe93ed9dffe1e5d94e61bfb429e57daa58feeeabf8dca954d85c041dee7cdb5844e5cd7df1b39be1f696fa419e2c65477036cb2a950
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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
|
|
|
@@ -155,6 +155,14 @@ slow.match?("foobar") # => true
|
|
|
155
155
|
/ `#stdlib` accessors. Replacement templates use rust/regex syntax (`$1`,
|
|
156
156
|
`${name}`, `$$`) on both paths; the stdlib fallback translates them for you.
|
|
157
157
|
|
|
158
|
+
You can force a specific engine via the `backend:` kwarg:
|
|
159
|
+
|
|
160
|
+
```ruby
|
|
161
|
+
Fast::Regexp.new('\w+', backend: :fast) # rust/regex only; raises on unsupported
|
|
162
|
+
Fast::Regexp.new(pat, backend: :stdlib) # skip rust/regex; use ::Regexp directly
|
|
163
|
+
Fast::Regexp.new('\w+', backend: :auto) # default — try rust, fall back on reject
|
|
164
|
+
```
|
|
165
|
+
|
|
158
166
|
> [!NOTE]
|
|
159
167
|
> The fast path is byte-based (rust/regex's `regex::bytes`), so `#=~` returns
|
|
160
168
|
> a *byte* offset. The stdlib fallback path returns the byte offset too, for
|
|
@@ -230,7 +238,7 @@ In-depth docs live under [`docs/`](docs/README.md), organized via the
|
|
|
230
238
|
- **Tutorial:** [Getting started](docs/tutorials/getting-started.md)
|
|
231
239
|
- **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
240
|
- **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)
|
|
241
|
+
- **Explainers:** [Engine fallback](docs/explainers/engine-fallback.md)
|
|
234
242
|
|
|
235
243
|
## Development
|
|
236
244
|
|
|
@@ -252,8 +260,7 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/jetpks
|
|
|
252
260
|
huge thanks for the original bindings and the clean magnus integration that
|
|
253
261
|
made this work easy to extend. This fork rebrands the gem, reshapes the
|
|
254
262
|
public API (`Fast::Regexp`, real `MatchData`, `sub`/`gsub`, `===`/`=~`,
|
|
255
|
-
`Regexp`-constructor coercion),
|
|
256
|
-
thread/fiber-friendly matching, and adds transparent fallback to stdlib
|
|
263
|
+
`Regexp`-constructor coercion), and adds transparent fallback to stdlib
|
|
257
264
|
`::Regexp` for patterns rust/regex can't compile.
|
|
258
265
|
|
|
259
266
|
## License
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
data/lib/fast_regexp/version.rb
CHANGED
data/lib/fast_regexp.rb
CHANGED
|
@@ -6,9 +6,9 @@ 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
13
|
end
|
|
14
14
|
end
|
|
@@ -34,6 +34,15 @@ module Fast
|
|
|
34
34
|
allocate.tap { |re| re.send(:initialize, translated, original: pattern, **opts) }
|
|
35
35
|
end
|
|
36
36
|
|
|
37
|
+
# Bulk-compile a symbol-keyed hash of patterns. Handy for defining a set
|
|
38
|
+
# of regex constants in one shot:
|
|
39
|
+
#
|
|
40
|
+
# RE = Fast::Regexp.create_many(word: '\w+', num: '\d+').freeze
|
|
41
|
+
# RE[:word].match("hello")
|
|
42
|
+
def create_many(**patterns)
|
|
43
|
+
patterns.transform_values { |pat| new(pat) }
|
|
44
|
+
end
|
|
45
|
+
|
|
37
46
|
private
|
|
38
47
|
|
|
39
48
|
def translate_regexp(regexp)
|
|
@@ -46,11 +55,17 @@ module Fast
|
|
|
46
55
|
|
|
47
56
|
attr_reader :pattern, :backend
|
|
48
57
|
|
|
58
|
+
BACKENDS = %i[auto fast stdlib].freeze
|
|
59
|
+
|
|
49
60
|
# Internal — use `Fast::Regexp.new`. `original` is the unmodified input
|
|
50
61
|
# (String or ::Regexp) so we can build an accurate stdlib fallback.
|
|
51
|
-
|
|
62
|
+
# `backend:` forces a specific engine: `:auto` (default) tries rust/regex
|
|
63
|
+
# and falls back to stdlib, `:fast` raises if rust/regex rejects the
|
|
64
|
+
# pattern, `:stdlib` skips rust/regex entirely.
|
|
65
|
+
def initialize(pattern, original: pattern, backend: :auto, **opts)
|
|
66
|
+
raise ArgumentError, "backend must be one of #{BACKENDS.inspect}" unless BACKENDS.include?(backend)
|
|
52
67
|
@pattern = pattern
|
|
53
|
-
@backend = compile_backend(pattern, original, opts)
|
|
68
|
+
@backend = compile_backend(pattern, original, backend, opts)
|
|
54
69
|
end
|
|
55
70
|
|
|
56
71
|
def fast? = @backend.is_a?(Native)
|
|
@@ -178,17 +193,22 @@ module Fast
|
|
|
178
193
|
count
|
|
179
194
|
end
|
|
180
195
|
|
|
181
|
-
def compile_backend(pattern, original, opts)
|
|
196
|
+
def compile_backend(pattern, original, backend, opts)
|
|
197
|
+
return compile_stdlib(pattern, original) if backend == :stdlib
|
|
182
198
|
Native._native_new(pattern, **opts)
|
|
183
199
|
rescue ArgumentError => e
|
|
200
|
+
raise if backend == :fast
|
|
201
|
+
compile_stdlib(pattern, original, fallback_from: e)
|
|
202
|
+
end
|
|
203
|
+
|
|
204
|
+
def compile_stdlib(pattern, original, fallback_from: nil)
|
|
184
205
|
return original if original.is_a?(::Regexp)
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
end
|
|
206
|
+
::Regexp.new(pattern)
|
|
207
|
+
rescue ::RegexpError => e
|
|
208
|
+
# Pattern is malformed in both engines (auto path) — surface the
|
|
209
|
+
# original rust/regex error since it's typically more detailed.
|
|
210
|
+
# Otherwise propagate the stdlib error as-is.
|
|
211
|
+
raise(fallback_from ? ArgumentError.new(fallback_from.message) : e)
|
|
192
212
|
end
|
|
193
213
|
|
|
194
214
|
# Maps positional capture indices to names for the stdlib backend so we
|