regexes 0.1.0 → 0.1.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: 7f272f5116d87f990a3f5acb0ca3fdcb105fbe981c8f9a3e9718505089279f83
4
- data.tar.gz: 1817efa5a01462e65a3e7bbcb0c13ecdbeb472ed4293a2c2300dd549c577abc7
3
+ metadata.gz: 22f968c2e09f83bc3d719faca12f94f1bf33cf67952b1b4efbbd990074b961a0
4
+ data.tar.gz: 3b4d1a1354d3d4d7150a109c76dec69e035bff4821e1aacc0b9872d62083574f
5
5
  SHA512:
6
- metadata.gz: 98a99c67338f7865fbb5e0900d3e38b9abea6d00959a44e8ad9d15740943791da85d5e08180e49d747d66c0e70df8af17addda11c31061371c04277431f0112b
7
- data.tar.gz: 7a58255860694fa63fffc664fe88c36ad1c827223f608fcbb17f2b2cd4305896720133fe643958a492ee7d3a74ca9ae6c977bc25315bc5033053c82ab3cfe485
6
+ metadata.gz: 1ece47cfdff4bb11dc0432831b67be30039e5ce1ba6625a65fd0023560f91f36dc2d08e39564badc10fa05e96a0acd1e9f9b781b50267ee920003501b342e1a6
7
+ data.tar.gz: e39fa7a4df61bf7b9ced1f7919a36bdbd46da2999a3e6f06666a539cdb638ed7c457f63ec6649459343ab35a9a71ff8f85fb7aebbe31aa41da7500720582a223
data/CHANGELOG.md CHANGED
@@ -1,5 +1,14 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.1 - 2026-11-22
4
+
5
+ ### Changed
6
+
7
+ - `leading`, `trailing` and `whole` leave out a boundary of one set at the end they anchor to the text:
8
+ `Regexes.uuid.whole` is `\A[0-9a-fA-F]{8}-…\z`, no longer `\A(?<![0-9a-fA-F])…(?![0-9a-fA-F])\z`.
9
+ Nothing lies past an anchored end for the boundary to refuse, so every pattern matches what it did;
10
+ `ecma_source` is shorter, and a JSON Schema built from it reads as one written by hand.
11
+
3
12
  ## 0.1.0 - 2026-11-21
4
13
 
5
14
  ### Added
data/README.md CHANGED
@@ -111,7 +111,7 @@ Every pattern but `emoji` translates into ECMAScript, for the browser, a mobile
111
111
  `pattern`:
112
112
 
113
113
  ```ruby
114
- Regexes.uuid.whole.ecma_source # => "^(?<![0-9a-fA-F])[0-9a-fA-F]{8}-…$"
114
+ Regexes.uuid.whole.ecma_source # => "^[0-9a-fA-F]{8}-…$"
115
115
  Regexes.uuid.whole.ecma_flags # => "u"
116
116
  ```
117
117
 
@@ -22,18 +22,24 @@ module Regexes
22
22
  class Expression < Regexp
23
23
  # What each kind of anchor writes at the start. A line starts at the start of the text, after a line feed,
24
24
  # and after a carriage return that no line feed follows, so +\r\n+, +\r+ and +\n+ each end one line.
25
- STARTS = {
25
+ STARTS = {
26
26
  text: '\A',
27
27
  line: '(?:\A|(?<=\n)|(?<=\r)(?!\n))'
28
28
  }.freeze
29
29
  # What each kind of anchor writes at the end. A line ends at the end of the text, before a carriage return,
30
30
  # and before a line feed that no carriage return comes before.
31
- ENDS = {
31
+ ENDS = {
32
32
  text: '\z',
33
33
  line: '(?:(?=\r|\z)|(?<!\r)(?=\n))'
34
34
  }.freeze
35
35
  # What a capture's name may be: what Ruby allows as one, and what +MatchData#[]+ reads by.
36
- CAPTURE_NAME = /\A[A-Za-z_][A-Za-z0-9_]*\z/
36
+ CAPTURE_NAME = /\A[A-Za-z_][A-Za-z0-9_]*\z/
37
+ # A negative lookbehind of one bracketed set, opening a body. It refuses one character before the match,
38
+ # so at the start of the text, where there is none, it always holds.
39
+ EDGE_LOOKBEHIND = /\A\(\?<!\[(?:\\.|[^\]\\])+\]\)/
40
+ # A negative lookahead of one bracketed set, closing a body. It refuses one character after the match, so
41
+ # at the end of the text it always holds.
42
+ EDGE_LOOKAHEAD = /\(\?!\[(?:\\.|[^\]\\])+\]\)\z/
37
43
 
38
44
  # @param body [String] the expression's source, without anchors
39
45
  # @param start [Symbol, nil] where it must match from: +:text+ (the text's start), +:line+ (a line's) or nil
@@ -45,7 +51,7 @@ module Regexes
45
51
  @start = start
46
52
  @finish = finish
47
53
  @single = single
48
- super("#{STARTS.fetch(start) if start}#{body}#{ENDS.fetch(finish) if finish}", options)
54
+ super("#{STARTS.fetch(start) if start}#{edged(body, start, finish)}#{ENDS.fetch(finish) if finish}", options)
49
55
  freeze
50
56
  end
51
57
 
@@ -206,7 +212,7 @@ module Regexes
206
212
  # The expression as ECMAScript writes it, for JavaScript (+new RegExp(source, flags)+, with {#ecma_flags})
207
213
  # and for a JSON Schema +pattern+. Anchors become +^+ and +$+, which there anchor to the text:
208
214
  #
209
- # Regexes.uuid.whole.ecma_source # => "^(?<![0-9a-fA-F])[0-9a-fA-F]{8}-…(?![0-9a-fA-F])$"
215
+ # Regexes.uuid.whole.ecma_source # => "^[0-9a-fA-F]{8}-…-[0-9a-fA-F]{12}$"
210
216
  #
211
217
  # A JSON Schema +pattern+ searches, as an unanchored expression does, so give it a +.whole+ expression's.
212
218
  #
@@ -227,6 +233,19 @@ module Regexes
227
233
 
228
234
  private
229
235
 
236
+ # The body as written between the anchors: a boundary at an end anchored to the text is left out, since
237
+ # nothing lies past that end for it to refuse. Searching keeps every boundary; the match is the same.
238
+ #
239
+ # @param body [String] the expression's source, without anchors
240
+ # @param start [Symbol, nil] the start's anchor, as for {#initialize}
241
+ # @param finish [Symbol, nil] the end's anchor, as for {#initialize}
242
+ # @return [String] the body without the boundaries its text anchors make redundant
243
+ def edged(body, start, finish)
244
+ body = body.sub(EDGE_LOOKBEHIND, '') if start == :text
245
+ body = body.sub(EDGE_LOOKAHEAD, '') if finish == :text
246
+ body
247
+ end
248
+
230
249
  # @param changes [Hash{Symbol => Object}] what differs from this expression
231
250
  # @return [Expression] this expression with the changes
232
251
  def varied(**changes)
@@ -2,5 +2,5 @@
2
2
 
3
3
  module Regexes
4
4
  # The library's version.
5
- VERSION = '0.1.0'
5
+ VERSION = '0.1.1'
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: regexes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Scholl