diff options
author | Araq <rumpf_a@web.de> | 2012-11-15 01:27:25 +0100 |
---|---|---|
committer | Araq <rumpf_a@web.de> | 2012-11-15 01:27:25 +0100 |
commit | 814fcb263939e8127eb89c379c448f481df14dbd (patch) | |
tree | ffbe247e03da9373caad8d1d079e21b314bf4cb1 /tests/run | |
parent | c439010d5275e4f6c41573f2679a298e73d128cc (diff) | |
download | Nim-814fcb263939e8127eb89c379c448f481df14dbd.tar.gz |
bugfix: stack traces; first class iterators almost working
Diffstat (limited to 'tests/run')
-rw-r--r-- | tests/run/titer8.nim | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/tests/run/titer8.nim b/tests/run/titer8.nim new file mode 100644 index 000000000..ae82c7d3c --- /dev/null +++ b/tests/run/titer8.nim @@ -0,0 +1,33 @@ +discard """ + output: '''tada +ta da''' +""" +# Test first class iterator: + +import strutils + +iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[ + token: string, isSep: bool] {.closure.} = + var i = 0 + while i < s.len: + var j = i + if s[j] in seps: + while j < s.len and s[j] in seps: inc(j) + if j > i: + yield (substr(s, i, j-1), true) + else: + while j < s.len and s[j] notin seps: inc(j) + if j > i: + yield (substr(s, i, j-1), false) + i = j + +for word, isSep in tokenize2("ta da", whiteSpace): + if not isSep: + stdout.write(word) +echo "" + +proc inProc() = + for word, isSep in tokenize2("ta da", whiteSpace): + stdout.write(word) + +inProc() |