ceml 0.3.0 → 0.3.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/VERSION +1 -1
- data/beginners-guide.md +7 -7
- data/ceml.gemspec +78 -0
- data/examples/sample_delegate.rb +4 -0
- data/lib/ceml/casting.rb +15 -33
- data/lib/ceml/casting_criterion.rb +39 -0
- data/lib/ceml/instructions.rb +11 -10
- data/lib/ceml/script.rb +136 -78
- data/lib/ceml/tt/casting.treetop +26 -29
- data/lib/ceml/tt/instructions.treetop +4 -8
- data/lib/ceml/tt/lexer.treetop +42 -3
- data/lib/ceml/tt/scripts.treetop +25 -10
- data/lib/ceml.rb +13 -14
- data/test/helper.rb +0 -19
- data/test/test_casting.rb +9 -10
- data/test/test_incident.rb +25 -0
- data/test/test_instructions.rb +2 -2
- data/test/test_scripts.rb +1 -1
- data/try +14 -0
- metadata +7 -7
- data/lib/ceml/tt/casting.rb +0 -618
- data/lib/ceml/tt/instructions.rb +0 -409
- data/lib/ceml/tt/lexer.rb +0 -400
- data/lib/ceml/tt/scripts.rb +0 -345
data/lib/ceml/tt/instructions.rb
DELETED
@@ -1,409 +0,0 @@
|
|
1
|
-
# Autogenerated from a Treetop grammar. Edits may be lost.
|
2
|
-
|
3
|
-
|
4
|
-
module CEML
|
5
|
-
module Instructions
|
6
|
-
include Treetop::Runtime
|
7
|
-
|
8
|
-
def root
|
9
|
-
@root || :instructions
|
10
|
-
end
|
11
|
-
|
12
|
-
include Lexer
|
13
|
-
|
14
|
-
def _nt_instructions
|
15
|
-
start_index = index
|
16
|
-
if node_cache[:instructions].has_key?(index)
|
17
|
-
cached = node_cache[:instructions][index]
|
18
|
-
@index = cached.interval.end if cached
|
19
|
-
return cached
|
20
|
-
end
|
21
|
-
|
22
|
-
s0, i0 = [], index
|
23
|
-
loop do
|
24
|
-
r1 = _nt_instruction
|
25
|
-
if r1
|
26
|
-
s0 << r1
|
27
|
-
else
|
28
|
-
break
|
29
|
-
end
|
30
|
-
end
|
31
|
-
if s0.empty?
|
32
|
-
@index = i0
|
33
|
-
r0 = nil
|
34
|
-
else
|
35
|
-
r0 = instantiate_node(Instructions,input, i0...index, s0)
|
36
|
-
end
|
37
|
-
|
38
|
-
node_cache[:instructions][start_index] = r0
|
39
|
-
|
40
|
-
r0
|
41
|
-
end
|
42
|
-
|
43
|
-
module Instruction0
|
44
|
-
|
45
|
-
INTERPOLATE_REGEX = /\|(\w+)\.?(\w+)?\|/
|
46
|
-
|
47
|
-
def interpolate(env)
|
48
|
-
text =~ INTERPOLATE_REGEX or return text
|
49
|
-
text.gsub(INTERPOLATE_REGEX) do |m|
|
50
|
-
var, role = *[$2, $1].compact
|
51
|
-
env.expand(role, var) or return false
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def role; id.text_value.to_sym; end
|
56
|
-
def text; super.text_value; end
|
57
|
-
def var; (!defined?(:about) || about.empty?) ? nil : about.varname.text_value; end
|
58
|
-
def key; var || text; end
|
59
|
-
def cmd;
|
60
|
-
text_value =~ /^ask/ and return :ask
|
61
|
-
text_value =~ /^(tell|assign)/ and return :tell
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
def _nt_instruction
|
66
|
-
start_index = index
|
67
|
-
if node_cache[:instruction].has_key?(index)
|
68
|
-
cached = node_cache[:instruction][index]
|
69
|
-
@index = cached.interval.end if cached
|
70
|
-
return cached
|
71
|
-
end
|
72
|
-
|
73
|
-
i0 = index
|
74
|
-
r1 = _nt_ask_stmt
|
75
|
-
if r1
|
76
|
-
r0 = r1
|
77
|
-
r0.extend(Instruction0)
|
78
|
-
else
|
79
|
-
r2 = _nt_tell_stmt
|
80
|
-
if r2
|
81
|
-
r0 = r2
|
82
|
-
r0.extend(Instruction0)
|
83
|
-
else
|
84
|
-
r3 = _nt_assign_stmt
|
85
|
-
if r3
|
86
|
-
r0 = r3
|
87
|
-
r0.extend(Instruction0)
|
88
|
-
else
|
89
|
-
@index = i0
|
90
|
-
r0 = nil
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
|
95
|
-
node_cache[:instruction][start_index] = r0
|
96
|
-
|
97
|
-
r0
|
98
|
-
end
|
99
|
-
|
100
|
-
module TellStmt0
|
101
|
-
def ws
|
102
|
-
elements[1]
|
103
|
-
end
|
104
|
-
|
105
|
-
def id
|
106
|
-
elements[2]
|
107
|
-
end
|
108
|
-
|
109
|
-
def text
|
110
|
-
elements[5]
|
111
|
-
end
|
112
|
-
|
113
|
-
def nl
|
114
|
-
elements[6]
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def _nt_tell_stmt
|
119
|
-
start_index = index
|
120
|
-
if node_cache[:tell_stmt].has_key?(index)
|
121
|
-
cached = node_cache[:tell_stmt][index]
|
122
|
-
@index = cached.interval.end if cached
|
123
|
-
return cached
|
124
|
-
end
|
125
|
-
|
126
|
-
i0, s0 = index, []
|
127
|
-
if has_terminal?('tell', false, index)
|
128
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index + 4))
|
129
|
-
@index += 4
|
130
|
-
else
|
131
|
-
terminal_parse_failure('tell')
|
132
|
-
r1 = nil
|
133
|
-
end
|
134
|
-
s0 << r1
|
135
|
-
if r1
|
136
|
-
r2 = _nt_ws
|
137
|
-
s0 << r2
|
138
|
-
if r2
|
139
|
-
r3 = _nt_id
|
140
|
-
s0 << r3
|
141
|
-
if r3
|
142
|
-
if has_terminal?(':', false, index)
|
143
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
144
|
-
@index += 1
|
145
|
-
else
|
146
|
-
terminal_parse_failure(':')
|
147
|
-
r4 = nil
|
148
|
-
end
|
149
|
-
s0 << r4
|
150
|
-
if r4
|
151
|
-
r6 = _nt_ws
|
152
|
-
if r6
|
153
|
-
r5 = r6
|
154
|
-
else
|
155
|
-
r5 = instantiate_node(SyntaxNode,input, index...index)
|
156
|
-
end
|
157
|
-
s0 << r5
|
158
|
-
if r5
|
159
|
-
r7 = _nt_text
|
160
|
-
s0 << r7
|
161
|
-
if r7
|
162
|
-
r8 = _nt_nl
|
163
|
-
s0 << r8
|
164
|
-
end
|
165
|
-
end
|
166
|
-
end
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
if s0.last
|
171
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
172
|
-
r0.extend(TellStmt0)
|
173
|
-
else
|
174
|
-
@index = i0
|
175
|
-
r0 = nil
|
176
|
-
end
|
177
|
-
|
178
|
-
node_cache[:tell_stmt][start_index] = r0
|
179
|
-
|
180
|
-
r0
|
181
|
-
end
|
182
|
-
|
183
|
-
module AssignStmt0
|
184
|
-
def ws
|
185
|
-
elements[1]
|
186
|
-
end
|
187
|
-
|
188
|
-
def id
|
189
|
-
elements[2]
|
190
|
-
end
|
191
|
-
|
192
|
-
def text
|
193
|
-
elements[5]
|
194
|
-
end
|
195
|
-
|
196
|
-
def nl
|
197
|
-
elements[6]
|
198
|
-
end
|
199
|
-
end
|
200
|
-
|
201
|
-
def _nt_assign_stmt
|
202
|
-
start_index = index
|
203
|
-
if node_cache[:assign_stmt].has_key?(index)
|
204
|
-
cached = node_cache[:assign_stmt][index]
|
205
|
-
@index = cached.interval.end if cached
|
206
|
-
return cached
|
207
|
-
end
|
208
|
-
|
209
|
-
i0, s0 = index, []
|
210
|
-
if has_terminal?('assign', false, index)
|
211
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index + 6))
|
212
|
-
@index += 6
|
213
|
-
else
|
214
|
-
terminal_parse_failure('assign')
|
215
|
-
r1 = nil
|
216
|
-
end
|
217
|
-
s0 << r1
|
218
|
-
if r1
|
219
|
-
r2 = _nt_ws
|
220
|
-
s0 << r2
|
221
|
-
if r2
|
222
|
-
r3 = _nt_id
|
223
|
-
s0 << r3
|
224
|
-
if r3
|
225
|
-
if has_terminal?(':', false, index)
|
226
|
-
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
227
|
-
@index += 1
|
228
|
-
else
|
229
|
-
terminal_parse_failure(':')
|
230
|
-
r4 = nil
|
231
|
-
end
|
232
|
-
s0 << r4
|
233
|
-
if r4
|
234
|
-
r6 = _nt_ws
|
235
|
-
if r6
|
236
|
-
r5 = r6
|
237
|
-
else
|
238
|
-
r5 = instantiate_node(SyntaxNode,input, index...index)
|
239
|
-
end
|
240
|
-
s0 << r5
|
241
|
-
if r5
|
242
|
-
r7 = _nt_text
|
243
|
-
s0 << r7
|
244
|
-
if r7
|
245
|
-
r8 = _nt_nl
|
246
|
-
s0 << r8
|
247
|
-
end
|
248
|
-
end
|
249
|
-
end
|
250
|
-
end
|
251
|
-
end
|
252
|
-
end
|
253
|
-
if s0.last
|
254
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
255
|
-
r0.extend(AssignStmt0)
|
256
|
-
else
|
257
|
-
@index = i0
|
258
|
-
r0 = nil
|
259
|
-
end
|
260
|
-
|
261
|
-
node_cache[:assign_stmt][start_index] = r0
|
262
|
-
|
263
|
-
r0
|
264
|
-
end
|
265
|
-
|
266
|
-
module AskStmt0
|
267
|
-
def ws1
|
268
|
-
elements[0]
|
269
|
-
end
|
270
|
-
|
271
|
-
def ws2
|
272
|
-
elements[2]
|
273
|
-
end
|
274
|
-
|
275
|
-
def varname
|
276
|
-
elements[3]
|
277
|
-
end
|
278
|
-
end
|
279
|
-
|
280
|
-
module AskStmt1
|
281
|
-
def ws
|
282
|
-
elements[1]
|
283
|
-
end
|
284
|
-
|
285
|
-
def id
|
286
|
-
elements[2]
|
287
|
-
end
|
288
|
-
|
289
|
-
def about
|
290
|
-
elements[3]
|
291
|
-
end
|
292
|
-
|
293
|
-
def text
|
294
|
-
elements[6]
|
295
|
-
end
|
296
|
-
|
297
|
-
def nl
|
298
|
-
elements[7]
|
299
|
-
end
|
300
|
-
end
|
301
|
-
|
302
|
-
def _nt_ask_stmt
|
303
|
-
start_index = index
|
304
|
-
if node_cache[:ask_stmt].has_key?(index)
|
305
|
-
cached = node_cache[:ask_stmt][index]
|
306
|
-
@index = cached.interval.end if cached
|
307
|
-
return cached
|
308
|
-
end
|
309
|
-
|
310
|
-
i0, s0 = index, []
|
311
|
-
if has_terminal?('ask', false, index)
|
312
|
-
r1 = instantiate_node(SyntaxNode,input, index...(index + 3))
|
313
|
-
@index += 3
|
314
|
-
else
|
315
|
-
terminal_parse_failure('ask')
|
316
|
-
r1 = nil
|
317
|
-
end
|
318
|
-
s0 << r1
|
319
|
-
if r1
|
320
|
-
r2 = _nt_ws
|
321
|
-
s0 << r2
|
322
|
-
if r2
|
323
|
-
r3 = _nt_id
|
324
|
-
s0 << r3
|
325
|
-
if r3
|
326
|
-
i5, s5 = index, []
|
327
|
-
r6 = _nt_ws
|
328
|
-
s5 << r6
|
329
|
-
if r6
|
330
|
-
if has_terminal?('re', false, index)
|
331
|
-
r7 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
332
|
-
@index += 2
|
333
|
-
else
|
334
|
-
terminal_parse_failure('re')
|
335
|
-
r7 = nil
|
336
|
-
end
|
337
|
-
s5 << r7
|
338
|
-
if r7
|
339
|
-
r8 = _nt_ws
|
340
|
-
s5 << r8
|
341
|
-
if r8
|
342
|
-
r9 = _nt_id
|
343
|
-
s5 << r9
|
344
|
-
end
|
345
|
-
end
|
346
|
-
end
|
347
|
-
if s5.last
|
348
|
-
r5 = instantiate_node(SyntaxNode,input, i5...index, s5)
|
349
|
-
r5.extend(AskStmt0)
|
350
|
-
else
|
351
|
-
@index = i5
|
352
|
-
r5 = nil
|
353
|
-
end
|
354
|
-
if r5
|
355
|
-
r4 = r5
|
356
|
-
else
|
357
|
-
r4 = instantiate_node(SyntaxNode,input, index...index)
|
358
|
-
end
|
359
|
-
s0 << r4
|
360
|
-
if r4
|
361
|
-
if has_terminal?(':', false, index)
|
362
|
-
r10 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
363
|
-
@index += 1
|
364
|
-
else
|
365
|
-
terminal_parse_failure(':')
|
366
|
-
r10 = nil
|
367
|
-
end
|
368
|
-
s0 << r10
|
369
|
-
if r10
|
370
|
-
r12 = _nt_ws
|
371
|
-
if r12
|
372
|
-
r11 = r12
|
373
|
-
else
|
374
|
-
r11 = instantiate_node(SyntaxNode,input, index...index)
|
375
|
-
end
|
376
|
-
s0 << r11
|
377
|
-
if r11
|
378
|
-
r13 = _nt_text
|
379
|
-
s0 << r13
|
380
|
-
if r13
|
381
|
-
r14 = _nt_nl
|
382
|
-
s0 << r14
|
383
|
-
end
|
384
|
-
end
|
385
|
-
end
|
386
|
-
end
|
387
|
-
end
|
388
|
-
end
|
389
|
-
end
|
390
|
-
if s0.last
|
391
|
-
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
392
|
-
r0.extend(AskStmt1)
|
393
|
-
else
|
394
|
-
@index = i0
|
395
|
-
r0 = nil
|
396
|
-
end
|
397
|
-
|
398
|
-
node_cache[:ask_stmt][start_index] = r0
|
399
|
-
|
400
|
-
r0
|
401
|
-
end
|
402
|
-
|
403
|
-
end
|
404
|
-
|
405
|
-
class InstructionsParser < Treetop::Runtime::CompiledParser
|
406
|
-
include Instructions
|
407
|
-
end
|
408
|
-
|
409
|
-
end
|