Fix macros.quote custom op symbol interpolation. (#17256)
Provides a workaround/fix for #7589. https://github.com/nim-lang/Nim/issues/7589 Updated docs and tutorial to reflect change. Updated runnableExamples to include an example. Co-authored-by: name <name@example.com>
This commit is contained in:
parent
171b03c386
commit
b2b23d723a
4 changed files with 85 additions and 51 deletions
|
|
@ -2021,18 +2021,28 @@ proc processQuotations(c: PContext; n: var PNode, op: string,
|
|||
n = newIdentNode(getIdent(c.cache, $quotes.len), n.info)
|
||||
ids.add n
|
||||
return
|
||||
|
||||
|
||||
template handlePrefixOp(prefixed) =
|
||||
if prefixed[0].kind == nkIdent:
|
||||
let examinedOp = prefixed[0].ident.s
|
||||
if examinedOp == op:
|
||||
returnQuote prefixed[1]
|
||||
elif examinedOp.startsWith(op):
|
||||
prefixed[0] = newIdentNode(getIdent(c.cache, examinedOp.substr(op.len)), prefixed.info)
|
||||
|
||||
if n.kind == nkPrefix:
|
||||
checkSonsLen(n, 2, c.config)
|
||||
if n[0].kind == nkIdent:
|
||||
var examinedOp = n[0].ident.s
|
||||
if examinedOp == op:
|
||||
returnQuote n[1]
|
||||
elif examinedOp.startsWith(op):
|
||||
n[0] = newIdentNode(getIdent(c.cache, examinedOp.substr(op.len)), n.info)
|
||||
elif n.kind == nkAccQuoted and op == "``":
|
||||
returnQuote n[0]
|
||||
handlePrefixOp(n)
|
||||
elif n.kind == nkAccQuoted:
|
||||
if op == "``":
|
||||
returnQuote n[0]
|
||||
else: # [bug #7589](https://github.com/nim-lang/Nim/issues/7589)
|
||||
if n.len == 2 and n[0].ident.s == op:
|
||||
var tempNode = nkPrefix.newTree()
|
||||
tempNode.newSons(2)
|
||||
tempNode[0] = n[0]
|
||||
tempNode[1] = n[1]
|
||||
handlePrefixOp(tempNode)
|
||||
elif n.kind == nkIdent:
|
||||
if n.ident.s == "result":
|
||||
n = ids[0]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue