Change expr/stmt in examples to untyped (#6734)

This commit is contained in:
Lynn C. Rees 2017-11-15 13:58:11 -07:00 • committed by Andreas Rumpf
commit ac5dff2e04
16 changed files with 56 additions and 119 deletions

View file

@ -1,20 +1,20 @@
import strutils
template html(name: expr, matter: stmt) {.immediate.} =
template html(name, matter: untyped) =
proc name(): string =
result = "<html>"
matter
result.add("</html>")
template nestedTag(tag: expr) {.immediate.} =
template tag(matter: stmt) {.immediate.} =
template nestedTag(tag: untyped) =
template tag(matter: typed) =
result.add("<" & astToStr(tag) & ">")
matter
result.add("</" & astToStr(tag) & ">")
template simpleTag(tag: expr) {.immediate.} =
template tag(matter: expr) {.immediate.} =
template simpleTag(tag: untyped) =
template tag(matter: untyped) =
result.add("<$1>$2</$1>" % [astToStr(tag), matter])
nestedTag body

View file

@ -5,7 +5,7 @@ import macros
proc invalidFormatString() =
echo "invalidFormatString"
template formatImpl(handleChar: expr) =
template formatImpl(handleChar: untyped) =
var i = 0
while i < f.len:
if f[i] == '$':
@ -24,11 +24,11 @@ template formatImpl(handleChar: expr) =
i += 1
proc `%`*(f: string, a: openArray[string]): string =
template identity(x: expr): expr = x
template identity(x: untyped): untyped = x
result = ""
formatImpl(identity)
macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): expr =
macro optFormat{`%`(f, a)}(f: string{lit}, a: openArray[string]): untyped =
result = newNimNode(nnkBracket)
#newCall("&")
let f = f.strVal

View file

@ -1,7 +1,7 @@
import macros
macro check(ex: expr): stmt =
macro check(ex: untyped): typed =
var info = ex.lineinfo
var expString = ex.toStrLit
result = quote do:

View file

@ -1,8 +1,9 @@
template htmlTag(tag: expr) {.immediate.} =
template htmlTag(tag: untyped) =
proc tag(): string = "<" & astToStr(tag) & ">"
htmlTag(br)
htmlTag(html)
echo br()
echo html()