birman 0.2.0 → 0.2.1

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: dffa403d5b8db3f4c977235997baedda18400899c9f1e692bf196bc6bb645152
4
- data.tar.gz: e62c15487c0f6d1c4494e9103a198677379772f5904112877f8988c41f6be4b2
3
+ metadata.gz: 6e56dfecb27c1584f8aefdb873503084e140abf83d53f2b85ed453ad1e25dbbe
4
+ data.tar.gz: 35b4ee8725298c3809fbde953f51fca4c550ac207a68a2eade43ad7745e02b15
5
5
  SHA512:
6
- metadata.gz: 51c0f918fec494fc1ef09b9af553f8824d486d2861d6a16a1b0bd06f273b20599f4d92844c2232c93dfd72e3b1635d3d8546e3ddee227b8a6406cebd7d67dbaf
7
- data.tar.gz: 39a35b19fb92866e48b8fc80e308af33d70c105f108fa5ca093e35e0df7aa0d8ef29c11922d8cf66ac14baec6263b2f494765d2b4888fe538fb706188f8ef802
6
+ metadata.gz: abf8ca7031fe77792fb4a3e0a2c8480358320b2edfeebe0e8da7de0814cf71cbccc5229cf8fb710ec1ddebd49208a9b6f7cf8d9a3b6a066830b57b7271e90827
7
+ data.tar.gz: bdf4b37b3adcfc42ce7f5eb1bee447c83bbe5cc25ab4795a6478991775f9d913554426abf5c6b1392314f072fced9e7f53b8615ffb4fe5eeb37d0483764ece40
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.2.1] - 2026-10-17
4
+
5
+ - **Fixed:** `rep` and `maybe` over something that can match empty.
6
+ An empty first match now counts, so `match(/a*/).rep(1)` accepts `""`
7
+ and `match(/a*/).maybe` gives `""` instead of `nil`. After real
8
+ matches, an empty one still just ends the repetition. (A plain
9
+ `.rep` over such a matcher now gives `[""]` on empty input, not `[]`.)
10
+ - **Fixed:** a `label` now replaces the low-level expectations when its
11
+ matcher succeeds without consuming anything, as it already did when
12
+ the matcher failed: `str("a").maybe.label("prefix") >> str("b")` on
13
+ `"x"` reports `expected prefix or "b"`.
14
+
3
15
  ## [0.2.0] - 2026-10-17
4
16
 
5
17
  - **Added:** `one_of` takes a hash mapping literals to the values they
data/README.md CHANGED
@@ -17,6 +17,12 @@ memoization, commit points, labels, and `Success`/`Failure` results.
17
17
  bundle add birman
18
18
  ```
19
19
 
20
+ or in your Gemfile:
21
+
22
+ ```ruby
23
+ gem "birman", "~> 0.2.1"
24
+ ```
25
+
20
26
  ```ruby
21
27
  require "birman"
22
28
 
@@ -235,7 +235,13 @@ module Birman
235
235
  values = []
236
236
  while max.nil? || values.size < max
237
237
  r = inner.match(ctx, pos) or break
238
- break if r.pos == pos # an empty match would loop forever
238
+ # Matching nothing ends the loop (repeating it would never stop).
239
+ # It still counts as the first match, so `x.rep(1)` and `x.maybe`
240
+ # work when x can match empty; after real matches it's just the end.
241
+ if r.pos == pos
242
+ values << r.value if values.empty?
243
+ break
244
+ end
239
245
 
240
246
  values << r.value
241
247
  pos = r.pos
@@ -291,8 +297,9 @@ module Birman
291
297
  def capture_key = inner.capture_key
292
298
  end
293
299
 
294
- # Names a matcher for error messages. If inner fails without getting
295
- # past its starting position, the error says "expected <name>"
300
+ # Names a matcher for error messages. If inner fails (or succeeds
301
+ # while consuming nothing) without getting past its starting
302
+ # position, the error says "expected <name>"
296
303
  # instead of listing every low-level alternative. If it got further,
297
304
  # the deeper (more specific) error is kept.
298
305
  Label = Data.define(:inner, :name) do
@@ -300,7 +307,7 @@ module Birman
300
307
 
301
308
  def match(ctx, pos)
302
309
  result, furthest, expected = ctx.isolate(pos) { inner.match(ctx, pos) }
303
- if result.nil? && furthest == pos
310
+ if furthest == pos && (result.nil? || (result.pos == pos && expected.any?))
304
311
  ctx.fail_at(pos, name)
305
312
  else
306
313
  ctx.merge(furthest, expected)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Birman
4
- VERSION = "0.2.0"
4
+ VERSION = "0.2.1"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birman
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tad Thorley