Created
February 14, 2018 15:56
-
-
Save Araq/f41cb3ca3441303a2808a9389650efda to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import macros, strutils | |
macro since*(version: string; symbol: untyped): untyped = | |
proc toVersion(s: string): int = | |
let v = s.split('.') | |
var w: array[3, int] | |
for i in 0 .. min(2, v.len): | |
w[i] = parseInt(v[i]) | |
result = w[0] * 1000_000 + w[1] * 1_000 + w[2] | |
let ab = version.strVal.split("..") | |
let real = NimMajor * 1000_000 + NimMinor * 1_000 + NimPatch | |
var enabled = false | |
if ab.len >= 2: | |
if real >= toVersion(ab[0]) and real <= toVersion(ab[1]): | |
enabled = true | |
# check that the version is not blacklisted. Always run over | |
# the full blacklist in order to check every version for syntax: | |
for i in 2 .. ab.len-1: | |
if toVersion(ab[i]) == real: enabled = false | |
elif ab.len == 1: | |
enabled = real >= toVersion(ab[0]) | |
else: | |
error("invalid version specification: " & version.strVal, version) | |
result = if enabled: symbol else: newStmtList() | |
proc testme() {.since"0.17.0..0.18.0..0.17.4".} = | |
echo "yes" | |
testme() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment