bugfix: stack traces; first class iterators almost working
This commit is contained in:
parent
c439010d52
commit
814fcb2639
13 changed files with 186 additions and 51 deletions
33
tests/run/titer8.nim
Normal file
33
tests/run/titer8.nim
Normal file
|
|
@ -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()
|
||||
Loading…
Add table
Add a link
Reference in a new issue