manamana 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,97 @@
1
+ module ManaMana
2
+
3
+ module RDSL
4
+
5
+ class Node
6
+ attr_reader :children, :name
7
+
8
+ def initialize(name='', children=[])
9
+ @children = children
10
+ @name = name
11
+ end
12
+
13
+ def ==(other_node)
14
+ name == other_node.name && @children == other_node.children
15
+ end
16
+ end
17
+
18
+ class RootNode < Node
19
+ def all_requirements
20
+ groups.map{ |g| g.requirements }.flatten.map{ |r| r.expand }.flatten
21
+ end
22
+
23
+ def groups
24
+ children
25
+ end
26
+ end
27
+
28
+ class GroupNode < Node
29
+ def all_requirements
30
+ requirements.map{ |r| r.expand }.flatten
31
+ end
32
+
33
+ def requirements
34
+ children
35
+ end
36
+ end
37
+
38
+ class RequirementNode < Node
39
+ def examples
40
+ # RowNode.new('', ['Role', 'Can or Cannot Create']),
41
+ # RowNode.new('', ['PM', 'Can Create' ]),
42
+ # RowNode.new('', ['User', 'Cannot Create' ])
43
+
44
+ # [
45
+ # { '<Role>' => 'PM', '<Can or Cannot Create>' => 'Can Create' },
46
+ # { '<Role>' => 'User', '<Can or Cannot Create>' => 'Cannot Create' }
47
+ # ]
48
+ return [] if children.length == 0
49
+
50
+ nodes = children[0].rows
51
+ headers = nodes[0].cells
52
+ rows = []
53
+
54
+ nodes[1..-1].each do |node|
55
+ row = {}
56
+ node.cells.each_with_index do |value, index|
57
+ row["<#{headers[index]}>"] = value
58
+ end
59
+ rows << row
60
+ end
61
+
62
+ rows
63
+ end
64
+
65
+ def expand
66
+ return [name] if examples.length == 0
67
+
68
+ requirements = []
69
+
70
+ examples.each do |row|
71
+ tmp = name.dup
72
+ row.each_key do |key|
73
+ tmp.gsub! key, row[key]
74
+ end
75
+ requirements << tmp
76
+ end
77
+
78
+ requirements
79
+ end
80
+ end
81
+
82
+ class ExamplesNode < Node
83
+ def rows
84
+ children
85
+ end
86
+ end
87
+
88
+
89
+ class RowNode < Node
90
+ def cells
91
+ children
92
+ end
93
+ end
94
+
95
+ end
96
+
97
+ end
@@ -0,0 +1,311 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.9
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+
9
+ require 'manamana/rdsl/lexer'
10
+ require 'manamana/rdsl/nodes'
11
+
12
+ module ManaMana
13
+ module RDSL
14
+ class Parser < Racc::Parser
15
+
16
+ module_eval(<<'...end parser.y/module_eval...', 'parser.y', 63)
17
+ def parse(code, show_tokens=false)
18
+ @tokens = Lexer.new.tokenize(code)
19
+ puts @tokens.inspect if show_tokens
20
+ do_parse
21
+ end
22
+
23
+ def next_token
24
+ @tokens.shift
25
+ end
26
+ ...end parser.y/module_eval...
27
+ ##### State transition tables begin ###
28
+
29
+ racc_action_table = [
30
+ 3, 8, 9, 8, 9, 18, 9, 10, 8, 3,
31
+ 4, 3, 8, 18, 23, 9, 18, 23 ]
32
+
33
+ racc_action_check = [
34
+ 3, 3, 3, 8, 8, 8, 9, 4, 5, 7,
35
+ 1, 0, 14, 15, 18, 21, 22, 23 ]
36
+
37
+ racc_action_pointer = [
38
+ 9, 10, nil, -2, 7, 5, nil, 7, 0, 2,
39
+ nil, nil, nil, nil, 9, 8, nil, nil, 8, nil,
40
+ nil, 11, 11, 11, nil, nil, nil ]
41
+
42
+ racc_action_default = [
43
+ -1, -24, -2, -3, -24, -4, -5, -6, -9, -17,
44
+ 27, -7, -8, -10, -11, -13, -14, -19, -24, -18,
45
+ -12, -15, -20, -22, -16, -21, -23 ]
46
+
47
+ racc_goto_table = [
48
+ 5, 14, 7, 16, 11, 15, 19, 13, 2, 22,
49
+ 21, 6, 25, 20, 26, 12, 1, nil, 24 ]
50
+
51
+ racc_goto_check = [
52
+ 3, 5, 4, 6, 4, 3, 3, 4, 2, 8,
53
+ 6, 2, 7, 4, 8, 2, 1, nil, 3 ]
54
+
55
+ racc_goto_pointer = [
56
+ nil, 16, 8, -3, -1, -7, -5, -10, -9 ]
57
+
58
+ racc_goto_default = [
59
+ nil, nil, nil, nil, nil, nil, nil, 17, nil ]
60
+
61
+ racc_reduce_table = [
62
+ 0, 0, :racc_error,
63
+ 0, 8, :_reduce_1,
64
+ 1, 8, :_reduce_2,
65
+ 1, 9, :_reduce_3,
66
+ 2, 9, :_reduce_4,
67
+ 2, 9, :_reduce_5,
68
+ 2, 9, :_reduce_6,
69
+ 3, 9, :_reduce_7,
70
+ 3, 9, :_reduce_8,
71
+ 1, 11, :_reduce_9,
72
+ 2, 11, :_reduce_10,
73
+ 2, 11, :_reduce_11,
74
+ 3, 11, :_reduce_12,
75
+ 1, 12, :_reduce_13,
76
+ 1, 12, :_reduce_14,
77
+ 2, 12, :_reduce_15,
78
+ 3, 12, :_reduce_16,
79
+ 1, 10, :_reduce_17,
80
+ 2, 10, :_reduce_18,
81
+ 1, 13, :_reduce_19,
82
+ 2, 14, :_reduce_20,
83
+ 3, 14, :_reduce_21,
84
+ 1, 15, :_reduce_22,
85
+ 2, 15, :_reduce_23 ]
86
+
87
+ racc_reduce_n = 24
88
+
89
+ racc_shift_n = 27
90
+
91
+ racc_token_table = {
92
+ false => 0,
93
+ :error => 1,
94
+ :GROUP => 2,
95
+ :REQUIREMENT => 3,
96
+ :TEXT => 4,
97
+ :ROW => 5,
98
+ :CELL => 6 }
99
+
100
+ racc_nt_base = 7
101
+
102
+ racc_use_result_var = true
103
+
104
+ Racc_arg = [
105
+ racc_action_table,
106
+ racc_action_check,
107
+ racc_action_default,
108
+ racc_action_pointer,
109
+ racc_goto_table,
110
+ racc_goto_check,
111
+ racc_goto_default,
112
+ racc_goto_pointer,
113
+ racc_nt_base,
114
+ racc_reduce_table,
115
+ racc_token_table,
116
+ racc_shift_n,
117
+ racc_reduce_n,
118
+ racc_use_result_var ]
119
+
120
+ Racc_token_to_s_table = [
121
+ "$end",
122
+ "error",
123
+ "GROUP",
124
+ "REQUIREMENT",
125
+ "TEXT",
126
+ "ROW",
127
+ "CELL",
128
+ "$start",
129
+ "Root",
130
+ "Groups",
131
+ "Text",
132
+ "Requirements",
133
+ "RequirementBody",
134
+ "Table",
135
+ "Rows",
136
+ "Cells" ]
137
+
138
+ Racc_debug_parser = false
139
+
140
+ ##### State transition tables end #####
141
+
142
+ # reduce 0 omitted
143
+
144
+ module_eval(<<'.,.,', 'parser.y', 10)
145
+ def _reduce_1(val, _values, result)
146
+ result = RootNode.new
147
+ result
148
+ end
149
+ .,.,
150
+
151
+ module_eval(<<'.,.,', 'parser.y', 11)
152
+ def _reduce_2(val, _values, result)
153
+ result = RootNode.new('', val[0])
154
+ result
155
+ end
156
+ .,.,
157
+
158
+ module_eval(<<'.,.,', 'parser.y', 15)
159
+ def _reduce_3(val, _values, result)
160
+ result = [ GroupNode.new(val[0]) ]
161
+ result
162
+ end
163
+ .,.,
164
+
165
+ module_eval(<<'.,.,', 'parser.y', 16)
166
+ def _reduce_4(val, _values, result)
167
+ result = [ GroupNode.new(val[0]) ]
168
+ result
169
+ end
170
+ .,.,
171
+
172
+ module_eval(<<'.,.,', 'parser.y', 17)
173
+ def _reduce_5(val, _values, result)
174
+ result = [ GroupNode.new(val[0]) ] + val[1]
175
+ result
176
+ end
177
+ .,.,
178
+
179
+ module_eval(<<'.,.,', 'parser.y', 18)
180
+ def _reduce_6(val, _values, result)
181
+ result = [ GroupNode.new(val[0], val[1]) ]
182
+ result
183
+ end
184
+ .,.,
185
+
186
+ module_eval(<<'.,.,', 'parser.y', 19)
187
+ def _reduce_7(val, _values, result)
188
+ result = [ GroupNode.new(val[0], val[2]) ]
189
+ result
190
+ end
191
+ .,.,
192
+
193
+ module_eval(<<'.,.,', 'parser.y', 20)
194
+ def _reduce_8(val, _values, result)
195
+ result = [ GroupNode.new(val[0], val[1]) ] + val[2]
196
+ result
197
+ end
198
+ .,.,
199
+
200
+ module_eval(<<'.,.,', 'parser.y', 24)
201
+ def _reduce_9(val, _values, result)
202
+ result = [ RequirementNode.new(val[0]) ]
203
+ result
204
+ end
205
+ .,.,
206
+
207
+ module_eval(<<'.,.,', 'parser.y', 25)
208
+ def _reduce_10(val, _values, result)
209
+ result = [ RequirementNode.new(val[0]) ] + val[1]
210
+ result
211
+ end
212
+ .,.,
213
+
214
+ module_eval(<<'.,.,', 'parser.y', 26)
215
+ def _reduce_11(val, _values, result)
216
+ result = [ RequirementNode.new(val[0], val[1]) ]
217
+ result
218
+ end
219
+ .,.,
220
+
221
+ module_eval(<<'.,.,', 'parser.y', 27)
222
+ def _reduce_12(val, _values, result)
223
+ result = [ RequirementNode.new(val[0], val[1]) ] + val[2]
224
+ result
225
+ end
226
+ .,.,
227
+
228
+ module_eval(<<'.,.,', 'parser.y', 31)
229
+ def _reduce_13(val, _values, result)
230
+ result = val[0]
231
+ result
232
+ end
233
+ .,.,
234
+
235
+ module_eval(<<'.,.,', 'parser.y', 32)
236
+ def _reduce_14(val, _values, result)
237
+ result = val[0]
238
+ result
239
+ end
240
+ .,.,
241
+
242
+ module_eval(<<'.,.,', 'parser.y', 33)
243
+ def _reduce_15(val, _values, result)
244
+ result = val[0] + val[1]
245
+ result
246
+ end
247
+ .,.,
248
+
249
+ module_eval(<<'.,.,', 'parser.y', 34)
250
+ def _reduce_16(val, _values, result)
251
+ result = val[0] + val[1] + val[2]
252
+ result
253
+ end
254
+ .,.,
255
+
256
+ module_eval(<<'.,.,', 'parser.y', 38)
257
+ def _reduce_17(val, _values, result)
258
+ result = []
259
+ result
260
+ end
261
+ .,.,
262
+
263
+ module_eval(<<'.,.,', 'parser.y', 39)
264
+ def _reduce_18(val, _values, result)
265
+ result = []
266
+ result
267
+ end
268
+ .,.,
269
+
270
+ module_eval(<<'.,.,', 'parser.y', 43)
271
+ def _reduce_19(val, _values, result)
272
+ result = [ ExamplesNode.new('', val[0]) ]
273
+ result
274
+ end
275
+ .,.,
276
+
277
+ module_eval(<<'.,.,', 'parser.y', 47)
278
+ def _reduce_20(val, _values, result)
279
+ result = [ RowNode.new('', val[1]) ]
280
+ result
281
+ end
282
+ .,.,
283
+
284
+ module_eval(<<'.,.,', 'parser.y', 48)
285
+ def _reduce_21(val, _values, result)
286
+ result = [ RowNode.new('', val[1]) ] + val[2]
287
+ result
288
+ end
289
+ .,.,
290
+
291
+ module_eval(<<'.,.,', 'parser.y', 52)
292
+ def _reduce_22(val, _values, result)
293
+ result = [ val[0] ]
294
+ result
295
+ end
296
+ .,.,
297
+
298
+ module_eval(<<'.,.,', 'parser.y', 53)
299
+ def _reduce_23(val, _values, result)
300
+ result = [ val[0] ] + val[1]
301
+ result
302
+ end
303
+ .,.,
304
+
305
+ def _reduce_none(val, _values, result)
306
+ val[0]
307
+ end
308
+
309
+ end # class Parser
310
+ end # module RDSL
311
+ end # module ManaMana
@@ -0,0 +1,27 @@
1
+ module ManaMana
2
+
3
+ class Runner
4
+ def recursive_require(in_dir)
5
+ Dir.entries(in_dir).each do |entry|
6
+ next if ['.', '..'].include? entry
7
+
8
+ path = File.join(in_dir, entry)
9
+
10
+ if File.directory?(path)
11
+ recursive_require(path)
12
+ else
13
+ require path
14
+ end
15
+ end
16
+ end
17
+
18
+ def start
19
+ require 'minitest/autorun'
20
+ require 'minitest/colorize'
21
+
22
+ recursive_require File.join(Dir.pwd, 'directives', 'utilities')
23
+ require File.join(Dir.pwd, '__spec__.rb')
24
+ end
25
+ end
26
+
27
+ end
@@ -0,0 +1,49 @@
1
+ require 'singleton'
2
+
3
+ module ManaMana
4
+
5
+ class Steps
6
+ include Singleton
7
+
8
+ def self.add(pattern, &block)
9
+ instance.add pattern, &block
10
+ end
11
+
12
+ def self.call(pattern)
13
+ instance.call pattern
14
+ end
15
+
16
+ attr_reader :steps
17
+
18
+ def initialize
19
+ @steps = []
20
+ end
21
+
22
+ def add(pattern, &block)
23
+ steps << { pattern: pattern, block: block }
24
+ end
25
+
26
+ # The step_name variable below is a string that may or
27
+ # may not match the regex pattern of one of the hashes
28
+ # in the steps array.
29
+ def call(step_name)
30
+ vars = nil
31
+ step = steps.find { |s| vars = s[:pattern].match(step_name) }
32
+
33
+ raise "Undefined step '#{ step_name }'" unless step
34
+
35
+ if vars.length > 1
36
+ step[:block].call(*vars[1..-1])
37
+ else
38
+ step[:block].call
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+
45
+ def step(pattern, &block)
46
+ Steps.add pattern, &block
47
+ end
48
+
49
+ end