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 +4 -4
- data/CHANGELOG.md +12 -0
- data/README.md +6 -0
- data/lib/birman/matchers.rb +11 -4
- data/lib/birman/version.rb +1 -1
- 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: 6e56dfecb27c1584f8aefdb873503084e140abf83d53f2b85ed453ad1e25dbbe
|
|
4
|
+
data.tar.gz: 35b4ee8725298c3809fbde953f51fca4c550ac207a68a2eade43ad7745e02b15
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
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
data/lib/birman/matchers.rb
CHANGED
|
@@ -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
|
-
|
|
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
|
|
295
|
-
#
|
|
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?
|
|
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)
|
data/lib/birman/version.rb
CHANGED