summary refs log tree commit diff stats
path: root/tests/macros/tlexerex.nim
blob: db2c38ef61daf8165af76f26072ff13dd552f6a7 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
import macros

macro match*(s: cstring|string; pos: int; sections: varargs[untyped]): untyped =
  for sec in sections:
    expectKind sec, nnkOfBranch
    expectLen sec, 2
  result = newStmtList()

when isMainModule:
  var input = "the input"
  var pos = 0
  match input, pos:
  of r"[a-zA-Z_]\w+": echo "an identifier"
  of r"\d+": echo "an integer"
  of r".": echo "something else"