hotcell 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +4 -1
- data/.rspec +1 -0
- data/.rvmrc +1 -1
- data/.travis.yml +7 -0
- data/Gemfile +4 -1
- data/README.md +361 -2
- data/Rakefile +28 -6
- data/ext/lexerc/extconf.rb +3 -0
- data/ext/lexerc/lexerc.c +618 -0
- data/ext/lexerc/lexerc.h +20 -0
- data/ext/lexerc/lexerc.rl +167 -0
- data/hotcell.gemspec +8 -7
- data/lib/hotcell/commands/case.rb +59 -0
- data/lib/hotcell/commands/cycle.rb +38 -0
- data/lib/hotcell/commands/for.rb +70 -0
- data/lib/hotcell/commands/if.rb +51 -0
- data/lib/hotcell/commands/include.rb +21 -0
- data/lib/hotcell/commands/scope.rb +13 -0
- data/lib/hotcell/commands/unless.rb +23 -0
- data/lib/hotcell/commands.rb +13 -0
- data/lib/hotcell/config.rb +33 -6
- data/lib/hotcell/context.rb +40 -7
- data/lib/hotcell/errors.rb +37 -28
- data/lib/hotcell/extensions.rb +4 -0
- data/lib/hotcell/lexer.rb +19 -635
- data/lib/hotcell/lexerr.rb +572 -0
- data/lib/hotcell/lexerr.rl +137 -0
- data/lib/hotcell/node/assigner.rb +1 -5
- data/lib/hotcell/node/block.rb +17 -40
- data/lib/hotcell/node/command.rb +29 -22
- data/lib/hotcell/node/hasher.rb +1 -1
- data/lib/hotcell/node/summoner.rb +2 -6
- data/lib/hotcell/node/tag.rb +10 -7
- data/lib/hotcell/node.rb +12 -1
- data/lib/hotcell/parser.rb +474 -408
- data/lib/hotcell/parser.y +175 -117
- data/lib/hotcell/resolver.rb +44 -0
- data/lib/hotcell/source.rb +35 -0
- data/lib/hotcell/template.rb +15 -6
- data/lib/hotcell/version.rb +1 -1
- data/lib/hotcell.rb +15 -10
- data/spec/data/templates/simple.hc +1 -0
- data/spec/lib/hotcell/commands/case_spec.rb +39 -0
- data/spec/lib/hotcell/commands/cycle_spec.rb +29 -0
- data/spec/lib/hotcell/commands/for_spec.rb +65 -0
- data/spec/lib/hotcell/commands/if_spec.rb +35 -0
- data/spec/lib/hotcell/commands/include_spec.rb +39 -0
- data/spec/lib/hotcell/commands/scope_spec.rb +16 -0
- data/spec/lib/hotcell/commands/unless_spec.rb +23 -0
- data/spec/lib/hotcell/config_spec.rb +35 -10
- data/spec/lib/hotcell/context_spec.rb +58 -18
- data/spec/lib/hotcell/lexer_spec.rb +37 -28
- data/spec/lib/hotcell/node/block_spec.rb +28 -56
- data/spec/lib/hotcell/node/command_spec.rb +7 -31
- data/spec/lib/hotcell/node/tag_spec.rb +16 -0
- data/spec/lib/hotcell/parser_spec.rb +152 -123
- data/spec/lib/hotcell/resolver_spec.rb +28 -0
- data/spec/lib/hotcell/source_spec.rb +41 -0
- data/spec/lib/hotcell/template_spec.rb +47 -4
- data/spec/lib/hotcell_spec.rb +2 -1
- data/spec/spec_helper.rb +6 -2
- metadata +54 -24
- data/lib/hotcell/.DS_Store +0 -0
- data/lib/hotcell/lexer.rl +0 -299
- data/misc/rage.rl +0 -1999
- data/misc/unicode2ragel.rb +0 -305
data/ext/lexerc/lexerc.c
ADDED
@@ -0,0 +1,618 @@
|
|
1
|
+
|
2
|
+
#line 1 "ext/lexerc/lexerc.rl"
|
3
|
+
|
4
|
+
#line 94 "ext/lexerc/lexerc.rl"
|
5
|
+
|
6
|
+
|
7
|
+
#include <ruby.h>
|
8
|
+
#include <lexerc.h>
|
9
|
+
|
10
|
+
static VALUE mHotcell;
|
11
|
+
static VALUE cHotcellLexer;
|
12
|
+
|
13
|
+
|
14
|
+
#line 15 "ext/lexerc/lexerc.c"
|
15
|
+
static const int puffer_lexer_start = 12;
|
16
|
+
static const int puffer_lexer_first_final = 12;
|
17
|
+
static const int puffer_lexer_error = 0;
|
18
|
+
|
19
|
+
static const int puffer_lexer_en_expression = 16;
|
20
|
+
static const int puffer_lexer_en_template_comment = 26;
|
21
|
+
static const int puffer_lexer_en_main = 12;
|
22
|
+
|
23
|
+
|
24
|
+
#line 103 "ext/lexerc/lexerc.rl"
|
25
|
+
|
26
|
+
static char *p;
|
27
|
+
static char *ts;
|
28
|
+
static char *te;
|
29
|
+
static char *data;
|
30
|
+
static VALUE encoding;
|
31
|
+
|
32
|
+
static VALUE tokenize(VALUE self) {
|
33
|
+
VALUE source = rb_iv_get(self, "@source");
|
34
|
+
encoding = rb_funcall(source, rb_intern("encoding"), 0);
|
35
|
+
VALUE string = rb_funcall(source, rb_intern("source"), 0);
|
36
|
+
rb_iv_set(self, "@token_array", rb_ary_new());
|
37
|
+
|
38
|
+
data = RSTRING_PTR(string);
|
39
|
+
unsigned long length = RSTRING_LEN(string);
|
40
|
+
|
41
|
+
int cs, top, act;
|
42
|
+
int *stack = malloc(sizeof(int) * 300);
|
43
|
+
|
44
|
+
p = data;
|
45
|
+
char *pe = data + length;
|
46
|
+
char *eof = pe;
|
47
|
+
|
48
|
+
|
49
|
+
#line 50 "ext/lexerc/lexerc.c"
|
50
|
+
{
|
51
|
+
cs = puffer_lexer_start;
|
52
|
+
top = 0;
|
53
|
+
ts = 0;
|
54
|
+
te = 0;
|
55
|
+
act = 0;
|
56
|
+
}
|
57
|
+
|
58
|
+
#line 127 "ext/lexerc/lexerc.rl"
|
59
|
+
|
60
|
+
#line 61 "ext/lexerc/lexerc.c"
|
61
|
+
{
|
62
|
+
if ( p == pe )
|
63
|
+
goto _test_eof;
|
64
|
+
goto _resume;
|
65
|
+
|
66
|
+
_again:
|
67
|
+
switch ( cs ) {
|
68
|
+
case 12: goto st12;
|
69
|
+
case 13: goto st13;
|
70
|
+
case 14: goto st14;
|
71
|
+
case 15: goto st15;
|
72
|
+
case 16: goto st16;
|
73
|
+
case 0: goto st0;
|
74
|
+
case 17: goto st17;
|
75
|
+
case 1: goto st1;
|
76
|
+
case 2: goto st2;
|
77
|
+
case 18: goto st18;
|
78
|
+
case 3: goto st3;
|
79
|
+
case 4: goto st4;
|
80
|
+
case 5: goto st5;
|
81
|
+
case 6: goto st6;
|
82
|
+
case 19: goto st19;
|
83
|
+
case 20: goto st20;
|
84
|
+
case 7: goto st7;
|
85
|
+
case 21: goto st21;
|
86
|
+
case 22: goto st22;
|
87
|
+
case 8: goto st8;
|
88
|
+
case 23: goto st23;
|
89
|
+
case 9: goto st9;
|
90
|
+
case 24: goto st24;
|
91
|
+
case 10: goto st10;
|
92
|
+
case 25: goto st25;
|
93
|
+
case 26: goto st26;
|
94
|
+
case 27: goto st27;
|
95
|
+
case 28: goto st28;
|
96
|
+
case 11: goto st11;
|
97
|
+
default: break;
|
98
|
+
}
|
99
|
+
|
100
|
+
if ( ++p == pe )
|
101
|
+
goto _test_eof;
|
102
|
+
_resume:
|
103
|
+
switch ( cs )
|
104
|
+
{
|
105
|
+
tr20:
|
106
|
+
#line 92 "ext/lexerc/lexerc.rl"
|
107
|
+
{te = p;p--;{ emit_template; }}
|
108
|
+
goto st12;
|
109
|
+
tr22:
|
110
|
+
#line 90 "ext/lexerc/lexerc.rl"
|
111
|
+
{te = p;p--;{ emit_tag; {stack[top++] = 12; goto st16;} }}
|
112
|
+
goto st12;
|
113
|
+
tr23:
|
114
|
+
#line 90 "ext/lexerc/lexerc.rl"
|
115
|
+
{te = p+1;{ emit_tag; {stack[top++] = 12; goto st16;} }}
|
116
|
+
goto st12;
|
117
|
+
tr24:
|
118
|
+
#line 91 "ext/lexerc/lexerc.rl"
|
119
|
+
{te = p+1;{ emit_comment; {stack[top++] = 12; goto st26;} }}
|
120
|
+
goto st12;
|
121
|
+
st12:
|
122
|
+
#line 1 "NONE"
|
123
|
+
{ts = 0;}
|
124
|
+
if ( ++p == pe )
|
125
|
+
goto _test_eof12;
|
126
|
+
case 12:
|
127
|
+
#line 1 "NONE"
|
128
|
+
{ts = p;}
|
129
|
+
#line 130 "ext/lexerc/lexerc.c"
|
130
|
+
if ( (*p) == 123 )
|
131
|
+
goto st14;
|
132
|
+
goto st13;
|
133
|
+
st13:
|
134
|
+
if ( ++p == pe )
|
135
|
+
goto _test_eof13;
|
136
|
+
case 13:
|
137
|
+
if ( (*p) == 123 )
|
138
|
+
goto tr20;
|
139
|
+
goto st13;
|
140
|
+
st14:
|
141
|
+
if ( ++p == pe )
|
142
|
+
goto _test_eof14;
|
143
|
+
case 14:
|
144
|
+
if ( (*p) == 123 )
|
145
|
+
goto st15;
|
146
|
+
goto tr20;
|
147
|
+
st15:
|
148
|
+
if ( ++p == pe )
|
149
|
+
goto _test_eof15;
|
150
|
+
case 15:
|
151
|
+
switch( (*p) ) {
|
152
|
+
case 33: goto tr23;
|
153
|
+
case 35: goto tr24;
|
154
|
+
}
|
155
|
+
goto tr22;
|
156
|
+
tr1:
|
157
|
+
#line 78 "ext/lexerc/lexerc.rl"
|
158
|
+
{te = p+1;{ emit_dstring; }}
|
159
|
+
goto st16;
|
160
|
+
tr3:
|
161
|
+
#line 80 "ext/lexerc/lexerc.rl"
|
162
|
+
{{p = ((te))-1;}{ emit_comment; }}
|
163
|
+
goto st16;
|
164
|
+
tr5:
|
165
|
+
#line 74 "ext/lexerc/lexerc.rl"
|
166
|
+
{te = p+1;{ emit_operator; }}
|
167
|
+
goto st16;
|
168
|
+
tr8:
|
169
|
+
#line 77 "ext/lexerc/lexerc.rl"
|
170
|
+
{te = p+1;{ emit_sstring; }}
|
171
|
+
goto st16;
|
172
|
+
tr10:
|
173
|
+
#line 1 "NONE"
|
174
|
+
{ switch( act ) {
|
175
|
+
case 2:
|
176
|
+
{{p = ((te))-1;} emit_operator; }
|
177
|
+
break;
|
178
|
+
case 3:
|
179
|
+
{{p = ((te))-1;} emit_numeric; }
|
180
|
+
break;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
goto st16;
|
184
|
+
tr12:
|
185
|
+
#line 74 "ext/lexerc/lexerc.rl"
|
186
|
+
{{p = ((te))-1;}{ emit_operator; }}
|
187
|
+
goto st16;
|
188
|
+
tr25:
|
189
|
+
#line 81 "ext/lexerc/lexerc.rl"
|
190
|
+
{te = p+1;}
|
191
|
+
goto st16;
|
192
|
+
tr36:
|
193
|
+
#line 74 "ext/lexerc/lexerc.rl"
|
194
|
+
{te = p;p--;{ emit_operator; }}
|
195
|
+
goto st16;
|
196
|
+
tr37:
|
197
|
+
#line 80 "ext/lexerc/lexerc.rl"
|
198
|
+
{te = p;p--;{ emit_comment; }}
|
199
|
+
goto st16;
|
200
|
+
tr40:
|
201
|
+
#line 79 "ext/lexerc/lexerc.rl"
|
202
|
+
{te = p;p--;{ emit_regexp; }}
|
203
|
+
goto st16;
|
204
|
+
tr41:
|
205
|
+
#line 76 "ext/lexerc/lexerc.rl"
|
206
|
+
{te = p;p--;{ emit_identifer; }}
|
207
|
+
goto st16;
|
208
|
+
tr42:
|
209
|
+
#line 76 "ext/lexerc/lexerc.rl"
|
210
|
+
{te = p+1;{ emit_identifer; }}
|
211
|
+
goto st16;
|
212
|
+
tr43:
|
213
|
+
#line 73 "ext/lexerc/lexerc.rl"
|
214
|
+
{te = p+1;{ emit_tag; {cs = stack[--top];goto _again;} }}
|
215
|
+
goto st16;
|
216
|
+
st16:
|
217
|
+
#line 1 "NONE"
|
218
|
+
{ts = 0;}
|
219
|
+
if ( ++p == pe )
|
220
|
+
goto _test_eof16;
|
221
|
+
case 16:
|
222
|
+
#line 1 "NONE"
|
223
|
+
{ts = p;}
|
224
|
+
#line 225 "ext/lexerc/lexerc.c"
|
225
|
+
switch( (*p) ) {
|
226
|
+
case 10: goto tr5;
|
227
|
+
case 32: goto tr25;
|
228
|
+
case 33: goto st17;
|
229
|
+
case 34: goto st1;
|
230
|
+
case 35: goto tr4;
|
231
|
+
case 38: goto st4;
|
232
|
+
case 39: goto st5;
|
233
|
+
case 42: goto st19;
|
234
|
+
case 45: goto tr29;
|
235
|
+
case 46: goto tr30;
|
236
|
+
case 47: goto tr31;
|
237
|
+
case 63: goto tr5;
|
238
|
+
case 91: goto tr5;
|
239
|
+
case 93: goto tr5;
|
240
|
+
case 95: goto st24;
|
241
|
+
case 123: goto tr5;
|
242
|
+
case 124: goto st10;
|
243
|
+
case 125: goto st25;
|
244
|
+
}
|
245
|
+
if ( (*p) < 58 ) {
|
246
|
+
if ( (*p) < 37 ) {
|
247
|
+
if ( 9 <= (*p) && (*p) <= 13 )
|
248
|
+
goto tr25;
|
249
|
+
} else if ( (*p) > 44 ) {
|
250
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
251
|
+
goto tr32;
|
252
|
+
} else
|
253
|
+
goto tr5;
|
254
|
+
} else if ( (*p) > 59 ) {
|
255
|
+
if ( (*p) < 65 ) {
|
256
|
+
if ( 60 <= (*p) && (*p) <= 62 )
|
257
|
+
goto st17;
|
258
|
+
} else if ( (*p) > 90 ) {
|
259
|
+
if ( 97 <= (*p) && (*p) <= 122 )
|
260
|
+
goto st24;
|
261
|
+
} else
|
262
|
+
goto st24;
|
263
|
+
} else
|
264
|
+
goto tr5;
|
265
|
+
goto st0;
|
266
|
+
st0:
|
267
|
+
cs = 0;
|
268
|
+
goto _out;
|
269
|
+
st17:
|
270
|
+
if ( ++p == pe )
|
271
|
+
goto _test_eof17;
|
272
|
+
case 17:
|
273
|
+
if ( (*p) == 61 )
|
274
|
+
goto tr5;
|
275
|
+
goto tr36;
|
276
|
+
st1:
|
277
|
+
if ( ++p == pe )
|
278
|
+
goto _test_eof1;
|
279
|
+
case 1:
|
280
|
+
switch( (*p) ) {
|
281
|
+
case 34: goto tr1;
|
282
|
+
case 92: goto st2;
|
283
|
+
}
|
284
|
+
goto st1;
|
285
|
+
st2:
|
286
|
+
if ( ++p == pe )
|
287
|
+
goto _test_eof2;
|
288
|
+
case 2:
|
289
|
+
goto st1;
|
290
|
+
tr4:
|
291
|
+
#line 1 "NONE"
|
292
|
+
{te = p+1;}
|
293
|
+
goto st18;
|
294
|
+
st18:
|
295
|
+
if ( ++p == pe )
|
296
|
+
goto _test_eof18;
|
297
|
+
case 18:
|
298
|
+
#line 299 "ext/lexerc/lexerc.c"
|
299
|
+
switch( (*p) ) {
|
300
|
+
case 10: goto tr37;
|
301
|
+
case 125: goto st3;
|
302
|
+
}
|
303
|
+
goto tr4;
|
304
|
+
st3:
|
305
|
+
if ( ++p == pe )
|
306
|
+
goto _test_eof3;
|
307
|
+
case 3:
|
308
|
+
if ( (*p) == 125 )
|
309
|
+
goto tr3;
|
310
|
+
goto tr4;
|
311
|
+
st4:
|
312
|
+
if ( ++p == pe )
|
313
|
+
goto _test_eof4;
|
314
|
+
case 4:
|
315
|
+
if ( (*p) == 38 )
|
316
|
+
goto tr5;
|
317
|
+
goto st0;
|
318
|
+
st5:
|
319
|
+
if ( ++p == pe )
|
320
|
+
goto _test_eof5;
|
321
|
+
case 5:
|
322
|
+
switch( (*p) ) {
|
323
|
+
case 39: goto tr8;
|
324
|
+
case 92: goto st6;
|
325
|
+
}
|
326
|
+
goto st5;
|
327
|
+
st6:
|
328
|
+
if ( ++p == pe )
|
329
|
+
goto _test_eof6;
|
330
|
+
case 6:
|
331
|
+
goto st5;
|
332
|
+
st19:
|
333
|
+
if ( ++p == pe )
|
334
|
+
goto _test_eof19;
|
335
|
+
case 19:
|
336
|
+
if ( (*p) == 42 )
|
337
|
+
goto tr5;
|
338
|
+
goto tr36;
|
339
|
+
tr32:
|
340
|
+
#line 1 "NONE"
|
341
|
+
{te = p+1;}
|
342
|
+
#line 75 "ext/lexerc/lexerc.rl"
|
343
|
+
{act = 3;}
|
344
|
+
goto st20;
|
345
|
+
tr29:
|
346
|
+
#line 1 "NONE"
|
347
|
+
{te = p+1;}
|
348
|
+
#line 74 "ext/lexerc/lexerc.rl"
|
349
|
+
{act = 2;}
|
350
|
+
goto st20;
|
351
|
+
st20:
|
352
|
+
if ( ++p == pe )
|
353
|
+
goto _test_eof20;
|
354
|
+
case 20:
|
355
|
+
#line 356 "ext/lexerc/lexerc.c"
|
356
|
+
if ( (*p) == 46 )
|
357
|
+
goto st7;
|
358
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
359
|
+
goto tr32;
|
360
|
+
goto tr10;
|
361
|
+
st7:
|
362
|
+
if ( ++p == pe )
|
363
|
+
goto _test_eof7;
|
364
|
+
case 7:
|
365
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
366
|
+
goto tr11;
|
367
|
+
goto tr10;
|
368
|
+
tr11:
|
369
|
+
#line 1 "NONE"
|
370
|
+
{te = p+1;}
|
371
|
+
#line 75 "ext/lexerc/lexerc.rl"
|
372
|
+
{act = 3;}
|
373
|
+
goto st21;
|
374
|
+
tr30:
|
375
|
+
#line 1 "NONE"
|
376
|
+
{te = p+1;}
|
377
|
+
#line 74 "ext/lexerc/lexerc.rl"
|
378
|
+
{act = 2;}
|
379
|
+
goto st21;
|
380
|
+
st21:
|
381
|
+
if ( ++p == pe )
|
382
|
+
goto _test_eof21;
|
383
|
+
case 21:
|
384
|
+
#line 385 "ext/lexerc/lexerc.c"
|
385
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
386
|
+
goto tr11;
|
387
|
+
goto tr10;
|
388
|
+
tr31:
|
389
|
+
#line 1 "NONE"
|
390
|
+
{te = p+1;}
|
391
|
+
#line 53 "ext/lexerc/lexerc.rl"
|
392
|
+
{ regexp_ambiguity({goto st16;}) }
|
393
|
+
goto st22;
|
394
|
+
st22:
|
395
|
+
if ( ++p == pe )
|
396
|
+
goto _test_eof22;
|
397
|
+
case 22:
|
398
|
+
#line 399 "ext/lexerc/lexerc.c"
|
399
|
+
switch( (*p) ) {
|
400
|
+
case 47: goto st23;
|
401
|
+
case 92: goto st9;
|
402
|
+
}
|
403
|
+
goto st8;
|
404
|
+
st8:
|
405
|
+
if ( ++p == pe )
|
406
|
+
goto _test_eof8;
|
407
|
+
case 8:
|
408
|
+
switch( (*p) ) {
|
409
|
+
case 47: goto st23;
|
410
|
+
case 92: goto st9;
|
411
|
+
}
|
412
|
+
goto st8;
|
413
|
+
st23:
|
414
|
+
if ( ++p == pe )
|
415
|
+
goto _test_eof23;
|
416
|
+
case 23:
|
417
|
+
if ( (*p) > 90 ) {
|
418
|
+
if ( 97 <= (*p) && (*p) <= 122 )
|
419
|
+
goto st23;
|
420
|
+
} else if ( (*p) >= 65 )
|
421
|
+
goto st23;
|
422
|
+
goto tr40;
|
423
|
+
st9:
|
424
|
+
if ( ++p == pe )
|
425
|
+
goto _test_eof9;
|
426
|
+
case 9:
|
427
|
+
goto st8;
|
428
|
+
st24:
|
429
|
+
if ( ++p == pe )
|
430
|
+
goto _test_eof24;
|
431
|
+
case 24:
|
432
|
+
switch( (*p) ) {
|
433
|
+
case 33: goto tr42;
|
434
|
+
case 63: goto tr42;
|
435
|
+
case 95: goto st24;
|
436
|
+
}
|
437
|
+
if ( (*p) < 65 ) {
|
438
|
+
if ( 48 <= (*p) && (*p) <= 57 )
|
439
|
+
goto st24;
|
440
|
+
} else if ( (*p) > 90 ) {
|
441
|
+
if ( 97 <= (*p) && (*p) <= 122 )
|
442
|
+
goto st24;
|
443
|
+
} else
|
444
|
+
goto st24;
|
445
|
+
goto tr41;
|
446
|
+
st10:
|
447
|
+
if ( ++p == pe )
|
448
|
+
goto _test_eof10;
|
449
|
+
case 10:
|
450
|
+
if ( (*p) == 124 )
|
451
|
+
goto tr5;
|
452
|
+
goto st0;
|
453
|
+
st25:
|
454
|
+
if ( ++p == pe )
|
455
|
+
goto _test_eof25;
|
456
|
+
case 25:
|
457
|
+
if ( (*p) == 125 )
|
458
|
+
goto tr43;
|
459
|
+
goto tr36;
|
460
|
+
tr16:
|
461
|
+
#line 86 "ext/lexerc/lexerc.rl"
|
462
|
+
{{p = ((te))-1;}{ emit_comment; }}
|
463
|
+
goto st26;
|
464
|
+
tr17:
|
465
|
+
#line 85 "ext/lexerc/lexerc.rl"
|
466
|
+
{te = p+1;{ emit_comment; {cs = stack[--top];goto _again;} }}
|
467
|
+
goto st26;
|
468
|
+
tr46:
|
469
|
+
#line 86 "ext/lexerc/lexerc.rl"
|
470
|
+
{te = p;p--;{ emit_comment; }}
|
471
|
+
goto st26;
|
472
|
+
st26:
|
473
|
+
#line 1 "NONE"
|
474
|
+
{ts = 0;}
|
475
|
+
if ( ++p == pe )
|
476
|
+
goto _test_eof26;
|
477
|
+
case 26:
|
478
|
+
#line 1 "NONE"
|
479
|
+
{ts = p;}
|
480
|
+
#line 481 "ext/lexerc/lexerc.c"
|
481
|
+
if ( (*p) == 35 )
|
482
|
+
goto tr45;
|
483
|
+
goto st27;
|
484
|
+
st27:
|
485
|
+
if ( ++p == pe )
|
486
|
+
goto _test_eof27;
|
487
|
+
case 27:
|
488
|
+
if ( (*p) == 35 )
|
489
|
+
goto tr46;
|
490
|
+
goto st27;
|
491
|
+
tr45:
|
492
|
+
#line 1 "NONE"
|
493
|
+
{te = p+1;}
|
494
|
+
goto st28;
|
495
|
+
st28:
|
496
|
+
if ( ++p == pe )
|
497
|
+
goto _test_eof28;
|
498
|
+
case 28:
|
499
|
+
#line 500 "ext/lexerc/lexerc.c"
|
500
|
+
if ( (*p) == 125 )
|
501
|
+
goto st11;
|
502
|
+
goto tr46;
|
503
|
+
st11:
|
504
|
+
if ( ++p == pe )
|
505
|
+
goto _test_eof11;
|
506
|
+
case 11:
|
507
|
+
if ( (*p) == 125 )
|
508
|
+
goto tr17;
|
509
|
+
goto tr16;
|
510
|
+
}
|
511
|
+
_test_eof12: cs = 12; goto _test_eof;
|
512
|
+
_test_eof13: cs = 13; goto _test_eof;
|
513
|
+
_test_eof14: cs = 14; goto _test_eof;
|
514
|
+
_test_eof15: cs = 15; goto _test_eof;
|
515
|
+
_test_eof16: cs = 16; goto _test_eof;
|
516
|
+
_test_eof17: cs = 17; goto _test_eof;
|
517
|
+
_test_eof1: cs = 1; goto _test_eof;
|
518
|
+
_test_eof2: cs = 2; goto _test_eof;
|
519
|
+
_test_eof18: cs = 18; goto _test_eof;
|
520
|
+
_test_eof3: cs = 3; goto _test_eof;
|
521
|
+
_test_eof4: cs = 4; goto _test_eof;
|
522
|
+
_test_eof5: cs = 5; goto _test_eof;
|
523
|
+
_test_eof6: cs = 6; goto _test_eof;
|
524
|
+
_test_eof19: cs = 19; goto _test_eof;
|
525
|
+
_test_eof20: cs = 20; goto _test_eof;
|
526
|
+
_test_eof7: cs = 7; goto _test_eof;
|
527
|
+
_test_eof21: cs = 21; goto _test_eof;
|
528
|
+
_test_eof22: cs = 22; goto _test_eof;
|
529
|
+
_test_eof8: cs = 8; goto _test_eof;
|
530
|
+
_test_eof23: cs = 23; goto _test_eof;
|
531
|
+
_test_eof9: cs = 9; goto _test_eof;
|
532
|
+
_test_eof24: cs = 24; goto _test_eof;
|
533
|
+
_test_eof10: cs = 10; goto _test_eof;
|
534
|
+
_test_eof25: cs = 25; goto _test_eof;
|
535
|
+
_test_eof26: cs = 26; goto _test_eof;
|
536
|
+
_test_eof27: cs = 27; goto _test_eof;
|
537
|
+
_test_eof28: cs = 28; goto _test_eof;
|
538
|
+
_test_eof11: cs = 11; goto _test_eof;
|
539
|
+
|
540
|
+
_test_eof: {}
|
541
|
+
if ( p == eof )
|
542
|
+
{
|
543
|
+
switch ( cs ) {
|
544
|
+
case 13: goto tr20;
|
545
|
+
case 14: goto tr20;
|
546
|
+
case 15: goto tr22;
|
547
|
+
case 17: goto tr36;
|
548
|
+
case 18: goto tr37;
|
549
|
+
case 3: goto tr3;
|
550
|
+
case 19: goto tr36;
|
551
|
+
case 20: goto tr10;
|
552
|
+
case 7: goto tr10;
|
553
|
+
case 21: goto tr10;
|
554
|
+
case 22: goto tr36;
|
555
|
+
case 8: goto tr12;
|
556
|
+
case 23: goto tr40;
|
557
|
+
case 9: goto tr12;
|
558
|
+
case 24: goto tr41;
|
559
|
+
case 25: goto tr36;
|
560
|
+
case 27: goto tr46;
|
561
|
+
case 28: goto tr46;
|
562
|
+
case 11: goto tr16;
|
563
|
+
case 5:
|
564
|
+
#line 45 "ext/lexerc/lexerc.rl"
|
565
|
+
{ raise_unterminated_string; }
|
566
|
+
break;
|
567
|
+
case 1:
|
568
|
+
#line 49 "ext/lexerc/lexerc.rl"
|
569
|
+
{ raise_unterminated_string; }
|
570
|
+
break;
|
571
|
+
#line 572 "ext/lexerc/lexerc.c"
|
572
|
+
}
|
573
|
+
}
|
574
|
+
|
575
|
+
_out: {}
|
576
|
+
}
|
577
|
+
|
578
|
+
#line 128 "ext/lexerc/lexerc.rl"
|
579
|
+
|
580
|
+
free(stack);
|
581
|
+
|
582
|
+
if (ts > 0 && ((ts - data) < (pe - data - 1))) {
|
583
|
+
raise_unexpected_symbol;
|
584
|
+
}
|
585
|
+
|
586
|
+
return rb_iv_get(self, "@token_array");
|
587
|
+
}
|
588
|
+
|
589
|
+
static VALUE current_position(VALUE self) {
|
590
|
+
return INT2FIX(ts - data);
|
591
|
+
}
|
592
|
+
|
593
|
+
static VALUE current_value(VALUE self) {
|
594
|
+
VALUE string = rb_str_new(ts, te - ts);
|
595
|
+
return rb_funcall(string, rb_intern("force_encoding"), 1, encoding);
|
596
|
+
}
|
597
|
+
|
598
|
+
static VALUE current_error(VALUE self) {
|
599
|
+
VALUE parsed = rb_str_new(ts, p - ts == 0 ? 1 : p - ts);
|
600
|
+
VALUE encoded = rb_funcall(parsed, rb_intern("force_encoding"), 1, encoding);
|
601
|
+
|
602
|
+
VALUE source = rb_iv_get(self, "@source");
|
603
|
+
VALUE info = rb_funcall(source, rb_intern("info"), 1, INT2FIX(ts - data));
|
604
|
+
VALUE line = rb_funcall(info, rb_intern("[]"), 1, ID2SYM(rb_intern("line")));
|
605
|
+
VALUE column = rb_funcall(info, rb_intern("[]"), 1, ID2SYM(rb_intern("column")));
|
606
|
+
|
607
|
+
return rb_ary_new3(3, encoded, line, column);
|
608
|
+
}
|
609
|
+
|
610
|
+
void Init_lexerc() {
|
611
|
+
mHotcell = rb_const_get(rb_cObject, rb_intern("Hotcell"));
|
612
|
+
cHotcellLexer = rb_const_get(mHotcell, rb_intern("Lexer"));
|
613
|
+
|
614
|
+
rb_define_method(cHotcellLexer, "tokenize", tokenize, 0);
|
615
|
+
rb_define_method(cHotcellLexer, "current_position", current_position, 0);
|
616
|
+
rb_define_method(cHotcellLexer, "current_value", current_value, 0);
|
617
|
+
rb_define_method(cHotcellLexer, "current_error", current_error, 0);
|
618
|
+
}
|
data/ext/lexerc/lexerc.h
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#define emit_tag rb_funcall(self, rb_intern("emit_tag"), 0)
|
2
|
+
#define emit_operator rb_funcall(self, rb_intern("emit_operator"), 0)
|
3
|
+
#define emit_numeric rb_funcall(self, rb_intern("emit_numeric"), 0)
|
4
|
+
#define emit_identifer rb_funcall(self, rb_intern("emit_identifer"), 0)
|
5
|
+
#define emit_sstring rb_funcall(self, rb_intern("emit_sstring"), 0)
|
6
|
+
#define emit_dstring rb_funcall(self, rb_intern("emit_dstring"), 0)
|
7
|
+
#define emit_regexp rb_funcall(self, rb_intern("emit_regexp"), 0)
|
8
|
+
#define emit_comment rb_funcall(self, rb_intern("emit_comment"), 0)
|
9
|
+
#define emit_template rb_funcall(self, rb_intern("emit_template"), 0)
|
10
|
+
|
11
|
+
#define raise_unterminated_string rb_funcall(self, rb_intern("raise_unterminated_string"), 0)
|
12
|
+
#define raise_unterminated_regexp rb_funcall(self, rb_intern("raise_unterminated_regexp"), 0)
|
13
|
+
#define raise_unexpected_symbol rb_funcall(self, rb_intern("raise_unexpected_symbol"), 0)
|
14
|
+
|
15
|
+
#define regexp_ambiguity(block) { \
|
16
|
+
if (rb_funcall(self, rb_intern("regexp_possible?"), 0) == Qfalse) { \
|
17
|
+
emit_operator; \
|
18
|
+
block; \
|
19
|
+
} \
|
20
|
+
}
|