new genAst as replacement for quote do (#17426)
* new `macros.genAst`: fixes all issues with `quote do` * add changelog entry * add workaround for https://github.com/nim-lang/Nim/issues/2465#issuecomment-511076669 * add test for #9607 * add kNoExposeLocalInjects option * add test case for nested application of genAst * genAst: automatically call newLit when needed * allow skipping `{}`: genAst: foo * add test that shows this fixes #11986 * add examples showing mixin; add examples showing passing types, macros, templates * move to std/genasts * improve docs
This commit is contained in:
parent
774e66f3d1
commit
9abd383a2a
5 changed files with 416 additions and 1 deletions
|
|
@ -539,6 +539,7 @@ proc parseStmt*(s: string): NimNode {.noSideEffect.} =
|
|||
|
||||
proc getAst*(macroOrTemplate: untyped): NimNode {.magic: "ExpandToAst", noSideEffect.}
|
||||
## Obtains the AST nodes returned from a macro or template invocation.
|
||||
## See also `genasts.genAst`.
|
||||
## Example:
|
||||
##
|
||||
## .. code-block:: nim
|
||||
|
|
@ -559,6 +560,8 @@ proc quote*(bl: typed, op = "``"): NimNode {.magic: "QuoteAst", noSideEffect.} =
|
|||
##
|
||||
## A custom operator interpolation needs accent quoted (``) whenever it resolves
|
||||
## to a symbol.
|
||||
##
|
||||
## See also `genasts <genasts.html>`_ which avoids some issues with `quote`.
|
||||
runnableExamples:
|
||||
macro check(ex: untyped) =
|
||||
# this is a simplified version of the check macro from the
|
||||
|
|
@ -1419,7 +1422,7 @@ proc expectIdent*(n: NimNode, name: string) {.since: (1,1).} =
|
|||
if not eqIdent(n, name):
|
||||
error("Expected identifier to be `" & name & "` here", n)
|
||||
|
||||
proc hasArgOfName*(params: NimNode; name: string): bool=
|
||||
proc hasArgOfName*(params: NimNode; name: string): bool =
|
||||
## Search `nnkFormalParams` for an argument.
|
||||
expectKind(params, nnkFormalParams)
|
||||
for i in 1..<params.len:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue