wml_action 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.
- checksums.yaml +15 -0
- data/.gitignore +17 -0
- data/.rubocop.yml +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +113 -0
- data/Rakefile +18 -0
- data/bin/wml_action +5 -0
- data/lib/wml_action/cli.rb +55 -0
- data/lib/wml_action/document.rb +22 -0
- data/lib/wml_action/lexer.rex +50 -0
- data/lib/wml_action/lexer.rex.rb +136 -0
- data/lib/wml_action/log.rb +19 -0
- data/lib/wml_action/parser.tab.rb +318 -0
- data/lib/wml_action/parser.y +52 -0
- data/lib/wml_action/tag.rb +144 -0
- data/lib/wml_action/version.rb +3 -0
- data/lib/wml_action.rb +9 -0
- data/spec/document_spec.rb +79 -0
- data/spec/fixtures/actions.cfg +14 -0
- data/spec/fixtures/as_from_file.cfg +15 -0
- data/spec/fixtures/attributes.cfg +7 -0
- data/spec/fixtures/filter.cfg +4 -0
- data/spec/fixtures/inners.cfg +11 -0
- data/spec/fixtures/macros.cfg +3 -0
- data/spec/fixtures/s_from_file.cfg +8 -0
- data/spec/fixtures/strings.cfg +9 -0
- data/spec/fixtures/tag.cfg +2 -0
- data/spec/tag_spec.rb +235 -0
- data/wml_action.gemspec +36 -0
- metadata +253 -0
@@ -0,0 +1,318 @@
|
|
1
|
+
#
|
2
|
+
# DO NOT MODIFY!!!!
|
3
|
+
# This file is automatically generated by Racc 1.4.11
|
4
|
+
# from Racc grammer file "".
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'racc/parser.rb'
|
8
|
+
|
9
|
+
#
|
10
|
+
# generated by racc
|
11
|
+
#
|
12
|
+
require 'wml_action/lexer.rex'
|
13
|
+
require 'wml_action/tag'
|
14
|
+
require 'wml_action/log'
|
15
|
+
|
16
|
+
module WMLAction
|
17
|
+
class Parser < Racc::Parser
|
18
|
+
|
19
|
+
module_eval(<<'...end parser.y/module_eval...', 'parser.y', 49)
|
20
|
+
include Log
|
21
|
+
|
22
|
+
...end parser.y/module_eval...
|
23
|
+
##### State transition tables begin ###
|
24
|
+
|
25
|
+
racc_action_table = [
|
26
|
+
4, 8, 14, 16, 17, 18, 22, 24, 25, 26,
|
27
|
+
27, 29, 19, 4, 18, 21, 4, 7, 5, 30,
|
28
|
+
31, 32 ]
|
29
|
+
|
30
|
+
racc_action_check = [
|
31
|
+
6, 6, 6, 6, 6, 6, 18, 18, 18, 18,
|
32
|
+
18, 19, 6, 15, 19, 15, 0, 5, 1, 23,
|
33
|
+
27, 30 ]
|
34
|
+
|
35
|
+
racc_action_pointer = [
|
36
|
+
14, 18, nil, nil, nil, 17, -2, nil, nil, nil,
|
37
|
+
nil, nil, nil, nil, nil, 11, nil, nil, -2, 7,
|
38
|
+
nil, nil, nil, 6, nil, nil, nil, 9, nil, nil,
|
39
|
+
12, nil, nil ]
|
40
|
+
|
41
|
+
racc_action_default = [
|
42
|
+
-1, -26, -2, -3, -5, -26, -26, 33, -4, -6,
|
43
|
+
-7, -8, -9, -10, -11, -26, -14, -15, -16, -26,
|
44
|
+
-12, -13, -17, -18, -19, -20, -21, -26, -24, -25,
|
45
|
+
-26, -22, -23 ]
|
46
|
+
|
47
|
+
racc_goto_table = [
|
48
|
+
3, 12, 10, 6, 9, 1, 11, 2, 13, 15,
|
49
|
+
23, nil, nil, nil, 28, 20 ]
|
50
|
+
|
51
|
+
racc_goto_check = [
|
52
|
+
3, 7, 6, 4, 5, 1, 3, 2, 8, 9,
|
53
|
+
10, nil, nil, nil, 7, 3 ]
|
54
|
+
|
55
|
+
racc_goto_pointer = [
|
56
|
+
nil, 5, 7, 0, -1, -2, -4, -5, 2, 3,
|
57
|
+
-8 ]
|
58
|
+
|
59
|
+
racc_goto_default = [
|
60
|
+
nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
|
61
|
+
nil ]
|
62
|
+
|
63
|
+
racc_reduce_table = [
|
64
|
+
0, 0, :racc_error,
|
65
|
+
0, 16, :_reduce_none,
|
66
|
+
1, 16, :_reduce_2,
|
67
|
+
1, 17, :_reduce_3,
|
68
|
+
3, 18, :_reduce_4,
|
69
|
+
0, 19, :_reduce_5,
|
70
|
+
2, 19, :_reduce_6,
|
71
|
+
1, 20, :_reduce_none,
|
72
|
+
1, 20, :_reduce_8,
|
73
|
+
1, 20, :_reduce_none,
|
74
|
+
1, 20, :_reduce_none,
|
75
|
+
1, 20, :_reduce_11,
|
76
|
+
2, 21, :_reduce_12,
|
77
|
+
2, 21, :_reduce_13,
|
78
|
+
1, 24, :_reduce_none,
|
79
|
+
1, 24, :_reduce_none,
|
80
|
+
1, 22, :_reduce_16,
|
81
|
+
2, 22, :_reduce_17,
|
82
|
+
2, 22, :_reduce_18,
|
83
|
+
2, 22, :_reduce_19,
|
84
|
+
2, 22, :_reduce_20,
|
85
|
+
1, 25, :_reduce_21,
|
86
|
+
2, 25, :_reduce_22,
|
87
|
+
3, 25, :_reduce_23,
|
88
|
+
2, 23, :_reduce_24,
|
89
|
+
2, 23, :_reduce_25 ]
|
90
|
+
|
91
|
+
racc_reduce_n = 26
|
92
|
+
|
93
|
+
racc_shift_n = 33
|
94
|
+
|
95
|
+
racc_token_table = {
|
96
|
+
false => 0,
|
97
|
+
:error => 1,
|
98
|
+
:OTAG => 2,
|
99
|
+
:CTAG => 3,
|
100
|
+
:MACRO => 4,
|
101
|
+
"+" => 5,
|
102
|
+
"-" => 6,
|
103
|
+
:ATTR => 7,
|
104
|
+
:APLAIN => 8,
|
105
|
+
:AMACRO => 9,
|
106
|
+
:ANUMBER => 10,
|
107
|
+
:ASTR => 11,
|
108
|
+
:UNDERSC => 12,
|
109
|
+
:APLUS => 13,
|
110
|
+
:SLASH => 14 }
|
111
|
+
|
112
|
+
racc_nt_base = 15
|
113
|
+
|
114
|
+
racc_use_result_var = true
|
115
|
+
|
116
|
+
Racc_arg = [
|
117
|
+
racc_action_table,
|
118
|
+
racc_action_check,
|
119
|
+
racc_action_default,
|
120
|
+
racc_action_pointer,
|
121
|
+
racc_goto_table,
|
122
|
+
racc_goto_check,
|
123
|
+
racc_goto_default,
|
124
|
+
racc_goto_pointer,
|
125
|
+
racc_nt_base,
|
126
|
+
racc_reduce_table,
|
127
|
+
racc_token_table,
|
128
|
+
racc_shift_n,
|
129
|
+
racc_reduce_n,
|
130
|
+
racc_use_result_var ]
|
131
|
+
|
132
|
+
Racc_token_to_s_table = [
|
133
|
+
"$end",
|
134
|
+
"error",
|
135
|
+
"OTAG",
|
136
|
+
"CTAG",
|
137
|
+
"MACRO",
|
138
|
+
"\"+\"",
|
139
|
+
"\"-\"",
|
140
|
+
"ATTR",
|
141
|
+
"APLAIN",
|
142
|
+
"AMACRO",
|
143
|
+
"ANUMBER",
|
144
|
+
"ASTR",
|
145
|
+
"UNDERSC",
|
146
|
+
"APLUS",
|
147
|
+
"SLASH",
|
148
|
+
"$start",
|
149
|
+
"target",
|
150
|
+
"wml_doc",
|
151
|
+
"tag",
|
152
|
+
"contents",
|
153
|
+
"content",
|
154
|
+
"action",
|
155
|
+
"attribute",
|
156
|
+
"filter",
|
157
|
+
"aop",
|
158
|
+
"string_val" ]
|
159
|
+
|
160
|
+
Racc_debug_parser = false
|
161
|
+
|
162
|
+
##### State transition tables end #####
|
163
|
+
|
164
|
+
# reduce 0 omitted
|
165
|
+
|
166
|
+
# reduce 1 omitted
|
167
|
+
|
168
|
+
module_eval(<<'.,.,', 'parser.y', 3)
|
169
|
+
def _reduce_2(val, _values, result)
|
170
|
+
log.debug 'Found a target'
|
171
|
+
result
|
172
|
+
end
|
173
|
+
.,.,
|
174
|
+
|
175
|
+
module_eval(<<'.,.,', 'parser.y', 5)
|
176
|
+
def _reduce_3(val, _values, result)
|
177
|
+
log.debug 'Found a doc'
|
178
|
+
result
|
179
|
+
end
|
180
|
+
.,.,
|
181
|
+
|
182
|
+
module_eval(<<'.,.,', 'parser.y', 7)
|
183
|
+
def _reduce_4(val, _values, result)
|
184
|
+
log.debug("Creating tag #{val[0]}"); return Tag.new(name: val[0], content: val[1])
|
185
|
+
result
|
186
|
+
end
|
187
|
+
.,.,
|
188
|
+
|
189
|
+
module_eval(<<'.,.,', 'parser.y', 9)
|
190
|
+
def _reduce_5(val, _values, result)
|
191
|
+
return []
|
192
|
+
result
|
193
|
+
end
|
194
|
+
.,.,
|
195
|
+
|
196
|
+
module_eval(<<'.,.,', 'parser.y', 10)
|
197
|
+
def _reduce_6(val, _values, result)
|
198
|
+
log.debug("Append #{val[1]} to #{val[0]}"); return val[0]? val[0].push(val[1]) : [val[1]]
|
199
|
+
result
|
200
|
+
end
|
201
|
+
.,.,
|
202
|
+
|
203
|
+
# reduce 7 omitted
|
204
|
+
|
205
|
+
module_eval(<<'.,.,', 'parser.y', 13)
|
206
|
+
def _reduce_8(val, _values, result)
|
207
|
+
log.debug "Found a content subtag #{val[0]}"
|
208
|
+
result
|
209
|
+
end
|
210
|
+
.,.,
|
211
|
+
|
212
|
+
# reduce 9 omitted
|
213
|
+
|
214
|
+
# reduce 10 omitted
|
215
|
+
|
216
|
+
module_eval(<<'.,.,', 'parser.y', 16)
|
217
|
+
def _reduce_11(val, _values, result)
|
218
|
+
log.debug "Found a macro #{val[0]}"; return Tag::Macro[val[0]]
|
219
|
+
result
|
220
|
+
end
|
221
|
+
.,.,
|
222
|
+
|
223
|
+
module_eval(<<'.,.,', 'parser.y', 18)
|
224
|
+
def _reduce_12(val, _values, result)
|
225
|
+
log.debug "Found a action tag #{val[0]}:#{val[1]}"; return Tag::Action[val[1],val[0]]
|
226
|
+
result
|
227
|
+
end
|
228
|
+
.,.,
|
229
|
+
|
230
|
+
module_eval(<<'.,.,', 'parser.y', 19)
|
231
|
+
def _reduce_13(val, _values, result)
|
232
|
+
log.debug "Found a action mac #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]]
|
233
|
+
result
|
234
|
+
end
|
235
|
+
.,.,
|
236
|
+
|
237
|
+
# reduce 14 omitted
|
238
|
+
|
239
|
+
# reduce 15 omitted
|
240
|
+
|
241
|
+
module_eval(<<'.,.,', 'parser.y', 24)
|
242
|
+
def _reduce_16(val, _values, result)
|
243
|
+
log.debug "Found empty attribute: #{val[0]}"; return Tag::Attribute[val[0],'']
|
244
|
+
result
|
245
|
+
end
|
246
|
+
.,.,
|
247
|
+
|
248
|
+
module_eval(<<'.,.,', 'parser.y', 25)
|
249
|
+
def _reduce_17(val, _values, result)
|
250
|
+
log.debug "Found plain attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
|
251
|
+
result
|
252
|
+
end
|
253
|
+
.,.,
|
254
|
+
|
255
|
+
module_eval(<<'.,.,', 'parser.y', 26)
|
256
|
+
def _reduce_18(val, _values, result)
|
257
|
+
log.debug "Found string attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
|
258
|
+
result
|
259
|
+
end
|
260
|
+
.,.,
|
261
|
+
|
262
|
+
module_eval(<<'.,.,', 'parser.y', 27)
|
263
|
+
def _reduce_19(val, _values, result)
|
264
|
+
log.debug "Found macro attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
|
265
|
+
result
|
266
|
+
end
|
267
|
+
.,.,
|
268
|
+
|
269
|
+
module_eval(<<'.,.,', 'parser.y', 28)
|
270
|
+
def _reduce_20(val, _values, result)
|
271
|
+
log.debug "Found numeric attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]]
|
272
|
+
result
|
273
|
+
end
|
274
|
+
.,.,
|
275
|
+
|
276
|
+
module_eval(<<'.,.,', 'parser.y', 30)
|
277
|
+
def _reduce_21(val, _values, result)
|
278
|
+
return " #{val[0]}"
|
279
|
+
result
|
280
|
+
end
|
281
|
+
.,.,
|
282
|
+
|
283
|
+
module_eval(<<'.,.,', 'parser.y', 31)
|
284
|
+
def _reduce_22(val, _values, result)
|
285
|
+
return ' '+val[0]+' '+val[1]
|
286
|
+
result
|
287
|
+
end
|
288
|
+
.,.,
|
289
|
+
|
290
|
+
module_eval(<<'.,.,', 'parser.y', 32)
|
291
|
+
def _reduce_23(val, _values, result)
|
292
|
+
return val[0] + '+' + val[2]
|
293
|
+
result
|
294
|
+
end
|
295
|
+
.,.,
|
296
|
+
|
297
|
+
module_eval(<<'.,.,', 'parser.y', 34)
|
298
|
+
def _reduce_24(val, _values, result)
|
299
|
+
log.debug "Found an attribute filter #{val[1]}"; return Tag::Filter[val[1]]
|
300
|
+
result
|
301
|
+
end
|
302
|
+
.,.,
|
303
|
+
|
304
|
+
module_eval(<<'.,.,', 'parser.y', 35)
|
305
|
+
def _reduce_25(val, _values, result)
|
306
|
+
log.debug "Found a macro filter #{val[1]}"; return Tag::Filter[Tag::Macro[val[1]]]
|
307
|
+
result
|
308
|
+
end
|
309
|
+
.,.,
|
310
|
+
|
311
|
+
def _reduce_none(val, _values, result)
|
312
|
+
val[0]
|
313
|
+
end
|
314
|
+
|
315
|
+
end # class Parser
|
316
|
+
end # module WMLAction
|
317
|
+
|
318
|
+
|
@@ -0,0 +1,52 @@
|
|
1
|
+
class WMLAction::Parser
|
2
|
+
rule
|
3
|
+
target : /* nothing */
|
4
|
+
| wml_doc { log.debug 'Found a target' }
|
5
|
+
|
6
|
+
wml_doc : tag { log.debug 'Found a doc' }
|
7
|
+
|
8
|
+
tag : OTAG contents CTAG { log.debug("Creating tag #{val[0]}"); return Tag.new(name: val[0], content: val[1]) }
|
9
|
+
|
10
|
+
contents : /* nothing */ { return [] }
|
11
|
+
| contents content { log.debug("Append #{val[1]} to #{val[0]}"); return val[0]? val[0].push(val[1]) : [val[1]] }
|
12
|
+
|
13
|
+
content : action
|
14
|
+
| tag { log.debug "Found a content subtag #{val[0]}" }
|
15
|
+
| attribute
|
16
|
+
| filter
|
17
|
+
| MACRO { log.debug "Found a macro #{val[0]}"; return Tag::Macro[val[0]] }
|
18
|
+
|
19
|
+
action : aop tag { log.debug "Found a action tag #{val[0]}:#{val[1]}"; return Tag::Action[val[1],val[0]] }
|
20
|
+
| aop MACRO { log.debug "Found a action mac #{val[0]}:#{val[1]}"; return Tag::Action[Tag::Macro[val[1]],val[0]] }
|
21
|
+
|
22
|
+
aop : '+'
|
23
|
+
| '-'
|
24
|
+
|
25
|
+
attribute : ATTR { log.debug "Found empty attribute: #{val[0]}"; return Tag::Attribute[val[0],''] }
|
26
|
+
| ATTR APLAIN { log.debug "Found plain attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]] }
|
27
|
+
| ATTR string_val { log.debug "Found string attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]] }
|
28
|
+
| ATTR AMACRO { log.debug "Found macro attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]] }
|
29
|
+
| ATTR ANUMBER { log.debug "Found numeric attribute: #{val[0]}:#{val[1]}"; return Tag::Attribute[val[0],val[1]] }
|
30
|
+
|
31
|
+
string_val : ASTR { return " #{val[0]}" }
|
32
|
+
| UNDERSC ASTR { return ' '+val[0]+' '+val[1] }
|
33
|
+
| string_val APLUS AMACRO { return val[0] + '+' + val[2] }
|
34
|
+
|
35
|
+
filter : SLASH attribute { log.debug "Found an attribute filter #{val[1]}"; return Tag::Filter[val[1]] }
|
36
|
+
| SLASH MACRO { log.debug "Found a macro filter #{val[1]}"; return Tag::Filter[Tag::Macro[val[1]]] }
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
---- header ----
|
41
|
+
#
|
42
|
+
# generated by racc
|
43
|
+
#
|
44
|
+
require 'wml_action/lexer.rex'
|
45
|
+
require 'wml_action/tag'
|
46
|
+
require 'wml_action/log'
|
47
|
+
|
48
|
+
---- inner ----
|
49
|
+
include Log
|
50
|
+
|
51
|
+
---- footer ----
|
52
|
+
|
@@ -0,0 +1,144 @@
|
|
1
|
+
require 'wml_action/log'
|
2
|
+
require 'set'
|
3
|
+
|
4
|
+
module WMLAction
|
5
|
+
class Tag
|
6
|
+
include Log
|
7
|
+
|
8
|
+
attr_accessor :name,:subs,:attrs,:macros,:filter, :actions
|
9
|
+
|
10
|
+
Attribute = Struct.new(:name, :value) do
|
11
|
+
def to_s(indent=0, dummy=0)
|
12
|
+
"#{name}=#{value}"
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Macro = Struct.new(:value) do
|
17
|
+
def to_s(indent=0, dummy=0)
|
18
|
+
value.to_s
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Action = Struct.new(:object, :action) do
|
23
|
+
def to_s(indent=0, dummy=0)
|
24
|
+
"#{action} #{object.to_s(indent,0)}"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
Filter = Struct.new(:value) do
|
29
|
+
def to_s(indent=0, dummy=0)
|
30
|
+
"/ #{ value }"
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
def initialize(values={})
|
35
|
+
@name=values[:name]||""
|
36
|
+
@subs=values[:subs]||Array.new
|
37
|
+
@attrs=values[:attrs]||Hash.new
|
38
|
+
@macros=values[:macros]||Set.new
|
39
|
+
@filter=values[:filter]||Array.new
|
40
|
+
@actions=values[:actions]||Array.new
|
41
|
+
load_content( values[:content] ) if values.key? :content
|
42
|
+
end
|
43
|
+
|
44
|
+
def <<(content)
|
45
|
+
case content
|
46
|
+
when Action then @actions << content
|
47
|
+
when Attribute then @attrs.merge!( Hash[*content] )
|
48
|
+
when Macro then @macros.add( content.value )
|
49
|
+
when Filter then @filter << content.value
|
50
|
+
when Tag then @subs << content
|
51
|
+
else raise TypeError.new("Can not add #{content.class}: #{content} to a Tag")
|
52
|
+
end
|
53
|
+
return self
|
54
|
+
end
|
55
|
+
|
56
|
+
def load_content(contents)
|
57
|
+
contents.each { |c| self<<c }
|
58
|
+
end
|
59
|
+
|
60
|
+
def to_s(indent=0,indent_first_line=1)
|
61
|
+
i=indent
|
62
|
+
t="\t"
|
63
|
+
ifl=indent_first_line
|
64
|
+
return <<-EOS.gsub(/^\s+\|/, '').gsub(/^$\n/,'')
|
65
|
+
|#{t*i*ifl}[#{@name}]
|
66
|
+
|#{(@filter.map { |f| "#{t*(i+1)}/ #{f}" }).join("\n")}
|
67
|
+
|#{(@actions.map { |a| "#{t*(i+1)}#{a.to_s(i+1)}" }).join("\n")}
|
68
|
+
|#{(@attrs.map { |k,v| "#{t*(i+1)}#{k}=#{v}" }).join("\n")}
|
69
|
+
|#{(@macros.map { |m| "#{t*(i+1)}#{m}" }).join("\n")}
|
70
|
+
|#{(@subs.map { |s| "#{s.to_s(i+1)}" }).join("\n")}
|
71
|
+
|#{t*i}[/#{@name}]
|
72
|
+
EOS
|
73
|
+
end
|
74
|
+
|
75
|
+
def merge(other)
|
76
|
+
return self unless @name == other.name
|
77
|
+
return self unless match?( other.filter )
|
78
|
+
log.info "Merging [#{@name}] section with [#{other.name}] with filter: #{other.filter}"
|
79
|
+
other.attrs.each_pair do |key,value|
|
80
|
+
log.debug "Processing key: #{key}=#{value}"
|
81
|
+
@attrs.store(key,value)
|
82
|
+
end
|
83
|
+
other.macros.each do |macro|
|
84
|
+
log.debug "Adding macro: #{macro}"
|
85
|
+
@macros<<(macro)
|
86
|
+
end
|
87
|
+
other.subs.each do |other_sub|
|
88
|
+
@subs.map { |sub| sub.merge(other_sub) }
|
89
|
+
end
|
90
|
+
other.actions.each do |a|
|
91
|
+
case a.action
|
92
|
+
when '+' then self << a.object
|
93
|
+
when '-' then delete( a.object )
|
94
|
+
else raise NoMethodError.new("Don't know what to do with #{a.action} action")
|
95
|
+
end
|
96
|
+
end
|
97
|
+
return self
|
98
|
+
end
|
99
|
+
|
100
|
+
def delete(content)
|
101
|
+
case content
|
102
|
+
when Tag then @subs.delete_if { |s| content.name == s.name && s.match?( content.filter ) }
|
103
|
+
when Macro then @macros.delete(content.value)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
107
|
+
def match?( filter )
|
108
|
+
return true if filter.empty?
|
109
|
+
filter.each do |f|
|
110
|
+
case f
|
111
|
+
when Attribute then return false unless attr_value?( f )
|
112
|
+
when Macro then return false unless macro?( f )
|
113
|
+
end
|
114
|
+
end
|
115
|
+
return true
|
116
|
+
end
|
117
|
+
|
118
|
+
def attr_value?( attr )
|
119
|
+
@attrs[attr.name] == attr.value
|
120
|
+
end
|
121
|
+
|
122
|
+
def attr?( attr )
|
123
|
+
@attrs.key?(attr.name)
|
124
|
+
end
|
125
|
+
|
126
|
+
def macro?( macro )
|
127
|
+
@macros.include?(macro.value)
|
128
|
+
end
|
129
|
+
|
130
|
+
def sub?( sub )
|
131
|
+
( @subs.keep_if { |s| s.name == sub.name && s.match?(sub.filter) } ).empty?
|
132
|
+
end
|
133
|
+
|
134
|
+
def filter?(filter)
|
135
|
+
@filter.include?(filter)
|
136
|
+
end
|
137
|
+
|
138
|
+
def action?(action)
|
139
|
+
@actions.include?(action)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
data/lib/wml_action.rb
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
require "wml_action"
|
2
|
+
require "debugger"
|
3
|
+
|
4
|
+
module WMLAction
|
5
|
+
|
6
|
+
describe Document do
|
7
|
+
|
8
|
+
it 'should read a tag' do
|
9
|
+
d = Document.from_file('spec/fixtures/tag.cfg')
|
10
|
+
expect(d.root.name).to eq "tag"
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should read inners" do
|
14
|
+
d = Document.from_file('spec/fixtures/inners.cfg')
|
15
|
+
s = d.root
|
16
|
+
expect(s.subs.length).to eq 3
|
17
|
+
expect(s.subs[0].name).to eq "inner"
|
18
|
+
expect(s.subs[1].name).to eq "multitag"
|
19
|
+
expect(s.subs[2].name).to eq "multitag"
|
20
|
+
end
|
21
|
+
|
22
|
+
it "should read atributes" do
|
23
|
+
d = Document.from_file('spec/fixtures/attributes.cfg')
|
24
|
+
s = d.root
|
25
|
+
expect(s.attrs.length).to eq 5
|
26
|
+
expect(s.attrs).to include "number"
|
27
|
+
expect(s.attrs["number"]).to eq 50
|
28
|
+
expect(s.attrs).to include "plain"
|
29
|
+
expect(s.attrs["plain"]).to eq "One, Another"
|
30
|
+
expect(s.attrs).to include "macrosed"
|
31
|
+
expect(s.attrs["macrosed"]).to eq "{AMACRO}"
|
32
|
+
expect(s.attrs).to include "likedigit"
|
33
|
+
expect(s.attrs["likedigit"]).to eq '0.1:0.2'
|
34
|
+
expect(s.attrs).to include "empty"
|
35
|
+
expect(s.attrs["empty"]).to eq ''
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should read string attributes" do
|
39
|
+
d = Document.from_file('spec/fixtures/strings.cfg')
|
40
|
+
s = d.root
|
41
|
+
expect(s.attrs.length).to eq 5
|
42
|
+
expect(s.attrs).to include "simple"
|
43
|
+
expect(s.attrs).to include "underscored"
|
44
|
+
expect(s.attrs).to include "multiline"
|
45
|
+
expect(s.attrs).to include "macrosed"
|
46
|
+
expect(s.attrs["simple"]).to eq ' "Hello"'
|
47
|
+
expect(s.attrs["underscored"]).to eq ' _ "Long Hello"'
|
48
|
+
expect(s.attrs["multiline"]).to eq " \"This is \nvery long\nlong string\""
|
49
|
+
expect(s.attrs["macrosed"]).to eq " \"This amount\"+{AMOUNT}"
|
50
|
+
end
|
51
|
+
|
52
|
+
it "should read macros" do
|
53
|
+
d = Document.from_file('spec/fixtures/macros.cfg')
|
54
|
+
s = d.root
|
55
|
+
expect(s.macros).to include "{USEFUL_MACRO}"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should read filters" do
|
59
|
+
d = Document.from_file('spec/fixtures/filter.cfg')
|
60
|
+
s = d.root
|
61
|
+
expect(s.filter.length).to eq 2
|
62
|
+
expect(s.filter[0]).to eq Tag::Attribute['type','flying']
|
63
|
+
expect(s.filter[1]).to eq Tag::Macro['{FIRST_STRIKE}']
|
64
|
+
end
|
65
|
+
|
66
|
+
it "should read actions" do
|
67
|
+
d = Document.from_file('spec/fixtures/actions.cfg')
|
68
|
+
s = d.root
|
69
|
+
expect(s.actions.length).to eq 4
|
70
|
+
expect(s.actions).to include Tag::Action[Tag::Macro['{VARIABLES}'],'+']
|
71
|
+
expect(s.actions).to include Tag::Action[Tag::Macro['{ABILITIES}'],'-']
|
72
|
+
expect(s.actions[2].action).to eq "+"
|
73
|
+
expect(s.actions[2].object.name).to eq "attack"
|
74
|
+
expect(s.actions[3].action).to eq "-"
|
75
|
+
expect(s.actions[3].object.name).to eq "resists"
|
76
|
+
end
|
77
|
+
|
78
|
+
end
|
79
|
+
end
|