ceml 0.2.0
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.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +4 -0
- data/Makefile +5 -0
- data/README.markdown +86 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/editors/CEML.tmbundle/Syntaxes/ceml.tmLanguage +322 -0
- data/editors/CEML.tmbundle/info.plist +17 -0
- data/examples/breakfast-exchange.ceml +15 -0
- data/examples/citizen-investigation.ceml +24 -0
- data/examples/high-fives.ceml +19 -0
- data/lib/ceml/casting.rb +52 -0
- data/lib/ceml/engine.rb +138 -0
- data/lib/ceml/instructions.rb +31 -0
- data/lib/ceml/script.rb +103 -0
- data/lib/ceml/tt/casting.rb +618 -0
- data/lib/ceml/tt/casting.treetop +50 -0
- data/lib/ceml/tt/instructions.rb +320 -0
- data/lib/ceml/tt/instructions.treetop +42 -0
- data/lib/ceml/tt/lexer.rb +400 -0
- data/lib/ceml/tt/lexer.treetop +34 -0
- data/lib/ceml/tt/scripts.rb +345 -0
- data/lib/ceml/tt/scripts.treetop +32 -0
- data/lib/ceml.rb +35 -0
- data/test/helper.rb +55 -0
- data/test/test_casting.rb +78 -0
- data/test/test_engine.rb +30 -0
- data/test/test_instructions.rb +27 -0
- data/test/test_scripts.rb +57 -0
- metadata +107 -0
|
@@ -0,0 +1,400 @@
|
|
|
1
|
+
# Autogenerated from a Treetop grammar. Edits may be lost.
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
module CEML
|
|
5
|
+
module Lexer
|
|
6
|
+
include Treetop::Runtime
|
|
7
|
+
|
|
8
|
+
def root
|
|
9
|
+
@root || :text
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
module Text0
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def _nt_text
|
|
16
|
+
start_index = index
|
|
17
|
+
if node_cache[:text].has_key?(index)
|
|
18
|
+
cached = node_cache[:text][index]
|
|
19
|
+
@index = cached.interval.end if cached
|
|
20
|
+
return cached
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
s0, i0 = [], index
|
|
24
|
+
loop do
|
|
25
|
+
i1, s1 = index, []
|
|
26
|
+
i2 = index
|
|
27
|
+
r3 = _nt_eol
|
|
28
|
+
if r3
|
|
29
|
+
r2 = nil
|
|
30
|
+
else
|
|
31
|
+
@index = i2
|
|
32
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
|
33
|
+
end
|
|
34
|
+
s1 << r2
|
|
35
|
+
if r2
|
|
36
|
+
if index < input_length
|
|
37
|
+
next_character = index + input[index..-1].match(/\A(.)/um).end(1)
|
|
38
|
+
r4 = instantiate_node(SyntaxNode,input, index...next_character)
|
|
39
|
+
@index = next_character
|
|
40
|
+
else
|
|
41
|
+
terminal_parse_failure("any character")
|
|
42
|
+
r4 = nil
|
|
43
|
+
end
|
|
44
|
+
s1 << r4
|
|
45
|
+
end
|
|
46
|
+
if s1.last
|
|
47
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
|
48
|
+
r1.extend(Text0)
|
|
49
|
+
else
|
|
50
|
+
@index = i1
|
|
51
|
+
r1 = nil
|
|
52
|
+
end
|
|
53
|
+
if r1
|
|
54
|
+
s0 << r1
|
|
55
|
+
else
|
|
56
|
+
break
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
if s0.empty?
|
|
60
|
+
@index = i0
|
|
61
|
+
r0 = nil
|
|
62
|
+
else
|
|
63
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
node_cache[:text][start_index] = r0
|
|
67
|
+
|
|
68
|
+
r0
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
module Nl0
|
|
72
|
+
def eol
|
|
73
|
+
elements[2]
|
|
74
|
+
end
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
def _nt_nl
|
|
78
|
+
start_index = index
|
|
79
|
+
if node_cache[:nl].has_key?(index)
|
|
80
|
+
cached = node_cache[:nl][index]
|
|
81
|
+
@index = cached.interval.end if cached
|
|
82
|
+
return cached
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
s0, i0 = [], index
|
|
86
|
+
loop do
|
|
87
|
+
i1, s1 = index, []
|
|
88
|
+
r3 = _nt_ws
|
|
89
|
+
if r3
|
|
90
|
+
r2 = r3
|
|
91
|
+
else
|
|
92
|
+
r2 = instantiate_node(SyntaxNode,input, index...index)
|
|
93
|
+
end
|
|
94
|
+
s1 << r2
|
|
95
|
+
if r2
|
|
96
|
+
r5 = _nt_comment
|
|
97
|
+
if r5
|
|
98
|
+
r4 = r5
|
|
99
|
+
else
|
|
100
|
+
r4 = instantiate_node(SyntaxNode,input, index...index)
|
|
101
|
+
end
|
|
102
|
+
s1 << r4
|
|
103
|
+
if r4
|
|
104
|
+
r6 = _nt_eol
|
|
105
|
+
s1 << r6
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
if s1.last
|
|
109
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
|
110
|
+
r1.extend(Nl0)
|
|
111
|
+
else
|
|
112
|
+
@index = i1
|
|
113
|
+
r1 = nil
|
|
114
|
+
end
|
|
115
|
+
if r1
|
|
116
|
+
s0 << r1
|
|
117
|
+
else
|
|
118
|
+
break
|
|
119
|
+
end
|
|
120
|
+
end
|
|
121
|
+
if s0.empty?
|
|
122
|
+
@index = i0
|
|
123
|
+
r0 = nil
|
|
124
|
+
else
|
|
125
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
node_cache[:nl][start_index] = r0
|
|
129
|
+
|
|
130
|
+
r0
|
|
131
|
+
end
|
|
132
|
+
|
|
133
|
+
def _nt_ws
|
|
134
|
+
start_index = index
|
|
135
|
+
if node_cache[:ws].has_key?(index)
|
|
136
|
+
cached = node_cache[:ws][index]
|
|
137
|
+
@index = cached.interval.end if cached
|
|
138
|
+
return cached
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
s0, i0 = [], index
|
|
142
|
+
loop do
|
|
143
|
+
if has_terminal?('\G[ \\t\\f]', true, index)
|
|
144
|
+
next_character = index + input[index..-1].match(/\A(.)/um).end(1)
|
|
145
|
+
r1 = true
|
|
146
|
+
@index = next_character
|
|
147
|
+
else
|
|
148
|
+
r1 = nil
|
|
149
|
+
end
|
|
150
|
+
if r1
|
|
151
|
+
s0 << r1
|
|
152
|
+
else
|
|
153
|
+
break
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
if s0.empty?
|
|
157
|
+
@index = i0
|
|
158
|
+
r0 = nil
|
|
159
|
+
else
|
|
160
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
161
|
+
end
|
|
162
|
+
|
|
163
|
+
node_cache[:ws][start_index] = r0
|
|
164
|
+
|
|
165
|
+
r0
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
module Comment0
|
|
169
|
+
def text
|
|
170
|
+
elements[1]
|
|
171
|
+
end
|
|
172
|
+
end
|
|
173
|
+
|
|
174
|
+
def _nt_comment
|
|
175
|
+
start_index = index
|
|
176
|
+
if node_cache[:comment].has_key?(index)
|
|
177
|
+
cached = node_cache[:comment][index]
|
|
178
|
+
@index = cached.interval.end if cached
|
|
179
|
+
return cached
|
|
180
|
+
end
|
|
181
|
+
|
|
182
|
+
i0, s0 = index, []
|
|
183
|
+
if has_terminal?('//', false, index)
|
|
184
|
+
r1 = instantiate_node(SyntaxNode,input, index...(index + 2))
|
|
185
|
+
@index += 2
|
|
186
|
+
else
|
|
187
|
+
terminal_parse_failure('//')
|
|
188
|
+
r1 = nil
|
|
189
|
+
end
|
|
190
|
+
s0 << r1
|
|
191
|
+
if r1
|
|
192
|
+
r2 = _nt_text
|
|
193
|
+
s0 << r2
|
|
194
|
+
end
|
|
195
|
+
if s0.last
|
|
196
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
197
|
+
r0.extend(Comment0)
|
|
198
|
+
else
|
|
199
|
+
@index = i0
|
|
200
|
+
r0 = nil
|
|
201
|
+
end
|
|
202
|
+
|
|
203
|
+
node_cache[:comment][start_index] = r0
|
|
204
|
+
|
|
205
|
+
r0
|
|
206
|
+
end
|
|
207
|
+
|
|
208
|
+
module Eol0
|
|
209
|
+
end
|
|
210
|
+
|
|
211
|
+
def _nt_eol
|
|
212
|
+
start_index = index
|
|
213
|
+
if node_cache[:eol].has_key?(index)
|
|
214
|
+
cached = node_cache[:eol][index]
|
|
215
|
+
@index = cached.interval.end if cached
|
|
216
|
+
return cached
|
|
217
|
+
end
|
|
218
|
+
|
|
219
|
+
i0 = index
|
|
220
|
+
i1, s1 = index, []
|
|
221
|
+
if has_terminal?("\r", false, index)
|
|
222
|
+
r2 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
|
223
|
+
@index += 1
|
|
224
|
+
else
|
|
225
|
+
terminal_parse_failure("\r")
|
|
226
|
+
r2 = nil
|
|
227
|
+
end
|
|
228
|
+
s1 << r2
|
|
229
|
+
if r2
|
|
230
|
+
if has_terminal?("\n", false, index)
|
|
231
|
+
r4 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
|
232
|
+
@index += 1
|
|
233
|
+
else
|
|
234
|
+
terminal_parse_failure("\n")
|
|
235
|
+
r4 = nil
|
|
236
|
+
end
|
|
237
|
+
if r4
|
|
238
|
+
r3 = r4
|
|
239
|
+
else
|
|
240
|
+
r3 = instantiate_node(SyntaxNode,input, index...index)
|
|
241
|
+
end
|
|
242
|
+
s1 << r3
|
|
243
|
+
end
|
|
244
|
+
if s1.last
|
|
245
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
|
246
|
+
r1.extend(Eol0)
|
|
247
|
+
else
|
|
248
|
+
@index = i1
|
|
249
|
+
r1 = nil
|
|
250
|
+
end
|
|
251
|
+
if r1
|
|
252
|
+
r0 = r1
|
|
253
|
+
else
|
|
254
|
+
if has_terminal?("\n", false, index)
|
|
255
|
+
r5 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
|
256
|
+
@index += 1
|
|
257
|
+
else
|
|
258
|
+
terminal_parse_failure("\n")
|
|
259
|
+
r5 = nil
|
|
260
|
+
end
|
|
261
|
+
if r5
|
|
262
|
+
r0 = r5
|
|
263
|
+
else
|
|
264
|
+
@index = i0
|
|
265
|
+
r0 = nil
|
|
266
|
+
end
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
node_cache[:eol][start_index] = r0
|
|
270
|
+
|
|
271
|
+
r0
|
|
272
|
+
end
|
|
273
|
+
|
|
274
|
+
module Number0
|
|
275
|
+
end
|
|
276
|
+
|
|
277
|
+
def _nt_number
|
|
278
|
+
start_index = index
|
|
279
|
+
if node_cache[:number].has_key?(index)
|
|
280
|
+
cached = node_cache[:number][index]
|
|
281
|
+
@index = cached.interval.end if cached
|
|
282
|
+
return cached
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
i0 = index
|
|
286
|
+
i1, s1 = index, []
|
|
287
|
+
s2, i2 = [], index
|
|
288
|
+
loop do
|
|
289
|
+
if has_terminal?('\G[1-9]', true, index)
|
|
290
|
+
next_character = index + input[index..-1].match(/\A(.)/um).end(1)
|
|
291
|
+
r3 = true
|
|
292
|
+
@index = next_character
|
|
293
|
+
else
|
|
294
|
+
r3 = nil
|
|
295
|
+
end
|
|
296
|
+
if r3
|
|
297
|
+
s2 << r3
|
|
298
|
+
else
|
|
299
|
+
break
|
|
300
|
+
end
|
|
301
|
+
end
|
|
302
|
+
if s2.empty?
|
|
303
|
+
@index = i2
|
|
304
|
+
r2 = nil
|
|
305
|
+
else
|
|
306
|
+
r2 = instantiate_node(SyntaxNode,input, i2...index, s2)
|
|
307
|
+
end
|
|
308
|
+
s1 << r2
|
|
309
|
+
if r2
|
|
310
|
+
s4, i4 = [], index
|
|
311
|
+
loop do
|
|
312
|
+
if has_terminal?('\G[0-9]', true, index)
|
|
313
|
+
next_character = index + input[index..-1].match(/\A(.)/um).end(1)
|
|
314
|
+
r5 = true
|
|
315
|
+
@index = next_character
|
|
316
|
+
else
|
|
317
|
+
r5 = nil
|
|
318
|
+
end
|
|
319
|
+
if r5
|
|
320
|
+
s4 << r5
|
|
321
|
+
else
|
|
322
|
+
break
|
|
323
|
+
end
|
|
324
|
+
end
|
|
325
|
+
r4 = instantiate_node(SyntaxNode,input, i4...index, s4)
|
|
326
|
+
s1 << r4
|
|
327
|
+
end
|
|
328
|
+
if s1.last
|
|
329
|
+
r1 = instantiate_node(SyntaxNode,input, i1...index, s1)
|
|
330
|
+
r1.extend(Number0)
|
|
331
|
+
else
|
|
332
|
+
@index = i1
|
|
333
|
+
r1 = nil
|
|
334
|
+
end
|
|
335
|
+
if r1
|
|
336
|
+
r0 = r1
|
|
337
|
+
else
|
|
338
|
+
if has_terminal?('0', false, index)
|
|
339
|
+
r6 = instantiate_node(SyntaxNode,input, index...(index + 1))
|
|
340
|
+
@index += 1
|
|
341
|
+
else
|
|
342
|
+
terminal_parse_failure('0')
|
|
343
|
+
r6 = nil
|
|
344
|
+
end
|
|
345
|
+
if r6
|
|
346
|
+
r0 = r6
|
|
347
|
+
else
|
|
348
|
+
@index = i0
|
|
349
|
+
r0 = nil
|
|
350
|
+
end
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
node_cache[:number][start_index] = r0
|
|
354
|
+
|
|
355
|
+
r0
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def _nt_id
|
|
359
|
+
start_index = index
|
|
360
|
+
if node_cache[:id].has_key?(index)
|
|
361
|
+
cached = node_cache[:id][index]
|
|
362
|
+
@index = cached.interval.end if cached
|
|
363
|
+
return cached
|
|
364
|
+
end
|
|
365
|
+
|
|
366
|
+
s0, i0 = [], index
|
|
367
|
+
loop do
|
|
368
|
+
if has_terminal?('\G[a-zA-Z_-]', true, index)
|
|
369
|
+
next_character = index + input[index..-1].match(/\A(.)/um).end(1)
|
|
370
|
+
r1 = true
|
|
371
|
+
@index = next_character
|
|
372
|
+
else
|
|
373
|
+
r1 = nil
|
|
374
|
+
end
|
|
375
|
+
if r1
|
|
376
|
+
s0 << r1
|
|
377
|
+
else
|
|
378
|
+
break
|
|
379
|
+
end
|
|
380
|
+
end
|
|
381
|
+
if s0.empty?
|
|
382
|
+
@index = i0
|
|
383
|
+
r0 = nil
|
|
384
|
+
else
|
|
385
|
+
r0 = instantiate_node(SyntaxNode,input, i0...index, s0)
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
node_cache[:id][start_index] = r0
|
|
389
|
+
|
|
390
|
+
r0
|
|
391
|
+
end
|
|
392
|
+
|
|
393
|
+
end
|
|
394
|
+
|
|
395
|
+
class LexerParser < Treetop::Runtime::CompiledParser
|
|
396
|
+
include Lexer
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
end
|
|
400
|
+
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
module CEML
|
|
2
|
+
grammar Lexer
|
|
3
|
+
|
|
4
|
+
rule text
|
|
5
|
+
(!eol .)+
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
rule nl
|
|
9
|
+
(ws? comment? eol)+
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
rule ws
|
|
13
|
+
[ \t\f]+
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
rule comment
|
|
17
|
+
'//' text
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
rule eol
|
|
21
|
+
("\r" "\n"?) / "\n"
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
rule number
|
|
25
|
+
[1-9]+ [0-9]* / '0'
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
rule id
|
|
29
|
+
[a-zA-Z_-]+
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|