genSym support for hygienic macros and templates.

example:
template hygienic(val: expr) =
  var `*x` = val
  echo `*x`

*x was chosen as mnemonic for "opposite of public" and thus private
This commit is contained in:
Zahary Karadjov 2012-03-26 04:36:26 +03:00
commit 6216046bc6
6 changed files with 34 additions and 70 deletions

View file

@ -11,7 +11,7 @@
import
intsets, ast, astalgo, idents, semdata, types, msgs, options, rodread,
renderer
renderer, wordrecg, idgen
proc considerAcc*(n: PNode): PIdent =
case n.kind
@ -21,6 +21,11 @@ proc considerAcc*(n: PNode): PIdent =
case n.len
of 0: GlobalError(n.info, errIdentifierExpected, renderTree(n))
of 1: result = considerAcc(n.sons[0])
of 2:
if n[0].ident.id == ord(wStar):
result = genSym(n[1].ident.s)
else:
result = getIdent(n[0].ident.s & n[1].ident.s)
else:
var id = ""
for i in 0.. <n.len: