bugfix: multiple yield statements and loop body vars

This commit is contained in:
Araq 2010-12-13 07:58:35 +01:00
commit 63ac32e6de
13 changed files with 256 additions and 75 deletions

View file

@ -0,0 +1,18 @@
type
TA = object
x, y: int
TB = object of TA
z: int
TC = object of TB
whatever: string
proc p(a: var TA) = nil
proc p(b: var TB) = nil
var c: TC
p(c)

View file

@ -9,7 +9,9 @@ proc QuickSort(list: seq[int]): seq[int] =
left.add(list[i])
elif list[i] > pivot:
right.add(list[i])
result = QuickSort(left) & pivot & QuickSort(right)
result = QuickSort(left) &
pivot &
QuickSort(right)
proc echoSeq(a: seq[int]) =
for i in low(a)..high(a):

View file

@ -34,6 +34,7 @@ tisopr.nim;falsetrue
titer2.nim;123
titer3.nim;1231
titer5.nim;abcxyz
titer6.nim;000
tlenopenarray.nim;1
tlowhigh.nim;10
tmatrix.nim;111

1 tack.nim 125
34 titer2.nim 123
35 titer3.nim 1231
36 titer5.nim abcxyz
37 titer6.nim 000
38 tlenopenarray.nim 1
39 tlowhigh.nim 10
40 tmatrix.nim 111

View file

@ -0,0 +1,31 @@
# Test iterator with more than 1 yield statement
import strutils
iterator tokenize2(s: string, seps: set[char] = Whitespace): tuple[
token: string, isSep: bool] =
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 (copy(s, i, j-1), true)
else:
while j < s.len and s[j] notin seps: inc(j)
if j > i:
yield (copy(s, i, j-1), false)
i = j
for word, isSep in tokenize2("ta da", whiteSpace):
var titer2TestVar = 0
stdout.write(titer2TestVar)
proc wordWrap2(s: string, maxLineWidth = 80,
splitLongWords = true,
seps: set[char] = whitespace,
newLine = "\n"): string =
result = ""
for word, isSep in tokenize2(s, seps):
var w = 0