summary refs log tree commit diff stats
path: root/tests/accept/run/tmacro2.nim
blob: 6aa9bb57d642be8cdfe84372f1a8797f9d406eda (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
discard """
  output: "ta-da Your value sir: 'HE!!!!o Wor!!d'"
"""

import macros, strutils

proc testBlock(): string {.compileTime.} = 
  block myBlock:
    while true:
      echo "inner block"
      break myBlock
    echo "outer block"
  result = "ta-da"

macro mac(n: expr): expr =
  expectKind(n, nnkCall)
  expectLen(n, 2)
  expectKind(n[1], nnkStrLit)
  var s: string = n[1].strVal
  s = s.replace("l", "!!")
  result = newStrLitNode("Your value sir: '$#'" % [s])

const s = testBlock() 
const t = mac("HEllo World")
echo s, " ", t