Skip to content

Commit

Permalink
post last changes fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
krux02 committed Aug 16, 2019
1 parent 78660b5 commit 1fc3e0a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
12 changes: 9 additions & 3 deletions lib/core/macros.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1633,7 +1633,7 @@ proc substitudeComments(symbols, values, n: NimNode): NimNode =
macro quoteAst*(args: varargs[untyped]): untyped =
## New Quasi-quoting operator. Accepts a list of symbols to inject
## into the generated code and a block of code. Returns an AST that
## generats the body AST. Within the body, identifiers are only
## generates the body AST. Within the body, identifiers are only
## injected from the outer scope, if they have been explicitly named
## in the list of symbols to inject.
##
Expand Down Expand Up @@ -1695,8 +1695,14 @@ macro quoteAst*(args: varargs[untyped]): untyped =

let templateCall = newCall(templateSym)
for i in 0 ..< args.len-1:
args[i].expectKind nnkIdent
templateCall.add newCall(bindSym"expectNimNode", args[i])
let symName = args[i]
# identifiers and quoted identifiers are allowed.
if symName.kind == nnkAccQuoted:
symName.expectLen 1
symName[0].expectKind nnkIdent
else:
symName.expectKind nnkIdent
templateCall.add newCall(bindSym"expectNimNode", symName)
for expr in extraCommentGenExpr:
templateCall.add expr
let getAstCall = newCall(bindSym"getAst", templateCall)
Expand Down
1 change: 1 addition & 0 deletions tests/macros/tquoteast.nim
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ macro fooB(): untyped =
result = quoteAst(`==`):
echo 3 == 4
doAssert result[0][1][0].kind == nnkClosedSymChoice
doAssert result[0][1][0] == `==`

fooB()

Expand Down
2 changes: 1 addition & 1 deletion tests/macros/tquoteasterror2.nim
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ errormsg: "undeclared identifier: 'a'"
# from the environment triggers a clean undeclared identifier error
# message.

import marcos
import macros

macro fooF(): untyped =
let a = @[1,2,3,4,5]
Expand Down

0 comments on commit 1fc3e0a

Please sign in to comment.