From b2c5f6f3c8a8d3e5b9f908353f3ea791cc771385 Mon Sep 17 00:00:00 2001 From: ringabout <43030857+ringabout@users.noreply.github.com> Date: Wed, 7 Sep 2022 03:38:08 +0800 Subject: give a deprecate warning when using `newPar` to construct tuple expressions (#20312) * error/deprecate when using `newPar` to construct tuple expressions * Update lib/core/macros.nim * fixes --- lib/core/macros.nim | 7 ++++++- lib/pure/strscans.nim | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/core/macros.nim b/lib/core/macros.nim index 61b3a7b43..59ed943d7 100644 --- a/lib/core/macros.nim +++ b/lib/core/macros.nim @@ -1073,7 +1073,12 @@ proc newStmtList*(stmts: varargs[NimNode]): NimNode = ## Create a new statement list. result = newNimNode(nnkStmtList).add(stmts) -proc newPar*(exprs: varargs[NimNode]): NimNode = +proc newPar*(exprs: NimNode): NimNode = + ## Create a new parentheses-enclosed expression. + newNimNode(nnkPar).add(exprs) + +proc newPar*(exprs: varargs[NimNode]): NimNode {.deprecated: + "don't use newPar/nnkPar to construct tuple expressions; use nnkTupleConstr instead".} = ## Create a new parentheses-enclosed expression. newNimNode(nnkPar).add(exprs) diff --git a/lib/pure/strscans.nim b/lib/pure/strscans.nim index 7db6f28af..8a1ea125f 100644 --- a/lib/pure/strscans.nim +++ b/lib/pure/strscans.nim @@ -512,7 +512,7 @@ macro scanTuple*(input: untyped; pattern: static[string]; matcherTypes: varargs[ inc userMatches else: discard inc p - result.add newPar(newCall(ident("scanf"), input, newStrLitNode(pattern))) + result.add nnkTupleConstr.newTree(newCall(ident("scanf"), input, newStrLitNode(pattern))) for arg in arguments: result[^1][0].add arg result[^1].add arg @@ -588,7 +588,7 @@ macro scanp*(input, idx: typed; pattern: varargs[untyped]): bool = action # (x) a # bind action a to (x) - if it[0].kind == nnkPar and it.len == 2: + if it[0].kind in {nnkPar, nnkTupleConstr} and it.len == 2: result = atm(it[0], input, idx, placeholder(it[1], input, idx)) elif it.kind == nnkInfix and it[0].eqIdent"->": # bind matching to some action: -- cgit 1.4.1-2-gfad0