matthewtodd-doily 0.1.0 → 0.1.1

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/Rakefile CHANGED
@@ -5,7 +5,7 @@ require 'cucumber/rake/task'
5
5
 
6
6
  spec = Gem::Specification.new do |s|
7
7
  s.name = 'doily'
8
- s.version = '0.1.0'
8
+ s.version = '0.1.1'
9
9
  s.summary = 'A Javascript (function) interpreter for Ruby.'
10
10
  s.files = FileList['Rakefile', '*.rdoc', 'features/**/*', 'lib/**/*', 'test/**/*'].to_a
11
11
  s.rdoc_options = %W[--main README.rdoc --title #{s.name}-#{s.version} --inline-source --line-numbers --all]
data/lib/doily/parser.rb CHANGED
@@ -13,9 +13,9 @@ module Doily
13
13
 
14
14
  class Parser < Racc::Parser
15
15
 
16
- module_eval <<'..end lib/doily/parser.y modeval..id32b1a5e4ef', 'lib/doily/parser.y', 107
16
+ module_eval <<'..end lib/doily/parser.y modeval..id2fd58564af', 'lib/doily/parser.y', 115
17
17
 
18
- def self.function(string)
18
+ def self.parse(string)
19
19
  new.parse(string)
20
20
  end
21
21
 
@@ -65,135 +65,146 @@ module_eval <<'..end lib/doily/parser.y modeval..id32b1a5e4ef', 'lib/doily/parse
65
65
  def next_token
66
66
  @tokens.shift
67
67
  end
68
- ..end lib/doily/parser.y modeval..id32b1a5e4ef
68
+ ..end lib/doily/parser.y modeval..id2fd58564af
69
69
 
70
70
  ##### racc 1.4.5 generates ###
71
71
 
72
72
  racc_reduce_table = [
73
73
  0, 0, :racc_error,
74
74
  1, 25, :_reduce_none,
75
- 5, 26, :_reduce_2,
76
- 0, 27, :_reduce_3,
77
- 1, 27, :_reduce_4,
78
- 3, 27, :_reduce_5,
79
- 2, 28, :_reduce_6,
80
- 3, 28, :_reduce_7,
81
- 1, 29, :_reduce_8,
82
- 2, 29, :_reduce_9,
83
- 1, 30, :_reduce_none,
84
- 1, 30, :_reduce_none,
85
- 2, 30, :_reduce_none,
86
- 5, 31, :_reduce_13,
87
- 7, 31, :_reduce_14,
88
- 9, 32, :_reduce_15,
89
- 1, 33, :_reduce_none,
90
- 1, 33, :_reduce_none,
91
- 1, 33, :_reduce_none,
92
- 1, 33, :_reduce_none,
93
- 1, 33, :_reduce_none,
75
+ 3, 25, :_reduce_2,
76
+ 5, 26, :_reduce_3,
77
+ 0, 28, :_reduce_4,
78
+ 1, 28, :_reduce_5,
79
+ 3, 28, :_reduce_6,
80
+ 2, 29, :_reduce_7,
81
+ 3, 29, :_reduce_8,
82
+ 1, 30, :_reduce_9,
83
+ 2, 30, :_reduce_10,
84
+ 1, 31, :_reduce_none,
85
+ 1, 31, :_reduce_none,
86
+ 2, 31, :_reduce_none,
87
+ 5, 32, :_reduce_14,
88
+ 7, 32, :_reduce_15,
89
+ 9, 33, :_reduce_16,
94
90
  1, 34, :_reduce_none,
95
- 1, 34, :_reduce_22,
96
- 1, 34, :_reduce_23,
97
91
  1, 34, :_reduce_none,
98
- 3, 34, :_reduce_25,
99
- 3, 34, :_reduce_26,
100
- 4, 34, :_reduce_27,
101
- 4, 34, :_reduce_28,
102
- 1, 39, :_reduce_29,
103
- 1, 40, :_reduce_30,
104
- 0, 41, :_reduce_31,
92
+ 1, 34, :_reduce_none,
93
+ 1, 34, :_reduce_none,
94
+ 1, 34, :_reduce_none,
95
+ 1, 35, :_reduce_none,
96
+ 1, 35, :_reduce_23,
97
+ 1, 35, :_reduce_24,
98
+ 1, 35, :_reduce_none,
99
+ 3, 35, :_reduce_26,
100
+ 3, 35, :_reduce_27,
101
+ 3, 35, :_reduce_28,
102
+ 4, 35, :_reduce_29,
103
+ 4, 35, :_reduce_30,
104
+ 1, 40, :_reduce_31,
105
105
  1, 41, :_reduce_32,
106
- 3, 41, :_reduce_33,
107
- 3, 43, :_reduce_34,
108
- 0, 42, :_reduce_35,
109
- 1, 42, :_reduce_36,
110
- 3, 42, :_reduce_37,
111
- 3, 36, :_reduce_38,
112
- 2, 35, :_reduce_39,
113
- 3, 37, :_reduce_40,
114
- 2, 38, :_reduce_41 ]
115
-
116
- racc_reduce_n = 42
117
-
118
- racc_shift_n = 78
106
+ 0, 27, :_reduce_33,
107
+ 1, 27, :_reduce_34,
108
+ 3, 27, :_reduce_35,
109
+ 3, 44, :_reduce_36,
110
+ 0, 42, :_reduce_37,
111
+ 1, 42, :_reduce_38,
112
+ 3, 42, :_reduce_39,
113
+ 0, 43, :_reduce_40,
114
+ 1, 43, :_reduce_41,
115
+ 3, 43, :_reduce_42,
116
+ 3, 37, :_reduce_43,
117
+ 2, 36, :_reduce_44,
118
+ 3, 38, :_reduce_45,
119
+ 2, 39, :_reduce_46 ]
120
+
121
+ racc_reduce_n = 47
122
+
123
+ racc_shift_n = 87
119
124
 
120
125
  racc_action_table = [
121
- 18, 76, 22, 24, 27, 29, 31, 33, 1, 55,
122
- 35, 58, 19, 23, 18, 65, 22, 24, 27, 29,
123
- 31, 33, 59, 60, 35, 62, 19, 24, 27, 29,
124
- 31, 33, 48, 35, 47, 46, 19, 24, 27, 29,
125
- 31, 33, 45, 63, 31, 41, 19, 24, 27, 29,
126
- 31, 33, 7, 31, 11, 10, 19, 24, 27, 29,
127
- 31, 33, 11, 9, 8, 72, 19, 24, 27, 29,
128
- 31, 33, 7, 11, 5, 4, 19, 24, 27, 29,
129
- 31, 33, 37, 38, 11, nil, 19, nil, nil, 39,
130
- 40, 27, 29, 31, 33, 27, 29, 31, 33, 19,
131
- 38, nil, nil, 19, nil, nil, 39, 40, 64, 27,
132
- 29, 31, 33, 27, 29, 31, 33, 19, 38, nil,
133
- 38, 19, 38, nil, 39, 40, 39, 40, 39, 40,
134
- 68, 73, 36, nil, nil, 35, 35, 35 ]
126
+ 54, 2, 55, 43, 21, 23, 8, 25, 78, 18,
127
+ 62, 1, 63, 59, 54, 20, 55, 43, 21, 23,
128
+ 8, 25, 67, 18, 53, 64, 50, 59, 85, 20,
129
+ 43, 21, 23, 8, 25, 59, 18, 43, 21, 23,
130
+ 8, 25, 20, 18, 43, 21, 23, 8, 25, 20,
131
+ 18, 43, 21, 23, 8, 25, 20, 18, 43, 21,
132
+ 23, 8, 25, 20, 18, 43, 21, 23, 8, 25,
133
+ 20, 18, 77, 21, 23, 8, 25, 20, 18, 59,
134
+ 21, 23, 8, 25, 20, 18, 48, 21, 23, 8,
135
+ 25, 20, 18, 37, 21, 23, 8, 25, 20, 18,
136
+ 68, 21, 23, 8, 25, 20, 18, 69, 21, 23,
137
+ 8, 25, 20, 18, 61, 70, 60, 29, 15, 20,
138
+ 29, 30, 59, 31, 30, 29, 31, 34, 29, 30,
139
+ 8, 31, 30, 65, 31, 29, 29, 49, 82, 30,
140
+ 30, 31, 31, 59, 27, 26, 8, 16, 15, 13,
141
+ 12, 34, 11, 81, 10, 34, 9, 8, 34 ]
135
142
 
136
143
  racc_action_check = [
137
- 11, 75, 11, 11, 11, 11, 11, 11, 0, 39,
138
- 75, 42, 11, 11, 30, 57, 30, 30, 30, 30,
139
- 30, 30, 43, 44, 57, 53, 30, 73, 73, 73,
140
- 73, 73, 28, 53, 25, 24, 73, 38, 38, 38,
141
- 38, 38, 22, 54, 19, 18, 38, 68, 68, 68,
142
- 68, 68, 10, 60, 9, 7, 68, 62, 62, 62,
143
- 62, 62, 65, 6, 5, 70, 62, 45, 45, 45,
144
- 45, 45, 4, 72, 2, 1, 45, 41, 41, 41,
145
- 41, 41, 15, 15, 76, nil, 41, nil, nil, 15,
146
- 15, 40, 40, 40, 40, 58, 58, 58, 58, 40,
147
- 56, nil, nil, 58, nil, nil, 56, 56, 56, 37,
148
- 37, 37, 37, 35, 35, 35, 35, 37, 50, nil,
149
- 66, 35, 52, nil, 50, 50, 66, 66, 52, 52,
150
- 61, 71, 14, nil, nil, 61, 71, 14 ]
144
+ 57, 0, 57, 57, 57, 57, 57, 57, 76, 57,
145
+ 43, 0, 45, 76, 34, 57, 34, 34, 34, 34,
146
+ 34, 34, 52, 34, 34, 46, 33, 52, 84, 34,
147
+ 60, 60, 60, 60, 60, 84, 60, 78, 78, 78,
148
+ 78, 78, 60, 78, 68, 68, 68, 68, 68, 78,
149
+ 68, 69, 69, 69, 69, 69, 68, 69, 29, 29,
150
+ 29, 29, 29, 69, 29, 82, 82, 82, 82, 82,
151
+ 29, 82, 75, 59, 59, 59, 59, 82, 59, 75,
152
+ 30, 30, 30, 30, 59, 30, 31, 13, 13, 13,
153
+ 13, 30, 13, 28, 49, 49, 49, 49, 13, 49,
154
+ 54, 61, 61, 61, 61, 49, 61, 55, 20, 20,
155
+ 20, 20, 61, 20, 39, 56, 38, 39, 27, 20,
156
+ 74, 39, 38, 39, 74, 72, 74, 26, 47, 72,
157
+ 18, 72, 47, 47, 47, 32, 19, 32, 80, 32,
158
+ 19, 32, 19, 80, 15, 14, 11, 10, 9, 7,
159
+ 6, 77, 5, 79, 3, 81, 2, 1, 85 ]
151
160
 
152
161
  racc_action_pointer = [
153
- 6, 63, 74, nil, 64, 64, 50, 41, nil, 39,
154
- 44, -3, nil, nil, 115, 71, nil, nil, 33, 35,
155
- nil, nil, 30, nil, 27, 11, nil, nil, 16, nil,
156
- 11, nil, nil, nil, nil, 106, nil, 102, 31, 1,
157
- 84, 71, -10, 6, 9, 61, nil, nil, nil, nil,
158
- 106, nil, 110, 11, 30, nil, 88, 2, 88, nil,
159
- 44, 113, 51, nil, nil, 47, 108, nil, 41, nil,
160
- 61, 114, 58, 21, nil, -12, 69, nil ]
162
+ -1, 148, 142, 154, nil, 136, 137, 128, nil, 140,
163
+ 147, 137, nil, 80, 130, 128, nil, nil, 121, 122,
164
+ 101, nil, nil, nil, nil, nil, 115, 110, 80, 52,
165
+ 73, 78, 121, 7, 11, nil, nil, nil, 100, 103,
166
+ nil, nil, nil, 2, nil, -11, 10, 114, nil, 87,
167
+ nil, nil, 5, nil, 86, 93, 102, -3, nil, 66,
168
+ 24, 94, nil, nil, nil, nil, nil, nil, 38, 45,
169
+ nil, nil, 111, nil, 106, 57, -9, 139, 31, 149,
170
+ 121, 143, 59, nil, 13, 146, nil ]
161
171
 
162
172
  racc_action_default = [
163
- -42, -42, -42, -1, -3, -42, -42, -4, 78, -42,
164
- -3, -42, -2, -5, -42, -16, -17, -18, -42, -31,
165
- -19, -20, -42, -6, -42, -21, -24, -23, -42, -29,
166
- -8, -30, -10, -22, -11, -42, -12, -42, -35, -42,
167
- -42, -42, -42, -42, -32, -42, -39, -41, -7, -9,
168
- -38, -21, -40, -36, -42, -26, -42, -42, -42, -25,
169
- -31, -42, -35, -28, -27, -42, -34, -33, -42, -37,
170
- -13, -42, -42, -42, -14, -42, -42, -15 ]
173
+ -47, -33, -47, -47, -1, -34, -47, -47, -32, -4,
174
+ -47, -33, -2, -47, -47, -5, 87, -35, -33, -36,
175
+ -37, -24, -22, -31, -25, -23, -47, -4, -47, -40,
176
+ -47, -47, -38, -47, -47, -3, -6, -26, -41, -17,
177
+ -18, -19, -20, -47, -21, -22, -47, -47, -28, -37,
178
+ -27, -12, -47, -7, -47, -47, -47, -9, -11, -47,
179
+ -40, -47, -44, -46, -30, -29, -39, -13, -47, -47,
180
+ -8, -10, -43, -42, -45, -47, -47, -47, -47, -14,
181
+ -47, -47, -47, -15, -47, -47, -16 ]
171
182
 
172
183
  racc_goto_table = [
173
- 12, 43, 42, 53, 54, 28, 57, 51, 6, 51,
174
- 61, 50, 51, 52, 13, 3, 56, 2, nil, nil,
175
- nil, nil, nil, nil, 49, nil, nil, 53, 69, nil,
176
- 51, nil, nil, 71, 66, nil, nil, nil, 75, nil,
177
- nil, nil, 67, 42, nil, nil, nil, nil, nil, nil,
178
- nil, nil, nil, nil, nil, nil, 70, nil, nil, nil,
179
- nil, nil, nil, 74, nil, nil, nil, 77 ]
184
+ 35, 19, 22, 46, 56, 14, 33, 6, 32, 22,
185
+ 52, 7, 4, 3, nil, nil, nil, 17, 47, 22,
186
+ nil, 7, nil, 36, 28, nil, nil, 71, 7, nil,
187
+ nil, nil, nil, 52, 73, 66, nil, 32, 22, nil,
188
+ nil, nil, nil, nil, 75, 76, nil, 72, 22, 74,
189
+ 22, 79, nil, nil, 80, 83, nil, nil, 84, 86 ]
180
190
 
181
191
  racc_goto_check = [
182
- 4, 17, 16, 9, 18, 5, 9, 15, 3, 15,
183
- 9, 10, 15, 10, 3, 2, 10, 1, nil, nil,
184
- nil, nil, nil, nil, 5, nil, nil, 9, 18, nil,
185
- 15, nil, nil, 9, 10, nil, nil, nil, 9, nil,
186
- nil, nil, 17, 16, nil, nil, nil, nil, nil, nil,
187
- nil, nil, nil, nil, nil, nil, 4, nil, nil, nil,
188
- nil, nil, nil, 4, nil, nil, nil, 4 ]
192
+ 5, 11, 16, 19, 6, 4, 18, 3, 11, 16,
193
+ 10, 17, 2, 1, nil, nil, nil, 3, 11, 16,
194
+ nil, 17, nil, 4, 3, nil, nil, 6, 17, nil,
195
+ nil, nil, nil, 10, 19, 18, nil, 11, 16, nil,
196
+ nil, nil, nil, nil, 10, 10, nil, 11, 16, 11,
197
+ 16, 5, nil, nil, 10, 5, nil, nil, 10, 5 ]
189
198
 
190
199
  racc_goto_pointer = [
191
- nil, 17, 15, 4, -9, -6, nil, nil, nil, -35,
192
- -24, nil, nil, nil, nil, -28, -17, -18, -34, nil ]
200
+ nil, 13, 12, 6, -4, -26, -30, nil, nil, nil,
201
+ -24, -12, nil, nil, nil, nil, -11, 10, -14, -26,
202
+ nil ]
193
203
 
194
204
  racc_goto_default = [
195
- nil, nil, nil, nil, nil, nil, 30, 32, 34, 14,
196
- 15, 16, 17, 20, 21, 25, 26, nil, nil, 44 ]
205
+ nil, nil, nil, nil, nil, nil, nil, 57, 58, 51,
206
+ 38, 39, 40, 41, 42, 44, 45, 24, nil, nil,
207
+ 5 ]
197
208
 
198
209
  racc_token_table = {
199
210
  false => 0,
@@ -208,15 +219,15 @@ racc_token_table = {
208
219
  :STRING_LITERAL => 9,
209
220
  :INTEGER_LITERAL => 10,
210
221
  :BINARY_OPERATOR => 11,
211
- "(" => 12,
212
- ")" => 13,
213
- "," => 14,
214
- "{" => 15,
215
- "}" => 16,
222
+ "{" => 12,
223
+ "}" => 13,
224
+ "(" => 14,
225
+ ")" => 15,
226
+ "," => 16,
216
227
  ";" => 17,
217
- "." => 18,
218
- "[" => 19,
219
- "]" => 20,
228
+ "[" => 18,
229
+ "]" => 19,
230
+ "." => 20,
220
231
  ":" => 21,
221
232
  "=" => 22,
222
233
  "++" => 23 }
@@ -254,21 +265,22 @@ Racc_token_to_s_table = [
254
265
  'STRING_LITERAL',
255
266
  'INTEGER_LITERAL',
256
267
  'BINARY_OPERATOR',
268
+ '"{"',
269
+ '"}"',
257
270
  '"("',
258
271
  '")"',
259
272
  '","',
260
- '"{"',
261
- '"}"',
262
273
  '";"',
263
- '"."',
264
274
  '"["',
265
275
  '"]"',
276
+ '"."',
266
277
  '":"',
267
278
  '"="',
268
279
  '"++"',
269
280
  '$start',
270
281
  'target',
271
282
  'function_definition',
283
+ 'key_value_list',
272
284
  'argument_name_list',
273
285
  'block',
274
286
  'statement_list',
@@ -283,7 +295,7 @@ Racc_token_to_s_table = [
283
295
  'increment',
284
296
  'variable',
285
297
  'string_literal',
286
- 'key_value_list',
298
+ 'reference_list',
287
299
  'argument_list',
288
300
  'key_value']
289
301
 
@@ -295,91 +307,96 @@ Racc_debug_parser = false
295
307
 
296
308
  # reduce 1 omitted
297
309
 
298
- module_eval <<'.,.,', 'lib/doily/parser.y', 10
310
+ module_eval <<'.,.,', 'lib/doily/parser.y', 7
299
311
  def _reduce_2( val, _values, result )
300
- result = Function.new(val[2], val[4])
312
+ result = Object.new(val[1]).to_ruby(nil)
301
313
  result
302
314
  end
303
315
  .,.,
304
316
 
305
- module_eval <<'.,.,', 'lib/doily/parser.y', 14
317
+ module_eval <<'.,.,', 'lib/doily/parser.y', 11
306
318
  def _reduce_3( val, _values, result )
307
- result = []
319
+ result = Function.new(val[2], val[4])
308
320
  result
309
321
  end
310
322
  .,.,
311
323
 
312
324
  module_eval <<'.,.,', 'lib/doily/parser.y', 15
313
325
  def _reduce_4( val, _values, result )
314
- result = [val[0]]
326
+ result = []
315
327
  result
316
328
  end
317
329
  .,.,
318
330
 
319
331
  module_eval <<'.,.,', 'lib/doily/parser.y', 16
320
332
  def _reduce_5( val, _values, result )
321
- result = [val[0]] + val[2]
333
+ result = [val[0]]
322
334
  result
323
335
  end
324
336
  .,.,
325
337
 
326
- module_eval <<'.,.,', 'lib/doily/parser.y', 20
338
+ module_eval <<'.,.,', 'lib/doily/parser.y', 17
327
339
  def _reduce_6( val, _values, result )
328
- result = Block.new([])
340
+ result = [val[0]] + val[2]
329
341
  result
330
342
  end
331
343
  .,.,
332
344
 
333
345
  module_eval <<'.,.,', 'lib/doily/parser.y', 21
334
346
  def _reduce_7( val, _values, result )
335
- result = Block.new(val[1])
347
+ result = Block.new([])
336
348
  result
337
349
  end
338
350
  .,.,
339
351
 
340
- module_eval <<'.,.,', 'lib/doily/parser.y', 25
352
+ module_eval <<'.,.,', 'lib/doily/parser.y', 22
341
353
  def _reduce_8( val, _values, result )
342
- result = [val[0]]
354
+ result = Block.new(val[1])
343
355
  result
344
356
  end
345
357
  .,.,
346
358
 
347
359
  module_eval <<'.,.,', 'lib/doily/parser.y', 26
348
360
  def _reduce_9( val, _values, result )
349
- result = [val[0]] + val[1]
361
+ result = [val[0]]
350
362
  result
351
363
  end
352
364
  .,.,
353
365
 
354
- # reduce 10 omitted
366
+ module_eval <<'.,.,', 'lib/doily/parser.y', 27
367
+ def _reduce_10( val, _values, result )
368
+ result = [val[0]] + val[1]
369
+ result
370
+ end
371
+ .,.,
355
372
 
356
373
  # reduce 11 omitted
357
374
 
358
375
  # reduce 12 omitted
359
376
 
360
- module_eval <<'.,.,', 'lib/doily/parser.y', 36
361
- def _reduce_13( val, _values, result )
377
+ # reduce 13 omitted
378
+
379
+ module_eval <<'.,.,', 'lib/doily/parser.y', 37
380
+ def _reduce_14( val, _values, result )
362
381
  result = Conditional.new(val[2], val[4])
363
382
  result
364
383
  end
365
384
  .,.,
366
385
 
367
- module_eval <<'.,.,', 'lib/doily/parser.y', 37
368
- def _reduce_14( val, _values, result )
386
+ module_eval <<'.,.,', 'lib/doily/parser.y', 38
387
+ def _reduce_15( val, _values, result )
369
388
  result = Conditional.new(val[2], val[4], val[6])
370
389
  result
371
390
  end
372
391
  .,.,
373
392
 
374
- module_eval <<'.,.,', 'lib/doily/parser.y', 41
375
- def _reduce_15( val, _values, result )
393
+ module_eval <<'.,.,', 'lib/doily/parser.y', 42
394
+ def _reduce_16( val, _values, result )
376
395
  result = Loop.new(val[2], val[4], val[6], val[8])
377
396
  result
378
397
  end
379
398
  .,.,
380
399
 
381
- # reduce 16 omitted
382
-
383
400
  # reduce 17 omitted
384
401
 
385
402
  # reduce 18 omitted
@@ -390,136 +407,166 @@ module_eval <<'.,.,', 'lib/doily/parser.y', 41
390
407
 
391
408
  # reduce 21 omitted
392
409
 
393
- module_eval <<'.,.,', 'lib/doily/parser.y', 54
394
- def _reduce_22( val, _values, result )
395
- result = Literal.new(val[0].to_i)
396
- result
397
- end
398
- .,.,
410
+ # reduce 22 omitted
399
411
 
400
412
  module_eval <<'.,.,', 'lib/doily/parser.y', 55
401
413
  def _reduce_23( val, _values, result )
402
- result = Literal.new(eval(val[0]))
414
+ result = Literal.new(val[0].to_i)
403
415
  result
404
416
  end
405
417
  .,.,
406
418
 
407
- # reduce 24 omitted
408
-
409
- module_eval <<'.,.,', 'lib/doily/parser.y', 57
410
- def _reduce_25( val, _values, result )
411
- result = Object.new(val[1])
419
+ module_eval <<'.,.,', 'lib/doily/parser.y', 56
420
+ def _reduce_24( val, _values, result )
421
+ result = Literal.new(eval(val[0]))
412
422
  result
413
423
  end
414
424
  .,.,
415
425
 
426
+ # reduce 25 omitted
427
+
416
428
  module_eval <<'.,.,', 'lib/doily/parser.y', 58
417
429
  def _reduce_26( val, _values, result )
418
- result = Access.new(val[0], Literal.new(val[2]))
430
+ result = Object.new(val[1])
419
431
  result
420
432
  end
421
433
  .,.,
422
434
 
423
435
  module_eval <<'.,.,', 'lib/doily/parser.y', 59
424
436
  def _reduce_27( val, _values, result )
425
- result = Access.new(val[0], val[2])
437
+ result = Array.new(val[1])
426
438
  result
427
439
  end
428
440
  .,.,
429
441
 
430
442
  module_eval <<'.,.,', 'lib/doily/parser.y', 60
431
443
  def _reduce_28( val, _values, result )
432
- result = Call.new(val[0], val[2])
444
+ result = Access.new(val[0], Literal.new(val[2]))
433
445
  result
434
446
  end
435
447
  .,.,
436
448
 
437
- module_eval <<'.,.,', 'lib/doily/parser.y', 64
449
+ module_eval <<'.,.,', 'lib/doily/parser.y', 61
438
450
  def _reduce_29( val, _values, result )
439
- result = Reference.new(val[0])
451
+ result = Access.new(val[0], val[2])
440
452
  result
441
453
  end
442
454
  .,.,
443
455
 
444
- module_eval <<'.,.,', 'lib/doily/parser.y', 68
456
+ module_eval <<'.,.,', 'lib/doily/parser.y', 62
445
457
  def _reduce_30( val, _values, result )
446
- result = Literal.new(eval(val[0]))
458
+ result = Call.new(val[0], val[2])
447
459
  result
448
460
  end
449
461
  .,.,
450
462
 
451
- module_eval <<'.,.,', 'lib/doily/parser.y', 72
463
+ module_eval <<'.,.,', 'lib/doily/parser.y', 66
452
464
  def _reduce_31( val, _values, result )
453
- result = {}
465
+ result = Reference.new(val[0])
454
466
  result
455
467
  end
456
468
  .,.,
457
469
 
458
- module_eval <<'.,.,', 'lib/doily/parser.y', 73
470
+ module_eval <<'.,.,', 'lib/doily/parser.y', 70
459
471
  def _reduce_32( val, _values, result )
460
- result = val[0]
472
+ result = Literal.new(eval(val[0]))
461
473
  result
462
474
  end
463
475
  .,.,
464
476
 
465
477
  module_eval <<'.,.,', 'lib/doily/parser.y', 74
466
478
  def _reduce_33( val, _values, result )
467
- result = val[0].merge(val[2])
479
+ result = {}
468
480
  result
469
481
  end
470
482
  .,.,
471
483
 
472
- module_eval <<'.,.,', 'lib/doily/parser.y', 78
484
+ module_eval <<'.,.,', 'lib/doily/parser.y', 75
473
485
  def _reduce_34( val, _values, result )
474
- result = { val[0] => val[2] }
486
+ result = val[0]
475
487
  result
476
488
  end
477
489
  .,.,
478
490
 
479
- module_eval <<'.,.,', 'lib/doily/parser.y', 82
491
+ module_eval <<'.,.,', 'lib/doily/parser.y', 76
480
492
  def _reduce_35( val, _values, result )
481
- result = []
493
+ result = val[0].merge(val[2])
482
494
  result
483
495
  end
484
496
  .,.,
485
497
 
486
- module_eval <<'.,.,', 'lib/doily/parser.y', 83
498
+ module_eval <<'.,.,', 'lib/doily/parser.y', 80
487
499
  def _reduce_36( val, _values, result )
488
- result = [val[0]]
500
+ result = { val[0] => val[2] }
489
501
  result
490
502
  end
491
503
  .,.,
492
504
 
493
505
  module_eval <<'.,.,', 'lib/doily/parser.y', 84
494
506
  def _reduce_37( val, _values, result )
495
- result = [val[0]] + val[2]
507
+ result = []
496
508
  result
497
509
  end
498
510
  .,.,
499
511
 
500
- module_eval <<'.,.,', 'lib/doily/parser.y', 88
512
+ module_eval <<'.,.,', 'lib/doily/parser.y', 85
501
513
  def _reduce_38( val, _values, result )
502
- result = Assignment.new(val[0], val[2])
514
+ result = [val[0]]
503
515
  result
504
516
  end
505
517
  .,.,
506
518
 
507
- module_eval <<'.,.,', 'lib/doily/parser.y', 92
519
+ module_eval <<'.,.,', 'lib/doily/parser.y', 86
508
520
  def _reduce_39( val, _values, result )
509
- result = Declaration.new(val[1])
521
+ result = [val[0]] + val[2]
510
522
  result
511
523
  end
512
524
  .,.,
513
525
 
514
- module_eval <<'.,.,', 'lib/doily/parser.y', 96
526
+ module_eval <<'.,.,', 'lib/doily/parser.y', 90
515
527
  def _reduce_40( val, _values, result )
516
- result = Call.new(Access.new(val[0], Literal.new(val[1])), [val[2]])
528
+ result = []
517
529
  result
518
530
  end
519
531
  .,.,
520
532
 
521
- module_eval <<'.,.,', 'lib/doily/parser.y', 100
533
+ module_eval <<'.,.,', 'lib/doily/parser.y', 91
522
534
  def _reduce_41( val, _values, result )
535
+ result = [val[0]]
536
+ result
537
+ end
538
+ .,.,
539
+
540
+ module_eval <<'.,.,', 'lib/doily/parser.y', 92
541
+ def _reduce_42( val, _values, result )
542
+ result = [val[0]] + val[2]
543
+ result
544
+ end
545
+ .,.,
546
+
547
+ module_eval <<'.,.,', 'lib/doily/parser.y', 96
548
+ def _reduce_43( val, _values, result )
549
+ result = Assignment.new(val[0], val[2])
550
+ result
551
+ end
552
+ .,.,
553
+
554
+ module_eval <<'.,.,', 'lib/doily/parser.y', 100
555
+ def _reduce_44( val, _values, result )
556
+ result = Declaration.new(val[1])
557
+ result
558
+ end
559
+ .,.,
560
+
561
+ module_eval <<'.,.,', 'lib/doily/parser.y', 104
562
+ def _reduce_45( val, _values, result )
563
+ result = Call.new(Access.new(val[0], Literal.new(val[1])), [val[2]])
564
+ result
565
+ end
566
+ .,.,
567
+
568
+ module_eval <<'.,.,', 'lib/doily/parser.y', 108
569
+ def _reduce_46( val, _values, result )
523
570
  result = Assignment.new(val[0], Call.new(Access.new(val[0], Literal.new('+')), [Literal.new(1)]))
524
571
  result
525
572
  end
data/lib/doily/parser.y CHANGED
@@ -5,6 +5,7 @@ class Doily::Parser
5
5
  rule
6
6
  target
7
7
  : function_definition
8
+ | '{' key_value_list '}' { result = Object.new(val[1]).to_ruby(nil) }
8
9
  ;
9
10
 
10
11
  function_definition
@@ -56,6 +57,7 @@ rule
56
57
  | BOOLEAN_LITERAL { result = Literal.new(eval(val[0])) }
57
58
  | string_literal
58
59
  | '{' key_value_list '}' { result = Object.new(val[1]) }
60
+ | '[' reference_list ']' { result = Array.new(val[1]) }
59
61
  | reference '.' IDENTIFIER { result = Access.new(val[0], Literal.new(val[2])) }
60
62
  | reference '[' reference ']' { result = Access.new(val[0], val[2]) }
61
63
  | reference '(' argument_list ')' { result = Call.new(val[0], val[2]) }
@@ -79,6 +81,12 @@ rule
79
81
  : string_literal ':' reference { result = { val[0] => val[2] }}
80
82
  ;
81
83
 
84
+ reference_list
85
+ : { result = []}
86
+ | reference { result = [val[0]]}
87
+ | reference ',' reference_list { result = [val[0]] + val[2]}
88
+ ;
89
+
82
90
  argument_list
83
91
  : { result = [] }
84
92
  | expression { result = [val[0]] }
@@ -105,7 +113,7 @@ rule
105
113
  require 'strscan'
106
114
  ---- inner ----
107
115
 
108
- def self.function(string)
116
+ def self.parse(string)
109
117
  new.parse(string)
110
118
  end
111
119
 
@@ -0,0 +1,11 @@
1
+ module Doily
2
+ class Array
3
+ def initialize(members)
4
+ @members = members
5
+ end
6
+
7
+ def to_ruby(binding)
8
+ @members.map { |member| member.to_ruby(binding) }
9
+ end
10
+ end
11
+ end
data/lib/doily.rb CHANGED
@@ -3,5 +3,5 @@ require 'doily/parser'
3
3
  require 'doily/types'
4
4
 
5
5
  def Doily(string)
6
- Doily::Parser.function(string)
6
+ Doily::Parser.parse(string)
7
7
  end
@@ -1,6 +1,6 @@
1
1
  require File.join(File.dirname(__FILE__), 'test_helper')
2
2
 
3
- class DoilyTest < Test::Unit::TestCase
3
+ class DoilyFunctionTest < Test::Unit::TestCase
4
4
  should 'handle nothing' do
5
5
  Doily('function() {}').call.should == nil
6
6
  end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ class DoilyHashTest < Test::Unit::TestCase
4
+ should 'handle a bare empty hash' do
5
+ Doily('{}').should == {}
6
+ end
7
+
8
+ should 'handle a simple hash' do
9
+ Doily('{"a":true, "b":42}').should == { 'a' => true, 'b' => 42 }
10
+ end
11
+
12
+ should 'handle a hash with an array' do
13
+ Doily('{"a":true, "b":[1, 2, 3]}').should == { 'a' => true, 'b' => [1, 2, 3] }
14
+ end
15
+
16
+ should 'handle a nested hash' do
17
+ Doily('{"a":true, "b":{"a":true, "b":[1, 2, 3]}}').should == { 'a' => true, 'b' => { 'a' => true, 'b' => [1, 2, 3] }}
18
+ end
19
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: matthewtodd-doily
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matthew Todd
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-06-27 00:00:00 -07:00
12
+ date: 2009-06-29 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,6 +67,7 @@ files:
67
67
  - lib/doily/parser.y
68
68
  - lib/doily/types
69
69
  - lib/doily/types/access.rb
70
+ - lib/doily/types/array.rb
70
71
  - lib/doily/types/assignment.rb
71
72
  - lib/doily/types/binding.rb
72
73
  - lib/doily/types/block.rb
@@ -80,7 +81,8 @@ files:
80
81
  - lib/doily/types/reference.rb
81
82
  - lib/doily/types.rb
82
83
  - lib/doily.rb
83
- - test/doily_test.rb
84
+ - test/doily_function_test.rb
85
+ - test/doily_hash_test.rb
84
86
  - test/test_helper.rb
85
87
  has_rdoc: false
86
88
  homepage:
@@ -89,7 +91,7 @@ rdoc_options:
89
91
  - --main
90
92
  - README.rdoc
91
93
  - --title
92
- - doily-0.1.0
94
+ - doily-0.1.1
93
95
  - --inline-source
94
96
  - --line-numbers
95
97
  - --all