flor 0.0.1 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.md +13 -0
- data/LICENSE.txt +1 -1
- data/Makefile +66 -0
- data/README.md +57 -0
- data/fail.txt +7 -0
- data/flor.gemspec +12 -9
- data/intercepted.txt +123 -0
- data/lib/flor/colours.rb +140 -0
- data/lib/flor/conf.rb +88 -0
- data/lib/flor/core/executor.rb +473 -0
- data/lib/flor/core/node.rb +397 -0
- data/lib/flor/core/procedure.rb +600 -0
- data/lib/flor/core/texecutor.rb +209 -0
- data/lib/flor/core.rb +93 -0
- data/lib/flor/dollar.rb +248 -0
- data/lib/flor/errors.rb +36 -0
- data/lib/flor/flor.rb +556 -0
- data/lib/flor/log.rb +336 -0
- data/lib/flor/migrations/0001_tables.rb +122 -0
- data/lib/flor/parser.rb +414 -0
- data/lib/flor/pcore/_arr.rb +49 -0
- data/lib/flor/pcore/_atom.rb +43 -0
- data/lib/flor/pcore/_att.rb +160 -0
- data/lib/flor/pcore/_dump.rb +60 -0
- data/lib/flor/pcore/_err.rb +30 -0
- data/lib/flor/pcore/_happly.rb +73 -0
- data/lib/flor/pcore/_obj.rb +65 -0
- data/lib/flor/pcore/_skip.rb +63 -0
- data/lib/flor/pcore/apply.rb +60 -0
- data/lib/flor/pcore/arith.rb +46 -0
- data/lib/flor/pcore/break.rb +71 -0
- data/lib/flor/pcore/cmp.rb +72 -0
- data/lib/flor/pcore/cond.rb +57 -0
- data/lib/flor/pcore/cursor.rb +223 -0
- data/lib/flor/pcore/define.rb +96 -0
- data/lib/flor/pcore/fail.rb +45 -0
- data/lib/flor/pcore/ife.rb +56 -0
- data/lib/flor/pcore/loop.rb +53 -0
- data/lib/flor/pcore/map.rb +75 -0
- data/lib/flor/pcore/match.rb +70 -0
- data/lib/flor/pcore/move.rb +65 -0
- data/lib/flor/pcore/noeval.rb +46 -0
- data/lib/flor/pcore/noret.rb +47 -0
- data/lib/flor/pcore/push.rb +69 -0
- data/lib/flor/pcore/sequence.rb +39 -0
- data/lib/flor/pcore/set.rb +76 -0
- data/lib/flor/pcore/stall.rb +35 -0
- data/lib/flor/pcore/until.rb +122 -0
- data/lib/flor/pcore/val.rb +40 -0
- data/lib/flor/punit/cancel.rb +69 -0
- data/lib/flor/punit/cmap.rb +76 -0
- data/lib/flor/punit/concurrence.rb +149 -0
- data/lib/flor/punit/every.rb +46 -0
- data/lib/flor/punit/on.rb +81 -0
- data/lib/flor/punit/schedule.rb +68 -0
- data/lib/flor/punit/signal.rb +47 -0
- data/lib/flor/punit/sleep.rb +53 -0
- data/lib/flor/punit/task.rb +109 -0
- data/lib/flor/punit/trace.rb +51 -0
- data/lib/flor/punit/trap.rb +100 -0
- data/lib/flor/to_string.rb +81 -0
- data/lib/flor/tools/env.rb +103 -0
- data/lib/flor/tools/repl.rb +231 -0
- data/lib/flor/unit/executor.rb +260 -0
- data/lib/flor/unit/hooker.rb +186 -0
- data/lib/flor/unit/journal.rb +52 -0
- data/lib/flor/unit/loader.rb +181 -0
- data/lib/flor/unit/logger.rb +181 -0
- data/lib/flor/unit/models/execution.rb +105 -0
- data/lib/flor/unit/models/pointer.rb +31 -0
- data/lib/flor/unit/models/timer.rb +52 -0
- data/lib/flor/unit/models/trace.rb +31 -0
- data/lib/flor/unit/models/trap.rb +130 -0
- data/lib/flor/unit/models.rb +106 -0
- data/lib/flor/unit/scheduler.rb +419 -0
- data/lib/flor/unit/storage.rb +633 -0
- data/lib/flor/unit/tasker.rb +191 -0
- data/lib/flor/unit/waiter.rb +146 -0
- data/lib/flor/unit/wlist.rb +77 -0
- data/lib/flor/unit.rb +50 -0
- data/lib/flor.rb +40 -3
- metadata +152 -22
- checksums.yaml +0 -7
- data/Rakefile +0 -52
@@ -0,0 +1,223 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Cursor < Flor::Procedure
|
27
|
+
#
|
28
|
+
# Executes child expressions in sequence, but may be "guided".
|
29
|
+
#
|
30
|
+
# ```
|
31
|
+
# cursor
|
32
|
+
# task 'alpha'
|
33
|
+
# task 'bravo' if f.amount > 2000
|
34
|
+
# task 'charly'
|
35
|
+
# ```
|
36
|
+
#
|
37
|
+
# ## break
|
38
|
+
#
|
39
|
+
# Cursor understands `break`. For example, this execution will go from
|
40
|
+
# "alpha" to "charly", task "bravo" will not be visited.
|
41
|
+
# ```
|
42
|
+
# cursor
|
43
|
+
# task 'alpha'
|
44
|
+
# break _
|
45
|
+
# task 'bravo'
|
46
|
+
# task 'charly'
|
47
|
+
# ```
|
48
|
+
|
49
|
+
name 'cursor'
|
50
|
+
|
51
|
+
def pre_execute
|
52
|
+
|
53
|
+
@node['subs'] = []
|
54
|
+
end
|
55
|
+
|
56
|
+
def receive_first
|
57
|
+
|
58
|
+
@node['vars'] =
|
59
|
+
{}
|
60
|
+
|
61
|
+
@node['vars']['break'] =
|
62
|
+
[ '_proc', { 'proc' => 'break', 'nid' => nid }, tree[-1] ]
|
63
|
+
@node['vars']['continue'] =
|
64
|
+
[ '_proc', { 'proc' => 'continue', 'nid' => nid }, tree[-1] ]
|
65
|
+
|
66
|
+
@node['vars']['move'] =
|
67
|
+
[ '_proc', { 'proc' => 'move', 'nid' => nid }, tree[-1] ]
|
68
|
+
|
69
|
+
super
|
70
|
+
end
|
71
|
+
|
72
|
+
def receive_att
|
73
|
+
|
74
|
+
receive_unkeyed_tag_att + super
|
75
|
+
end
|
76
|
+
|
77
|
+
def receive_non_att
|
78
|
+
|
79
|
+
if @ncid >= children.size
|
80
|
+
if @message['orl'] == 'continue'
|
81
|
+
@node['subs'] << counter_next('subs')
|
82
|
+
execute_child(first_non_att_child_id, @node['subs'].last)
|
83
|
+
else
|
84
|
+
reply
|
85
|
+
end
|
86
|
+
else
|
87
|
+
execute_child(@ncid, @node['subs'].last)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
def cancel_when_closed
|
92
|
+
|
93
|
+
return [] unless @message['flavour'] == 'break'
|
94
|
+
|
95
|
+
cancel
|
96
|
+
end
|
97
|
+
|
98
|
+
def cancel
|
99
|
+
|
100
|
+
fla = @message['flavour']
|
101
|
+
|
102
|
+
# busy = @node['on_receive_last']
|
103
|
+
#
|
104
|
+
# close_node
|
105
|
+
#
|
106
|
+
# @node['on_receive_last'] =
|
107
|
+
# if fla == 'continue'
|
108
|
+
# @node['subs'] << counter_next('subs')
|
109
|
+
# execute_child(first_non_att_child_id, @node['subs'].last, 'orl' => fla)
|
110
|
+
# elsif fla == 'move'
|
111
|
+
# @node['subs'] << counter_next('subs')
|
112
|
+
# execute_child(move_target_child_id, @node['subs'].last, 'orl' => fla)
|
113
|
+
# else # 'break'
|
114
|
+
# nil
|
115
|
+
# end
|
116
|
+
#
|
117
|
+
# return [] if busy
|
118
|
+
# # <------- that implies that upon a sound reply,
|
119
|
+
# # @node['on_receive_last'] is set to nil!
|
120
|
+
# # @node['status'] is cleaned...
|
121
|
+
#
|
122
|
+
# super.tap { |ms| pp ms }
|
123
|
+
|
124
|
+
#if nid == '0_1_0'
|
125
|
+
# puts "\\" * 80
|
126
|
+
# puts caller[0, 7]
|
127
|
+
#end
|
128
|
+
|
129
|
+
if fla == 'continue'
|
130
|
+
|
131
|
+
@node['on_receive_last'] =
|
132
|
+
reply(
|
133
|
+
'nid' => nid, 'from' => "#{nid}_#{children.size + 1}",
|
134
|
+
'orl' => fla,
|
135
|
+
'payload' => Flor.dup(message['payload']))
|
136
|
+
|
137
|
+
elsif fla == 'move'
|
138
|
+
|
139
|
+
@node['subs'] << counter_next('subs')
|
140
|
+
|
141
|
+
@node['on_receive_last'] =
|
142
|
+
execute_child(move_target_child_id, @node['subs'].last, 'orl' => fla)
|
143
|
+
|
144
|
+
else
|
145
|
+
|
146
|
+
@node['on_receive_last'] = nil
|
147
|
+
end
|
148
|
+
|
149
|
+
super#.tap { |ms| pp ms }
|
150
|
+
end
|
151
|
+
|
152
|
+
protected
|
153
|
+
|
154
|
+
def move_target_child_id
|
155
|
+
|
156
|
+
to = @message['to']
|
157
|
+
|
158
|
+
fail("move target #{to.inspect} is not a string") unless to.is_a?(String)
|
159
|
+
|
160
|
+
find_tag_target(to) ||
|
161
|
+
find_string_arg_target(to) ||
|
162
|
+
find_string_target(to) ||
|
163
|
+
find_name_target(to) ||
|
164
|
+
find_att_target(to) ||
|
165
|
+
fail("move target #{to.inspect} not found")
|
166
|
+
end
|
167
|
+
|
168
|
+
def find_tag_target(to)
|
169
|
+
|
170
|
+
tree[1]
|
171
|
+
.index { |c|
|
172
|
+
c[1].is_a?(Array) &&
|
173
|
+
c[1].index { |cc|
|
174
|
+
Flor.is_tree?(cc) &&
|
175
|
+
cc[0] == '_att' &&
|
176
|
+
cc[1].size == 2 &&
|
177
|
+
cc[1][0][0] == 'tag' &&
|
178
|
+
%w[ _sqs _dqs ].include?(cc[1][1][0]) &&
|
179
|
+
cc[1][1][1] == to
|
180
|
+
}
|
181
|
+
}
|
182
|
+
end
|
183
|
+
|
184
|
+
def find_string_arg_target(to)
|
185
|
+
|
186
|
+
tree[1]
|
187
|
+
.index { |c|
|
188
|
+
c[1].is_a?(Array) &&
|
189
|
+
c[1].index { |cc|
|
190
|
+
Flor.is_tree?(cc) &&
|
191
|
+
cc[0] == '_att' &&
|
192
|
+
cc[1].size == 1 &&
|
193
|
+
%w[ _sqs _dqs ].include?(cc[1][0][0]) &&
|
194
|
+
cc[1][0][1] == to
|
195
|
+
}
|
196
|
+
}
|
197
|
+
end
|
198
|
+
|
199
|
+
def find_string_target(to)
|
200
|
+
|
201
|
+
tree[1].index { |c| %w[ _sqs _dqs ].include?(c[0]) && c[1] == to }
|
202
|
+
end
|
203
|
+
|
204
|
+
def find_name_target(to)
|
205
|
+
|
206
|
+
tree[1].index { |c| c[0] == to }
|
207
|
+
end
|
208
|
+
|
209
|
+
def find_att_target(to)
|
210
|
+
|
211
|
+
tree[1]
|
212
|
+
.index { |c|
|
213
|
+
c[0] == '_' &&
|
214
|
+
c[1].is_a?(Array) &&
|
215
|
+
c[1].find { |cc|
|
216
|
+
cc[0] == '_att' &&
|
217
|
+
cc[1].is_a?(Array) &&
|
218
|
+
cc[1][0][0, 2] == [ 'here', [] ]
|
219
|
+
}
|
220
|
+
}
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Define < Flor::Procedure
|
27
|
+
#
|
28
|
+
# Defines a function.
|
29
|
+
#
|
30
|
+
# In its `define` flavour, will take a function body and assign it to
|
31
|
+
# variable.
|
32
|
+
# ```
|
33
|
+
# define sum a, b # make variable 'sum' hold the function
|
34
|
+
# +
|
35
|
+
# a
|
36
|
+
# b
|
37
|
+
# # yields the function, like `fun` and `def` do
|
38
|
+
#
|
39
|
+
# sum 1 2
|
40
|
+
# # will yield 3
|
41
|
+
# ```
|
42
|
+
#
|
43
|
+
# In the `fun` and `def` flavours, the function is unnamed, it's thus not
|
44
|
+
# bound in a local variable.
|
45
|
+
# ```
|
46
|
+
# map [ 1, 2, 3 ]
|
47
|
+
# def x
|
48
|
+
# + x 3
|
49
|
+
# # yields [ 4, 5, 6 ]
|
50
|
+
# ```
|
51
|
+
#
|
52
|
+
# It's OK to generate the function name at the last moment:
|
53
|
+
# ```
|
54
|
+
# sequence
|
55
|
+
# set prefix "my"
|
56
|
+
# define "$(prefix)-sum" a b
|
57
|
+
# + a b
|
58
|
+
# ```
|
59
|
+
|
60
|
+
names %w[ def fun define ]
|
61
|
+
|
62
|
+
def execute
|
63
|
+
|
64
|
+
if i = att_children.index { |c| %w[ _dqs _sqs ].include?(c[1].first.first) }
|
65
|
+
execute_child(i)
|
66
|
+
else
|
67
|
+
receive_att
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def receive_att
|
72
|
+
|
73
|
+
t = tree
|
74
|
+
cnode = lookup_var_node(@node, 'l')
|
75
|
+
cnid = cnode['nid']
|
76
|
+
fun = counter_next('funs') - 1
|
77
|
+
(cnode['closures'] ||= []) << fun
|
78
|
+
|
79
|
+
val = [ '_func', { 'nid' => nid, 'cnid' => cnid, 'fun' => fun }, t[2] ]
|
80
|
+
|
81
|
+
if t[0] == 'define'
|
82
|
+
name =
|
83
|
+
if @message['point'] == 'execute'
|
84
|
+
t[1].first[1].first[0]
|
85
|
+
else
|
86
|
+
payload['ret']
|
87
|
+
end
|
88
|
+
set_var('', name, val)
|
89
|
+
end
|
90
|
+
|
91
|
+
payload['ret'] = val
|
92
|
+
|
93
|
+
reply
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Fail < Flor::Procedure
|
27
|
+
|
28
|
+
names 'fail', 'error'
|
29
|
+
|
30
|
+
def receive_last
|
31
|
+
|
32
|
+
err =
|
33
|
+
Flor::FlorError.new(
|
34
|
+
(payload['ret'] || 'error').to_s,
|
35
|
+
Flor::Node.new(@executor, @node, @message))
|
36
|
+
|
37
|
+
#fail err
|
38
|
+
#
|
39
|
+
# let's reply with the failed message directly,
|
40
|
+
# no need for a Ruby backtrace, it's an error at the Flor level.
|
41
|
+
#
|
42
|
+
reply('point' => 'failed', 'error' => Flor.to_error(err))
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
@@ -0,0 +1,56 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Ife < Flor::Procedure
|
27
|
+
|
28
|
+
names 'ife', 'unlesse'
|
29
|
+
|
30
|
+
def pre_execute
|
31
|
+
|
32
|
+
unatt_unkeyed_children
|
33
|
+
end
|
34
|
+
|
35
|
+
def receive_non_att
|
36
|
+
|
37
|
+
return reply if @fcid > first_unkeyed_child_id
|
38
|
+
# "else" or "then" answered, replying to parent...
|
39
|
+
|
40
|
+
off =
|
41
|
+
if tree[0] == 'unlesse'
|
42
|
+
Flor.false?(payload['ret']) ? 1 : 2
|
43
|
+
else # 'ife'
|
44
|
+
Flor.true?(payload['ret']) ? 1 : 2
|
45
|
+
end
|
46
|
+
|
47
|
+
nxt = @fcid + off
|
48
|
+
|
49
|
+
if nxt >= children.size
|
50
|
+
reply('ret' => node_payload_ret)
|
51
|
+
else
|
52
|
+
execute_child(nxt)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
@@ -0,0 +1,53 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Loop < Flor::Pro::Cursor
|
27
|
+
#
|
28
|
+
# Executes child expressions in sequence, then loops around.
|
29
|
+
#
|
30
|
+
# It's mostly a [cursor](cursor.md) that loops upon going past its
|
31
|
+
# last child.
|
32
|
+
#
|
33
|
+
# ```
|
34
|
+
# loop
|
35
|
+
# task 'alpha'
|
36
|
+
# task 'bravo'
|
37
|
+
# ```
|
38
|
+
#
|
39
|
+
# Accepts `break` and `continue` like `cursor` does.
|
40
|
+
|
41
|
+
name 'loop'
|
42
|
+
|
43
|
+
def receive_non_att
|
44
|
+
|
45
|
+
if @ncid >= children.size
|
46
|
+
@node['subs'] << counter_next('subs')
|
47
|
+
execute_child(first_non_att_child_id, @node['subs'].last)
|
48
|
+
else
|
49
|
+
execute_child(@ncid, @node['subs'].last)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
@@ -0,0 +1,75 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Map < Flor::Procedure
|
27
|
+
|
28
|
+
name 'map'
|
29
|
+
|
30
|
+
def pre_execute
|
31
|
+
|
32
|
+
#@node['ret'] = Flor.dup(payload['ret']) # now using @node['payload']
|
33
|
+
|
34
|
+
@node['vars'] = {}
|
35
|
+
# just to store the local idx
|
36
|
+
|
37
|
+
@node['col'] = nil
|
38
|
+
@node['idx'] = -1
|
39
|
+
@node['fun'] = nil
|
40
|
+
@node['res'] = []
|
41
|
+
|
42
|
+
unatt_unkeyed_children
|
43
|
+
end
|
44
|
+
|
45
|
+
def receive_non_att
|
46
|
+
|
47
|
+
@node['col'] ||=
|
48
|
+
Flor.to_coll(
|
49
|
+
if Flor.is_func_tree?(payload['ret'])
|
50
|
+
node_payload_ret
|
51
|
+
else
|
52
|
+
payload['ret']
|
53
|
+
end)
|
54
|
+
|
55
|
+
return execute_child(@ncid) \
|
56
|
+
if @node['fun'] == nil && children[@ncid] != nil
|
57
|
+
|
58
|
+
if @node['idx'] < 0
|
59
|
+
@node['fun'] = payload['ret']
|
60
|
+
else
|
61
|
+
@node['res'] << payload['ret']
|
62
|
+
end
|
63
|
+
|
64
|
+
@node['idx'] += 1
|
65
|
+
@node['mtime'] = Flor.tstamp
|
66
|
+
|
67
|
+
return reply('ret' => @node['res']) \
|
68
|
+
if @node['idx'] == @node['col'].size
|
69
|
+
|
70
|
+
@node['vars']['idx'] = @node['idx']
|
71
|
+
|
72
|
+
apply(@node['fun'], @node['col'][@node['idx'], 1], tree[2])
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
@@ -0,0 +1,70 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Match < Flor::Procedure
|
27
|
+
|
28
|
+
names %w[ match match? ]
|
29
|
+
|
30
|
+
def pre_execute
|
31
|
+
|
32
|
+
@node['rets'] = []
|
33
|
+
end
|
34
|
+
|
35
|
+
def receive_last
|
36
|
+
|
37
|
+
rex, str = arguments
|
38
|
+
|
39
|
+
m = rex.match(str)
|
40
|
+
|
41
|
+
payload['ret'] =
|
42
|
+
if @node['heap'] == 'match?'
|
43
|
+
!! m
|
44
|
+
else
|
45
|
+
m ? m.to_a : []
|
46
|
+
end
|
47
|
+
|
48
|
+
reply
|
49
|
+
end
|
50
|
+
|
51
|
+
protected
|
52
|
+
|
53
|
+
def arguments
|
54
|
+
|
55
|
+
fail ArgumentError.new(
|
56
|
+
"'match' needs at least 2 arguments"
|
57
|
+
) if @node['rets'].size < 2
|
58
|
+
|
59
|
+
rex = @node['rets']
|
60
|
+
.find { |r| r.is_a?(Array) && r[0] == '_rxs' } || @node['rets'].last
|
61
|
+
|
62
|
+
str = (@node['rets'] - [ rex ]).first
|
63
|
+
|
64
|
+
rex = rex.is_a?(String) ? rex : rex[1].to_s
|
65
|
+
rex = rex.match(/\A\/[^\/]*\/[a-z]*\z/) ? Kernel.eval(rex) : Regexp.new(rex)
|
66
|
+
|
67
|
+
[ rex, str ]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
@@ -0,0 +1,65 @@
|
|
1
|
+
#--
|
2
|
+
# Copyright (c) 2015-2017, John Mettraux, jmettraux+flor@gmail.com
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
5
|
+
# of this software and associated documentation files (the "Software"), to deal
|
6
|
+
# in the Software without restriction, including without limitation the rights
|
7
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
8
|
+
# copies of the Software, and to permit persons to whom the Software is
|
9
|
+
# furnished to do so, subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in
|
12
|
+
# all copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
16
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
17
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
18
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
19
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
20
|
+
# THE SOFTWARE.
|
21
|
+
#
|
22
|
+
# Made in Japan.
|
23
|
+
#++
|
24
|
+
|
25
|
+
|
26
|
+
class Flor::Pro::Move < Flor::Procedure
|
27
|
+
#
|
28
|
+
# Moves a cursor to a given position
|
29
|
+
#
|
30
|
+
# ```
|
31
|
+
# cursor
|
32
|
+
# do-this
|
33
|
+
# move to: 'do-that-other-thing'
|
34
|
+
# do-that # got skipped
|
35
|
+
# do-that-other-thing
|
36
|
+
# ```
|
37
|
+
|
38
|
+
name 'move'
|
39
|
+
|
40
|
+
def pre_execute
|
41
|
+
|
42
|
+
@node['atts_accepting_symbols'] = %w[ to ]
|
43
|
+
|
44
|
+
@node['atts'] = []
|
45
|
+
end
|
46
|
+
|
47
|
+
def receive_last
|
48
|
+
|
49
|
+
ref = att('ref', nil)
|
50
|
+
nid = tags_to_nids(ref).first || @node['heat'][1]['nid']
|
51
|
+
|
52
|
+
to = att('to')
|
53
|
+
|
54
|
+
rep = is_ancestor_node?(nid) ? [] : reply
|
55
|
+
|
56
|
+
reply(
|
57
|
+
'point' => 'cancel',
|
58
|
+
'nid' => nid,
|
59
|
+
'flavour' => @node['heap'], # "move"
|
60
|
+
'payload' => rep.any? ? payload.copy_current : payload.current,
|
61
|
+
'to' => to) +
|
62
|
+
rep
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|