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
|
# File 'lib/interscript/interpreter.rb', line 8
def call(str, stage=:main, each: false, &block)
stage = @map.stages[stage]
s =
if each
e = Enumerator.new do |yielder|
options = []
options_set = false
choices = nil
i = 0
loop do
result = nil
f = Fiber.new do
$select_nth_string = true
result = Stage.new(@map, str).execute_rule(stage)
$select_nth_string = false
Fiber.yield(:end)
end
iter = 0
loop do
break if f.resume == :end
type, value, hash = f.resume
if options_set
f.resume(choices[i][iter])
else
options[iter] = value
f.resume(0)
end
iter += 1
end
unless options_set
options_set = true
opts = options.map { |i| (0...i).to_a }
choices = opts[0].product(*opts[1..-1])
end
yielder.yield(result)
i += 1
break if i == choices.length
end
end
if block_given?
e.each(&block)
else
e
end
else
Stage.new(@map, str).execute_rule(stage)
end
end
|