bugfix: multiple yield statements and loop body vars
This commit is contained in:
parent
e7fe8edab3
commit
63ac32e6de
13 changed files with 256 additions and 75 deletions
18
tests/accept/compile/toop.nim
Normal file
18
tests/accept/compile/toop.nim
Normal 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)
|
||||
|
||||
|
|
@ -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):
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
31
tests/accept/run/titer6.nim
Normal file
31
tests/accept/run/titer6.nim
Normal 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
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue