diff --git a/stew/shims/enumutils.nim b/stew/shims/enumutils.nim index 7750df1..0f59835 100644 --- a/stew/shims/enumutils.nim +++ b/stew/shims/enumutils.nim @@ -1,77 +1,3 @@ -when (NimMajor, NimMinor) > (1, 4): - import std/enumutils - export enumutils - -else: # Copy from `std/enumutils` - # - # - # Nim's Runtime Library - # (c) Copyright 2020 Nim contributors - # - # See the file "copying.txt", included in this - # distribution, for details about the copyright. - # - - import macros - from typetraits import OrdinalEnum, HoleyEnum - export typetraits - - # xxx `genEnumCaseStmt` needs tests and runnableExamples - - macro genEnumCaseStmt*(typ: typedesc, argSym: typed, default: typed, - userMin, userMax: static[int], normalizer: static[proc(s :string): string]): untyped = - # generates a case stmt, which assigns the correct enum field given - # a normalized string comparison to the `argSym` input. - # string normalization is done using passed normalizer. - # NOTE: for an enum with fields Foo, Bar, ... we cannot generate - # `of "Foo".nimIdentNormalize: Foo`. - # This will fail, if the enum is not defined at top level (e.g. in a block). - # Thus we check for the field value of the (possible holed enum) and convert - # the integer value to the generic argument `typ`. - let typ = typ.getTypeInst[1] - let impl = typ.getImpl[2] - expectKind impl, nnkEnumTy - let normalizerNode = quote: `normalizer` - expectKind normalizerNode, nnkSym - result = nnkCaseStmt.newTree(newCall(normalizerNode, argSym)) - # stores all processed field strings to give error msg for ambiguous enums - var foundFields: seq[string] = @[] - var fStr = "" # string of current field - var fNum = BiggestInt(0) # int value of current field - for f in impl: - case f.kind - of nnkEmpty: continue # skip first node of `enumTy` - of nnkSym, nnkIdent: fStr = f.strVal - of nnkAccQuoted: - fStr = "" - for ch in f: - fStr.add ch.strVal - of nnkEnumFieldDef: - case f[1].kind - of nnkStrLit: fStr = f[1].strVal - of nnkTupleConstr: - fStr = f[1][1].strVal - fNum = f[1][0].intVal - of nnkIntLit: - fStr = f[0].strVal - fNum = f[1].intVal - else: error("Invalid tuple syntax!", f[1]) - else: error("Invalid node for enum type `" & $f.kind & "`!", f) - # add field if string not already added - if fNum >= userMin and fNum <= userMax: - fStr = normalizer(fStr) - if fStr notin foundFields: - result.add nnkOfBranch.newTree(newLit fStr, nnkCall.newTree(typ, newLit fNum)) - foundFields.add fStr - else: - error("Ambiguous enums cannot be parsed, field " & $fStr & - " appears multiple times!", f) - inc fNum - # finally add else branch to raise or use default - if default == nil: - let raiseStmt = quote do: - raise newException(ValueError, "Invalid enum value: " & $`argSym`) - result.add nnkElse.newTree(raiseStmt) - else: - expectKind(default, nnkSym) - result.add nnkElse.newTree(default) +{.deprecated: "use std/enumutils".} +import std/enumutils +export enumutils diff --git a/stew/shims/macros.nim b/stew/shims/macros.nim index e6e014f..ba3614d 100644 --- a/stew/shims/macros.nim +++ b/stew/shims/macros.nim @@ -414,13 +414,7 @@ iterator baseTypes*(exceptionType: NimNode): NimNode = yield typ macro unpackArgs*(callee: untyped, args: untyped): untyped = - # nnkArglist was changed to nnkArgList - # https://github.com/nim-lang/Nim/pull/17529 - # https://github.com/nim-lang/Nim/pull/19822 - const ArgKind = when (NimMajor, NimMinor) < (1, 6): - nnkArglist - else: - nnkArgList + const ArgKind = nnkArgList result = newCall(callee) for arg in args: diff --git a/stew/shims/net.nim b/stew/shims/net.nim index 3695e35..d7d1816 100644 --- a/stew/shims/net.nim +++ b/stew/shims/net.nim @@ -5,10 +5,7 @@ type ValidIpAddress* {.requiresInit.} = object value: IpAddress -when (NimMajor, NimMinor) < (1, 4): - {.push raises: [Defect].} -else: - {.push raises: [].} +{.push raises: [].} func ipv4*(address: array[4, byte]): ValidIpAddress = ValidIpAddress(value: IpAddress(family: IPv4, address_v4: address)) diff --git a/stew/shims/typetraits.nim b/stew/shims/typetraits.nim index c56570a..7639c04 100644 --- a/stew/shims/typetraits.nim +++ b/stew/shims/typetraits.nim @@ -1,15 +1,3 @@ +{.deprecated: "use std/typetraits".} import std/typetraits export typetraits - -when (NimMajor, NimMinor) < (1, 6): # Copy from `std/typetraits` - # - # - # Nim's Runtime Library - # (c) Copyright 2012 Nim Contributors - # - # See the file "copying.txt", included in this - # distribution, for details about the copyright. - # - - type HoleyEnum* = (not Ordinal) and enum ## Enum with holes. - type OrdinalEnum* = Ordinal and enum ## Enum without holes.