mirror of
https://github.com/nim-lang/Nim.git
synced 2026-01-03 19:52:36 +00:00
16 lines
384 B
Nim
16 lines
384 B
Nim
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"
|