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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7d582628d35a655bddbc2957b25874b21ee2c7a53c3cde023c1cf7a2a7570ed2
4
- data.tar.gz: 161d29c08b3897f77248b624904fa26ddf7512ae73f74f31d845ac545d70bfea
3
+ metadata.gz: '039084596a2999534c4e78c9c3fc008ddcf0712a573c93234f4191d9b8e6fd3d'
4
+ data.tar.gz: 8f2629a2a40c5a82c26f73ce9826954bf8de24ab879757c7e672808a3b1edf26
5
5
  SHA512:
6
- metadata.gz: d53c46c5cc47cc38d4b1b64c1c93473850ee5b9ae864538c0792a2675b9bf64496eb7328193678bff35990810be6dbe80340cd74d6dd099fedb6f4f79607a262
7
- data.tar.gz: 280a5bc0c14b490089cc6a3098bceba67bd58dfb347a526c3ee979ad11561888fdb7342a53173c7a854727d352b8ab0cf4f900740f448958e867308ee47834de
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 and GVL-releasing matching on the common path, and a single uniform API (`Fast::Regexp`, `Fast::Regexp::MatchData`) regardless of which engine actually ran underneath.
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), [Concurrency and GVL](docs/explainers/concurrency-and-gvl.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), releases the GVL around regex execution for
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
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Fast
4
4
  class Regexp
5
- VERSION = "0.5.0"
5
+ VERSION = "0.6.0"
6
6
  end
7
7
  end
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
- # GVL-releasing, byte-based). If the pattern uses features rust/regex does
10
- # not support (lookaround, backreferences, possessive quantifiers, etc.) we
11
- # fall back to `::Regexp` so consumers don't have to juggle two libraries.
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
- def initialize(pattern, original: pattern, **opts)
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
- begin
186
- ::Regexp.new(pattern)
187
- rescue ::RegexpError
188
- # Pattern is malformed in both engines surface the original
189
- # rust/regex error so the user sees the more detailed message.
190
- raise ArgumentError, e.message
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
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fast_regexp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Eric Jacobs