Skip to content

Commit c0101cf

Browse files
authored
Merge pull request #21 from nitely/nim_0_19
support nim 0.19
2 parents bd4d338 + 7829b0e commit c0101cf

File tree

8 files changed

+300
-217
lines changed

8 files changed

+300
-217
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
services:
22
- docker
33
env:
4-
- NIM=0.17.2
54
- NIM=0.18.0-alpine
5+
- NIM=0.19.0-alpine
66
before_install:
77
- docker pull nimlang/nim:$NIM
88
script:

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
v0.8.0
2+
==================
3+
4+
* Drop Nim 0.17 support
5+
* Add Nim 0.19 support
6+
* Update dependencies
7+
* Remove deprecated `match` and `find`
8+
returning `Option[RegexMatch]`
9+
110
v0.7.4
211
==================
312

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ nimble install regex
2121

2222
# Compatibility
2323

24-
Nim 0.17.2, 0.18.0
24+
Nim 0.18.0, +0.19.0
2525

2626
## Docs
2727

docs/index.html

Lines changed: 88 additions & 85 deletions
Large diffs are not rendered by default.

regex.nimble

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# Package
22

3-
version = "0.7.4"
3+
version = "0.8.0"
44
author = "Esteban Castro Borsani (@nitely)"
55
description = "Linear time regex matching"
66
license = "MIT"
77
srcDir = "src"
88
skipDirs = @["tests"]
99

10-
requires "nim >= 0.17.2"
11-
requires "unicodedb >= 0.5.1 & < 0.6"
12-
requires "unicodeplus >= 0.3.0 & < 0.4"
10+
requires "nim >= 0.18.0"
11+
requires "unicodedb >= 0.6.0 & < 0.7"
12+
requires "unicodeplus >= 0.4.0 & < 0.5"
1313

1414
task test, "Test":
1515
exec "nim c -r src/regex.nim"

src/regex.nim

Lines changed: 20 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -153,15 +153,12 @@ import algorithm
153153
import strutils
154154
import sets
155155
import tables
156-
import options
157156
import parseutils
158157

159158
import unicodedb/properties
160159
import unicodedb/types
161160
import unicodeplus except isUpper, isLower
162161

163-
export Option, isSome, get
164-
165162
type
166163
RegexError* = object of ValueError
167164
## raised when the pattern
@@ -2043,7 +2040,8 @@ iterator group*(m: RegexMatch, i: int): Slice[int] =
20432040
## let
20442041
## expected = ["a", "b", "c"]
20452042
## text = "abc"
2046-
## m = text.match(re"(\w)+").get()
2043+
## var m: RegexMatch
2044+
## doAssert text.match(re"(\w)+", m)
20472045
## var i = 0
20482046
## for bounds in m.group(0):
20492047
## doAssert(expected[i] == text[bounds])
@@ -2064,7 +2062,8 @@ iterator group*(m: RegexMatch, s: string): Slice[int] =
20642062
## let
20652063
## expected = ["a", "b", "c"]
20662064
## text = "abc"
2067-
## m = text.match(re"(?P<foo>\w)+").get()
2065+
## var m: RegexMatch
2066+
## doAssert text.match(re"(?P<foo>\w)+", m)
20682067
## var i = 0
20692068
## for bounds in m.group("foo"):
20702069
## doAssert(expected[i] == text[bounds])
@@ -2082,8 +2081,14 @@ proc groupsCount*(m: RegexMatch): int =
20822081
## return the number of capturing groups
20832082
##
20842083
## .. code-block:: nim
2085-
## doAssert("ab".match(re"(a)(b)").get().groupsCount == 2)
2086-
## doAssert("ab".match(re"((ab))").get().groupsCount == 2)
2084+
## block:
2085+
## var m: RegexMatch
2086+
## doAssert "ab".match(re"(a)(b)", m)
2087+
## doAssert m.groupsCount == 2
2088+
## block:
2089+
## var m: RegexMatch
2090+
## doAssert "ab".match(re"((ab))", m)
2091+
## doAssert m.groupsCount == 2
20872092
##
20882093
m.groups.len
20892094

@@ -2177,10 +2182,7 @@ proc populateCaptures(
21772182
# then calculate slices for each match
21782183
# (a group can have multiple matches).
21792184
# Note the given `capture` is in reverse order (leaf to root)
2180-
if result.groups.len == 0: # todo: remove in Nim 0.18.1
2181-
result.groups = newSeq[Slice[int]](gc)
2182-
else:
2183-
result.groups.setLen(gc)
2185+
result.groups.setLen(gc)
21842186
var
21852187
curr = cIdx
21862188
ci = 0
@@ -2198,10 +2200,7 @@ proc populateCaptures(
21982200
else:
21992201
g.b = -1 # 0 .. -1
22002202
assert ci mod 2 == 0
2201-
if result.captures.len == 0: # todo: remove in Nim 0.18.1
2202-
result.captures = newSeq[Slice[int]](ci div 2)
2203-
else:
2204-
result.captures.setLen(ci div 2)
2203+
result.captures.setLen(ci div 2)
22052204
curr = cIdx
22062205
while curr != 0:
22072206
let
@@ -2406,15 +2405,6 @@ proc match*(
24062405
pattern.groupsCount > 0)
24072406
result = matchImpl(ds, s, pattern, m, start)
24082407

2409-
proc match*(
2410-
s: string,
2411-
pattern: Regex,
2412-
start=0): Option[RegexMatch] {.deprecated.} =
2413-
## Deprecated, use ``match(string, Regex, var RegexMatch)`` instead
2414-
var m = RegexMatch()
2415-
if match(s, pattern, m, start):
2416-
result = some(m)
2417-
24182408
proc contains*(s: string, pattern: Regex): bool =
24192409
## search for the pattern anywhere
24202410
## in the string. It returns as soon
@@ -2514,15 +2504,6 @@ proc find*(
25142504
pattern.groupsCount > 0)
25152505
result = findImpl(ds, s, pattern, m, start)
25162506

2517-
proc find*(
2518-
s: string,
2519-
pattern: Regex,
2520-
start = 0): Option[RegexMatch] {.deprecated.} =
2521-
## Deprecated, use ``find(string, Regex, var RegexMatch)`` instead
2522-
var m = RegexMatch()
2523-
if find(s, pattern, m, start):
2524-
result = some(m)
2525-
25262507
template runeIncAt(s: string, n: var int) =
25272508
## increment ``n`` up to
25282509
## next rune's index
@@ -2558,9 +2539,12 @@ iterator findAll*(
25582539
##
25592540
## .. code-block:: nim
25602541
## var i = 0
2561-
## let expected = [1 .. 2, 4 .. 5]
2562-
## for m in findAll("abcabc", re"bc"):
2563-
## doAssert(m.boundaries == expected[i])
2542+
## let
2543+
## expected = [1 .. 2, 4 .. 5]
2544+
## text = "abcabc"
2545+
## for m in findAll(text, re"bc"):
2546+
## doAssert text[m.boundaries] == "bc"
2547+
## doAssert m.boundaries == expected[i]
25642548
## inc i
25652549
##
25662550
for m in findAllImpl(s, pattern, start):
@@ -2570,14 +2554,6 @@ proc findAll*(s: string, pattern: Regex, start = 0): seq[RegexMatch] =
25702554
## search through the string and
25712555
## return each match. Empty matches
25722556
## (start > end) are included
2573-
##
2574-
## .. code-block:: nim
2575-
## let
2576-
## expected = [1 .. 2, 4 .. 5]
2577-
## ms = findAll("abcabc", re"bc")
2578-
## for i, m in ms:
2579-
## doAssert(m.boundaries == expected[i])
2580-
##
25812557
result = newSeqOfCap[RegexMatch](s.len)
25822558
for slc in findAll(s, pattern, start):
25832559
result.add(slc)

0 commit comments

Comments
 (0)