Skip to content

Commit

Permalink
Merge pull request #21 from nitely/nim_0_19
Browse files Browse the repository at this point in the history
support nim 0.19
  • Loading branch information
nitely committed Oct 8, 2018
2 parents bd4d338 + 7829b0e commit c0101cf
Show file tree
Hide file tree
Showing 8 changed files with 300 additions and 217 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
services:
- docker
env:
- NIM=0.17.2
- NIM=0.18.0-alpine
- NIM=0.19.0-alpine
before_install:
- docker pull nimlang/nim:$NIM
script:
Expand Down
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
v0.8.0
==================

* Drop Nim 0.17 support
* Add Nim 0.19 support
* Update dependencies
* Remove deprecated `match` and `find`
returning `Option[RegexMatch]`

v0.7.4
==================

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ nimble install regex

# Compatibility

Nim 0.17.2, 0.18.0
Nim 0.18.0, +0.19.0

## Docs

Expand Down
173 changes: 88 additions & 85 deletions docs/index.html

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions regex.nimble
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
# Package

version = "0.7.4"
version = "0.8.0"
author = "Esteban Castro Borsani (@nitely)"
description = "Linear time regex matching"
license = "MIT"
srcDir = "src"
skipDirs = @["tests"]

requires "nim >= 0.17.2"
requires "unicodedb >= 0.5.1 & < 0.6"
requires "unicodeplus >= 0.3.0 & < 0.4"
requires "nim >= 0.18.0"
requires "unicodedb >= 0.6.0 & < 0.7"
requires "unicodeplus >= 0.4.0 & < 0.5"

task test, "Test":
exec "nim c -r src/regex.nim"
Expand Down
64 changes: 20 additions & 44 deletions src/regex.nim
Original file line number Diff line number Diff line change
Expand Up @@ -153,15 +153,12 @@ import algorithm
import strutils
import sets
import tables
import options
import parseutils

import unicodedb/properties
import unicodedb/types
import unicodeplus except isUpper, isLower

export Option, isSome, get

type
RegexError* = object of ValueError
## raised when the pattern
Expand Down Expand Up @@ -2043,7 +2040,8 @@ iterator group*(m: RegexMatch, i: int): Slice[int] =
## let
## expected = ["a", "b", "c"]
## text = "abc"
## m = text.match(re"(\w)+").get()
## var m: RegexMatch
## doAssert text.match(re"(\w)+", m)
## var i = 0
## for bounds in m.group(0):
## doAssert(expected[i] == text[bounds])
Expand All @@ -2064,7 +2062,8 @@ iterator group*(m: RegexMatch, s: string): Slice[int] =
## let
## expected = ["a", "b", "c"]
## text = "abc"
## m = text.match(re"(?P<foo>\w)+").get()
## var m: RegexMatch
## doAssert text.match(re"(?P<foo>\w)+", m)
## var i = 0
## for bounds in m.group("foo"):
## doAssert(expected[i] == text[bounds])
Expand All @@ -2082,8 +2081,14 @@ proc groupsCount*(m: RegexMatch): int =
## return the number of capturing groups
##
## .. code-block:: nim
## doAssert("ab".match(re"(a)(b)").get().groupsCount == 2)
## doAssert("ab".match(re"((ab))").get().groupsCount == 2)
## block:
## var m: RegexMatch
## doAssert "ab".match(re"(a)(b)", m)
## doAssert m.groupsCount == 2
## block:
## var m: RegexMatch
## doAssert "ab".match(re"((ab))", m)
## doAssert m.groupsCount == 2
##
m.groups.len

Expand Down Expand Up @@ -2177,10 +2182,7 @@ proc populateCaptures(
# then calculate slices for each match
# (a group can have multiple matches).
# Note the given `capture` is in reverse order (leaf to root)
if result.groups.len == 0: # todo: remove in Nim 0.18.1
result.groups = newSeq[Slice[int]](gc)
else:
result.groups.setLen(gc)
result.groups.setLen(gc)
var
curr = cIdx
ci = 0
Expand All @@ -2198,10 +2200,7 @@ proc populateCaptures(
else:
g.b = -1 # 0 .. -1
assert ci mod 2 == 0
if result.captures.len == 0: # todo: remove in Nim 0.18.1
result.captures = newSeq[Slice[int]](ci div 2)
else:
result.captures.setLen(ci div 2)
result.captures.setLen(ci div 2)
curr = cIdx
while curr != 0:
let
Expand Down Expand Up @@ -2406,15 +2405,6 @@ proc match*(
pattern.groupsCount > 0)
result = matchImpl(ds, s, pattern, m, start)

proc match*(
s: string,
pattern: Regex,
start=0): Option[RegexMatch] {.deprecated.} =
## Deprecated, use ``match(string, Regex, var RegexMatch)`` instead
var m = RegexMatch()
if match(s, pattern, m, start):
result = some(m)

proc contains*(s: string, pattern: Regex): bool =
## search for the pattern anywhere
## in the string. It returns as soon
Expand Down Expand Up @@ -2514,15 +2504,6 @@ proc find*(
pattern.groupsCount > 0)
result = findImpl(ds, s, pattern, m, start)

proc find*(
s: string,
pattern: Regex,
start = 0): Option[RegexMatch] {.deprecated.} =
## Deprecated, use ``find(string, Regex, var RegexMatch)`` instead
var m = RegexMatch()
if find(s, pattern, m, start):
result = some(m)

template runeIncAt(s: string, n: var int) =
## increment ``n`` up to
## next rune's index
Expand Down Expand Up @@ -2558,9 +2539,12 @@ iterator findAll*(
##
## .. code-block:: nim
## var i = 0
## let expected = [1 .. 2, 4 .. 5]
## for m in findAll("abcabc", re"bc"):
## doAssert(m.boundaries == expected[i])
## let
## expected = [1 .. 2, 4 .. 5]
## text = "abcabc"
## for m in findAll(text, re"bc"):
## doAssert text[m.boundaries] == "bc"
## doAssert m.boundaries == expected[i]
## inc i
##
for m in findAllImpl(s, pattern, start):
Expand All @@ -2570,14 +2554,6 @@ proc findAll*(s: string, pattern: Regex, start = 0): seq[RegexMatch] =
## search through the string and
## return each match. Empty matches
## (start > end) are included
##
## .. code-block:: nim
## let
## expected = [1 .. 2, 4 .. 5]
## ms = findAll("abcabc", re"bc")
## for i, m in ms:
## doAssert(m.boundaries == expected[i])
##
result = newSeqOfCap[RegexMatch](s.len)
for slc in findAll(s, pattern, start):
result.add(slc)
Expand Down
Loading

0 comments on commit c0101cf

Please sign in to comment.