aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorkitsunyan2020-04-26 05:14:06 +0000
committerkitsunyan2020-04-26 05:14:06 +0000
commitc86dac32d38cf2be5faa6118911429a231de8805 (patch)
tree75e9f8fb5ee37d81a01edc35b9a4534f6b56c9cc /src
parent38a6904a948661802d2c744e0c2b9759e11fbd70 (diff)
Backport list comprehension
Diffstat (limited to 'src')
-rw-r--r--src/args.nim2
-rw-r--r--src/aur.nim2
-rw-r--r--src/common.nim2
-rw-r--r--src/feature/syncinfo.nim2
-rw-r--r--src/feature/syncinstall.nim2
-rw-r--r--src/format.nim2
-rw-r--r--src/lc.nim30
-rw-r--r--src/main.nim2
-rw-r--r--src/package.nim3
-rw-r--r--src/pacman.nim2
10 files changed, 40 insertions, 9 deletions
diff --git a/src/args.nim b/src/args.nim
index fd03ee0..87fbaf3 100644
--- a/src/args.nim
+++ b/src/args.nim
@@ -1,6 +1,6 @@
import
options, os, posix, sequtils, sets, strutils, sugar,
- utils
+ lc, utils
type
ArgumentType* {.pure.} = enum
diff --git a/src/aur.nim b/src/aur.nim
index 399183c..cd1c744 100644
--- a/src/aur.nim
+++ b/src/aur.nim
@@ -1,6 +1,6 @@
import
json, lists, options, re, sequtils, sets, strutils, sugar, tables,
- package, utils,
+ lc, package, utils,
"wrapper/curl"
type
diff --git a/src/common.nim b/src/common.nim
index 8db3a79..3f9013c 100644
--- a/src/common.nim
+++ b/src/common.nim
@@ -1,6 +1,6 @@
import
options, os, osproc, posix, sequtils, sets, strutils, sugar, tables,
- args, config, format, lists, package, pacman, utils,
+ args, config, format, lc, lists, package, pacman, utils,
"wrapper/alpm"
type
diff --git a/src/feature/syncinfo.nim b/src/feature/syncinfo.nim
index 4f758fe..f4c6f7a 100644
--- a/src/feature/syncinfo.nim
+++ b/src/feature/syncinfo.nim
@@ -1,6 +1,6 @@
import
options, posix, sequtils, strutils, sugar, tables,
- "../args", "../aur", "../common", "../config", "../format", "../package",
+ "../args", "../aur", "../common", "../config", "../format", "../lc", "../package",
"../pacman", "../utils",
"../wrapper/alpm"
diff --git a/src/feature/syncinstall.nim b/src/feature/syncinstall.nim
index 7aba043..0a9170d 100644
--- a/src/feature/syncinstall.nim
+++ b/src/feature/syncinstall.nim
@@ -1,6 +1,6 @@
import
algorithm, options, os, posix, sequtils, sets, strutils, sugar, tables,
- "../args", "../aur", "../config", "../common", "../format", "../lists", "../package",
+ "../args", "../aur", "../config", "../common", "../format", "../lc", "../lists", "../package",
"../pacman", "../utils",
"../wrapper/alpm"
diff --git a/src/format.nim b/src/format.nim
index 2ac39dc..e8645b8 100644
--- a/src/format.nim
+++ b/src/format.nim
@@ -1,6 +1,6 @@
import
macros, options, posix, sequtils, strutils, sugar, times, unicode,
- utils
+ lc, utils
type
PackageLineFormat* = tuple[
diff --git a/src/lc.nim b/src/lc.nim
new file mode 100644
index 0000000..0e75d28
--- /dev/null
+++ b/src/lc.nim
@@ -0,0 +1,30 @@
+import macros
+
+# backported list comprehension from earlier nim versions
+
+type ListComprehension = object
+var lc*: ListComprehension
+
+template `|`*(lc: ListComprehension, comp: untyped): untyped = lc
+
+macro `[]`*(lc: ListComprehension, comp, typ: untyped): untyped =
+ 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))))
diff --git a/src/main.nim b/src/main.nim
index 92e8887..f815f8f 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
+ args, config, format, lc, pacman, utils
import
"feature/localquery",
diff --git a/src/package.nim b/src/package.nim
index 5b87184..b4153db 100644
--- a/src/package.nim
+++ b/src/package.nim
@@ -1,5 +1,6 @@
import
- options, os, re, sequtils, sets, strutils, sugar, tables, utils,
+ options, os, re, sequtils, sets, strutils, sugar, tables,
+ lc, utils,
"wrapper/alpm"
type
diff --git a/src/pacman.nim b/src/pacman.nim
index 857581f..5766ee2 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
+ args, config, lc, utils
type
OpGroup* {.pure.} = enum