hotcell 0.0.1 → 0.1.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.
Files changed (67) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +4 -1
  3. data/.rspec +1 -0
  4. data/.rvmrc +1 -1
  5. data/.travis.yml +7 -0
  6. data/Gemfile +4 -1
  7. data/README.md +361 -2
  8. data/Rakefile +28 -6
  9. data/ext/lexerc/extconf.rb +3 -0
  10. data/ext/lexerc/lexerc.c +618 -0
  11. data/ext/lexerc/lexerc.h +20 -0
  12. data/ext/lexerc/lexerc.rl +167 -0
  13. data/hotcell.gemspec +8 -7
  14. data/lib/hotcell/commands/case.rb +59 -0
  15. data/lib/hotcell/commands/cycle.rb +38 -0
  16. data/lib/hotcell/commands/for.rb +70 -0
  17. data/lib/hotcell/commands/if.rb +51 -0
  18. data/lib/hotcell/commands/include.rb +21 -0
  19. data/lib/hotcell/commands/scope.rb +13 -0
  20. data/lib/hotcell/commands/unless.rb +23 -0
  21. data/lib/hotcell/commands.rb +13 -0
  22. data/lib/hotcell/config.rb +33 -6
  23. data/lib/hotcell/context.rb +40 -7
  24. data/lib/hotcell/errors.rb +37 -28
  25. data/lib/hotcell/extensions.rb +4 -0
  26. data/lib/hotcell/lexer.rb +19 -635
  27. data/lib/hotcell/lexerr.rb +572 -0
  28. data/lib/hotcell/lexerr.rl +137 -0
  29. data/lib/hotcell/node/assigner.rb +1 -5
  30. data/lib/hotcell/node/block.rb +17 -40
  31. data/lib/hotcell/node/command.rb +29 -22
  32. data/lib/hotcell/node/hasher.rb +1 -1
  33. data/lib/hotcell/node/summoner.rb +2 -6
  34. data/lib/hotcell/node/tag.rb +10 -7
  35. data/lib/hotcell/node.rb +12 -1
  36. data/lib/hotcell/parser.rb +474 -408
  37. data/lib/hotcell/parser.y +175 -117
  38. data/lib/hotcell/resolver.rb +44 -0
  39. data/lib/hotcell/source.rb +35 -0
  40. data/lib/hotcell/template.rb +15 -6
  41. data/lib/hotcell/version.rb +1 -1
  42. data/lib/hotcell.rb +15 -10
  43. data/spec/data/templates/simple.hc +1 -0
  44. data/spec/lib/hotcell/commands/case_spec.rb +39 -0
  45. data/spec/lib/hotcell/commands/cycle_spec.rb +29 -0
  46. data/spec/lib/hotcell/commands/for_spec.rb +65 -0
  47. data/spec/lib/hotcell/commands/if_spec.rb +35 -0
  48. data/spec/lib/hotcell/commands/include_spec.rb +39 -0
  49. data/spec/lib/hotcell/commands/scope_spec.rb +16 -0
  50. data/spec/lib/hotcell/commands/unless_spec.rb +23 -0
  51. data/spec/lib/hotcell/config_spec.rb +35 -10
  52. data/spec/lib/hotcell/context_spec.rb +58 -18
  53. data/spec/lib/hotcell/lexer_spec.rb +37 -28
  54. data/spec/lib/hotcell/node/block_spec.rb +28 -56
  55. data/spec/lib/hotcell/node/command_spec.rb +7 -31
  56. data/spec/lib/hotcell/node/tag_spec.rb +16 -0
  57. data/spec/lib/hotcell/parser_spec.rb +152 -123
  58. data/spec/lib/hotcell/resolver_spec.rb +28 -0
  59. data/spec/lib/hotcell/source_spec.rb +41 -0
  60. data/spec/lib/hotcell/template_spec.rb +47 -4
  61. data/spec/lib/hotcell_spec.rb +2 -1
  62. data/spec/spec_helper.rb +6 -2
  63. metadata +54 -24
  64. data/lib/hotcell/.DS_Store +0 -0
  65. data/lib/hotcell/lexer.rl +0 -299
  66. data/misc/rage.rl +0 -1999
  67. data/misc/unicode2ragel.rb +0 -305
@@ -0,0 +1,572 @@
1
+
2
+ # line 1 "lib/hotcell/lexerr.rl"
3
+
4
+ # line 100 "lib/hotcell/lexerr.rl"
5
+
6
+ #%
7
+
8
+ Hotcell::Lexer.class_eval do
9
+ def current_position
10
+ @ts
11
+ end
12
+
13
+ def current_value
14
+ @data[@ts...@te].pack(Hotcell::Source::PACK_MODE).force_encoding(@source.encoding)
15
+ end
16
+
17
+ def current_error
18
+ value = @data[@ts..@p].pack(Hotcell::Source::PACK_MODE).force_encoding(@source.encoding)
19
+ [value, *@source.info(@ts).values_at(:line, :column)]
20
+ end
21
+
22
+ def tokenize
23
+
24
+ # line 25 "lib/hotcell/lexerr.rb"
25
+ class << self
26
+ attr_accessor :_puffer_lexer_trans_keys
27
+ private :_puffer_lexer_trans_keys, :_puffer_lexer_trans_keys=
28
+ end
29
+ self._puffer_lexer_trans_keys = [
30
+ 0, 0, 34, 92, 0, 0,
31
+ 125, 125, 38, 38, 39,
32
+ 92, 0, 0, 48, 57,
33
+ 47, 92, 0, 0, 124, 124,
34
+ 125, 125, 123, 123, 123,
35
+ 123, 123, 123, 33, 35,
36
+ 9, 125, 61, 61, 10, 125,
37
+ 42, 42, 46, 57, 48,
38
+ 57, 47, 92, 65, 122,
39
+ 33, 122, 125, 125, 35, 35,
40
+ 35, 35, 125, 125, 0
41
+ ]
42
+
43
+ class << self
44
+ attr_accessor :_puffer_lexer_key_spans
45
+ private :_puffer_lexer_key_spans, :_puffer_lexer_key_spans=
46
+ end
47
+ self._puffer_lexer_key_spans = [
48
+ 0, 59, 0, 1, 1, 54, 0, 10,
49
+ 46, 0, 1, 1, 1, 1, 1, 3,
50
+ 117, 1, 116, 1, 12, 10, 46, 58,
51
+ 90, 1, 1, 1, 1
52
+ ]
53
+
54
+ class << self
55
+ attr_accessor :_puffer_lexer_index_offsets
56
+ private :_puffer_lexer_index_offsets, :_puffer_lexer_index_offsets=
57
+ end
58
+ self._puffer_lexer_index_offsets = [
59
+ 0, 0, 60, 61, 63, 65, 120, 121,
60
+ 132, 179, 180, 182, 184, 186, 188, 190,
61
+ 194, 312, 314, 431, 433, 446, 457, 504,
62
+ 563, 654, 656, 658, 660
63
+ ]
64
+
65
+ class << self
66
+ attr_accessor :_puffer_lexer_indicies
67
+ private :_puffer_lexer_indicies, :_puffer_lexer_indicies=
68
+ end
69
+ self._puffer_lexer_indicies = [
70
+ 1, 0, 0, 0, 0, 0, 0, 0,
71
+ 0, 0, 0, 0, 0, 0, 0, 0,
72
+ 0, 0, 0, 0, 0, 0, 0, 0,
73
+ 0, 0, 0, 0, 0, 0, 0, 0,
74
+ 0, 0, 0, 0, 0, 0, 0, 0,
75
+ 0, 0, 0, 0, 0, 0, 0, 0,
76
+ 0, 0, 0, 0, 0, 0, 0, 0,
77
+ 0, 0, 2, 0, 0, 3, 4, 5,
78
+ 6, 8, 7, 7, 7, 7, 7, 7,
79
+ 7, 7, 7, 7, 7, 7, 7, 7,
80
+ 7, 7, 7, 7, 7, 7, 7, 7,
81
+ 7, 7, 7, 7, 7, 7, 7, 7,
82
+ 7, 7, 7, 7, 7, 7, 7, 7,
83
+ 7, 7, 7, 7, 7, 7, 7, 7,
84
+ 7, 7, 7, 7, 7, 7, 9, 7,
85
+ 7, 11, 11, 11, 11, 11, 11, 11,
86
+ 11, 11, 11, 10, 14, 13, 13, 13,
87
+ 13, 13, 13, 13, 13, 13, 13, 13,
88
+ 13, 13, 13, 13, 13, 13, 13, 13,
89
+ 13, 13, 13, 13, 13, 13, 13, 13,
90
+ 13, 13, 13, 13, 13, 13, 13, 13,
91
+ 13, 13, 13, 13, 13, 13, 13, 13,
92
+ 13, 15, 13, 13, 5, 6, 17, 16,
93
+ 19, 18, 20, 18, 21, 20, 23, 22,
94
+ 24, 22, 25, 5, 25, 25, 25, 6,
95
+ 6, 6, 6, 6, 6, 6, 6, 6,
96
+ 6, 6, 6, 6, 6, 6, 6, 6,
97
+ 6, 25, 26, 0, 4, 6, 5, 27,
98
+ 7, 5, 5, 28, 5, 5, 29, 30,
99
+ 31, 32, 32, 32, 32, 32, 32, 32,
100
+ 32, 32, 32, 5, 5, 26, 26, 26,
101
+ 5, 6, 33, 33, 33, 33, 33, 33,
102
+ 33, 33, 33, 33, 33, 33, 33, 33,
103
+ 33, 33, 33, 33, 33, 33, 33, 33,
104
+ 33, 33, 33, 33, 5, 6, 5, 6,
105
+ 33, 6, 33, 33, 33, 33, 33, 33,
106
+ 33, 33, 33, 33, 33, 33, 33, 33,
107
+ 33, 33, 33, 33, 33, 33, 33, 33,
108
+ 33, 33, 33, 33, 5, 34, 35, 6,
109
+ 5, 36, 37, 4, 4, 4, 4, 4,
110
+ 4, 4, 4, 4, 4, 4, 4, 4,
111
+ 4, 4, 4, 4, 4, 4, 4, 4,
112
+ 4, 4, 4, 4, 4, 4, 4, 4,
113
+ 4, 4, 4, 4, 4, 4, 4, 4,
114
+ 4, 4, 4, 4, 4, 4, 4, 4,
115
+ 4, 4, 4, 4, 4, 4, 4, 4,
116
+ 4, 4, 4, 4, 4, 4, 4, 4,
117
+ 4, 4, 4, 4, 4, 4, 4, 4,
118
+ 4, 4, 4, 4, 4, 4, 4, 4,
119
+ 4, 4, 4, 4, 4, 4, 4, 4,
120
+ 4, 4, 4, 4, 4, 4, 4, 4,
121
+ 4, 4, 4, 4, 4, 4, 4, 4,
122
+ 4, 4, 4, 4, 4, 4, 4, 4,
123
+ 4, 4, 4, 4, 4, 38, 4, 5,
124
+ 36, 39, 10, 32, 32, 32, 32, 32,
125
+ 32, 32, 32, 32, 32, 10, 11, 11,
126
+ 11, 11, 11, 11, 11, 11, 11, 11,
127
+ 10, 14, 13, 13, 13, 13, 13, 13,
128
+ 13, 13, 13, 13, 13, 13, 13, 13,
129
+ 13, 13, 13, 13, 13, 13, 13, 13,
130
+ 13, 13, 13, 13, 13, 13, 13, 13,
131
+ 13, 13, 13, 13, 13, 13, 13, 13,
132
+ 13, 13, 13, 13, 13, 13, 15, 13,
133
+ 14, 14, 14, 14, 14, 14, 14, 14,
134
+ 14, 14, 14, 14, 14, 14, 14, 14,
135
+ 14, 14, 14, 14, 14, 14, 14, 14,
136
+ 14, 14, 40, 40, 40, 40, 40, 40,
137
+ 14, 14, 14, 14, 14, 14, 14, 14,
138
+ 14, 14, 14, 14, 14, 14, 14, 14,
139
+ 14, 14, 14, 14, 14, 14, 14, 14,
140
+ 14, 14, 40, 42, 41, 41, 41, 41,
141
+ 41, 41, 41, 41, 41, 41, 41, 41,
142
+ 41, 41, 33, 33, 33, 33, 33, 33,
143
+ 33, 33, 33, 33, 41, 41, 41, 41,
144
+ 41, 42, 41, 33, 33, 33, 33, 33,
145
+ 33, 33, 33, 33, 33, 33, 33, 33,
146
+ 33, 33, 33, 33, 33, 33, 33, 33,
147
+ 33, 33, 33, 33, 33, 41, 41, 41,
148
+ 41, 33, 41, 33, 33, 33, 33, 33,
149
+ 33, 33, 33, 33, 33, 33, 33, 33,
150
+ 33, 33, 33, 33, 33, 33, 33, 33,
151
+ 33, 33, 33, 33, 33, 41, 43, 36,
152
+ 45, 44, 46, 44, 47, 46, 0
153
+ ]
154
+
155
+ class << self
156
+ attr_accessor :_puffer_lexer_trans_targs
157
+ private :_puffer_lexer_trans_targs, :_puffer_lexer_trans_targs=
158
+ end
159
+ self._puffer_lexer_trans_targs = [
160
+ 1, 16, 2, 16, 18, 16, 0, 5,
161
+ 16, 6, 16, 21, 16, 8, 23, 9,
162
+ 26, 26, 13, 14, 12, 15, 12, 12,
163
+ 12, 16, 17, 4, 19, 20, 21, 22,
164
+ 20, 24, 10, 25, 16, 16, 3, 7,
165
+ 16, 16, 16, 16, 27, 28, 26, 11
166
+ ]
167
+
168
+ class << self
169
+ attr_accessor :_puffer_lexer_trans_actions
170
+ private :_puffer_lexer_trans_actions, :_puffer_lexer_trans_actions=
171
+ end
172
+ self._puffer_lexer_trans_actions = [
173
+ 0, 2, 0, 3, 4, 5, 0, 0,
174
+ 7, 0, 8, 9, 10, 0, 0, 0,
175
+ 11, 12, 0, 0, 15, 0, 16, 17,
176
+ 18, 19, 0, 0, 0, 20, 20, 21,
177
+ 9, 0, 0, 0, 22, 23, 0, 0,
178
+ 24, 25, 26, 27, 0, 4, 28, 0
179
+ ]
180
+
181
+ class << self
182
+ attr_accessor :_puffer_lexer_to_state_actions
183
+ private :_puffer_lexer_to_state_actions, :_puffer_lexer_to_state_actions=
184
+ end
185
+ self._puffer_lexer_to_state_actions = [
186
+ 0, 0, 0, 0, 0, 0, 0, 0,
187
+ 0, 0, 0, 0, 13, 0, 0, 0,
188
+ 13, 0, 0, 0, 0, 0, 0, 0,
189
+ 0, 0, 13, 0, 0
190
+ ]
191
+
192
+ class << self
193
+ attr_accessor :_puffer_lexer_from_state_actions
194
+ private :_puffer_lexer_from_state_actions, :_puffer_lexer_from_state_actions=
195
+ end
196
+ self._puffer_lexer_from_state_actions = [
197
+ 0, 0, 0, 0, 0, 0, 0, 0,
198
+ 0, 0, 0, 0, 14, 0, 0, 0,
199
+ 14, 0, 0, 0, 0, 0, 0, 0,
200
+ 0, 0, 14, 0, 0
201
+ ]
202
+
203
+ class << self
204
+ attr_accessor :_puffer_lexer_eof_actions
205
+ private :_puffer_lexer_eof_actions, :_puffer_lexer_eof_actions=
206
+ end
207
+ self._puffer_lexer_eof_actions = [
208
+ 0, 1, 0, 0, 0, 6, 0, 0,
209
+ 0, 0, 0, 0, 0, 0, 0, 0,
210
+ 0, 0, 0, 0, 0, 0, 0, 0,
211
+ 0, 0, 0, 0, 0
212
+ ]
213
+
214
+ class << self
215
+ attr_accessor :_puffer_lexer_eof_trans
216
+ private :_puffer_lexer_eof_trans, :_puffer_lexer_eof_trans=
217
+ end
218
+ self._puffer_lexer_eof_trans = [
219
+ 0, 0, 0, 4, 0, 0, 0, 11,
220
+ 13, 13, 0, 17, 0, 21, 21, 23,
221
+ 0, 37, 38, 37, 11, 11, 37, 41,
222
+ 42, 37, 0, 47, 47
223
+ ]
224
+
225
+ class << self
226
+ attr_accessor :puffer_lexer_start
227
+ end
228
+ self.puffer_lexer_start = 12;
229
+ class << self
230
+ attr_accessor :puffer_lexer_first_final
231
+ end
232
+ self.puffer_lexer_first_final = 12;
233
+ class << self
234
+ attr_accessor :puffer_lexer_error
235
+ end
236
+ self.puffer_lexer_error = 0;
237
+
238
+ class << self
239
+ attr_accessor :puffer_lexer_en_expression
240
+ end
241
+ self.puffer_lexer_en_expression = 16;
242
+ class << self
243
+ attr_accessor :puffer_lexer_en_template_comment
244
+ end
245
+ self.puffer_lexer_en_template_comment = 26;
246
+ class << self
247
+ attr_accessor :puffer_lexer_en_main
248
+ end
249
+ self.puffer_lexer_en_main = 12;
250
+
251
+
252
+ # line 119 "lib/hotcell/lexerr.rl"
253
+ #%
254
+
255
+ @data = @source.data
256
+ @token_array = []
257
+
258
+
259
+ # line 260 "lib/hotcell/lexerr.rb"
260
+ begin
261
+ @p ||= 0
262
+ pe ||= @data.length
263
+ cs = puffer_lexer_start
264
+ top = 0
265
+ @ts = nil
266
+ @te = nil
267
+ act = 0
268
+ end
269
+
270
+ # line 125 "lib/hotcell/lexerr.rl"
271
+ #%
272
+
273
+ eof = pe
274
+ stack = []
275
+
276
+
277
+ # line 278 "lib/hotcell/lexerr.rb"
278
+ begin
279
+ testEof = false
280
+ _slen, _trans, _keys, _inds, _acts, _nacts = nil
281
+ _goto_level = 0
282
+ _resume = 10
283
+ _eof_trans = 15
284
+ _again = 20
285
+ _test_eof = 30
286
+ _out = 40
287
+ while true
288
+ if _goto_level <= 0
289
+ if @p == pe
290
+ _goto_level = _test_eof
291
+ next
292
+ end
293
+ if cs == 0
294
+ _goto_level = _out
295
+ next
296
+ end
297
+ end
298
+ if _goto_level <= _resume
299
+ case _puffer_lexer_from_state_actions[cs]
300
+ when 14 then
301
+ # line 1 "NONE"
302
+ begin
303
+ @ts = @p
304
+ end
305
+ # line 306 "lib/hotcell/lexerr.rb"
306
+ end
307
+ _keys = cs << 1
308
+ _inds = _puffer_lexer_index_offsets[cs]
309
+ _slen = _puffer_lexer_key_spans[cs]
310
+ _trans = if ( _slen > 0 &&
311
+ _puffer_lexer_trans_keys[_keys] <= @data[ @p].ord &&
312
+ @data[ @p].ord <= _puffer_lexer_trans_keys[_keys + 1]
313
+ ) then
314
+ _puffer_lexer_indicies[ _inds + @data[ @p].ord - _puffer_lexer_trans_keys[_keys] ]
315
+ else
316
+ _puffer_lexer_indicies[ _inds + _slen ]
317
+ end
318
+ end
319
+ if _goto_level <= _eof_trans
320
+ cs = _puffer_lexer_trans_targs[_trans]
321
+ if _puffer_lexer_trans_actions[_trans] != 0
322
+ case _puffer_lexer_trans_actions[_trans]
323
+ when 4 then
324
+ # line 1 "NONE"
325
+ begin
326
+ @te = @p+1
327
+ end
328
+ when 27 then
329
+ # line 79 "lib/hotcell/lexerr.rl"
330
+ begin
331
+ @te = @p+1
332
+ begin emit_tag(); begin
333
+ top -= 1
334
+ cs = stack[top]
335
+ _goto_level = _again
336
+ next
337
+ end
338
+ end
339
+ end
340
+ when 5 then
341
+ # line 80 "lib/hotcell/lexerr.rl"
342
+ begin
343
+ @te = @p+1
344
+ begin emit_operator(); end
345
+ end
346
+ when 26 then
347
+ # line 82 "lib/hotcell/lexerr.rl"
348
+ begin
349
+ @te = @p+1
350
+ begin emit_identifer(); end
351
+ end
352
+ when 7 then
353
+ # line 83 "lib/hotcell/lexerr.rl"
354
+ begin
355
+ @te = @p+1
356
+ begin emit_sstring(); end
357
+ end
358
+ when 2 then
359
+ # line 84 "lib/hotcell/lexerr.rl"
360
+ begin
361
+ @te = @p+1
362
+ begin emit_dstring(); end
363
+ end
364
+ when 19 then
365
+ # line 87 "lib/hotcell/lexerr.rl"
366
+ begin
367
+ @te = @p+1
368
+ end
369
+ when 22 then
370
+ # line 80 "lib/hotcell/lexerr.rl"
371
+ begin
372
+ @te = @p
373
+ @p = @p - 1; begin emit_operator(); end
374
+ end
375
+ when 25 then
376
+ # line 82 "lib/hotcell/lexerr.rl"
377
+ begin
378
+ @te = @p
379
+ @p = @p - 1; begin emit_identifer(); end
380
+ end
381
+ when 24 then
382
+ # line 85 "lib/hotcell/lexerr.rl"
383
+ begin
384
+ @te = @p
385
+ @p = @p - 1; begin emit_regexp(); end
386
+ end
387
+ when 23 then
388
+ # line 86 "lib/hotcell/lexerr.rl"
389
+ begin
390
+ @te = @p
391
+ @p = @p - 1; begin emit_comment(); end
392
+ end
393
+ when 10 then
394
+ # line 80 "lib/hotcell/lexerr.rl"
395
+ begin
396
+ begin @p = (( @te))-1; end
397
+ begin emit_operator(); end
398
+ end
399
+ when 3 then
400
+ # line 86 "lib/hotcell/lexerr.rl"
401
+ begin
402
+ begin @p = (( @te))-1; end
403
+ begin emit_comment(); end
404
+ end
405
+ when 8 then
406
+ # line 1 "NONE"
407
+ begin
408
+ case act
409
+ when 2 then
410
+ begin begin @p = (( @te))-1; end
411
+ emit_operator(); end
412
+ when 3 then
413
+ begin begin @p = (( @te))-1; end
414
+ emit_numeric(); end
415
+ end
416
+ end
417
+ when 12 then
418
+ # line 91 "lib/hotcell/lexerr.rl"
419
+ begin
420
+ @te = @p+1
421
+ begin emit_comment(); begin
422
+ top -= 1
423
+ cs = stack[top]
424
+ _goto_level = _again
425
+ next
426
+ end
427
+ end
428
+ end
429
+ when 28 then
430
+ # line 92 "lib/hotcell/lexerr.rl"
431
+ begin
432
+ @te = @p
433
+ @p = @p - 1; begin emit_comment(); end
434
+ end
435
+ when 11 then
436
+ # line 92 "lib/hotcell/lexerr.rl"
437
+ begin
438
+ begin @p = (( @te))-1; end
439
+ begin emit_comment(); end
440
+ end
441
+ when 17 then
442
+ # line 96 "lib/hotcell/lexerr.rl"
443
+ begin
444
+ @te = @p+1
445
+ begin emit_tag(); begin
446
+ stack[top] = cs
447
+ top+= 1
448
+ cs = 16
449
+ _goto_level = _again
450
+ next
451
+ end
452
+ end
453
+ end
454
+ when 18 then
455
+ # line 97 "lib/hotcell/lexerr.rl"
456
+ begin
457
+ @te = @p+1
458
+ begin emit_comment(); begin
459
+ stack[top] = cs
460
+ top+= 1
461
+ cs = 26
462
+ _goto_level = _again
463
+ next
464
+ end
465
+ end
466
+ end
467
+ when 16 then
468
+ # line 96 "lib/hotcell/lexerr.rl"
469
+ begin
470
+ @te = @p
471
+ @p = @p - 1; begin emit_tag(); begin
472
+ stack[top] = cs
473
+ top+= 1
474
+ cs = 16
475
+ _goto_level = _again
476
+ next
477
+ end
478
+ end
479
+ end
480
+ when 15 then
481
+ # line 98 "lib/hotcell/lexerr.rl"
482
+ begin
483
+ @te = @p
484
+ @p = @p - 1; begin emit_template(); end
485
+ end
486
+ when 21 then
487
+ # line 1 "NONE"
488
+ begin
489
+ @te = @p+1
490
+ end
491
+ # line 59 "lib/hotcell/lexerr.rl"
492
+ begin
493
+ regexp_ambiguity { begin
494
+ cs = 16
495
+ _goto_level = _again
496
+ next
497
+ end
498
+ } end
499
+ when 20 then
500
+ # line 1 "NONE"
501
+ begin
502
+ @te = @p+1
503
+ end
504
+ # line 80 "lib/hotcell/lexerr.rl"
505
+ begin
506
+ act = 2; end
507
+ when 9 then
508
+ # line 1 "NONE"
509
+ begin
510
+ @te = @p+1
511
+ end
512
+ # line 81 "lib/hotcell/lexerr.rl"
513
+ begin
514
+ act = 3; end
515
+ # line 516 "lib/hotcell/lexerr.rb"
516
+ end
517
+ end
518
+ end
519
+ if _goto_level <= _again
520
+ case _puffer_lexer_to_state_actions[cs]
521
+ when 13 then
522
+ # line 1 "NONE"
523
+ begin
524
+ @ts = nil; end
525
+ # line 526 "lib/hotcell/lexerr.rb"
526
+ end
527
+
528
+ if cs == 0
529
+ _goto_level = _out
530
+ next
531
+ end
532
+ @p += 1
533
+ if @p != pe
534
+ _goto_level = _resume
535
+ next
536
+ end
537
+ end
538
+ if _goto_level <= _test_eof
539
+ if @p == eof
540
+ if _puffer_lexer_eof_trans[cs] > 0
541
+ _trans = _puffer_lexer_eof_trans[cs] - 1;
542
+ _goto_level = _eof_trans
543
+ next;
544
+ end
545
+ case _puffer_lexer_eof_actions[cs]
546
+ when 6 then
547
+ # line 51 "lib/hotcell/lexerr.rl"
548
+ begin
549
+ raise_unterminated_string(); end
550
+ when 1 then
551
+ # line 55 "lib/hotcell/lexerr.rl"
552
+ begin
553
+ raise_unterminated_string(); end
554
+ # line 555 "lib/hotcell/lexerr.rb"
555
+ end
556
+ end
557
+
558
+ end
559
+ if _goto_level <= _out
560
+ break
561
+ end
562
+ end
563
+ end
564
+
565
+ # line 131 "lib/hotcell/lexerr.rl"
566
+ #%
567
+
568
+ raise_unexpected_symbol unless @ts.nil?
569
+
570
+ @token_array
571
+ end
572
+ end
@@ -0,0 +1,137 @@
1
+ %%{
2
+ #%
3
+ machine puffer_lexer;
4
+
5
+ variable data @data;
6
+ variable te @te;
7
+ variable ts @ts;
8
+ variable p @p;
9
+
10
+ plus = '+';
11
+ minus = '-';
12
+ multiply = '*';
13
+ power = '**';
14
+ divide = '/';
15
+ modulo = '%';
16
+ arithmetic = plus | minus | multiply | power | divide | modulo;
17
+
18
+ and = '&&';
19
+ or = '||';
20
+ not = '!';
21
+ equal = '==';
22
+ inequal = '!=';
23
+ gt = '>';
24
+ gte = '>=';
25
+ lt = '<';
26
+ lte = '<=';
27
+ logic = and | or | not | equal | inequal | gt | gte | lt | lte;
28
+
29
+ assign = '=';
30
+ comma = ',';
31
+ period = '.';
32
+ colon = ':';
33
+ question = '?';
34
+ semicolon = ';';
35
+ newline = '\n';
36
+ flow = assign | comma | period | colon | question | semicolon | newline;
37
+
38
+ array_open = '[';
39
+ array_close = ']';
40
+ hash_open = '{';
41
+ hash_close = '}';
42
+ bracket_open = '(';
43
+ bracket_close = ')';
44
+ structure = array_open | array_close | hash_open | hash_close | bracket_open | bracket_close;
45
+
46
+
47
+ escaped_symbol = '\\' any;
48
+
49
+ squote = "'";
50
+ snon_quote = [^\\'];
51
+ sstring = squote (snon_quote | escaped_symbol)* squote @lerr{ raise_unterminated_string(); };
52
+
53
+ dquote = '"';
54
+ dnon_quote = [^\\"];
55
+ dstring = dquote (dnon_quote | escaped_symbol)* dquote @lerr{ raise_unterminated_string(); };
56
+
57
+ rquote = '/';
58
+ rnon_quote = [^\\/];
59
+ regexp = rquote @{ regexp_ambiguity { fgoto expression; } }
60
+ (rnon_quote | escaped_symbol)* rquote alpha* @lerr{ raise_unterminated_regexp(); };
61
+
62
+
63
+ numeric = '-'? digit* ('.' digit+)?;
64
+ identifer = (alpha | '_') (alnum | '_')* [?!]?;
65
+ operator = arithmetic | logic | flow | structure;
66
+ comment = '#' ([^\n}]+ | '}' [^}])*;
67
+ blank = [\t\v\f\r ];
68
+
69
+ tag_open = '{{' '!'?;
70
+ tag_close = '}}';
71
+ template = [^{]+ | '{';
72
+
73
+ template_comment_open = '{{#';
74
+ template_comment_close = '#}}';
75
+ template_comment_body = [^\#]+ | '#';
76
+
77
+
78
+ expression := |*
79
+ tag_close => { emit_tag(); fret; };
80
+ operator => { emit_operator(); };
81
+ numeric => { emit_numeric(); };
82
+ identifer => { emit_identifer(); };
83
+ sstring => { emit_sstring(); };
84
+ dstring => { emit_dstring(); };
85
+ regexp => { emit_regexp(); };
86
+ comment => { emit_comment(); };
87
+ blank;
88
+ *|;
89
+
90
+ template_comment := |*
91
+ template_comment_close => { emit_comment(); fret; };
92
+ template_comment_body => { emit_comment(); };
93
+ *|;
94
+
95
+ main := |*
96
+ tag_open => { emit_tag(); fcall expression; };
97
+ template_comment_open => { emit_comment(); fcall template_comment; };
98
+ template => { emit_template(); };
99
+ *|;
100
+ }%%
101
+ #%
102
+
103
+ Hotcell::Lexer.class_eval do
104
+ def current_position
105
+ @ts
106
+ end
107
+
108
+ def current_value
109
+ @data[@ts...@te].pack(Hotcell::Source::PACK_MODE).force_encoding(@source.encoding)
110
+ end
111
+
112
+ def current_error
113
+ value = @data[@ts..@p].pack(Hotcell::Source::PACK_MODE).force_encoding(@source.encoding)
114
+ [value, *@source.info(@ts).values_at(:line, :column)]
115
+ end
116
+
117
+ def tokenize
118
+ %% write data;
119
+ #%
120
+
121
+ @data = @source.data
122
+ @token_array = []
123
+
124
+ %% write init;
125
+ #%
126
+
127
+ eof = pe
128
+ stack = []
129
+
130
+ %% write exec;
131
+ #%
132
+
133
+ raise_unexpected_symbol unless @ts.nil?
134
+
135
+ @token_array
136
+ end
137
+ end
@@ -1,10 +1,6 @@
1
1
  module Hotcell
2
2
  class Assigner < Hotcell::Node
3
- def initialize *attrs
4
- super :ASSIGN, *attrs
5
- end
6
-
7
- def process context, name, value
3
+ def process context, value
8
4
  context[name] = value
9
5
  end
10
6
  end