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
This commit is contained in:
parent
5d947bb791
commit
b2c5f6f3c8
2 changed files with 8 additions and 3 deletions
|
|
@ -1073,7 +1073,12 @@ proc newStmtList*(stmts: varargs[NimNode]): NimNode =
|
||||||
## Create a new statement list.
|
## Create a new statement list.
|
||||||
result = newNimNode(nnkStmtList).add(stmts)
|
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.
|
## Create a new parentheses-enclosed expression.
|
||||||
newNimNode(nnkPar).add(exprs)
|
newNimNode(nnkPar).add(exprs)
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -512,7 +512,7 @@ macro scanTuple*(input: untyped; pattern: static[string]; matcherTypes: varargs[
|
||||||
inc userMatches
|
inc userMatches
|
||||||
else: discard
|
else: discard
|
||||||
inc p
|
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:
|
for arg in arguments:
|
||||||
result[^1][0].add arg
|
result[^1][0].add arg
|
||||||
result[^1].add arg
|
result[^1].add arg
|
||||||
|
|
@ -588,7 +588,7 @@ macro scanp*(input, idx: typed; pattern: varargs[untyped]): bool =
|
||||||
action
|
action
|
||||||
|
|
||||||
# (x) a # bind action a to (x)
|
# (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))
|
result = atm(it[0], input, idx, placeholder(it[1], input, idx))
|
||||||
elif it.kind == nnkInfix and it[0].eqIdent"->":
|
elif it.kind == nnkInfix and it[0].eqIdent"->":
|
||||||
# bind matching to some action:
|
# bind matching to some action:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue