From cb63408d7d9de91020a7a815216b531fdf944b47 Mon Sep 17 00:00:00 2001 From: Benjamin Shirley-Quirk Date: Wed, 5 Aug 2020 01:44:55 +0100 Subject: removed listcomp.nim --- Makefile | 1 - src/args.nim | 9 +++--- src/aur.nim | 2 +- src/common.nim | 2 +- src/feature/syncinfo.nim | 2 +- src/feature/syncinstall.nim | 2 +- src/format.nim | 2 +- src/listcomp.nim | 69 --------------------------------------------- src/main.nim | 2 +- src/package.nim | 2 +- src/pacman.nim | 2 +- 11 files changed, 12 insertions(+), 83 deletions(-) delete mode 100644 src/listcomp.nim diff --git a/Makefile b/Makefile index 2af010c..04ce4cb 100644 --- a/Makefile +++ b/Makefile @@ -55,7 +55,6 @@ NIM_OPTIMIZE = size NIM_CACHE_DIR = nimcache NIM_OPTIONS = \ - --useVersion:'1.0' \ --putenv:'PROG_VERSION'="${RVERSION}" \ --putenv:'PROG_COPYRIGHT'="${COPYRIGHT}" \ --putenv:'PROG_PKGLIBDIR'="${PKGLIBDIR}" \ diff --git a/src/args.nim b/src/args.nim index acf9604..b93d5fb 100644 --- a/src/args.nim +++ b/src/args.nim @@ -1,6 +1,6 @@ import options, os, posix, sequtils, sets, strutils, sugar, - utils, "listcomp" + utils type ArgumentType* {.pure.} = enum @@ -105,13 +105,12 @@ proc splitArgs*(params: seq[string], let consumedNext = argsResult.map(a => a.consumedNext).foldl(a or b) let newNext = next.filter(n => not consumedNext) when NimVersion >= "1.2": - let lc = collect(newSeq): + return((block:collect(newSeq): for x in argsResult: (x.key,x.value,ArgumentType.short) - return (lc, newNext, stdinConsumed, false) + ), newNext, stdinConsumed, false) else: - return (lc[(x.key, x.value, ArgumentType.short) | (x <- argsResult), Argument], - newNext, stdinConsumed, false) + return (lc[(x.key, x.value, ArgumentType.short) | (x <- argsResult), Argument], newNext, stdinConsumed, false) else: return (@[(current, none(string), ArgumentType.target)], next, stdinConsumed, false) diff --git a/src/aur.nim b/src/aur.nim index 49e350c..542a21c 100644 --- a/src/aur.nim +++ b/src/aur.nim @@ -1,7 +1,7 @@ import json, lists, options, re, sequtils, sets, strutils, sugar, tables, package, utils, - "wrapper/curl", "listcomp" + "wrapper/curl" type AurComment* = tuple[ diff --git a/src/common.nim b/src/common.nim index af1f21e..0f2804b 100644 --- a/src/common.nim +++ b/src/common.nim @@ -1,7 +1,7 @@ import options, os, osproc, posix, sequtils, sets, strutils, sugar, tables, args, config, format, lists, package, pacman, utils, - "wrapper/alpm", "listcomp" + "wrapper/alpm" type CacheKind* {.pure.} = enum diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim index 77e94bf..6b2278d 100644 --- a/src/feature/syncinfo.nim +++ b/src/feature/syncinfo.nim @@ -2,7 +2,7 @@ import options, posix, sequtils, strutils, sugar, tables, "../args", "../aur", "../common", "../config", "../format", "../package", "../pacman", "../utils", - "../wrapper/alpm", "../listcomp" + "../wrapper/alpm" const pacmanInfoStrings = [ diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim index abb25b5..b6347f9 100644 --- a/src/feature/syncinstall.nim +++ b/src/feature/syncinstall.nim @@ -2,7 +2,7 @@ import algorithm, options, os, posix, sequtils, sets, strutils, sugar, tables, "../args", "../aur", "../config", "../common", "../format", "../lists", "../package", "../pacman", "../utils", - "../wrapper/alpm", "../listcomp" + "../wrapper/alpm" type Installed = tuple[ diff --git a/src/format.nim b/src/format.nim index f85733a..f4255fb 100644 --- a/src/format.nim +++ b/src/format.nim @@ -1,6 +1,6 @@ import macros, options, posix, sequtils, strutils, sugar, times, unicode, - utils, "listcomp" + utils type PackageLineFormat* = tuple[ diff --git a/src/listcomp.nim b/src/listcomp.nim deleted file mode 100644 index c9f8dc0..0000000 --- a/src/listcomp.nim +++ /dev/null @@ -1,69 +0,0 @@ -import macros - -type ListComprehension = object -var lc* : ListComprehension - -template `|`*(lc: ListComprehension, comp: untyped): untyped = lc - -macro `[]`*(lc: ListComprehension, comp, typ: untyped): untyped = - ## List comprehension, returns a sequence. `comp` is the actual list - ## comprehension, for example ``x | (x <- 1..10, x mod 2 == 0)``. `typ` is - ## the type that will be stored inside the result seq. - ## - ## .. code-block:: nim - ## - ## echo lc[x | (x <- 1..10, x mod 2 == 0), int] - ## - ## const n = 20 - ## echo lc[(x,y,z) | (x <- 1..n, y <- x..n, z <- y..n, x*x + y*y == z*z), - ## tuple[a,b,c: int]] - - expectLen(comp, 3) - expectKind(comp, nnkInfix) - assert($comp[0] == "|") - - result = newCall( - newDotExpr( - newIdentNode("result"), - newIdentNode("add")), - comp[1]) - - for i in countdown(comp[2].len-1, 0): - let x = comp[2][i] - expectMinLen(x, 1) - if x[0].kind == nnkIdent and x[0].strVal == "<-": - expectLen(x, 3) - result = newNimNode(nnkForStmt).add(x[1], x[2], result) - else: - result = newIfStmt((x, result)) - - result = newNimNode(nnkCall).add( - newNimNode(nnkPar).add( - newNimNode(nnkLambda).add( - newEmptyNode(), - newEmptyNode(), - newEmptyNode(), - newNimNode(nnkFormalParams).add( - newNimNode(nnkBracketExpr).add( - newIdentNode("seq"), - typ)), - newEmptyNode(), - newEmptyNode(), - newStmtList( - newAssignment( - newIdentNode("result"), - newNimNode(nnkPrefix).add( - newIdentNode("@"), - newNimNode(nnkBracket))), - result)))) - - -when isMainModule: - var a = lc[x | (x <- 1..10, x mod 2 == 0), int] - assert a == @[2, 4, 6, 8, 10] - - const n = 20 - var b = lc[(x,y,z) | (x <- 1..n, y <- x..n, z <- y..n, x*x + y*y == z*z), - tuple[a,b,c: int]] - assert b == @[(a: 3, b: 4, c: 5), (a: 5, b: 12, c: 13), (a: 6, b: 8, c: 10), -(a: 8, b: 15, c: 17), (a: 9, b: 12, c: 15), (a: 12, b: 16, c: 20)] diff --git a/src/main.nim b/src/main.nim index 87bb8d2..458ba72 100644 --- a/src/main.nim +++ b/src/main.nim @@ -1,6 +1,6 @@ import options, os, posix, re, sequtils, strutils, sugar, - args, config, format, pacman, utils, "listcomp" + args, config, format, pacman, utils import "feature/localquery", diff --git a/src/package.nim b/src/package.nim index 181b5bf..3014cba 100644 --- a/src/package.nim +++ b/src/package.nim @@ -1,6 +1,6 @@ import options, os, re, sequtils, sets, strutils, sugar, tables, utils, - "wrapper/alpm", "listcomp" + "wrapper/alpm" type ConstraintOperation* {.pure.} = enum diff --git a/src/pacman.nim b/src/pacman.nim index 8b72538..f9fc978 100644 --- a/src/pacman.nim +++ b/src/pacman.nim @@ -1,6 +1,6 @@ import macros, options, posix, sequtils, sets, strutils, sugar, tables, - args, config, utils, "listcomp" + args, config, utils type OpGroup* {.pure.} = enum -- cgit v1.2.3-70-g09d2