parse 'of' branches for macros properly

This commit is contained in:
Araq 2015-04-19 14:25:16 +02:00
commit 9abfc60db4
2 changed files with 25 additions and 2 deletions

16
tests/macros/tlexerex.nim Normal file
View file

@ -0,0 +1,16 @@
import macros
macro match*(s: cstring|string; pos: int; sections: untyped): untyped =
for sec in sections.children:
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"