Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

remove compile-time checks for unsupported, pre-1.6 Nim versions #142

Merged
merged 1 commit into from
Jun 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions src/regex/common.nim
Original file line number Diff line number Diff line change
@@ -1,13 +1,6 @@
import std/unicode
import std/strutils

when (NimMajor, NimMinor, NimPatch) < (0, 20, 0):
import sets
proc initHashSet*[T](size = 2): HashSet[T] =
result = initSet[T](size)
proc toHashSet*[T](keys: openArray[T]): HashSet[T] =
result = toSet[T](keys)

type
RegexError* = object of ValueError
## raised when the pattern
Expand Down
2 changes: 1 addition & 1 deletion src/regex/compiler.nim
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func reImpl*(s: string, flags: RegexFlags = {}): Regex {.inline.} =
flags: flags,
litOpt: opt
)
when defined(regexDotDir) and (NimMajor, NimMinor) >= (1, 2):
when defined(regexDotDir):
const regexDotDir {.strdefine.} = ""
graphToFile(result, regexDotDir)

Expand Down
24 changes: 11 additions & 13 deletions src/regex/dotgraph.nim
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import std/strutils
when (NimMajor, NimMinor) >= (1, 2):
import std/hashes
import std/os
import std/hashes
import std/os

import ./nfatype
import ./types
Expand Down Expand Up @@ -48,13 +47,12 @@ func graph*(nfa: Nfa): string =
func graph*(regex: Regex): string =
result = graph(regex.nfa)

when (NimMajor, NimMinor) >= (1, 2):
func graphToFile*(regex: Regex, dir: string) =
{.noSideEffect.}:
if dir.len > 0:
let content = graph(regex)
let fname = $hash(content) & ".dot"
try:
writeFile(dir / fname, content)
except IOError:
debugEcho "write file error"
func graphToFile*(regex: Regex, dir: string) =
{.noSideEffect.}:
if dir.len > 0:
let content = graph(regex)
let fname = $hash(content) & ".dot"
try:
writeFile(dir / fname, content)
except IOError:
debugEcho "write file error"
3 changes: 0 additions & 3 deletions src/regex/litopt.nim
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ import ./types
import ./nodematch
import ./nfa

when (NimMajor, NimMinor, NimPatch) < (0, 20, 0):
import common

type
LitNfa = Enfa
End = seq[int16]
Expand Down
4 changes: 0 additions & 4 deletions src/regex/nfa.nim
Original file line number Diff line number Diff line change
Expand Up @@ -193,10 +193,6 @@ func teClosure(
for s in eNfa.s[state].next:
teClosure(result, eNfa, s, processing, eTransitions)

when (NimMajor, NimMinor, NimPatch) < (1,4,0) and not declared(IndexDefect):
# avoids a warning
type IndexDefect = IndexError

func eRemoval*(eNfa: Enfa): Nfa {.raises: [].} =
## Remove e-transitions and return
## remaining state transtions and
Expand Down
6 changes: 1 addition & 5 deletions src/regex/parser.nim
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,10 @@ func parseRepRange(sc: Scanner[Rune]): Node =
var
firstNum: int
lastNum: int
when (NimMajor, NimMinor, NimPatch) < (0, 19, 9):
type MyError = ref OverflowError
else:
type MyError = ref ValueError
try:
discard parseInt(first, firstNum)
discard parseInt(last, lastNum)
except MyError:
except ValueError:
prettyCheck(
false,
"Invalid repetition range. Max value is $#" %% $int16.high)
Expand Down
3 changes: 1 addition & 2 deletions src/regex/types.nim
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# XXX hack because of nfamatch compile warning
when NimMajor >= 1:
{.used.}
{.used.}

import std/unicode
import std/sets
Expand Down
Loading
Loading