mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-17 18:17:11 +00:00
fixes #120
This commit is contained in:
@@ -234,16 +234,14 @@ proc getAst*(macroOrTemplate: expr): PNimrodNode {.magic: "ExpandToAst".}
|
||||
## macro FooMacro() =
|
||||
## var ast = getAst(BarTemplate())
|
||||
|
||||
template emit*(s: expr): stmt =
|
||||
template emit*(e: expr[string]): stmt =
|
||||
## accepts a single string argument and treats it as nimrod code
|
||||
## that should be inserted verbatim in the program
|
||||
## Example:
|
||||
##
|
||||
## emit("echo " & '"' & "hello world".toUpper & '"')
|
||||
##
|
||||
block:
|
||||
const evaluated = s
|
||||
eval: result = evaluated.parseStmt
|
||||
eval: result = e.parseStmt
|
||||
|
||||
proc expectKind*(n: PNimrodNode, k: TNimrodNodeKind) {.compileTime.} =
|
||||
## checks that `n` is of kind `k`. If this is not the case,
|
||||
|
||||
@@ -2349,9 +2349,8 @@ template eval*(blk: stmt): stmt =
|
||||
## executes a block of code at compile time just as if it was a macro
|
||||
## optionally, the block can return an AST tree that will replace the
|
||||
## eval expression
|
||||
block:
|
||||
macro payload(x: stmt): stmt = blk
|
||||
payload()
|
||||
macro payload: stmt {.gensym.} = blk
|
||||
payload()
|
||||
|
||||
proc insert*(x: var string, item: string, i = 0) {.noSideEffect.} =
|
||||
## inserts `item` into `x` at position `i`.
|
||||
|
||||
Reference in New Issue
Block a user