diff options
author | Araq <rumpf_a@web.de> | 2014-03-13 22:29:48 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2014-03-13 22:29:48 +0100 |
commit | 3e056afb1c481d35403c93bc17307b46be5e20f2 (patch) | |
tree | 997aeee1899a13d4a7014d4713252eaf27effd2f | |
parent | 1c35fb3c89bbac393b50c4bc6fe8205af2b7fb9d (diff) | |
download | Nim-3e056afb1c481d35403c93bc17307b46be5e20f2.tar.gz |
fixes #993
-rw-r--r-- | compiler/semtempl.nim | 8 | ||||
-rw-r--r-- | lib/pure/parsesql.nim | 2 | ||||
-rw-r--r-- | tests/template/tissue993.nim | 21 |
3 files changed, 29 insertions, 2 deletions
diff --git a/compiler/semtempl.nim b/compiler/semtempl.nim index 42268d44f..363c5246f 100644 --- a/compiler/semtempl.nim +++ b/compiler/semtempl.nim @@ -155,7 +155,11 @@ proc addLocalDecl(c: var TemplCtx, n: var PNode, k: TSymKind) = of nkPragmaExpr: x = x[0] of nkIdent: break else: illFormedAst(x) - c.toInject.incl(x.ident.id) + let ident = getIdentNode(c, x) + if not isTemplParam(c, ident): + c.toInject.incl(x.ident.id) + else: + replaceIdentBySym(n, ident) else: let ident = getIdentNode(c, n) if not isTemplParam(c, ident): @@ -359,6 +363,8 @@ proc semTemplBody(c: var TemplCtx, n: PNode): PNode = result = semRoutineInTemplBody(c, n, skConverter) of nkPragmaExpr: result.sons[0] = semTemplBody(c, n.sons[0]) + of nkPostfix: + result.sons[1] = semTemplBody(c, n.sons[1]) of nkPragma: discard else: diff --git a/lib/pure/parsesql.nim b/lib/pure/parsesql.nim index 3f9686e1e..bd8836f7c 100644 --- a/lib/pure/parsesql.nim +++ b/lib/pure/parsesql.nim @@ -267,7 +267,7 @@ proc getSymbol(c: var TSqlLexer, tok: var TToken) = while true: add(tok.literal, buf[pos]) Inc(pos) - if not (buf[pos] in {'a'..'z','A'..'Z','0'..'9','_','$', '\128'..'\255'}): + if buf[pos] notin {'a'..'z','A'..'Z','0'..'9','_','$', '\128'..'\255'}: break c.bufpos = pos tok.kind = tkIdentifier diff --git a/tests/template/tissue993.nim b/tests/template/tissue993.nim new file mode 100644 index 000000000..d39f43942 --- /dev/null +++ b/tests/template/tissue993.nim @@ -0,0 +1,21 @@ + +type pnode* = ref object of tobject + +template litNode (name, ty): stmt = + type name* = ref object of PNode + val*: ty +litNode PIntNode, int + +import json + +template withKey*(j: PJsonNode; key: string; varname: expr; + body:stmt): stmt {.immediate.} = + if j.hasKey(key): + let varname{.inject.}= j[key] + block: + body + +var j = parsejson("{\"zzz\":1}") +withkey(j, "foo", x): + echo(x) + |