1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126
|
-- is sane
::foo::
::bar::
::baz::
a = 0
-- does not affect indentation when put on a separate line
for z=1,10 do
::foo::
bar
end
a = 0
-- XFAIL: does not affect indentation before block modifiers
::foo:: for z=1,10 do
bar
end
a = 0
-- does not affect indentation after block modifiers
for z=1,10 do ::foo::
bar
end
a = 0
-- reindents according to luawiki examples: 1
for z=1,10 do
::foo::
for y=1,10 do ::bar
for x=1,10 do
if x^2 + y^2 == z^2 then
print('found a Pythagorean triple:', x, y, z)
goto done
goto done2
end
end
::done2::
end
end
::done::
-- reindents according to luawiki examples: 2
for z=1,10 do
for y=1,10 do
for x=1,10 do
if x^2 + y^2 == z^2 then
print('found a Pythagorean triple:', x, y, z)
print('now trying next z...')
goto zcontinue
end
end
end
::zcontinue::
end
-- reindents according to luawiki examples: 3
for x=1,5 do ::redo::
print(x .. ' + 1 = ?')
local y = tonumber(io.read'*l')
if y ~= x + 1 then goto redo end
end
-- reindents according to luawiki examples: 4
::a::
print 'A'
if math.random() < 0.3 then goto c end
::b::
print 'B'
if math.random() < 0.5 then goto a end
::c::
print 'C'
if math.random() < 0.1 then goto a else goto b end
-- reindents according to luawiki examples: 5
function fact_(n, ans)
::call::
if n == 0 then
return ans
else
n, ans = n - 1, ans * n
goto call
end
end
print(fact_(5, 1)) --> 120
-- reindents according to luawiki examples: 6
function f()
if not g() then goto fail end
if not h() then goto cleanup_g end
if not i() then goto cleanup_h end
do return true end -- need do/end?
::cleanup_h::
undo_h()
::cleanup_g::
undo_g()
::fail::
return false
end
-- reindents according to luawiki examples: 7
::redo::
for x=1,10 do
for y=1,10 do
if not f(x,y) then goto continue end
if not g(x,y) then goto skip end
if not h(x,y) then goto redo end
::continue::
end
end ::skip::
print('foo')
|