edn_turbo 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,6 +7,7 @@
7
7
  #include <rice/Hash.hpp>
8
8
  #include <rice/Array.hpp>
9
9
  #include <rice/to_from_ruby.hpp>
10
+ #include <rice/Exception.hpp>
10
11
 
11
12
  #include "edn_parser.h"
12
13
 
@@ -19,15 +20,15 @@
19
20
  //
20
21
 
21
22
 
22
- #line 61 "edn_parser.rl"
23
+ #line 62 "edn_parser.rl"
23
24
 
24
25
 
25
26
  // ============================================================
26
- // machine for parsing various types
27
+ // machine for parsing various EDN token types
27
28
  //
28
29
 
29
30
 
30
- #line 31 "edn_parser.cc"
31
+ #line 32 "edn_parser.cc"
31
32
  static const int EDN_value_start = 1;
32
33
  static const int EDN_value_first_final = 2;
33
34
  static const int EDN_value_error = 0;
@@ -35,13 +36,12 @@ static const int EDN_value_error = 0;
35
36
  static const int EDN_value_en_main = 1;
36
37
 
37
38
 
38
- #line 160 "edn_parser.rl"
39
+ #line 170 "edn_parser.rl"
39
40
 
40
41
 
41
42
 
42
43
  const char *edn::Parser::parse_value(const char *p, const char *pe, Rice::Object& o)
43
44
  {
44
- //std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
45
45
  int cs;
46
46
 
47
47
 
@@ -50,7 +50,7 @@ const char *edn::Parser::parse_value(const char *p, const char *pe, Rice::Object
50
50
  cs = EDN_value_start;
51
51
  }
52
52
 
53
- #line 169 "edn_parser.rl"
53
+ #line 178 "edn_parser.rl"
54
54
 
55
55
  #line 56 "edn_parser.cc"
56
56
  {
@@ -94,36 +94,41 @@ st0:
94
94
  cs = 0;
95
95
  goto _out;
96
96
  tr0:
97
- #line 93 "edn_parser.rl"
97
+ #line 106 "edn_parser.rl"
98
98
  {
99
+ // stand-alone operators *, +, -, etc.
99
100
  const char *np = parse_operator(p, pe, o);
100
101
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
101
102
  }
102
103
  goto st2;
103
104
  tr2:
104
- #line 83 "edn_parser.rl"
105
+ #line 74 "edn_parser.rl"
105
106
  {
107
+ // string types within double-quotes
106
108
  const char *np = parse_string(p, pe, o);
107
109
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
108
110
  }
109
111
  goto st2;
110
112
  tr3:
111
- #line 73 "edn_parser.rl"
113
+ #line 151 "edn_parser.rl"
112
114
  {
115
+ // handles tokens w/ leading # ("#_", "#{", and tagged elems)
113
116
  const char *np = parse_dispatch(p + 1, pe, o);
114
117
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
115
118
  }
116
119
  goto st2;
117
120
  tr4:
118
- #line 136 "edn_parser.rl"
121
+ #line 139 "edn_parser.rl"
119
122
  {
123
+ // (
120
124
  const char *np = parse_list(p, pe, o);
121
125
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
122
126
  }
123
127
  goto st2;
124
128
  tr5:
125
- #line 112 "edn_parser.rl"
129
+ #line 86 "edn_parser.rl"
126
130
  {
131
+ // tokens w/ leading digits: non-negative integers & decimals.
127
132
  // try to parse a decimal first
128
133
  const char *np = parse_decimal(p, pe, o);
129
134
  if (np == NULL) {
@@ -143,15 +148,17 @@ tr5:
143
148
  }
144
149
  goto st2;
145
150
  tr6:
146
- #line 88 "edn_parser.rl"
151
+ #line 80 "edn_parser.rl"
147
152
  {
153
+ // tokens with a leading ':'
148
154
  const char *np = parse_keyword(p, pe, o);
149
155
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
150
156
  }
151
157
  goto st2;
152
158
  tr7:
153
- #line 98 "edn_parser.rl"
159
+ #line 118 "edn_parser.rl"
154
160
  {
161
+ // user identifiers and reserved keywords (true, false, nil)
155
162
  std::string sym;
156
163
  const char *np = parse_symbol(p, pe, sym);
157
164
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {
@@ -166,22 +173,25 @@ tr7:
166
173
  }
167
174
  goto st2;
168
175
  tr8:
169
- #line 131 "edn_parser.rl"
176
+ #line 133 "edn_parser.rl"
170
177
  {
178
+ // [
171
179
  const char *np = parse_vector(p, pe, o);
172
180
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
173
181
  }
174
182
  goto st2;
175
183
  tr9:
176
- #line 78 "edn_parser.rl"
184
+ #line 112 "edn_parser.rl"
177
185
  {
186
+ // tokens w/ leading \ (escaped characters \newline, \c, etc.)
178
187
  const char *np = parse_esc_char(p, pe, o);
179
188
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
180
189
  }
181
190
  goto st2;
182
191
  tr10:
183
- #line 141 "edn_parser.rl"
192
+ #line 145 "edn_parser.rl"
184
193
  {
194
+ // {
185
195
  const char *np = parse_map(p, pe, o);
186
196
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
187
197
  }
@@ -190,9 +200,9 @@ st2:
190
200
  if ( ++p == pe )
191
201
  goto _test_eof2;
192
202
  case 2:
193
- #line 146 "edn_parser.rl"
203
+ #line 61 "edn_parser.rl"
194
204
  { p--; {p++; cs = 2; goto _out;} }
195
- #line 196 "edn_parser.cc"
205
+ #line 206 "edn_parser.cc"
196
206
  goto st0;
197
207
  }
198
208
  _test_eof2: cs = 2; goto _test_eof;
@@ -201,7 +211,7 @@ case 2:
201
211
  _out: {}
202
212
  }
203
213
 
204
- #line 170 "edn_parser.rl"
214
+ #line 179 "edn_parser.rl"
205
215
 
206
216
  if (cs >= EDN_value_first_final) {
207
217
  return p;
@@ -217,420 +227,290 @@ case 2:
217
227
 
218
228
 
219
229
  // ============================================================
220
- // operator parsing
230
+ // string parsing - incoming string is raw so interpreting utf
231
+ // encodings & unicode values might be necessary. To optimize things a
232
+ // bit, we mark the string for encoding if anything outside of the
233
+ // ascii range is found.
221
234
  //
222
235
 
223
- #line 224 "edn_parser.cc"
224
- static const int EDN_operator_start = 1;
225
- static const int EDN_operator_first_final = 3;
226
- static const int EDN_operator_error = 0;
236
+ #line 237 "edn_parser.cc"
237
+ static const int EDN_string_start = 1;
238
+ static const int EDN_string_first_final = 8;
239
+ static const int EDN_string_error = 0;
227
240
 
228
- static const int EDN_operator_en_main = 1;
241
+ static const int EDN_string_en_main = 1;
229
242
 
230
243
 
231
- #line 237 "edn_parser.rl"
244
+ #line 224 "edn_parser.rl"
232
245
 
233
246
 
234
247
 
235
- const char* edn::Parser::parse_operator(const char *p, const char *pe, Rice::Object& o)
248
+ const char* edn::Parser::parse_string(const char *p, const char *pe, Rice::Object& o)
236
249
  {
237
250
  // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
251
+ static const char* EDN_TYPE = "string";
238
252
  int cs;
239
- std::string op;
253
+ bool encode = false;
254
+ const char *eof = pe;
255
+ Rice::String s;
240
256
 
241
257
 
242
- #line 243 "edn_parser.cc"
258
+ #line 259 "edn_parser.cc"
243
259
  {
244
- cs = EDN_operator_start;
260
+ cs = EDN_string_start;
245
261
  }
246
262
 
247
- #line 247 "edn_parser.rl"
263
+ #line 237 "edn_parser.rl"
248
264
  p_save = p;
249
265
 
250
- #line 251 "edn_parser.cc"
266
+ #line 267 "edn_parser.cc"
251
267
  {
252
268
  if ( p == pe )
253
269
  goto _test_eof;
254
270
  switch ( cs )
255
271
  {
256
272
  case 1:
257
- switch( (*p) ) {
258
- case 33: goto st3;
259
- case 42: goto st3;
260
- case 43: goto st7;
261
- case 45: goto st7;
262
- case 46: goto st9;
263
- case 47: goto st3;
264
- case 95: goto st3;
265
- }
266
- if ( (*p) > 38 ) {
267
- if ( 60 <= (*p) && (*p) <= 63 )
268
- goto st3;
269
- } else if ( (*p) >= 36 )
270
- goto st3;
273
+ if ( (*p) == 34 )
274
+ goto st2;
275
+ goto st0;
276
+ tr3:
277
+ #line 54 "edn_parser.rl"
278
+ {
279
+ std::stringstream s;
280
+ s << "unterminated " << EDN_TYPE;
281
+ error(__FUNCTION__, s.str());
282
+ p--; {p++; cs = 0; goto _out;}
283
+ }
271
284
  goto st0;
285
+ #line 286 "edn_parser.cc"
272
286
  st0:
273
287
  cs = 0;
274
288
  goto _out;
289
+ tr2:
290
+ #line 213 "edn_parser.rl"
291
+ {
292
+ encode = true;
293
+ }
294
+ goto st2;
295
+ st2:
296
+ if ( ++p == pe )
297
+ goto _test_eof2;
298
+ case 2:
299
+ #line 300 "edn_parser.cc"
300
+ switch( (*p) ) {
301
+ case 34: goto tr4;
302
+ case 92: goto tr5;
303
+ }
304
+ if ( (*p) > -11 ) {
305
+ if ( 0 <= (*p) && (*p) <= 31 )
306
+ goto tr3;
307
+ } else if ( (*p) >= -62 )
308
+ goto tr2;
309
+ goto st2;
310
+ tr4:
311
+ #line 205 "edn_parser.rl"
312
+ {
313
+ if (Parser::parse_byte_stream(p_save + 1, p, s, encode)) {
314
+ {p = (( p + 1))-1;}
315
+ } else {
316
+ p--; {p++; cs = 8; goto _out;}
317
+ }
318
+ }
319
+ #line 61 "edn_parser.rl"
320
+ { p--; {p++; cs = 8; goto _out;} }
321
+ goto st8;
322
+ st8:
323
+ if ( ++p == pe )
324
+ goto _test_eof8;
325
+ case 8:
326
+ #line 327 "edn_parser.cc"
327
+ goto st0;
328
+ tr5:
329
+ #line 213 "edn_parser.rl"
330
+ {
331
+ encode = true;
332
+ }
333
+ goto st3;
275
334
  st3:
276
335
  if ( ++p == pe )
277
336
  goto _test_eof3;
278
337
  case 3:
338
+ #line 339 "edn_parser.cc"
279
339
  switch( (*p) ) {
280
- case 10: goto tr8;
281
- case 32: goto tr7;
282
- case 33: goto st0;
283
- case 44: goto tr7;
284
- case 59: goto tr9;
285
- case 95: goto st0;
340
+ case 34: goto tr2;
341
+ case 47: goto tr2;
342
+ case 92: goto tr2;
343
+ case 98: goto tr2;
344
+ case 102: goto tr2;
345
+ case 110: goto tr2;
346
+ case 114: goto tr2;
347
+ case 116: goto tr2;
348
+ case 117: goto tr6;
286
349
  }
287
- if ( (*p) < 42 ) {
288
- if ( (*p) > 13 ) {
289
- if ( 36 <= (*p) && (*p) <= 38 )
290
- goto st0;
291
- } else if ( (*p) >= 9 )
292
- goto tr7;
293
- } else if ( (*p) > 57 ) {
294
- if ( (*p) < 65 ) {
295
- if ( 60 <= (*p) && (*p) <= 63 )
296
- goto st0;
297
- } else if ( (*p) > 90 ) {
298
- if ( 97 <= (*p) && (*p) <= 122 )
299
- goto st0;
300
- } else
301
- goto st0;
302
- } else
350
+ if ( 0 <= (*p) && (*p) <= 31 )
303
351
  goto st0;
304
- goto tr6;
352
+ goto st2;
305
353
  tr6:
306
- #line 223 "edn_parser.rl"
354
+ #line 213 "edn_parser.rl"
307
355
  {
308
- // std::cerr << "PARSE OP::OP '" << *(fpc-1) << "', pe: '" << *pe << "'" << std::endl;
309
- std::string sym;
310
- sym += *(p - 1);
311
- o = Parser::make_edn_symbol(sym);
356
+ encode = true;
312
357
  }
313
- #line 230 "edn_parser.rl"
314
- { p--; {p++; cs = 4; goto _out;} }
315
- goto st4;
316
- tr10:
317
- #line 230 "edn_parser.rl"
318
- { p--; {p++; cs = 4; goto _out;} }
319
358
  goto st4;
320
359
  st4:
321
360
  if ( ++p == pe )
322
361
  goto _test_eof4;
323
362
  case 4:
324
- #line 325 "edn_parser.cc"
363
+ #line 364 "edn_parser.cc"
364
+ if ( (*p) < 65 ) {
365
+ if ( 48 <= (*p) && (*p) <= 57 )
366
+ goto tr7;
367
+ } else if ( (*p) > 70 ) {
368
+ if ( 97 <= (*p) && (*p) <= 102 )
369
+ goto tr7;
370
+ } else
371
+ goto tr7;
325
372
  goto st0;
326
- tr5:
327
- #line 23 "edn_parser.rl"
328
- { line_number++; }
329
- goto st5;
330
373
  tr7:
331
- #line 223 "edn_parser.rl"
374
+ #line 213 "edn_parser.rl"
332
375
  {
333
- // std::cerr << "PARSE OP::OP '" << *(fpc-1) << "', pe: '" << *pe << "'" << std::endl;
334
- std::string sym;
335
- sym += *(p - 1);
336
- o = Parser::make_edn_symbol(sym);
337
- }
338
- #line 230 "edn_parser.rl"
339
- { p--; {p++; cs = 5; goto _out;} }
340
- goto st5;
341
- tr8:
342
- #line 223 "edn_parser.rl"
343
- {
344
- // std::cerr << "PARSE OP::OP '" << *(fpc-1) << "', pe: '" << *pe << "'" << std::endl;
345
- std::string sym;
346
- sym += *(p - 1);
347
- o = Parser::make_edn_symbol(sym);
376
+ encode = true;
348
377
  }
349
- #line 23 "edn_parser.rl"
350
- { line_number++; }
351
- #line 230 "edn_parser.rl"
352
- { p--; {p++; cs = 5; goto _out;} }
353
- goto st5;
354
- tr11:
355
- #line 230 "edn_parser.rl"
356
- { p--; {p++; cs = 5; goto _out;} }
357
- goto st5;
358
- tr12:
359
- #line 23 "edn_parser.rl"
360
- { line_number++; }
361
- #line 230 "edn_parser.rl"
362
- { p--; {p++; cs = 5; goto _out;} }
363
378
  goto st5;
364
379
  st5:
365
380
  if ( ++p == pe )
366
381
  goto _test_eof5;
367
382
  case 5:
368
- #line 369 "edn_parser.cc"
369
- switch( (*p) ) {
370
- case 10: goto tr12;
371
- case 32: goto tr11;
372
- case 33: goto st0;
373
- case 44: goto tr11;
374
- case 59: goto tr13;
375
- case 95: goto st0;
376
- }
377
- if ( (*p) < 42 ) {
378
- if ( (*p) > 13 ) {
379
- if ( 36 <= (*p) && (*p) <= 38 )
380
- goto st0;
381
- } else if ( (*p) >= 9 )
382
- goto tr11;
383
- } else if ( (*p) > 57 ) {
384
- if ( (*p) < 65 ) {
385
- if ( 60 <= (*p) && (*p) <= 63 )
386
- goto st0;
387
- } else if ( (*p) > 90 ) {
388
- if ( 97 <= (*p) && (*p) <= 122 )
389
- goto st0;
390
- } else
391
- goto st0;
383
+ #line 384 "edn_parser.cc"
384
+ if ( (*p) < 65 ) {
385
+ if ( 48 <= (*p) && (*p) <= 57 )
386
+ goto tr8;
387
+ } else if ( (*p) > 70 ) {
388
+ if ( 97 <= (*p) && (*p) <= 102 )
389
+ goto tr8;
392
390
  } else
393
- goto st0;
394
- goto tr10;
395
- tr9:
396
- #line 223 "edn_parser.rl"
391
+ goto tr8;
392
+ goto st0;
393
+ tr8:
394
+ #line 213 "edn_parser.rl"
397
395
  {
398
- // std::cerr << "PARSE OP::OP '" << *(fpc-1) << "', pe: '" << *pe << "'" << std::endl;
399
- std::string sym;
400
- sym += *(p - 1);
401
- o = Parser::make_edn_symbol(sym);
396
+ encode = true;
402
397
  }
403
- #line 230 "edn_parser.rl"
404
- { p--; {p++; cs = 6; goto _out;} }
405
- goto st6;
406
- tr13:
407
- #line 230 "edn_parser.rl"
408
- { p--; {p++; cs = 6; goto _out;} }
409
398
  goto st6;
410
399
  st6:
411
400
  if ( ++p == pe )
412
401
  goto _test_eof6;
413
402
  case 6:
414
- #line 415 "edn_parser.cc"
415
- if ( (*p) == 10 )
416
- goto tr5;
417
- goto st2;
418
- st2:
419
- if ( ++p == pe )
420
- goto _test_eof2;
421
- case 2:
422
- if ( (*p) == 10 )
423
- goto tr5;
424
- goto st2;
403
+ #line 404 "edn_parser.cc"
404
+ if ( (*p) < 65 ) {
405
+ if ( 48 <= (*p) && (*p) <= 57 )
406
+ goto tr9;
407
+ } else if ( (*p) > 70 ) {
408
+ if ( 97 <= (*p) && (*p) <= 102 )
409
+ goto tr9;
410
+ } else
411
+ goto tr9;
412
+ goto st0;
413
+ tr9:
414
+ #line 213 "edn_parser.rl"
415
+ {
416
+ encode = true;
417
+ }
418
+ goto st7;
425
419
  st7:
426
420
  if ( ++p == pe )
427
421
  goto _test_eof7;
428
422
  case 7:
429
- switch( (*p) ) {
430
- case 10: goto tr8;
431
- case 32: goto tr7;
432
- case 33: goto st0;
433
- case 44: goto tr7;
434
- case 59: goto tr9;
435
- case 95: goto st0;
436
- }
437
- if ( (*p) < 48 ) {
438
- if ( (*p) < 36 ) {
439
- if ( 9 <= (*p) && (*p) <= 13 )
440
- goto tr7;
441
- } else if ( (*p) > 38 ) {
442
- if ( 42 <= (*p) && (*p) <= 47 )
443
- goto st0;
444
- } else
445
- goto st0;
446
- } else if ( (*p) > 57 ) {
447
- if ( (*p) < 65 ) {
448
- if ( 60 <= (*p) && (*p) <= 63 )
449
- goto st0;
450
- } else if ( (*p) > 90 ) {
451
- if ( 97 <= (*p) && (*p) <= 122 )
452
- goto tr15;
453
- } else
454
- goto tr15;
423
+ #line 424 "edn_parser.cc"
424
+ if ( (*p) < 65 ) {
425
+ if ( 48 <= (*p) && (*p) <= 57 )
426
+ goto tr2;
427
+ } else if ( (*p) > 70 ) {
428
+ if ( 97 <= (*p) && (*p) <= 102 )
429
+ goto tr2;
455
430
  } else
456
- goto tr14;
457
- goto tr6;
458
- tr14:
459
- #line 203 "edn_parser.rl"
460
- {
461
- //std::cerr << "PARSE OP::NUM '" << (fpc - 1) << "'" << std::endl;
462
- // try to parse a decimal first
463
- const char *np = parse_decimal(p_save, pe, o);
464
- if (np == NULL) {
465
- // if we can't, try to parse it as an int
466
- np = parse_integer(p_save, pe, o);
467
- }
468
-
469
- if (np) {
470
- {p = (( np))-1;}
471
- p--;
472
- {p++; cs = 8; goto _out;}
473
- }
474
- else {
475
- error(__FUNCTION__, *p);
476
- {p = (( pe))-1;}
477
- }
478
- }
479
- goto st8;
480
- tr15:
481
- #line 193 "edn_parser.rl"
482
- {
483
- // std::cerr << "PARSE OP::SYM '" << (fpc - 1) << "'" << std::endl;
484
- std::string sym;
485
- const char *np = parse_symbol(p_save, pe, sym);
486
- if (np == NULL) { p--; {p++; cs = 8; goto _out;} } else {
487
- o = Parser::make_edn_symbol(sym);
488
- {p = (( np))-1;}
489
- }
490
- }
491
- goto st8;
492
- st8:
493
- if ( ++p == pe )
494
- goto _test_eof8;
495
- case 8:
496
- #line 497 "edn_parser.cc"
497
- switch( (*p) ) {
498
- case 33: goto st0;
499
- case 95: goto st0;
500
- }
501
- if ( (*p) < 45 ) {
502
- if ( (*p) > 38 ) {
503
- if ( 42 <= (*p) && (*p) <= 43 )
504
- goto st0;
505
- } else if ( (*p) >= 36 )
506
- goto st0;
507
- } else if ( (*p) > 57 ) {
508
- if ( (*p) < 65 ) {
509
- if ( 60 <= (*p) && (*p) <= 63 )
510
- goto st0;
511
- } else if ( (*p) > 90 ) {
512
- if ( 97 <= (*p) && (*p) <= 122 )
513
- goto st0;
514
- } else
515
- goto st0;
516
- } else
517
- goto st0;
518
- goto tr10;
519
- st9:
520
- if ( ++p == pe )
521
- goto _test_eof9;
522
- case 9:
523
- switch( (*p) ) {
524
- case 10: goto tr8;
525
- case 32: goto tr7;
526
- case 33: goto st0;
527
- case 44: goto tr7;
528
- case 59: goto tr9;
529
- case 95: goto st0;
530
- }
531
- if ( (*p) < 42 ) {
532
- if ( (*p) > 13 ) {
533
- if ( 36 <= (*p) && (*p) <= 38 )
534
- goto st0;
535
- } else if ( (*p) >= 9 )
536
- goto tr7;
537
- } else if ( (*p) > 57 ) {
538
- if ( (*p) < 65 ) {
539
- if ( 60 <= (*p) && (*p) <= 63 )
540
- goto st0;
541
- } else if ( (*p) > 90 ) {
542
- if ( 97 <= (*p) && (*p) <= 122 )
543
- goto tr15;
544
- } else
545
- goto tr15;
546
- } else
547
- goto st0;
548
- goto tr6;
549
- }
550
- _test_eof3: cs = 3; goto _test_eof;
551
- _test_eof4: cs = 4; goto _test_eof;
552
- _test_eof5: cs = 5; goto _test_eof;
553
- _test_eof6: cs = 6; goto _test_eof;
554
- _test_eof2: cs = 2; goto _test_eof;
555
- _test_eof7: cs = 7; goto _test_eof;
556
- _test_eof8: cs = 8; goto _test_eof;
557
- _test_eof9: cs = 9; goto _test_eof;
431
+ goto tr2;
432
+ goto st0;
433
+ }
434
+ _test_eof2: cs = 2; goto _test_eof;
435
+ _test_eof8: cs = 8; goto _test_eof;
436
+ _test_eof3: cs = 3; goto _test_eof;
437
+ _test_eof4: cs = 4; goto _test_eof;
438
+ _test_eof5: cs = 5; goto _test_eof;
439
+ _test_eof6: cs = 6; goto _test_eof;
440
+ _test_eof7: cs = 7; goto _test_eof;
558
441
 
559
442
  _test_eof: {}
560
443
  if ( p == eof )
561
444
  {
562
445
  switch ( cs ) {
563
- case 3:
564
- case 7:
565
- case 9:
566
- #line 223 "edn_parser.rl"
446
+ case 2:
447
+ #line 54 "edn_parser.rl"
567
448
  {
568
- // std::cerr << "PARSE OP::OP '" << *(fpc-1) << "', pe: '" << *pe << "'" << std::endl;
569
- std::string sym;
570
- sym += *(p - 1);
571
- o = Parser::make_edn_symbol(sym);
572
- }
449
+ std::stringstream s;
450
+ s << "unterminated " << EDN_TYPE;
451
+ error(__FUNCTION__, s.str());
452
+ p--; {p++; cs = 0; goto _out;}
453
+ }
573
454
  break;
574
- #line 575 "edn_parser.cc"
455
+ #line 456 "edn_parser.cc"
575
456
  }
576
457
  }
577
458
 
578
459
  _out: {}
579
460
  }
580
461
 
581
- #line 249 "edn_parser.rl"
462
+ #line 239 "edn_parser.rl"
582
463
 
583
- if (cs >= EDN_operator_first_final) {
584
- return p;
464
+ if (cs >= EDN_string_first_final) {
465
+ o = s;
466
+ return p + 1;
585
467
  }
586
- else if (cs == EDN_operator_error) {
587
- error(__FUNCTION__, *p);
468
+ else if (cs == EDN_string_error) {
588
469
  return pe;
589
470
  }
590
- else if (cs == EDN_operator_en_main) {} // silence ragel warning
471
+ else if (cs == EDN_string_en_main) {} // silence ragel warning
591
472
  return NULL;
592
473
  }
593
474
 
594
475
 
595
476
 
596
477
  // ============================================================
597
- // escaped char parsing
478
+ // keyword parsing
598
479
  //
599
480
 
600
- #line 601 "edn_parser.cc"
601
- static const int EDN_escaped_char_start = 1;
602
- static const int EDN_escaped_char_first_final = 4;
603
- static const int EDN_escaped_char_error = 0;
481
+ #line 482 "edn_parser.cc"
482
+ static const int EDN_keyword_start = 1;
483
+ static const int EDN_keyword_first_final = 3;
484
+ static const int EDN_keyword_error = 0;
604
485
 
605
- static const int EDN_escaped_char_en_main = 1;
486
+ static const int EDN_keyword_en_main = 1;
606
487
 
607
488
 
608
- #line 279 "edn_parser.rl"
489
+ #line 269 "edn_parser.rl"
609
490
 
610
491
 
611
492
 
612
- const char* edn::Parser::parse_esc_char(const char *p, const char *pe, Rice::Object& o)
493
+ const char* edn::Parser::parse_keyword(const char *p, const char *pe, Rice::Object& o)
613
494
  {
614
- //std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
615
495
  int cs;
616
496
 
617
497
 
618
- #line 619 "edn_parser.cc"
498
+ #line 499 "edn_parser.cc"
619
499
  {
620
- cs = EDN_escaped_char_start;
500
+ cs = EDN_keyword_start;
621
501
  }
622
502
 
623
- #line 288 "edn_parser.rl"
503
+ #line 277 "edn_parser.rl"
624
504
  p_save = p;
625
505
 
626
- #line 627 "edn_parser.cc"
506
+ #line 507 "edn_parser.cc"
627
507
  {
628
508
  if ( p == pe )
629
509
  goto _test_eof;
630
510
  switch ( cs )
631
511
  {
632
512
  case 1:
633
- if ( (*p) == 92 )
513
+ if ( (*p) == 58 )
634
514
  goto st2;
635
515
  goto st0;
636
516
  st0:
@@ -640,158 +520,111 @@ st2:
640
520
  if ( ++p == pe )
641
521
  goto _test_eof2;
642
522
  case 2:
643
- if ( (*p) > 90 ) {
644
- if ( 97 <= (*p) && (*p) <= 122 )
645
- goto st4;
646
- } else if ( (*p) >= 65 )
647
- goto st4;
648
- goto st0;
649
- st4:
650
- if ( ++p == pe )
651
- goto _test_eof4;
652
- case 4:
653
- switch( (*p) ) {
654
- case 10: goto tr7;
655
- case 32: goto tr6;
656
- case 44: goto tr6;
657
- case 59: goto tr8;
658
- case 92: goto st0;
659
- }
523
+ if ( (*p) == 35 )
524
+ goto st3;
660
525
  if ( (*p) < 65 ) {
661
- if ( 9 <= (*p) && (*p) <= 13 )
662
- goto tr6;
526
+ if ( 46 <= (*p) && (*p) <= 47 )
527
+ goto st3;
663
528
  } else if ( (*p) > 90 ) {
664
529
  if ( 97 <= (*p) && (*p) <= 122 )
665
- goto st4;
530
+ goto st3;
666
531
  } else
667
- goto st4;
668
- goto tr5;
669
- tr5:
670
- #line 274 "edn_parser.rl"
671
- { p--; {p++; cs = 5; goto _out;} }
672
- goto st5;
673
- st5:
674
- if ( ++p == pe )
675
- goto _test_eof5;
676
- case 5:
677
- #line 678 "edn_parser.cc"
532
+ goto st3;
678
533
  goto st0;
679
- tr4:
680
- #line 23 "edn_parser.rl"
681
- { line_number++; }
682
- goto st6;
683
- tr6:
684
- #line 274 "edn_parser.rl"
685
- { p--; {p++; cs = 6; goto _out;} }
686
- goto st6;
687
- tr7:
688
- #line 23 "edn_parser.rl"
689
- { line_number++; }
690
- #line 274 "edn_parser.rl"
691
- { p--; {p++; cs = 6; goto _out;} }
692
- goto st6;
693
- st6:
534
+ st3:
694
535
  if ( ++p == pe )
695
- goto _test_eof6;
696
- case 6:
697
- #line 698 "edn_parser.cc"
536
+ goto _test_eof3;
537
+ case 3:
698
538
  switch( (*p) ) {
699
- case 10: goto tr7;
700
- case 32: goto tr6;
701
- case 44: goto tr6;
702
- case 59: goto tr8;
703
- case 92: goto st0;
539
+ case 33: goto st3;
540
+ case 95: goto st3;
704
541
  }
705
- if ( (*p) < 65 ) {
706
- if ( 9 <= (*p) && (*p) <= 13 )
707
- goto tr6;
708
- } else if ( (*p) > 90 ) {
709
- if ( 97 <= (*p) && (*p) <= 122 )
710
- goto st0;
542
+ if ( (*p) < 45 ) {
543
+ if ( (*p) > 38 ) {
544
+ if ( 42 <= (*p) && (*p) <= 43 )
545
+ goto st3;
546
+ } else if ( (*p) >= 35 )
547
+ goto st3;
548
+ } else if ( (*p) > 58 ) {
549
+ if ( (*p) < 65 ) {
550
+ if ( 60 <= (*p) && (*p) <= 63 )
551
+ goto st3;
552
+ } else if ( (*p) > 90 ) {
553
+ if ( 97 <= (*p) && (*p) <= 122 )
554
+ goto st3;
555
+ } else
556
+ goto st3;
711
557
  } else
712
- goto st0;
713
- goto tr5;
714
- tr8:
715
- #line 274 "edn_parser.rl"
716
- { p--; {p++; cs = 7; goto _out;} }
717
- goto st7;
718
- st7:
719
- if ( ++p == pe )
720
- goto _test_eof7;
721
- case 7:
722
- #line 723 "edn_parser.cc"
723
- if ( (*p) == 10 )
724
- goto tr4;
725
- goto st3;
726
- st3:
558
+ goto st3;
559
+ goto tr3;
560
+ tr3:
561
+ #line 61 "edn_parser.rl"
562
+ { p--; {p++; cs = 4; goto _out;} }
563
+ goto st4;
564
+ st4:
727
565
  if ( ++p == pe )
728
- goto _test_eof3;
729
- case 3:
730
- if ( (*p) == 10 )
731
- goto tr4;
732
- goto st3;
566
+ goto _test_eof4;
567
+ case 4:
568
+ #line 569 "edn_parser.cc"
569
+ goto st0;
733
570
  }
734
571
  _test_eof2: cs = 2; goto _test_eof;
735
- _test_eof4: cs = 4; goto _test_eof;
736
- _test_eof5: cs = 5; goto _test_eof;
737
- _test_eof6: cs = 6; goto _test_eof;
738
- _test_eof7: cs = 7; goto _test_eof;
739
572
  _test_eof3: cs = 3; goto _test_eof;
573
+ _test_eof4: cs = 4; goto _test_eof;
740
574
 
741
575
  _test_eof: {}
742
576
  _out: {}
743
577
  }
744
578
 
745
- #line 290 "edn_parser.rl"
579
+ #line 279 "edn_parser.rl"
746
580
 
747
- if (cs >= EDN_escaped_char_first_final) {
748
- if (!Parser::parse_escaped_char(p_save + 1, p, o)) {
749
- return pe;
750
- }
581
+ if (cs >= EDN_keyword_first_final) {
582
+ std::string buf;
583
+ uint32_t len = p - p_save;
584
+ // don't include leading ':' because Rice::Symbol will handle it
585
+ buf.append(p_save + 1, len - 1);
586
+ o = Rice::Symbol(buf);
751
587
  return p;
752
588
  }
753
- else if (cs == EDN_escaped_char_error) {
589
+ else if (cs == EDN_keyword_error) {
754
590
  error(__FUNCTION__, *p);
755
591
  return pe;
756
592
  }
757
- else if (cs == EDN_escaped_char_en_main) {} // silence ragel warning
593
+ else if (cs == EDN_keyword_en_main) {} // silence ragel warning
758
594
  return NULL;
759
595
  }
760
596
 
761
597
 
762
598
 
763
-
764
599
  // ============================================================
765
- // symbol parsing
600
+ // decimal parsing machine
766
601
  //
767
602
 
768
- #line 769 "edn_parser.cc"
769
- static const int EDN_symbol_start = 1;
770
- static const int EDN_symbol_first_final = 4;
771
- static const int EDN_symbol_error = 0;
603
+ #line 604 "edn_parser.cc"
604
+ static const int EDN_decimal_start = 1;
605
+ static const int EDN_decimal_first_final = 9;
772
606
 
773
- static const int EDN_symbol_en_main = 1;
607
+ static const int EDN_decimal_en_main = 1;
774
608
 
775
609
 
776
- #line 323 "edn_parser.rl"
610
+ #line 312 "edn_parser.rl"
777
611
 
778
612
 
779
613
 
780
- const char* edn::Parser::parse_symbol(const char *p, const char *pe, std::string& s)
614
+ const char* edn::Parser::parse_decimal(const char *p, const char *pe, Rice::Object& o)
781
615
  {
782
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
783
616
  int cs;
784
617
 
785
618
 
786
- #line 787 "edn_parser.cc"
619
+ #line 620 "edn_parser.cc"
787
620
  {
788
- cs = EDN_symbol_start;
621
+ cs = EDN_decimal_start;
789
622
  }
790
623
 
791
- #line 332 "edn_parser.rl"
624
+ #line 320 "edn_parser.rl"
792
625
  p_save = p;
793
626
 
794
- #line 795 "edn_parser.cc"
627
+ #line 628 "edn_parser.cc"
795
628
  {
796
629
  if ( p == pe )
797
630
  goto _test_eof;
@@ -799,34 +632,377 @@ const char* edn::Parser::parse_symbol(const char *p, const char *pe, std::string
799
632
  {
800
633
  case 1:
801
634
  switch( (*p) ) {
802
- case 33: goto st4;
803
- case 95: goto st4;
804
- }
805
- if ( (*p) < 45 ) {
806
- if ( (*p) > 38 ) {
807
- if ( 42 <= (*p) && (*p) <= 43 )
808
- goto st4;
809
- } else if ( (*p) >= 36 )
810
- goto st4;
811
- } else if ( (*p) > 47 ) {
812
- if ( (*p) < 65 ) {
813
- if ( 60 <= (*p) && (*p) <= 63 )
814
- goto st4;
815
- } else if ( (*p) > 90 ) {
816
- if ( 97 <= (*p) && (*p) <= 122 )
817
- goto st8;
818
- } else
819
- goto st8;
820
- } else
821
- goto st4;
635
+ case 43: goto st2;
636
+ case 45: goto st2;
637
+ case 48: goto st3;
638
+ }
639
+ if ( 49 <= (*p) && (*p) <= 57 )
640
+ goto st8;
822
641
  goto st0;
823
642
  st0:
824
643
  cs = 0;
825
644
  goto _out;
645
+ st2:
646
+ if ( ++p == pe )
647
+ goto _test_eof2;
648
+ case 2:
649
+ if ( (*p) == 48 )
650
+ goto st3;
651
+ if ( 49 <= (*p) && (*p) <= 57 )
652
+ goto st8;
653
+ goto st0;
654
+ st3:
655
+ if ( ++p == pe )
656
+ goto _test_eof3;
657
+ case 3:
658
+ switch( (*p) ) {
659
+ case 46: goto st9;
660
+ case 69: goto st6;
661
+ case 101: goto st6;
662
+ }
663
+ goto st0;
664
+ st9:
665
+ if ( ++p == pe )
666
+ goto _test_eof9;
667
+ case 9:
668
+ switch( (*p) ) {
669
+ case 43: goto st0;
670
+ case 69: goto st4;
671
+ case 77: goto st12;
672
+ case 101: goto st4;
673
+ }
674
+ if ( (*p) > 46 ) {
675
+ if ( 48 <= (*p) && (*p) <= 57 )
676
+ goto st9;
677
+ } else if ( (*p) >= 45 )
678
+ goto st0;
679
+ goto tr10;
680
+ tr10:
681
+ #line 61 "edn_parser.rl"
682
+ { p--; {p++; cs = 10; goto _out;} }
683
+ goto st10;
684
+ st10:
685
+ if ( ++p == pe )
686
+ goto _test_eof10;
687
+ case 10:
688
+ #line 689 "edn_parser.cc"
689
+ goto st0;
826
690
  st4:
827
691
  if ( ++p == pe )
828
692
  goto _test_eof4;
829
693
  case 4:
694
+ switch( (*p) ) {
695
+ case 43: goto st5;
696
+ case 45: goto st5;
697
+ }
698
+ if ( 48 <= (*p) && (*p) <= 57 )
699
+ goto st11;
700
+ goto st0;
701
+ st5:
702
+ if ( ++p == pe )
703
+ goto _test_eof5;
704
+ case 5:
705
+ if ( 48 <= (*p) && (*p) <= 57 )
706
+ goto st11;
707
+ goto st0;
708
+ st11:
709
+ if ( ++p == pe )
710
+ goto _test_eof11;
711
+ case 11:
712
+ switch( (*p) ) {
713
+ case 43: goto st0;
714
+ case 69: goto st0;
715
+ case 77: goto st12;
716
+ case 101: goto st0;
717
+ }
718
+ if ( (*p) > 46 ) {
719
+ if ( 48 <= (*p) && (*p) <= 57 )
720
+ goto st11;
721
+ } else if ( (*p) >= 45 )
722
+ goto st0;
723
+ goto tr10;
724
+ st12:
725
+ if ( ++p == pe )
726
+ goto _test_eof12;
727
+ case 12:
728
+ switch( (*p) ) {
729
+ case 43: goto st0;
730
+ case 69: goto st0;
731
+ case 77: goto st0;
732
+ case 101: goto st0;
733
+ }
734
+ if ( (*p) > 46 ) {
735
+ if ( 48 <= (*p) && (*p) <= 57 )
736
+ goto st0;
737
+ } else if ( (*p) >= 45 )
738
+ goto st0;
739
+ goto tr10;
740
+ st6:
741
+ if ( ++p == pe )
742
+ goto _test_eof6;
743
+ case 6:
744
+ switch( (*p) ) {
745
+ case 43: goto st7;
746
+ case 45: goto st7;
747
+ }
748
+ if ( 48 <= (*p) && (*p) <= 57 )
749
+ goto st13;
750
+ goto st0;
751
+ st7:
752
+ if ( ++p == pe )
753
+ goto _test_eof7;
754
+ case 7:
755
+ if ( 48 <= (*p) && (*p) <= 57 )
756
+ goto st13;
757
+ goto st0;
758
+ st13:
759
+ if ( ++p == pe )
760
+ goto _test_eof13;
761
+ case 13:
762
+ switch( (*p) ) {
763
+ case 43: goto st0;
764
+ case 69: goto st0;
765
+ case 77: goto st0;
766
+ case 101: goto st0;
767
+ }
768
+ if ( (*p) > 46 ) {
769
+ if ( 48 <= (*p) && (*p) <= 57 )
770
+ goto st13;
771
+ } else if ( (*p) >= 45 )
772
+ goto st0;
773
+ goto tr10;
774
+ st8:
775
+ if ( ++p == pe )
776
+ goto _test_eof8;
777
+ case 8:
778
+ switch( (*p) ) {
779
+ case 46: goto st9;
780
+ case 69: goto st6;
781
+ case 101: goto st6;
782
+ }
783
+ if ( 48 <= (*p) && (*p) <= 57 )
784
+ goto st8;
785
+ goto st0;
786
+ }
787
+ _test_eof2: cs = 2; goto _test_eof;
788
+ _test_eof3: cs = 3; goto _test_eof;
789
+ _test_eof9: cs = 9; goto _test_eof;
790
+ _test_eof10: cs = 10; goto _test_eof;
791
+ _test_eof4: cs = 4; goto _test_eof;
792
+ _test_eof5: cs = 5; goto _test_eof;
793
+ _test_eof11: cs = 11; goto _test_eof;
794
+ _test_eof12: cs = 12; goto _test_eof;
795
+ _test_eof6: cs = 6; goto _test_eof;
796
+ _test_eof7: cs = 7; goto _test_eof;
797
+ _test_eof13: cs = 13; goto _test_eof;
798
+ _test_eof8: cs = 8; goto _test_eof;
799
+
800
+ _test_eof: {}
801
+ _out: {}
802
+ }
803
+
804
+ #line 322 "edn_parser.rl"
805
+
806
+ if (cs >= EDN_decimal_first_final) {
807
+ o = Parser::float_to_ruby(p_save, p - p_save);
808
+ return p + 1;
809
+ }
810
+ else if (cs == EDN_decimal_en_main) {} // silence ragel warning
811
+ return NULL;
812
+ }
813
+
814
+
815
+ // ============================================================
816
+ // integer parsing machine
817
+ //
818
+
819
+ #line 820 "edn_parser.cc"
820
+ static const int EDN_integer_start = 1;
821
+ static const int EDN_integer_first_final = 3;
822
+
823
+ static const int EDN_integer_en_main = 1;
824
+
825
+
826
+ #line 345 "edn_parser.rl"
827
+
828
+
829
+ const char* edn::Parser::parse_integer(const char *p, const char *pe, Rice::Object& o)
830
+ {
831
+ int cs;
832
+
833
+
834
+ #line 835 "edn_parser.cc"
835
+ {
836
+ cs = EDN_integer_start;
837
+ }
838
+
839
+ #line 352 "edn_parser.rl"
840
+ p_save = p;
841
+
842
+ #line 843 "edn_parser.cc"
843
+ {
844
+ if ( p == pe )
845
+ goto _test_eof;
846
+ switch ( cs )
847
+ {
848
+ case 1:
849
+ switch( (*p) ) {
850
+ case 43: goto st2;
851
+ case 45: goto st2;
852
+ case 48: goto st3;
853
+ }
854
+ if ( 49 <= (*p) && (*p) <= 57 )
855
+ goto st6;
856
+ goto st0;
857
+ st0:
858
+ cs = 0;
859
+ goto _out;
860
+ st2:
861
+ if ( ++p == pe )
862
+ goto _test_eof2;
863
+ case 2:
864
+ if ( (*p) == 48 )
865
+ goto st3;
866
+ if ( 49 <= (*p) && (*p) <= 57 )
867
+ goto st6;
868
+ goto st0;
869
+ st3:
870
+ if ( ++p == pe )
871
+ goto _test_eof3;
872
+ case 3:
873
+ switch( (*p) ) {
874
+ case 43: goto st0;
875
+ case 45: goto st0;
876
+ }
877
+ if ( (*p) > 57 ) {
878
+ if ( 77 <= (*p) && (*p) <= 78 )
879
+ goto st5;
880
+ } else if ( (*p) >= 48 )
881
+ goto st0;
882
+ goto tr4;
883
+ tr4:
884
+ #line 61 "edn_parser.rl"
885
+ { p--; {p++; cs = 4; goto _out;} }
886
+ goto st4;
887
+ st4:
888
+ if ( ++p == pe )
889
+ goto _test_eof4;
890
+ case 4:
891
+ #line 892 "edn_parser.cc"
892
+ goto st0;
893
+ st5:
894
+ if ( ++p == pe )
895
+ goto _test_eof5;
896
+ case 5:
897
+ switch( (*p) ) {
898
+ case 43: goto st0;
899
+ case 45: goto st0;
900
+ }
901
+ if ( (*p) > 57 ) {
902
+ if ( 77 <= (*p) && (*p) <= 78 )
903
+ goto st0;
904
+ } else if ( (*p) >= 48 )
905
+ goto st0;
906
+ goto tr4;
907
+ st6:
908
+ if ( ++p == pe )
909
+ goto _test_eof6;
910
+ case 6:
911
+ switch( (*p) ) {
912
+ case 43: goto st0;
913
+ case 45: goto st0;
914
+ }
915
+ if ( (*p) > 57 ) {
916
+ if ( 77 <= (*p) && (*p) <= 78 )
917
+ goto st5;
918
+ } else if ( (*p) >= 48 )
919
+ goto st6;
920
+ goto tr4;
921
+ }
922
+ _test_eof2: cs = 2; goto _test_eof;
923
+ _test_eof3: cs = 3; goto _test_eof;
924
+ _test_eof4: cs = 4; goto _test_eof;
925
+ _test_eof5: cs = 5; goto _test_eof;
926
+ _test_eof6: cs = 6; goto _test_eof;
927
+
928
+ _test_eof: {}
929
+ _out: {}
930
+ }
931
+
932
+ #line 354 "edn_parser.rl"
933
+
934
+ if (cs >= EDN_integer_first_final) {
935
+ o = Parser::integer_to_ruby(p_save, p - p_save);
936
+ return p + 1;
937
+ }
938
+ else if (cs == EDN_integer_en_main) {} // silence ragel warning
939
+ return NULL;
940
+ }
941
+
942
+
943
+
944
+ // ============================================================
945
+ // operator parsing - handles tokens w/ a leading operator:
946
+ //
947
+ // 1. symbols w/ leading operator: -something, .somethingelse
948
+ // 2. number values w/ leading - or +
949
+ // 3. stand-alone operators: +, -, /, *, etc.
950
+ //
951
+
952
+ #line 953 "edn_parser.cc"
953
+ static const int EDN_operator_start = 1;
954
+ static const int EDN_operator_first_final = 3;
955
+ static const int EDN_operator_error = 0;
956
+
957
+ static const int EDN_operator_en_main = 1;
958
+
959
+
960
+ #line 424 "edn_parser.rl"
961
+
962
+
963
+
964
+ const char* edn::Parser::parse_operator(const char *p, const char *pe, Rice::Object& o)
965
+ {
966
+ int cs;
967
+
968
+
969
+ #line 970 "edn_parser.cc"
970
+ {
971
+ cs = EDN_operator_start;
972
+ }
973
+
974
+ #line 432 "edn_parser.rl"
975
+ p_save = p;
976
+
977
+ #line 978 "edn_parser.cc"
978
+ {
979
+ if ( p == pe )
980
+ goto _test_eof;
981
+ switch ( cs )
982
+ {
983
+ case 1:
984
+ switch( (*p) ) {
985
+ case 33: goto st3;
986
+ case 42: goto st3;
987
+ case 43: goto st7;
988
+ case 45: goto st7;
989
+ case 46: goto st9;
990
+ case 47: goto st3;
991
+ case 95: goto st3;
992
+ }
993
+ if ( (*p) > 38 ) {
994
+ if ( 60 <= (*p) && (*p) <= 63 )
995
+ goto st3;
996
+ } else if ( (*p) >= 36 )
997
+ goto st3;
998
+ goto st0;
999
+ st0:
1000
+ cs = 0;
1001
+ goto _out;
1002
+ st3:
1003
+ if ( ++p == pe )
1004
+ goto _test_eof3;
1005
+ case 3:
830
1006
  switch( (*p) ) {
831
1007
  case 10: goto tr8;
832
1008
  case 32: goto tr7;
@@ -837,135 +1013,239 @@ case 4:
837
1013
  }
838
1014
  if ( (*p) < 42 ) {
839
1015
  if ( (*p) > 13 ) {
840
- if ( 35 <= (*p) && (*p) <= 38 )
1016
+ if ( 36 <= (*p) && (*p) <= 38 )
841
1017
  goto st0;
842
1018
  } else if ( (*p) >= 9 )
843
1019
  goto tr7;
844
- } else if ( (*p) > 63 ) {
845
- if ( (*p) > 90 ) {
1020
+ } else if ( (*p) > 57 ) {
1021
+ if ( (*p) < 65 ) {
1022
+ if ( 60 <= (*p) && (*p) <= 63 )
1023
+ goto st0;
1024
+ } else if ( (*p) > 90 ) {
846
1025
  if ( 97 <= (*p) && (*p) <= 122 )
847
- goto st8;
848
- } else if ( (*p) >= 65 )
849
- goto st8;
1026
+ goto st0;
1027
+ } else
1028
+ goto st0;
850
1029
  } else
851
1030
  goto st0;
852
1031
  goto tr6;
853
1032
  tr6:
854
- #line 317 "edn_parser.rl"
855
- { p--; {p++; cs = 5; goto _out;} }
856
- goto st5;
857
- st5:
1033
+ #line 411 "edn_parser.rl"
1034
+ {
1035
+ // stand-alone operators (-, +, /, ... etc)
1036
+ std::string sym;
1037
+ sym += *(p_save);
1038
+ o = Parser::make_edn_symbol(sym);
1039
+ }
1040
+ #line 61 "edn_parser.rl"
1041
+ { p--; {p++; cs = 4; goto _out;} }
1042
+ goto st4;
1043
+ tr10:
1044
+ #line 61 "edn_parser.rl"
1045
+ { p--; {p++; cs = 4; goto _out;} }
1046
+ goto st4;
1047
+ st4:
858
1048
  if ( ++p == pe )
859
- goto _test_eof5;
860
- case 5:
861
- #line 862 "edn_parser.cc"
1049
+ goto _test_eof4;
1050
+ case 4:
1051
+ #line 1052 "edn_parser.cc"
862
1052
  goto st0;
863
- tr4:
864
- #line 23 "edn_parser.rl"
1053
+ tr5:
1054
+ #line 24 "edn_parser.rl"
865
1055
  { line_number++; }
866
- goto st6;
1056
+ goto st5;
867
1057
  tr7:
868
- #line 317 "edn_parser.rl"
869
- { p--; {p++; cs = 6; goto _out;} }
870
- goto st6;
1058
+ #line 411 "edn_parser.rl"
1059
+ {
1060
+ // stand-alone operators (-, +, /, ... etc)
1061
+ std::string sym;
1062
+ sym += *(p_save);
1063
+ o = Parser::make_edn_symbol(sym);
1064
+ }
1065
+ #line 61 "edn_parser.rl"
1066
+ { p--; {p++; cs = 5; goto _out;} }
1067
+ goto st5;
871
1068
  tr8:
872
- #line 23 "edn_parser.rl"
1069
+ #line 411 "edn_parser.rl"
1070
+ {
1071
+ // stand-alone operators (-, +, /, ... etc)
1072
+ std::string sym;
1073
+ sym += *(p_save);
1074
+ o = Parser::make_edn_symbol(sym);
1075
+ }
1076
+ #line 24 "edn_parser.rl"
873
1077
  { line_number++; }
874
- #line 317 "edn_parser.rl"
875
- { p--; {p++; cs = 6; goto _out;} }
876
- goto st6;
877
- st6:
1078
+ #line 61 "edn_parser.rl"
1079
+ { p--; {p++; cs = 5; goto _out;} }
1080
+ goto st5;
1081
+ tr11:
1082
+ #line 61 "edn_parser.rl"
1083
+ { p--; {p++; cs = 5; goto _out;} }
1084
+ goto st5;
1085
+ tr12:
1086
+ #line 24 "edn_parser.rl"
1087
+ { line_number++; }
1088
+ #line 61 "edn_parser.rl"
1089
+ { p--; {p++; cs = 5; goto _out;} }
1090
+ goto st5;
1091
+ st5:
878
1092
  if ( ++p == pe )
879
- goto _test_eof6;
880
- case 6:
881
- #line 882 "edn_parser.cc"
1093
+ goto _test_eof5;
1094
+ case 5:
1095
+ #line 1096 "edn_parser.cc"
882
1096
  switch( (*p) ) {
883
- case 10: goto tr8;
884
- case 32: goto tr7;
1097
+ case 10: goto tr12;
1098
+ case 32: goto tr11;
885
1099
  case 33: goto st0;
886
- case 44: goto tr7;
887
- case 59: goto tr9;
1100
+ case 44: goto tr11;
1101
+ case 59: goto tr13;
888
1102
  case 95: goto st0;
889
1103
  }
890
1104
  if ( (*p) < 42 ) {
891
1105
  if ( (*p) > 13 ) {
892
- if ( 35 <= (*p) && (*p) <= 38 )
1106
+ if ( 36 <= (*p) && (*p) <= 38 )
893
1107
  goto st0;
894
1108
  } else if ( (*p) >= 9 )
895
- goto tr7;
896
- } else if ( (*p) > 63 ) {
897
- if ( (*p) > 90 ) {
1109
+ goto tr11;
1110
+ } else if ( (*p) > 57 ) {
1111
+ if ( (*p) < 65 ) {
1112
+ if ( 60 <= (*p) && (*p) <= 63 )
1113
+ goto st0;
1114
+ } else if ( (*p) > 90 ) {
898
1115
  if ( 97 <= (*p) && (*p) <= 122 )
899
1116
  goto st0;
900
- } else if ( (*p) >= 65 )
1117
+ } else
901
1118
  goto st0;
902
1119
  } else
903
1120
  goto st0;
904
- goto tr6;
1121
+ goto tr10;
905
1122
  tr9:
906
- #line 317 "edn_parser.rl"
907
- { p--; {p++; cs = 7; goto _out;} }
908
- goto st7;
909
- st7:
1123
+ #line 411 "edn_parser.rl"
1124
+ {
1125
+ // stand-alone operators (-, +, /, ... etc)
1126
+ std::string sym;
1127
+ sym += *(p_save);
1128
+ o = Parser::make_edn_symbol(sym);
1129
+ }
1130
+ #line 61 "edn_parser.rl"
1131
+ { p--; {p++; cs = 6; goto _out;} }
1132
+ goto st6;
1133
+ tr13:
1134
+ #line 61 "edn_parser.rl"
1135
+ { p--; {p++; cs = 6; goto _out;} }
1136
+ goto st6;
1137
+ st6:
910
1138
  if ( ++p == pe )
911
- goto _test_eof7;
912
- case 7:
913
- #line 914 "edn_parser.cc"
1139
+ goto _test_eof6;
1140
+ case 6:
1141
+ #line 1142 "edn_parser.cc"
914
1142
  if ( (*p) == 10 )
915
- goto tr4;
1143
+ goto tr5;
916
1144
  goto st2;
917
1145
  st2:
918
1146
  if ( ++p == pe )
919
1147
  goto _test_eof2;
920
1148
  case 2:
921
1149
  if ( (*p) == 10 )
922
- goto tr4;
1150
+ goto tr5;
923
1151
  goto st2;
924
- st8:
1152
+ st7:
925
1153
  if ( ++p == pe )
926
- goto _test_eof8;
927
- case 8:
1154
+ goto _test_eof7;
1155
+ case 7:
928
1156
  switch( (*p) ) {
929
1157
  case 10: goto tr8;
930
1158
  case 32: goto tr7;
931
1159
  case 33: goto st0;
932
- case 35: goto st8;
933
1160
  case 44: goto tr7;
934
- case 47: goto st3;
935
1161
  case 59: goto tr9;
936
- case 95: goto st8;
1162
+ case 95: goto st0;
937
1163
  }
938
- if ( (*p) < 45 ) {
1164
+ if ( (*p) < 48 ) {
939
1165
  if ( (*p) < 36 ) {
940
1166
  if ( 9 <= (*p) && (*p) <= 13 )
941
1167
  goto tr7;
942
1168
  } else if ( (*p) > 38 ) {
943
- if ( 42 <= (*p) && (*p) <= 43 )
1169
+ if ( 42 <= (*p) && (*p) <= 47 )
944
1170
  goto st0;
945
1171
  } else
946
1172
  goto st0;
947
- } else if ( (*p) > 58 ) {
1173
+ } else if ( (*p) > 57 ) {
948
1174
  if ( (*p) < 65 ) {
949
1175
  if ( 60 <= (*p) && (*p) <= 63 )
950
1176
  goto st0;
951
1177
  } else if ( (*p) > 90 ) {
952
1178
  if ( 97 <= (*p) && (*p) <= 122 )
953
- goto st8;
1179
+ goto tr15;
954
1180
  } else
955
- goto st8;
1181
+ goto tr15;
956
1182
  } else
957
- goto st8;
1183
+ goto tr14;
958
1184
  goto tr6;
959
- st3:
1185
+ tr14:
1186
+ #line 388 "edn_parser.rl"
1187
+ {
1188
+ // parse a number with the leading symbol - this is slightly
1189
+ // different than the one within EDN_value since it includes
1190
+ // the leading - or +
1191
+ //
1192
+ // try to parse a decimal first
1193
+ const char *np = parse_decimal(p_save, pe, o);
1194
+ if (np == NULL) {
1195
+ // if we can't, try to parse it as an int
1196
+ np = parse_integer(p_save, pe, o);
1197
+ }
1198
+
1199
+ if (np) {
1200
+ {p = (( np))-1;}
1201
+ p--;
1202
+ {p++; cs = 8; goto _out;}
1203
+ }
1204
+ else {
1205
+ error(__FUNCTION__, *p);
1206
+ {p = (( pe))-1;}
1207
+ }
1208
+ }
1209
+ goto st8;
1210
+ tr15:
1211
+ #line 378 "edn_parser.rl"
1212
+ {
1213
+ // parse a symbol including the leading operator (-, +, .)
1214
+ std::string sym;
1215
+ const char *np = parse_symbol(p_save, pe, sym);
1216
+ if (np == NULL) { p--; {p++; cs = 8; goto _out;} } else {
1217
+ o = Parser::make_edn_symbol(sym);
1218
+ {p = (( np))-1;}
1219
+ }
1220
+ }
1221
+ goto st8;
1222
+ st8:
960
1223
  if ( ++p == pe )
961
- goto _test_eof3;
962
- case 3:
963
- if ( (*p) > 90 ) {
964
- if ( 97 <= (*p) && (*p) <= 122 )
965
- goto st9;
966
- } else if ( (*p) >= 65 )
967
- goto st9;
968
- goto st0;
1224
+ goto _test_eof8;
1225
+ case 8:
1226
+ #line 1227 "edn_parser.cc"
1227
+ switch( (*p) ) {
1228
+ case 33: goto st0;
1229
+ case 95: goto st0;
1230
+ }
1231
+ if ( (*p) < 45 ) {
1232
+ if ( (*p) > 38 ) {
1233
+ if ( 42 <= (*p) && (*p) <= 43 )
1234
+ goto st0;
1235
+ } else if ( (*p) >= 36 )
1236
+ goto st0;
1237
+ } else if ( (*p) > 57 ) {
1238
+ if ( (*p) < 65 ) {
1239
+ if ( 60 <= (*p) && (*p) <= 63 )
1240
+ goto st0;
1241
+ } else if ( (*p) > 90 ) {
1242
+ if ( 97 <= (*p) && (*p) <= 122 )
1243
+ goto st0;
1244
+ } else
1245
+ goto st0;
1246
+ } else
1247
+ goto st0;
1248
+ goto tr10;
969
1249
  st9:
970
1250
  if ( ++p == pe )
971
1251
  goto _test_eof9;
@@ -974,106 +1254,112 @@ case 9:
974
1254
  case 10: goto tr8;
975
1255
  case 32: goto tr7;
976
1256
  case 33: goto st0;
977
- case 35: goto st9;
978
1257
  case 44: goto tr7;
979
- case 47: goto st0;
980
1258
  case 59: goto tr9;
981
- case 95: goto st9;
1259
+ case 95: goto st0;
982
1260
  }
983
- if ( (*p) < 45 ) {
984
- if ( (*p) < 36 ) {
985
- if ( 9 <= (*p) && (*p) <= 13 )
986
- goto tr7;
987
- } else if ( (*p) > 38 ) {
988
- if ( 42 <= (*p) && (*p) <= 43 )
1261
+ if ( (*p) < 42 ) {
1262
+ if ( (*p) > 13 ) {
1263
+ if ( 36 <= (*p) && (*p) <= 38 )
989
1264
  goto st0;
990
- } else
991
- goto st0;
992
- } else if ( (*p) > 58 ) {
1265
+ } else if ( (*p) >= 9 )
1266
+ goto tr7;
1267
+ } else if ( (*p) > 57 ) {
993
1268
  if ( (*p) < 65 ) {
994
1269
  if ( 60 <= (*p) && (*p) <= 63 )
995
1270
  goto st0;
996
1271
  } else if ( (*p) > 90 ) {
997
1272
  if ( 97 <= (*p) && (*p) <= 122 )
998
- goto st9;
1273
+ goto tr15;
999
1274
  } else
1000
- goto st9;
1275
+ goto tr15;
1001
1276
  } else
1002
- goto st9;
1277
+ goto st0;
1003
1278
  goto tr6;
1004
1279
  }
1280
+ _test_eof3: cs = 3; goto _test_eof;
1005
1281
  _test_eof4: cs = 4; goto _test_eof;
1006
1282
  _test_eof5: cs = 5; goto _test_eof;
1007
1283
  _test_eof6: cs = 6; goto _test_eof;
1008
- _test_eof7: cs = 7; goto _test_eof;
1009
1284
  _test_eof2: cs = 2; goto _test_eof;
1285
+ _test_eof7: cs = 7; goto _test_eof;
1010
1286
  _test_eof8: cs = 8; goto _test_eof;
1011
- _test_eof3: cs = 3; goto _test_eof;
1012
1287
  _test_eof9: cs = 9; goto _test_eof;
1013
1288
 
1014
1289
  _test_eof: {}
1015
- _out: {}
1290
+ if ( p == eof )
1291
+ {
1292
+ switch ( cs ) {
1293
+ case 3:
1294
+ case 7:
1295
+ case 9:
1296
+ #line 411 "edn_parser.rl"
1297
+ {
1298
+ // stand-alone operators (-, +, /, ... etc)
1299
+ std::string sym;
1300
+ sym += *(p_save);
1301
+ o = Parser::make_edn_symbol(sym);
1302
+ }
1303
+ break;
1304
+ #line 1305 "edn_parser.cc"
1305
+ }
1016
1306
  }
1017
1307
 
1018
- #line 334 "edn_parser.rl"
1308
+ _out: {}
1309
+ }
1019
1310
 
1020
- if (cs >= EDN_symbol_first_final) {
1021
- uint32_t len = p - p_save;
1022
- std::string buf;
1023
- buf.append(p_save, len);
1311
+ #line 434 "edn_parser.rl"
1024
1312
 
1025
- s = buf;
1313
+ if (cs >= EDN_operator_first_final) {
1026
1314
  return p;
1027
1315
  }
1028
- else if (cs == EDN_symbol_error) {
1316
+ else if (cs == EDN_operator_error) {
1029
1317
  error(__FUNCTION__, *p);
1030
1318
  return pe;
1031
1319
  }
1032
- else if (cs == EDN_symbol_en_main) {} // silence ragel warning
1320
+ else if (cs == EDN_operator_en_main) {} // silence ragel warning
1033
1321
  return NULL;
1034
1322
  }
1035
1323
 
1036
1324
 
1037
1325
 
1038
-
1039
1326
  // ============================================================
1040
- // keyword parsing
1327
+ // escaped char parsing - handles \c, \newline, \formfeed, etc.
1041
1328
  //
1042
1329
 
1043
- #line 1044 "edn_parser.cc"
1044
- static const int EDN_keyword_start = 1;
1045
- static const int EDN_keyword_first_final = 3;
1046
- static const int EDN_keyword_error = 0;
1330
+ #line 1331 "edn_parser.cc"
1331
+ static const int EDN_escaped_char_start = 1;
1332
+ static const int EDN_escaped_char_first_final = 4;
1333
+ static const int EDN_escaped_char_error = 0;
1047
1334
 
1048
- static const int EDN_keyword_en_main = 1;
1335
+ static const int EDN_escaped_char_en_main = 1;
1049
1336
 
1050
1337
 
1051
- #line 371 "edn_parser.rl"
1338
+ #line 463 "edn_parser.rl"
1052
1339
 
1053
1340
 
1054
1341
 
1055
- const char* edn::Parser::parse_keyword(const char *p, const char *pe, Rice::Object& o)
1342
+ const char* edn::Parser::parse_esc_char(const char *p, const char *pe, Rice::Object& o)
1056
1343
  {
1057
1344
  int cs;
1058
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
1059
1345
 
1060
1346
 
1061
- #line 1062 "edn_parser.cc"
1347
+ #line 1348 "edn_parser.cc"
1062
1348
  {
1063
- cs = EDN_keyword_start;
1349
+ cs = EDN_escaped_char_start;
1064
1350
  }
1065
1351
 
1066
- #line 380 "edn_parser.rl"
1352
+ #line 471 "edn_parser.rl"
1067
1353
  p_save = p;
1068
1354
 
1069
- #line 1070 "edn_parser.cc"
1355
+ #line 1356 "edn_parser.cc"
1070
1356
  {
1071
1357
  if ( p == pe )
1072
1358
  goto _test_eof;
1073
1359
  switch ( cs )
1074
1360
  {
1075
1361
  case 1:
1076
- if ( (*p) == 58 )
1362
+ if ( (*p) == 92 )
1077
1363
  goto st2;
1078
1364
  goto st0;
1079
1365
  st0:
@@ -1083,134 +1369,188 @@ st2:
1083
1369
  if ( ++p == pe )
1084
1370
  goto _test_eof2;
1085
1371
  case 2:
1086
- if ( (*p) == 35 )
1087
- goto st3;
1372
+ if ( (*p) > 90 ) {
1373
+ if ( 97 <= (*p) && (*p) <= 122 )
1374
+ goto st4;
1375
+ } else if ( (*p) >= 65 )
1376
+ goto st4;
1377
+ goto st0;
1378
+ st4:
1379
+ if ( ++p == pe )
1380
+ goto _test_eof4;
1381
+ case 4:
1382
+ switch( (*p) ) {
1383
+ case 10: goto tr7;
1384
+ case 32: goto tr6;
1385
+ case 44: goto tr6;
1386
+ case 59: goto tr8;
1387
+ case 92: goto st0;
1388
+ }
1389
+ if ( (*p) < 65 ) {
1390
+ if ( 9 <= (*p) && (*p) <= 13 )
1391
+ goto tr6;
1392
+ } else if ( (*p) > 90 ) {
1393
+ if ( 97 <= (*p) && (*p) <= 122 )
1394
+ goto st4;
1395
+ } else
1396
+ goto st4;
1397
+ goto tr5;
1398
+ tr5:
1399
+ #line 61 "edn_parser.rl"
1400
+ { p--; {p++; cs = 5; goto _out;} }
1401
+ goto st5;
1402
+ st5:
1403
+ if ( ++p == pe )
1404
+ goto _test_eof5;
1405
+ case 5:
1406
+ #line 1407 "edn_parser.cc"
1407
+ goto st0;
1408
+ tr4:
1409
+ #line 24 "edn_parser.rl"
1410
+ { line_number++; }
1411
+ goto st6;
1412
+ tr6:
1413
+ #line 61 "edn_parser.rl"
1414
+ { p--; {p++; cs = 6; goto _out;} }
1415
+ goto st6;
1416
+ tr7:
1417
+ #line 24 "edn_parser.rl"
1418
+ { line_number++; }
1419
+ #line 61 "edn_parser.rl"
1420
+ { p--; {p++; cs = 6; goto _out;} }
1421
+ goto st6;
1422
+ st6:
1423
+ if ( ++p == pe )
1424
+ goto _test_eof6;
1425
+ case 6:
1426
+ #line 1427 "edn_parser.cc"
1427
+ switch( (*p) ) {
1428
+ case 10: goto tr7;
1429
+ case 32: goto tr6;
1430
+ case 44: goto tr6;
1431
+ case 59: goto tr8;
1432
+ case 92: goto st0;
1433
+ }
1088
1434
  if ( (*p) < 65 ) {
1089
- if ( 46 <= (*p) && (*p) <= 47 )
1090
- goto st3;
1435
+ if ( 9 <= (*p) && (*p) <= 13 )
1436
+ goto tr6;
1091
1437
  } else if ( (*p) > 90 ) {
1092
1438
  if ( 97 <= (*p) && (*p) <= 122 )
1093
- goto st3;
1439
+ goto st0;
1094
1440
  } else
1095
- goto st3;
1096
- goto st0;
1441
+ goto st0;
1442
+ goto tr5;
1443
+ tr8:
1444
+ #line 61 "edn_parser.rl"
1445
+ { p--; {p++; cs = 7; goto _out;} }
1446
+ goto st7;
1447
+ st7:
1448
+ if ( ++p == pe )
1449
+ goto _test_eof7;
1450
+ case 7:
1451
+ #line 1452 "edn_parser.cc"
1452
+ if ( (*p) == 10 )
1453
+ goto tr4;
1454
+ goto st3;
1097
1455
  st3:
1098
1456
  if ( ++p == pe )
1099
1457
  goto _test_eof3;
1100
1458
  case 3:
1101
- switch( (*p) ) {
1102
- case 33: goto st3;
1103
- case 95: goto st3;
1104
- }
1105
- if ( (*p) < 45 ) {
1106
- if ( (*p) > 38 ) {
1107
- if ( 42 <= (*p) && (*p) <= 43 )
1108
- goto st3;
1109
- } else if ( (*p) >= 35 )
1110
- goto st3;
1111
- } else if ( (*p) > 58 ) {
1112
- if ( (*p) < 65 ) {
1113
- if ( 60 <= (*p) && (*p) <= 63 )
1114
- goto st3;
1115
- } else if ( (*p) > 90 ) {
1116
- if ( 97 <= (*p) && (*p) <= 122 )
1117
- goto st3;
1118
- } else
1119
- goto st3;
1120
- } else
1121
- goto st3;
1122
- goto tr3;
1123
- tr3:
1124
- #line 368 "edn_parser.rl"
1125
- { p--; {p++; cs = 4; goto _out;} }
1126
- goto st4;
1127
- st4:
1128
- if ( ++p == pe )
1129
- goto _test_eof4;
1130
- case 4:
1131
- #line 1132 "edn_parser.cc"
1132
- goto st0;
1459
+ if ( (*p) == 10 )
1460
+ goto tr4;
1461
+ goto st3;
1133
1462
  }
1134
1463
  _test_eof2: cs = 2; goto _test_eof;
1135
- _test_eof3: cs = 3; goto _test_eof;
1136
1464
  _test_eof4: cs = 4; goto _test_eof;
1465
+ _test_eof5: cs = 5; goto _test_eof;
1466
+ _test_eof6: cs = 6; goto _test_eof;
1467
+ _test_eof7: cs = 7; goto _test_eof;
1468
+ _test_eof3: cs = 3; goto _test_eof;
1137
1469
 
1138
1470
  _test_eof: {}
1139
1471
  _out: {}
1140
1472
  }
1141
1473
 
1142
- #line 382 "edn_parser.rl"
1474
+ #line 473 "edn_parser.rl"
1143
1475
 
1144
- if (cs >= EDN_keyword_first_final) {
1145
- uint32_t len = p - p_save - 1; // don't include leading ':' because Rice::Symbol will handle it
1146
- std::string buf;
1147
- buf.append(p_save + 1, len);
1148
- o = Rice::Symbol(buf);
1476
+ if (cs >= EDN_escaped_char_first_final) {
1477
+ // convert the escaped value to a character
1478
+ if (!Parser::parse_escaped_char(p_save + 1, p, o)) {
1479
+ return pe;
1480
+ }
1149
1481
  return p;
1150
1482
  }
1151
- else if (cs == EDN_keyword_error) {
1483
+ else if (cs == EDN_escaped_char_error) {
1152
1484
  error(__FUNCTION__, *p);
1153
1485
  return pe;
1154
1486
  }
1155
- else if (cs == EDN_keyword_en_main) {} // silence ragel warning
1487
+ else if (cs == EDN_escaped_char_en_main) {} // silence ragel warning
1156
1488
  return NULL;
1157
1489
  }
1158
1490
 
1159
1491
 
1160
1492
 
1493
+
1161
1494
  // ============================================================
1162
- // string parsing
1495
+ // symbol parsing - handles identifiers that begin with an alpha
1496
+ // character and an optional leading operator (name, -today,
1497
+ // .yesterday)
1163
1498
  //
1164
1499
 
1165
- #line 1166 "edn_parser.cc"
1166
- static const int EDN_string_start = 1;
1167
- static const int EDN_string_first_final = 8;
1168
- static const int EDN_string_error = 0;
1500
+ #line 1501 "edn_parser.cc"
1501
+ static const int EDN_symbol_start = 1;
1502
+ static const int EDN_symbol_first_final = 5;
1503
+ static const int EDN_symbol_error = 0;
1169
1504
 
1170
- static const int EDN_string_en_main = 1;
1505
+ static const int EDN_symbol_en_main = 1;
1171
1506
 
1172
1507
 
1173
- #line 426 "edn_parser.rl"
1508
+ #line 507 "edn_parser.rl"
1174
1509
 
1175
1510
 
1176
1511
 
1177
- const char* edn::Parser::parse_string(const char *p, const char *pe, Rice::Object& o)
1512
+ const char* edn::Parser::parse_symbol(const char *p, const char *pe, std::string& sym)
1178
1513
  {
1179
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
1180
- static const char* EDN_TYPE = "string";
1181
1514
  int cs;
1182
- const char *eof = pe;
1183
1515
 
1184
- Rice::String s;
1185
1516
 
1186
- #line 1187 "edn_parser.cc"
1517
+ #line 1518 "edn_parser.cc"
1187
1518
  {
1188
- cs = EDN_string_start;
1519
+ cs = EDN_symbol_start;
1189
1520
  }
1190
1521
 
1191
- #line 438 "edn_parser.rl"
1522
+ #line 515 "edn_parser.rl"
1192
1523
  p_save = p;
1193
1524
 
1194
- #line 1195 "edn_parser.cc"
1525
+ #line 1526 "edn_parser.cc"
1195
1526
  {
1196
1527
  if ( p == pe )
1197
1528
  goto _test_eof;
1198
1529
  switch ( cs )
1199
1530
  {
1200
1531
  case 1:
1201
- if ( (*p) == 34 )
1532
+ switch( (*p) ) {
1533
+ case 33: goto st2;
1534
+ case 95: goto st2;
1535
+ }
1536
+ if ( (*p) < 45 ) {
1537
+ if ( (*p) > 38 ) {
1538
+ if ( 42 <= (*p) && (*p) <= 43 )
1539
+ goto st2;
1540
+ } else if ( (*p) >= 36 )
1541
+ goto st2;
1542
+ } else if ( (*p) > 47 ) {
1543
+ if ( (*p) < 65 ) {
1544
+ if ( 60 <= (*p) && (*p) <= 63 )
1545
+ goto st2;
1546
+ } else if ( (*p) > 90 ) {
1547
+ if ( 97 <= (*p) && (*p) <= 122 )
1548
+ goto st5;
1549
+ } else
1550
+ goto st5;
1551
+ } else
1202
1552
  goto st2;
1203
1553
  goto st0;
1204
- tr2:
1205
- #line 55 "edn_parser.rl"
1206
- {
1207
- std::stringstream s;
1208
- s << "unterminated " << EDN_TYPE;
1209
- error(__FUNCTION__, s.str());
1210
- p--; {p++; cs = 0; goto _out;}
1211
- }
1212
- goto st0;
1213
- #line 1214 "edn_parser.cc"
1214
1554
  st0:
1215
1555
  cs = 0;
1216
1556
  goto _out;
@@ -1218,535 +1558,599 @@ st2:
1218
1558
  if ( ++p == pe )
1219
1559
  goto _test_eof2;
1220
1560
  case 2:
1221
- switch( (*p) ) {
1222
- case 34: goto tr3;
1223
- case 92: goto st3;
1224
- }
1225
- if ( 0 <= (*p) && (*p) <= 31 )
1226
- goto tr2;
1227
- goto st2;
1228
- tr3:
1229
- #line 409 "edn_parser.rl"
1230
- {
1231
- if (!Parser::parse_byte_stream(p_save + 1, p, s)) {
1232
- p--;
1233
- {p++; cs = 8; goto _out;}
1234
- } else {
1235
- {p = (( p + 1))-1;}
1236
- }
1237
- }
1238
- #line 418 "edn_parser.rl"
1239
- { p--; {p++; cs = 8; goto _out;} }
1240
- goto st8;
1241
- st8:
1242
- if ( ++p == pe )
1243
- goto _test_eof8;
1244
- case 8:
1245
- #line 1246 "edn_parser.cc"
1246
- goto st0;
1247
- st3:
1248
- if ( ++p == pe )
1249
- goto _test_eof3;
1250
- case 3:
1251
- if ( (*p) == 117 )
1252
- goto st4;
1253
- if ( 0 <= (*p) && (*p) <= 31 )
1254
- goto st0;
1255
- goto st2;
1256
- st4:
1257
- if ( ++p == pe )
1258
- goto _test_eof4;
1259
- case 4:
1260
- if ( (*p) < 65 ) {
1261
- if ( 48 <= (*p) && (*p) <= 57 )
1262
- goto st5;
1263
- } else if ( (*p) > 70 ) {
1264
- if ( 97 <= (*p) && (*p) <= 102 )
1561
+ if ( (*p) > 90 ) {
1562
+ if ( 97 <= (*p) && (*p) <= 122 )
1265
1563
  goto st5;
1266
- } else
1564
+ } else if ( (*p) >= 65 )
1267
1565
  goto st5;
1268
1566
  goto st0;
1269
1567
  st5:
1270
1568
  if ( ++p == pe )
1271
1569
  goto _test_eof5;
1272
1570
  case 5:
1273
- if ( (*p) < 65 ) {
1274
- if ( 48 <= (*p) && (*p) <= 57 )
1275
- goto st6;
1276
- } else if ( (*p) > 70 ) {
1277
- if ( 97 <= (*p) && (*p) <= 102 )
1278
- goto st6;
1571
+ switch( (*p) ) {
1572
+ case 10: goto tr8;
1573
+ case 32: goto tr7;
1574
+ case 33: goto st0;
1575
+ case 35: goto st5;
1576
+ case 44: goto tr7;
1577
+ case 47: goto st4;
1578
+ case 59: goto tr10;
1579
+ case 95: goto st5;
1580
+ }
1581
+ if ( (*p) < 45 ) {
1582
+ if ( (*p) < 36 ) {
1583
+ if ( 9 <= (*p) && (*p) <= 13 )
1584
+ goto tr7;
1585
+ } else if ( (*p) > 38 ) {
1586
+ if ( 42 <= (*p) && (*p) <= 43 )
1587
+ goto st0;
1588
+ } else
1589
+ goto st0;
1590
+ } else if ( (*p) > 58 ) {
1591
+ if ( (*p) < 65 ) {
1592
+ if ( 60 <= (*p) && (*p) <= 63 )
1593
+ goto st0;
1594
+ } else if ( (*p) > 90 ) {
1595
+ if ( 97 <= (*p) && (*p) <= 122 )
1596
+ goto st5;
1597
+ } else
1598
+ goto st5;
1279
1599
  } else
1280
- goto st6;
1281
- goto st0;
1600
+ goto st5;
1601
+ goto tr6;
1602
+ tr6:
1603
+ #line 61 "edn_parser.rl"
1604
+ { p--; {p++; cs = 6; goto _out;} }
1605
+ goto st6;
1282
1606
  st6:
1283
1607
  if ( ++p == pe )
1284
1608
  goto _test_eof6;
1285
1609
  case 6:
1286
- if ( (*p) < 65 ) {
1287
- if ( 48 <= (*p) && (*p) <= 57 )
1288
- goto st7;
1289
- } else if ( (*p) > 70 ) {
1290
- if ( 97 <= (*p) && (*p) <= 102 )
1291
- goto st7;
1610
+ #line 1611 "edn_parser.cc"
1611
+ goto st0;
1612
+ tr4:
1613
+ #line 24 "edn_parser.rl"
1614
+ { line_number++; }
1615
+ goto st7;
1616
+ tr7:
1617
+ #line 61 "edn_parser.rl"
1618
+ { p--; {p++; cs = 7; goto _out;} }
1619
+ goto st7;
1620
+ tr8:
1621
+ #line 24 "edn_parser.rl"
1622
+ { line_number++; }
1623
+ #line 61 "edn_parser.rl"
1624
+ { p--; {p++; cs = 7; goto _out;} }
1625
+ goto st7;
1626
+ st7:
1627
+ if ( ++p == pe )
1628
+ goto _test_eof7;
1629
+ case 7:
1630
+ #line 1631 "edn_parser.cc"
1631
+ switch( (*p) ) {
1632
+ case 10: goto tr8;
1633
+ case 32: goto tr7;
1634
+ case 33: goto st0;
1635
+ case 44: goto tr7;
1636
+ case 59: goto tr10;
1637
+ case 95: goto st0;
1638
+ }
1639
+ if ( (*p) < 42 ) {
1640
+ if ( (*p) > 13 ) {
1641
+ if ( 35 <= (*p) && (*p) <= 38 )
1642
+ goto st0;
1643
+ } else if ( (*p) >= 9 )
1644
+ goto tr7;
1645
+ } else if ( (*p) > 63 ) {
1646
+ if ( (*p) > 90 ) {
1647
+ if ( 97 <= (*p) && (*p) <= 122 )
1648
+ goto st0;
1649
+ } else if ( (*p) >= 65 )
1650
+ goto st0;
1292
1651
  } else
1293
- goto st7;
1652
+ goto st0;
1653
+ goto tr6;
1654
+ tr10:
1655
+ #line 61 "edn_parser.rl"
1656
+ { p--; {p++; cs = 8; goto _out;} }
1657
+ goto st8;
1658
+ st8:
1659
+ if ( ++p == pe )
1660
+ goto _test_eof8;
1661
+ case 8:
1662
+ #line 1663 "edn_parser.cc"
1663
+ if ( (*p) == 10 )
1664
+ goto tr4;
1665
+ goto st3;
1666
+ st3:
1667
+ if ( ++p == pe )
1668
+ goto _test_eof3;
1669
+ case 3:
1670
+ if ( (*p) == 10 )
1671
+ goto tr4;
1672
+ goto st3;
1673
+ st4:
1674
+ if ( ++p == pe )
1675
+ goto _test_eof4;
1676
+ case 4:
1677
+ if ( (*p) > 90 ) {
1678
+ if ( 97 <= (*p) && (*p) <= 122 )
1679
+ goto st9;
1680
+ } else if ( (*p) >= 65 )
1681
+ goto st9;
1294
1682
  goto st0;
1295
- st7:
1683
+ st9:
1296
1684
  if ( ++p == pe )
1297
- goto _test_eof7;
1298
- case 7:
1299
- if ( (*p) < 65 ) {
1300
- if ( 48 <= (*p) && (*p) <= 57 )
1301
- goto st2;
1302
- } else if ( (*p) > 70 ) {
1303
- if ( 97 <= (*p) && (*p) <= 102 )
1304
- goto st2;
1685
+ goto _test_eof9;
1686
+ case 9:
1687
+ switch( (*p) ) {
1688
+ case 10: goto tr8;
1689
+ case 32: goto tr7;
1690
+ case 33: goto st0;
1691
+ case 35: goto st9;
1692
+ case 44: goto tr7;
1693
+ case 47: goto st0;
1694
+ case 59: goto tr10;
1695
+ case 95: goto st9;
1696
+ }
1697
+ if ( (*p) < 45 ) {
1698
+ if ( (*p) < 36 ) {
1699
+ if ( 9 <= (*p) && (*p) <= 13 )
1700
+ goto tr7;
1701
+ } else if ( (*p) > 38 ) {
1702
+ if ( 42 <= (*p) && (*p) <= 43 )
1703
+ goto st0;
1704
+ } else
1705
+ goto st0;
1706
+ } else if ( (*p) > 58 ) {
1707
+ if ( (*p) < 65 ) {
1708
+ if ( 60 <= (*p) && (*p) <= 63 )
1709
+ goto st0;
1710
+ } else if ( (*p) > 90 ) {
1711
+ if ( 97 <= (*p) && (*p) <= 122 )
1712
+ goto st9;
1713
+ } else
1714
+ goto st9;
1305
1715
  } else
1306
- goto st2;
1307
- goto st0;
1716
+ goto st9;
1717
+ goto tr6;
1308
1718
  }
1309
1719
  _test_eof2: cs = 2; goto _test_eof;
1310
- _test_eof8: cs = 8; goto _test_eof;
1311
- _test_eof3: cs = 3; goto _test_eof;
1312
- _test_eof4: cs = 4; goto _test_eof;
1313
1720
  _test_eof5: cs = 5; goto _test_eof;
1314
1721
  _test_eof6: cs = 6; goto _test_eof;
1315
1722
  _test_eof7: cs = 7; goto _test_eof;
1723
+ _test_eof8: cs = 8; goto _test_eof;
1724
+ _test_eof3: cs = 3; goto _test_eof;
1725
+ _test_eof4: cs = 4; goto _test_eof;
1726
+ _test_eof9: cs = 9; goto _test_eof;
1316
1727
 
1317
1728
  _test_eof: {}
1318
- if ( p == eof )
1319
- {
1320
- switch ( cs ) {
1321
- case 2:
1322
- #line 55 "edn_parser.rl"
1323
- {
1324
- std::stringstream s;
1325
- s << "unterminated " << EDN_TYPE;
1326
- error(__FUNCTION__, s.str());
1327
- p--; {p++; cs = 0; goto _out;}
1328
- }
1329
- break;
1330
- #line 1331 "edn_parser.cc"
1331
- }
1332
- }
1333
-
1334
1729
  _out: {}
1335
1730
  }
1336
1731
 
1337
- #line 440 "edn_parser.rl"
1732
+ #line 517 "edn_parser.rl"
1338
1733
 
1339
- if (cs >= EDN_string_first_final) {
1340
- o = s;
1341
- return p + 1;
1734
+ if (cs >= EDN_symbol_first_final) {
1735
+ // copy the symbol text
1736
+ sym.clear();
1737
+ sym.append(p_save, p - p_save);
1738
+ return p;
1342
1739
  }
1343
- else if (cs == EDN_string_error) {
1740
+ else if (cs == EDN_symbol_error) {
1741
+ error(__FUNCTION__, *p);
1344
1742
  return pe;
1345
1743
  }
1346
- else if (cs == EDN_string_en_main) {} // silence ragel warning
1744
+ else if (cs == EDN_symbol_en_main) {} // silence ragel warning
1347
1745
  return NULL;
1348
1746
  }
1349
1747
 
1748
+
1749
+
1350
1750
  // ============================================================
1351
- // decimal parsing grammar
1751
+ // EDN_sequence_common is used to parse EDN containers - elements are
1752
+ // initially stored in a rice array and then the final corresponding
1753
+ // container is built from the list (although, for vectors, lists, and
1754
+ // sets the same array is used)
1352
1755
  //
1353
1756
 
1354
- #line 1355 "edn_parser.cc"
1355
- static const int EDN_decimal_start = 1;
1356
- static const int EDN_decimal_first_final = 9;
1757
+ #line 572 "edn_parser.rl"
1357
1758
 
1358
- static const int EDN_decimal_en_main = 1;
1759
+
1760
+ //
1761
+ // vector-specific machine
1762
+
1763
+ #line 1764 "edn_parser.cc"
1764
+ static const int EDN_vector_start = 1;
1765
+ static const int EDN_vector_first_final = 4;
1766
+ static const int EDN_vector_error = 0;
1767
+
1768
+ static const int EDN_vector_en_main = 1;
1359
1769
 
1360
1770
 
1361
- #line 467 "edn_parser.rl"
1771
+ #line 588 "edn_parser.rl"
1362
1772
 
1363
1773
 
1364
1774
 
1365
- const char* edn::Parser::parse_decimal(const char *p, const char *pe, Rice::Object& o)
1775
+ //
1776
+ // vector parsing
1777
+ //
1778
+ const char* edn::Parser::parse_vector(const char *p, const char *pe, Rice::Object& o)
1366
1779
  {
1780
+ static const char* EDN_TYPE = "vector";
1781
+
1367
1782
  int cs;
1783
+ Rice::Array elems; // will store the vector's elements
1368
1784
 
1369
1785
 
1370
- #line 1371 "edn_parser.cc"
1786
+ #line 1787 "edn_parser.cc"
1371
1787
  {
1372
- cs = EDN_decimal_start;
1788
+ cs = EDN_vector_start;
1373
1789
  }
1374
1790
 
1375
- #line 475 "edn_parser.rl"
1376
- p_save = p;
1791
+ #line 602 "edn_parser.rl"
1377
1792
 
1378
- #line 1379 "edn_parser.cc"
1793
+ #line 1794 "edn_parser.cc"
1379
1794
  {
1380
1795
  if ( p == pe )
1381
1796
  goto _test_eof;
1382
1797
  switch ( cs )
1383
1798
  {
1384
1799
  case 1:
1385
- switch( (*p) ) {
1386
- case 43: goto st2;
1387
- case 45: goto st2;
1388
- case 48: goto st3;
1389
- }
1390
- if ( 49 <= (*p) && (*p) <= 57 )
1391
- goto st8;
1800
+ if ( (*p) == 91 )
1801
+ goto st2;
1802
+ goto st0;
1803
+ tr2:
1804
+ #line 54 "edn_parser.rl"
1805
+ {
1806
+ std::stringstream s;
1807
+ s << "unterminated " << EDN_TYPE;
1808
+ error(__FUNCTION__, s.str());
1809
+ p--; {p++; cs = 0; goto _out;}
1810
+ }
1392
1811
  goto st0;
1812
+ #line 1813 "edn_parser.cc"
1393
1813
  st0:
1394
1814
  cs = 0;
1395
1815
  goto _out;
1816
+ tr3:
1817
+ #line 24 "edn_parser.rl"
1818
+ { line_number++; }
1819
+ goto st2;
1820
+ tr4:
1821
+ #line 544 "edn_parser.rl"
1822
+ {
1823
+ // reads an item within a sequence (vector, list, map, or
1824
+ // set). Regardless of the sequence type, an array of the
1825
+ // items is built. Once done, the sequence parser will convert
1826
+ // if needed
1827
+ Rice::Object e;
1828
+ const char *np = parse_value(p, pe, e);
1829
+ if (np == NULL) {
1830
+ p--; {p++; cs = 2; goto _out;}
1831
+ } else {
1832
+ // if there's an entry in the discard list, the current
1833
+ // object is not meant to be kept due to a #_ so don't
1834
+ // push it into the list of elements
1835
+ if (!discard.empty()) {
1836
+ discard.pop();
1837
+ }
1838
+ else {
1839
+ // otherwise we add it to the list of elements for the
1840
+ // corresponding container
1841
+ elems.push(e);
1842
+ }
1843
+ {p = (( np))-1;}
1844
+ }
1845
+ }
1846
+ goto st2;
1396
1847
  st2:
1397
1848
  if ( ++p == pe )
1398
- goto _test_eof2;
1399
- case 2:
1400
- if ( (*p) == 48 )
1401
- goto st3;
1402
- if ( 49 <= (*p) && (*p) <= 57 )
1403
- goto st8;
1404
- goto st0;
1405
- st3:
1406
- if ( ++p == pe )
1407
- goto _test_eof3;
1408
- case 3:
1409
- switch( (*p) ) {
1410
- case 46: goto st9;
1411
- case 69: goto st6;
1412
- case 101: goto st6;
1413
- }
1414
- goto st0;
1415
- st9:
1416
- if ( ++p == pe )
1417
- goto _test_eof9;
1418
- case 9:
1419
- switch( (*p) ) {
1420
- case 43: goto st0;
1421
- case 69: goto st4;
1422
- case 77: goto st12;
1423
- case 101: goto st4;
1424
- }
1425
- if ( (*p) > 46 ) {
1426
- if ( 48 <= (*p) && (*p) <= 57 )
1427
- goto st9;
1428
- } else if ( (*p) >= 45 )
1429
- goto st0;
1430
- goto tr10;
1431
- tr10:
1432
- #line 461 "edn_parser.rl"
1433
- { p--; {p++; cs = 10; goto _out;} }
1434
- goto st10;
1435
- st10:
1436
- if ( ++p == pe )
1437
- goto _test_eof10;
1438
- case 10:
1439
- #line 1440 "edn_parser.cc"
1440
- goto st0;
1441
- st4:
1442
- if ( ++p == pe )
1443
- goto _test_eof4;
1444
- case 4:
1445
- switch( (*p) ) {
1446
- case 43: goto st5;
1447
- case 45: goto st5;
1448
- }
1449
- if ( 48 <= (*p) && (*p) <= 57 )
1450
- goto st11;
1451
- goto st0;
1452
- st5:
1453
- if ( ++p == pe )
1454
- goto _test_eof5;
1455
- case 5:
1456
- if ( 48 <= (*p) && (*p) <= 57 )
1457
- goto st11;
1458
- goto st0;
1459
- st11:
1460
- if ( ++p == pe )
1461
- goto _test_eof11;
1462
- case 11:
1463
- switch( (*p) ) {
1464
- case 43: goto st0;
1465
- case 69: goto st0;
1466
- case 77: goto st12;
1467
- case 101: goto st0;
1468
- }
1469
- if ( (*p) > 46 ) {
1470
- if ( 48 <= (*p) && (*p) <= 57 )
1471
- goto st11;
1472
- } else if ( (*p) >= 45 )
1473
- goto st0;
1474
- goto tr10;
1475
- st12:
1476
- if ( ++p == pe )
1477
- goto _test_eof12;
1478
- case 12:
1479
- switch( (*p) ) {
1480
- case 43: goto st0;
1481
- case 69: goto st0;
1482
- case 77: goto st0;
1483
- case 101: goto st0;
1484
- }
1485
- if ( (*p) > 46 ) {
1486
- if ( 48 <= (*p) && (*p) <= 57 )
1487
- goto st0;
1488
- } else if ( (*p) >= 45 )
1489
- goto st0;
1490
- goto tr10;
1491
- st6:
1492
- if ( ++p == pe )
1493
- goto _test_eof6;
1494
- case 6:
1495
- switch( (*p) ) {
1496
- case 43: goto st7;
1497
- case 45: goto st7;
1498
- }
1499
- if ( 48 <= (*p) && (*p) <= 57 )
1500
- goto st13;
1501
- goto st0;
1502
- st7:
1503
- if ( ++p == pe )
1504
- goto _test_eof7;
1505
- case 7:
1506
- if ( 48 <= (*p) && (*p) <= 57 )
1507
- goto st13;
1508
- goto st0;
1509
- st13:
1510
- if ( ++p == pe )
1511
- goto _test_eof13;
1512
- case 13:
1849
+ goto _test_eof2;
1850
+ case 2:
1851
+ #line 1852 "edn_parser.cc"
1513
1852
  switch( (*p) ) {
1514
- case 43: goto st0;
1515
- case 69: goto st0;
1516
- case 77: goto st0;
1517
- case 101: goto st0;
1853
+ case 10: goto tr3;
1854
+ case 32: goto st2;
1855
+ case 40: goto tr4;
1856
+ case 44: goto st2;
1857
+ case 59: goto st3;
1858
+ case 93: goto tr6;
1859
+ case 95: goto tr4;
1518
1860
  }
1519
- if ( (*p) > 46 ) {
1520
- if ( 48 <= (*p) && (*p) <= 57 )
1521
- goto st13;
1522
- } else if ( (*p) >= 45 )
1523
- goto st0;
1524
- goto tr10;
1525
- st8:
1861
+ if ( (*p) < 42 ) {
1862
+ if ( (*p) > 13 ) {
1863
+ if ( 33 <= (*p) && (*p) <= 38 )
1864
+ goto tr4;
1865
+ } else if ( (*p) >= 9 )
1866
+ goto st2;
1867
+ } else if ( (*p) > 63 ) {
1868
+ if ( (*p) > 92 ) {
1869
+ if ( 97 <= (*p) && (*p) <= 123 )
1870
+ goto tr4;
1871
+ } else if ( (*p) >= 65 )
1872
+ goto tr4;
1873
+ } else
1874
+ goto tr4;
1875
+ goto tr2;
1876
+ st3:
1526
1877
  if ( ++p == pe )
1527
- goto _test_eof8;
1528
- case 8:
1529
- switch( (*p) ) {
1530
- case 46: goto st9;
1531
- case 69: goto st6;
1532
- case 101: goto st6;
1533
- }
1534
- if ( 48 <= (*p) && (*p) <= 57 )
1535
- goto st8;
1878
+ goto _test_eof3;
1879
+ case 3:
1880
+ if ( (*p) == 10 )
1881
+ goto tr3;
1882
+ goto st3;
1883
+ tr6:
1884
+ #line 61 "edn_parser.rl"
1885
+ { p--; {p++; cs = 4; goto _out;} }
1886
+ goto st4;
1887
+ st4:
1888
+ if ( ++p == pe )
1889
+ goto _test_eof4;
1890
+ case 4:
1891
+ #line 1892 "edn_parser.cc"
1536
1892
  goto st0;
1537
1893
  }
1538
1894
  _test_eof2: cs = 2; goto _test_eof;
1539
1895
  _test_eof3: cs = 3; goto _test_eof;
1540
- _test_eof9: cs = 9; goto _test_eof;
1541
- _test_eof10: cs = 10; goto _test_eof;
1542
1896
  _test_eof4: cs = 4; goto _test_eof;
1543
- _test_eof5: cs = 5; goto _test_eof;
1544
- _test_eof11: cs = 11; goto _test_eof;
1545
- _test_eof12: cs = 12; goto _test_eof;
1546
- _test_eof6: cs = 6; goto _test_eof;
1547
- _test_eof7: cs = 7; goto _test_eof;
1548
- _test_eof13: cs = 13; goto _test_eof;
1549
- _test_eof8: cs = 8; goto _test_eof;
1550
1897
 
1551
1898
  _test_eof: {}
1899
+ if ( p == eof )
1900
+ {
1901
+ switch ( cs ) {
1902
+ case 2:
1903
+ case 3:
1904
+ #line 54 "edn_parser.rl"
1905
+ {
1906
+ std::stringstream s;
1907
+ s << "unterminated " << EDN_TYPE;
1908
+ error(__FUNCTION__, s.str());
1909
+ p--; {p++; cs = 0; goto _out;}
1910
+ }
1911
+ break;
1912
+ #line 1913 "edn_parser.cc"
1913
+ }
1914
+ }
1915
+
1552
1916
  _out: {}
1553
1917
  }
1554
1918
 
1555
- #line 477 "edn_parser.rl"
1919
+ #line 603 "edn_parser.rl"
1556
1920
 
1557
- if (cs >= EDN_decimal_first_final) {
1558
- o = Parser::float_to_ruby(p_save, p - p_save);
1921
+ if (cs >= EDN_vector_first_final) {
1922
+ o = elems;
1559
1923
  return p + 1;
1560
1924
  }
1561
- else if (cs == EDN_decimal_en_main) {} // silence ragel warning
1925
+ else if (cs == EDN_vector_error) {
1926
+ error(__FUNCTION__, *p);
1927
+ return pe;
1928
+ }
1929
+ else if (cs == EDN_vector_en_main) {} // silence ragel warning
1562
1930
  return NULL;
1563
1931
  }
1564
1932
 
1565
1933
 
1934
+
1566
1935
  // ============================================================
1567
- // integer parsing grammar
1936
+ // list parsing machine
1568
1937
  //
1569
1938
 
1570
- #line 1571 "edn_parser.cc"
1571
- static const int EDN_integer_start = 1;
1572
- static const int EDN_integer_first_final = 3;
1939
+ #line 1940 "edn_parser.cc"
1940
+ static const int EDN_list_start = 1;
1941
+ static const int EDN_list_first_final = 4;
1942
+ static const int EDN_list_error = 0;
1573
1943
 
1574
- static const int EDN_integer_en_main = 1;
1944
+ static const int EDN_list_en_main = 1;
1575
1945
 
1576
1946
 
1577
- #line 501 "edn_parser.rl"
1947
+ #line 632 "edn_parser.rl"
1578
1948
 
1579
1949
 
1580
- const char* edn::Parser::parse_integer(const char *p, const char *pe, Rice::Object& o)
1950
+ //
1951
+ // list parsing
1952
+ //
1953
+ const char* edn::Parser::parse_list(const char *p, const char *pe, Rice::Object& o)
1581
1954
  {
1955
+ static const char* EDN_TYPE = "list";
1956
+
1582
1957
  int cs;
1958
+ Rice::Array elems;
1583
1959
 
1584
1960
 
1585
- #line 1586 "edn_parser.cc"
1961
+ #line 1962 "edn_parser.cc"
1586
1962
  {
1587
- cs = EDN_integer_start;
1963
+ cs = EDN_list_start;
1588
1964
  }
1589
1965
 
1590
- #line 508 "edn_parser.rl"
1591
- p_save = p;
1966
+ #line 645 "edn_parser.rl"
1592
1967
 
1593
- #line 1594 "edn_parser.cc"
1968
+ #line 1969 "edn_parser.cc"
1594
1969
  {
1595
1970
  if ( p == pe )
1596
1971
  goto _test_eof;
1597
1972
  switch ( cs )
1598
1973
  {
1599
1974
  case 1:
1600
- switch( (*p) ) {
1601
- case 43: goto st2;
1602
- case 45: goto st2;
1603
- case 48: goto st3;
1604
- }
1605
- if ( 49 <= (*p) && (*p) <= 57 )
1606
- goto st6;
1975
+ if ( (*p) == 40 )
1976
+ goto st2;
1977
+ goto st0;
1978
+ tr2:
1979
+ #line 54 "edn_parser.rl"
1980
+ {
1981
+ std::stringstream s;
1982
+ s << "unterminated " << EDN_TYPE;
1983
+ error(__FUNCTION__, s.str());
1984
+ p--; {p++; cs = 0; goto _out;}
1985
+ }
1607
1986
  goto st0;
1987
+ #line 1988 "edn_parser.cc"
1608
1988
  st0:
1609
1989
  cs = 0;
1610
1990
  goto _out;
1991
+ tr3:
1992
+ #line 24 "edn_parser.rl"
1993
+ { line_number++; }
1994
+ goto st2;
1995
+ tr4:
1996
+ #line 544 "edn_parser.rl"
1997
+ {
1998
+ // reads an item within a sequence (vector, list, map, or
1999
+ // set). Regardless of the sequence type, an array of the
2000
+ // items is built. Once done, the sequence parser will convert
2001
+ // if needed
2002
+ Rice::Object e;
2003
+ const char *np = parse_value(p, pe, e);
2004
+ if (np == NULL) {
2005
+ p--; {p++; cs = 2; goto _out;}
2006
+ } else {
2007
+ // if there's an entry in the discard list, the current
2008
+ // object is not meant to be kept due to a #_ so don't
2009
+ // push it into the list of elements
2010
+ if (!discard.empty()) {
2011
+ discard.pop();
2012
+ }
2013
+ else {
2014
+ // otherwise we add it to the list of elements for the
2015
+ // corresponding container
2016
+ elems.push(e);
2017
+ }
2018
+ {p = (( np))-1;}
2019
+ }
2020
+ }
2021
+ goto st2;
1611
2022
  st2:
1612
2023
  if ( ++p == pe )
1613
2024
  goto _test_eof2;
1614
2025
  case 2:
1615
- if ( (*p) == 48 )
1616
- goto st3;
1617
- if ( 49 <= (*p) && (*p) <= 57 )
1618
- goto st6;
1619
- goto st0;
1620
- st3:
1621
- if ( ++p == pe )
1622
- goto _test_eof3;
1623
- case 3:
2026
+ #line 2027 "edn_parser.cc"
1624
2027
  switch( (*p) ) {
1625
- case 43: goto st0;
1626
- case 45: goto st0;
2028
+ case 10: goto tr3;
2029
+ case 32: goto st2;
2030
+ case 41: goto tr5;
2031
+ case 44: goto st2;
2032
+ case 59: goto st3;
2033
+ case 95: goto tr4;
1627
2034
  }
1628
- if ( (*p) > 57 ) {
1629
- if ( 77 <= (*p) && (*p) <= 78 )
1630
- goto st5;
1631
- } else if ( (*p) >= 48 )
1632
- goto st0;
1633
- goto tr4;
1634
- tr4:
1635
- #line 496 "edn_parser.rl"
2035
+ if ( (*p) < 40 ) {
2036
+ if ( (*p) > 13 ) {
2037
+ if ( 33 <= (*p) && (*p) <= 38 )
2038
+ goto tr4;
2039
+ } else if ( (*p) >= 9 )
2040
+ goto st2;
2041
+ } else if ( (*p) > 63 ) {
2042
+ if ( (*p) > 92 ) {
2043
+ if ( 97 <= (*p) && (*p) <= 123 )
2044
+ goto tr4;
2045
+ } else if ( (*p) >= 65 )
2046
+ goto tr4;
2047
+ } else
2048
+ goto tr4;
2049
+ goto tr2;
2050
+ tr5:
2051
+ #line 61 "edn_parser.rl"
1636
2052
  { p--; {p++; cs = 4; goto _out;} }
1637
2053
  goto st4;
1638
2054
  st4:
1639
2055
  if ( ++p == pe )
1640
2056
  goto _test_eof4;
1641
2057
  case 4:
1642
- #line 1643 "edn_parser.cc"
2058
+ #line 2059 "edn_parser.cc"
1643
2059
  goto st0;
1644
- st5:
1645
- if ( ++p == pe )
1646
- goto _test_eof5;
1647
- case 5:
1648
- switch( (*p) ) {
1649
- case 43: goto st0;
1650
- case 45: goto st0;
1651
- }
1652
- if ( (*p) > 57 ) {
1653
- if ( 77 <= (*p) && (*p) <= 78 )
1654
- goto st0;
1655
- } else if ( (*p) >= 48 )
1656
- goto st0;
1657
- goto tr4;
1658
- st6:
2060
+ st3:
1659
2061
  if ( ++p == pe )
1660
- goto _test_eof6;
1661
- case 6:
1662
- switch( (*p) ) {
1663
- case 43: goto st0;
1664
- case 45: goto st0;
1665
- }
1666
- if ( (*p) > 57 ) {
1667
- if ( 77 <= (*p) && (*p) <= 78 )
1668
- goto st5;
1669
- } else if ( (*p) >= 48 )
1670
- goto st6;
1671
- goto tr4;
2062
+ goto _test_eof3;
2063
+ case 3:
2064
+ if ( (*p) == 10 )
2065
+ goto tr3;
2066
+ goto st3;
1672
2067
  }
1673
2068
  _test_eof2: cs = 2; goto _test_eof;
1674
- _test_eof3: cs = 3; goto _test_eof;
1675
2069
  _test_eof4: cs = 4; goto _test_eof;
1676
- _test_eof5: cs = 5; goto _test_eof;
1677
- _test_eof6: cs = 6; goto _test_eof;
2070
+ _test_eof3: cs = 3; goto _test_eof;
1678
2071
 
1679
2072
  _test_eof: {}
2073
+ if ( p == eof )
2074
+ {
2075
+ switch ( cs ) {
2076
+ case 2:
2077
+ case 3:
2078
+ #line 54 "edn_parser.rl"
2079
+ {
2080
+ std::stringstream s;
2081
+ s << "unterminated " << EDN_TYPE;
2082
+ error(__FUNCTION__, s.str());
2083
+ p--; {p++; cs = 0; goto _out;}
2084
+ }
2085
+ break;
2086
+ #line 2087 "edn_parser.cc"
2087
+ }
2088
+ }
2089
+
1680
2090
  _out: {}
1681
2091
  }
1682
2092
 
1683
- #line 510 "edn_parser.rl"
2093
+ #line 646 "edn_parser.rl"
1684
2094
 
1685
- if (cs >= EDN_integer_first_final) {
1686
- o = Parser::integer_to_ruby(p_save, p - p_save);
2095
+ if (cs >= EDN_list_first_final) {
2096
+ o = elems;
1687
2097
  return p + 1;
1688
2098
  }
1689
- else if (cs == EDN_integer_en_main) {} // silence ragel warning
1690
- return NULL;
1691
- }
1692
-
1693
-
1694
- // ============================================================
1695
- // EDN_sequence_common is used to parse EDN containers - elements are
1696
- // initially stored in a rice array and then the final corresponding
1697
- // container is built from the list (although, for vectors, lists, and
1698
- // sets the same array is used)
1699
- //
2099
+ else if (cs == EDN_list_error) {
2100
+ error(__FUNCTION__, *p);
2101
+ return pe;
2102
+ }
2103
+ else if (cs == EDN_list_en_main) {} // silence ragel warning
2104
+ return NULL;
2105
+ }
1700
2106
 
1701
- #line 554 "edn_parser.rl"
1702
2107
 
1703
2108
 
2109
+ // ============================================================
2110
+ // hash parsing
1704
2111
  //
1705
- // vector-specific machine
1706
2112
 
1707
- #line 1708 "edn_parser.cc"
1708
- static const int EDN_vector_start = 1;
1709
- static const int EDN_vector_first_final = 4;
1710
- static const int EDN_vector_error = 0;
2113
+ #line 2114 "edn_parser.cc"
2114
+ static const int EDN_map_start = 1;
2115
+ static const int EDN_map_first_final = 4;
2116
+ static const int EDN_map_error = 0;
1711
2117
 
1712
- static const int EDN_vector_en_main = 1;
2118
+ static const int EDN_map_en_main = 1;
1713
2119
 
1714
2120
 
1715
- #line 570 "edn_parser.rl"
2121
+ #line 676 "edn_parser.rl"
1716
2122
 
1717
2123
 
1718
2124
 
1719
- //
1720
- // vector parsing
1721
- //
1722
- const char* edn::Parser::parse_vector(const char *p, const char *pe, Rice::Object& o)
2125
+ const char* edn::Parser::parse_map(const char *p, const char *pe, Rice::Object& o)
1723
2126
  {
1724
- //std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
1725
- static const char* EDN_TYPE = "vector";
2127
+ static const char* EDN_TYPE = "map";
1726
2128
 
1727
2129
  int cs;
1728
- Rice::Array arr;
2130
+ // since we don't know whether we're looking at a key or value,
2131
+ // initially store all elements in a list
2132
+ Rice::Array elems;
1729
2133
 
1730
2134
 
1731
- #line 1732 "edn_parser.cc"
2135
+ #line 2136 "edn_parser.cc"
1732
2136
  {
1733
- cs = EDN_vector_start;
2137
+ cs = EDN_map_start;
1734
2138
  }
1735
2139
 
1736
- #line 585 "edn_parser.rl"
2140
+ #line 689 "edn_parser.rl"
1737
2141
 
1738
- #line 1739 "edn_parser.cc"
2142
+ #line 2143 "edn_parser.cc"
1739
2143
  {
1740
2144
  if ( p == pe )
1741
2145
  goto _test_eof;
1742
2146
  switch ( cs )
1743
2147
  {
1744
2148
  case 1:
1745
- if ( (*p) == 91 )
2149
+ if ( (*p) == 123 )
1746
2150
  goto st2;
1747
2151
  goto st0;
1748
2152
  tr2:
1749
- #line 55 "edn_parser.rl"
2153
+ #line 54 "edn_parser.rl"
1750
2154
  {
1751
2155
  std::stringstream s;
1752
2156
  s << "unterminated " << EDN_TYPE;
@@ -1754,30 +2158,36 @@ tr2:
1754
2158
  p--; {p++; cs = 0; goto _out;}
1755
2159
  }
1756
2160
  goto st0;
1757
- #line 1758 "edn_parser.cc"
2161
+ #line 2162 "edn_parser.cc"
1758
2162
  st0:
1759
2163
  cs = 0;
1760
2164
  goto _out;
1761
2165
  tr3:
1762
- #line 23 "edn_parser.rl"
2166
+ #line 24 "edn_parser.rl"
1763
2167
  { line_number++; }
1764
2168
  goto st2;
1765
2169
  tr4:
1766
- #line 530 "edn_parser.rl"
1767
- {
1768
- Rice::Object v;
1769
- const char *np = parse_value(p, pe, v);
2170
+ #line 544 "edn_parser.rl"
2171
+ {
2172
+ // reads an item within a sequence (vector, list, map, or
2173
+ // set). Regardless of the sequence type, an array of the
2174
+ // items is built. Once done, the sequence parser will convert
2175
+ // if needed
2176
+ Rice::Object e;
2177
+ const char *np = parse_value(p, pe, e);
1770
2178
  if (np == NULL) {
1771
2179
  p--; {p++; cs = 2; goto _out;}
1772
2180
  } else {
1773
2181
  // if there's an entry in the discard list, the current
1774
- // object is not meant to be kept
2182
+ // object is not meant to be kept due to a #_ so don't
2183
+ // push it into the list of elements
1775
2184
  if (!discard.empty()) {
1776
2185
  discard.pop();
1777
2186
  }
1778
2187
  else {
1779
- // otherwise we add it to the sequence
1780
- arr.push(v);
2188
+ // otherwise we add it to the list of elements for the
2189
+ // corresponding container
2190
+ elems.push(e);
1781
2191
  }
1782
2192
  {p = (( np))-1;}
1783
2193
  }
@@ -1787,15 +2197,15 @@ st2:
1787
2197
  if ( ++p == pe )
1788
2198
  goto _test_eof2;
1789
2199
  case 2:
1790
- #line 1791 "edn_parser.cc"
2200
+ #line 2201 "edn_parser.cc"
1791
2201
  switch( (*p) ) {
1792
2202
  case 10: goto tr3;
1793
2203
  case 32: goto st2;
1794
2204
  case 40: goto tr4;
1795
2205
  case 44: goto st2;
1796
2206
  case 59: goto st3;
1797
- case 93: goto tr6;
1798
2207
  case 95: goto tr4;
2208
+ case 125: goto tr6;
1799
2209
  }
1800
2210
  if ( (*p) < 42 ) {
1801
2211
  if ( (*p) > 13 ) {
@@ -1820,14 +2230,14 @@ case 3:
1820
2230
  goto tr3;
1821
2231
  goto st3;
1822
2232
  tr6:
1823
- #line 553 "edn_parser.rl"
2233
+ #line 61 "edn_parser.rl"
1824
2234
  { p--; {p++; cs = 4; goto _out;} }
1825
2235
  goto st4;
1826
2236
  st4:
1827
2237
  if ( ++p == pe )
1828
2238
  goto _test_eof4;
1829
2239
  case 4:
1830
- #line 1831 "edn_parser.cc"
2240
+ #line 2241 "edn_parser.cc"
1831
2241
  goto st0;
1832
2242
  }
1833
2243
  _test_eof2: cs = 2; goto _test_eof;
@@ -1840,7 +2250,7 @@ case 4:
1840
2250
  switch ( cs ) {
1841
2251
  case 2:
1842
2252
  case 3:
1843
- #line 55 "edn_parser.rl"
2253
+ #line 54 "edn_parser.rl"
1844
2254
  {
1845
2255
  std::stringstream s;
1846
2256
  s << "unterminated " << EDN_TYPE;
@@ -1848,202 +2258,156 @@ case 4:
1848
2258
  p--; {p++; cs = 0; goto _out;}
1849
2259
  }
1850
2260
  break;
1851
- #line 1852 "edn_parser.cc"
2261
+ #line 2262 "edn_parser.cc"
1852
2262
  }
1853
2263
  }
1854
2264
 
1855
2265
  _out: {}
1856
2266
  }
1857
2267
 
1858
- #line 586 "edn_parser.rl"
2268
+ #line 690 "edn_parser.rl"
1859
2269
 
1860
- if (cs >= EDN_vector_first_final) {
1861
- o = arr;
2270
+ if (cs >= EDN_map_first_final) {
2271
+
2272
+ // hash parsing is done. Make sure we have an even count
2273
+ if ((elems.size() % 2) != 0) {
2274
+ error(__FUNCTION__, "odd number of elements in map");
2275
+ return pe;
2276
+ }
2277
+
2278
+ // now convert the sequence to a hash
2279
+ Rice::Hash rslt;
2280
+ while (elems.size())
2281
+ {
2282
+ Rice::Object k = elems.shift();
2283
+ rslt[k] = elems.shift();
2284
+ }
2285
+
2286
+ o = rslt;
1862
2287
  return p + 1;
1863
2288
  }
1864
- else if (cs == EDN_vector_error) {
1865
- error(__FUNCTION__, *p);
2289
+ else if (cs == EDN_map_error) {
1866
2290
  return pe;
1867
2291
  }
1868
- else if (cs == EDN_vector_en_main) {} // silence ragel warning
2292
+ else if (cs == EDN_map_en_main) {} // silence ragel warning
1869
2293
  return NULL;
1870
2294
  }
1871
2295
 
1872
2296
 
1873
2297
 
1874
2298
  // ============================================================
1875
- // list parsing machine
2299
+ // dispatch - handles all tokens with a leading #, then delegates to
2300
+ // the corresponding machine. This machine consumes the # and passes
2301
+ // the remaining data to the correct parser
1876
2302
  //
1877
2303
 
1878
- #line 1879 "edn_parser.cc"
1879
- static const int EDN_list_start = 1;
1880
- static const int EDN_list_first_final = 4;
1881
- static const int EDN_list_error = 0;
2304
+ #line 2305 "edn_parser.cc"
2305
+ static const int EDN_dispatch_start = 1;
2306
+ static const int EDN_dispatch_first_final = 2;
2307
+ static const int EDN_dispatch_error = 0;
1882
2308
 
1883
- static const int EDN_list_en_main = 1;
2309
+ static const int EDN_dispatch_en_main = 1;
1884
2310
 
1885
2311
 
1886
- #line 615 "edn_parser.rl"
2312
+ #line 754 "edn_parser.rl"
1887
2313
 
1888
2314
 
1889
- //
1890
- // list parsing
1891
- //
1892
- const char* edn::Parser::parse_list(const char *p, const char *pe, Rice::Object& o)
1893
- {
1894
- static const char* EDN_TYPE = "list";
1895
2315
 
2316
+ const char* edn::Parser::parse_dispatch(const char *p, const char *pe, Rice::Object& o)
2317
+ {
1896
2318
  int cs;
1897
- Rice::Array arr;
1898
2319
 
1899
2320
 
1900
- #line 1901 "edn_parser.cc"
2321
+ #line 2322 "edn_parser.cc"
1901
2322
  {
1902
- cs = EDN_list_start;
2323
+ cs = EDN_dispatch_start;
1903
2324
  }
1904
2325
 
1905
- #line 628 "edn_parser.rl"
2326
+ #line 762 "edn_parser.rl"
1906
2327
 
1907
- #line 1908 "edn_parser.cc"
2328
+ #line 2329 "edn_parser.cc"
1908
2329
  {
1909
2330
  if ( p == pe )
1910
2331
  goto _test_eof;
1911
2332
  switch ( cs )
1912
2333
  {
1913
2334
  case 1:
1914
- if ( (*p) == 40 )
1915
- goto st2;
1916
- goto st0;
1917
- tr2:
1918
- #line 55 "edn_parser.rl"
1919
- {
1920
- std::stringstream s;
1921
- s << "unterminated " << EDN_TYPE;
1922
- error(__FUNCTION__, s.str());
1923
- p--; {p++; cs = 0; goto _out;}
1924
- }
2335
+ switch( (*p) ) {
2336
+ case 95: goto tr2;
2337
+ case 123: goto tr3;
2338
+ }
2339
+ if ( (*p) > 90 ) {
2340
+ if ( 97 <= (*p) && (*p) <= 122 )
2341
+ goto tr0;
2342
+ } else if ( (*p) >= 65 )
2343
+ goto tr0;
1925
2344
  goto st0;
1926
- #line 1927 "edn_parser.cc"
1927
2345
  st0:
1928
2346
  cs = 0;
1929
2347
  goto _out;
1930
- tr3:
1931
- #line 23 "edn_parser.rl"
1932
- { line_number++; }
2348
+ tr0:
2349
+ #line 742 "edn_parser.rl"
2350
+ {
2351
+ // #inst, #uuid, or #user/tag
2352
+ const char *np = parse_tagged(p, pe, o);
2353
+ if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
2354
+ }
2355
+ #line 61 "edn_parser.rl"
2356
+ { p--; {p++; cs = 2; goto _out;} }
1933
2357
  goto st2;
1934
- tr4:
1935
- #line 530 "edn_parser.rl"
2358
+ tr2:
2359
+ #line 736 "edn_parser.rl"
1936
2360
  {
1937
- Rice::Object v;
1938
- const char *np = parse_value(p, pe, v);
1939
- if (np == NULL) {
1940
- p--; {p++; cs = 2; goto _out;}
1941
- } else {
1942
- // if there's an entry in the discard list, the current
1943
- // object is not meant to be kept
1944
- if (!discard.empty()) {
1945
- discard.pop();
1946
- }
1947
- else {
1948
- // otherwise we add it to the sequence
1949
- arr.push(v);
1950
- }
1951
- {p = (( np))-1;}
1952
- }
2361
+ // discard token #_
2362
+ const char *np = parse_discard(p, pe);
2363
+ if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
2364
+ }
2365
+ #line 61 "edn_parser.rl"
2366
+ { p--; {p++; cs = 2; goto _out;} }
2367
+ goto st2;
2368
+ tr3:
2369
+ #line 730 "edn_parser.rl"
2370
+ {
2371
+ // #{ }
2372
+ const char *np = parse_set(p, pe, o);
2373
+ if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
1953
2374
  }
2375
+ #line 61 "edn_parser.rl"
2376
+ { p--; {p++; cs = 2; goto _out;} }
1954
2377
  goto st2;
1955
2378
  st2:
1956
2379
  if ( ++p == pe )
1957
2380
  goto _test_eof2;
1958
2381
  case 2:
1959
- #line 1960 "edn_parser.cc"
1960
- switch( (*p) ) {
1961
- case 10: goto tr3;
1962
- case 32: goto st2;
1963
- case 41: goto tr5;
1964
- case 44: goto st2;
1965
- case 59: goto st3;
1966
- case 95: goto tr4;
1967
- }
1968
- if ( (*p) < 40 ) {
1969
- if ( (*p) > 13 ) {
1970
- if ( 33 <= (*p) && (*p) <= 38 )
1971
- goto tr4;
1972
- } else if ( (*p) >= 9 )
1973
- goto st2;
1974
- } else if ( (*p) > 63 ) {
1975
- if ( (*p) > 92 ) {
1976
- if ( 97 <= (*p) && (*p) <= 123 )
1977
- goto tr4;
1978
- } else if ( (*p) >= 65 )
1979
- goto tr4;
1980
- } else
1981
- goto tr4;
1982
- goto tr2;
1983
- tr5:
1984
- #line 553 "edn_parser.rl"
1985
- { p--; {p++; cs = 4; goto _out;} }
1986
- goto st4;
1987
- st4:
1988
- if ( ++p == pe )
1989
- goto _test_eof4;
1990
- case 4:
1991
- #line 1992 "edn_parser.cc"
2382
+ #line 2383 "edn_parser.cc"
1992
2383
  goto st0;
1993
- st3:
1994
- if ( ++p == pe )
1995
- goto _test_eof3;
1996
- case 3:
1997
- if ( (*p) == 10 )
1998
- goto tr3;
1999
- goto st3;
2000
2384
  }
2001
2385
  _test_eof2: cs = 2; goto _test_eof;
2002
- _test_eof4: cs = 4; goto _test_eof;
2003
- _test_eof3: cs = 3; goto _test_eof;
2004
2386
 
2005
2387
  _test_eof: {}
2006
- if ( p == eof )
2007
- {
2008
- switch ( cs ) {
2009
- case 2:
2010
- case 3:
2011
- #line 55 "edn_parser.rl"
2012
- {
2013
- std::stringstream s;
2014
- s << "unterminated " << EDN_TYPE;
2015
- error(__FUNCTION__, s.str());
2016
- p--; {p++; cs = 0; goto _out;}
2017
- }
2018
- break;
2019
- #line 2020 "edn_parser.cc"
2020
- }
2021
- }
2022
-
2023
2388
  _out: {}
2024
2389
  }
2025
2390
 
2026
- #line 629 "edn_parser.rl"
2391
+ #line 763 "edn_parser.rl"
2027
2392
 
2028
- if (cs >= EDN_list_first_final) {
2029
- o = arr;
2393
+ if (cs >= EDN_dispatch_first_final) {
2030
2394
  return p + 1;
2031
2395
  }
2032
- else if (cs == EDN_list_error) {
2396
+ else if (cs == EDN_dispatch_error) {
2033
2397
  error(__FUNCTION__, *p);
2034
2398
  return pe;
2035
2399
  }
2036
- else if (cs == EDN_list_en_main) {} // silence ragel warning
2400
+ else if (cs == EDN_dispatch_en_main) {} // silence ragel warning
2401
+
2037
2402
  return NULL;
2038
2403
  }
2039
2404
 
2040
2405
 
2041
-
2042
2406
  // ============================================================
2043
2407
  // set parsing machine
2044
2408
  //
2045
2409
 
2046
- #line 2047 "edn_parser.cc"
2410
+ #line 2411 "edn_parser.cc"
2047
2411
  static const int EDN_set_start = 1;
2048
2412
  static const int EDN_set_first_final = 4;
2049
2413
  static const int EDN_set_error = 0;
@@ -2051,7 +2415,7 @@ static const int EDN_set_error = 0;
2051
2415
  static const int EDN_set_en_main = 1;
2052
2416
 
2053
2417
 
2054
- #line 659 "edn_parser.rl"
2418
+ #line 792 "edn_parser.rl"
2055
2419
 
2056
2420
 
2057
2421
  //
@@ -2059,21 +2423,20 @@ static const int EDN_set_en_main = 1;
2059
2423
  //
2060
2424
  const char* edn::Parser::parse_set(const char *p, const char *pe, Rice::Object& o)
2061
2425
  {
2062
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
2063
2426
  static const char* EDN_TYPE = "set";
2064
2427
 
2065
2428
  int cs;
2066
- Rice::Array arr; // store as a vector; then convert to a set once done
2429
+ Rice::Array elems; // stored as a vector
2067
2430
 
2068
2431
 
2069
- #line 2070 "edn_parser.cc"
2432
+ #line 2433 "edn_parser.cc"
2070
2433
  {
2071
2434
  cs = EDN_set_start;
2072
2435
  }
2073
2436
 
2074
- #line 673 "edn_parser.rl"
2437
+ #line 805 "edn_parser.rl"
2075
2438
 
2076
- #line 2077 "edn_parser.cc"
2439
+ #line 2440 "edn_parser.cc"
2077
2440
  {
2078
2441
  if ( p == pe )
2079
2442
  goto _test_eof;
@@ -2084,7 +2447,7 @@ case 1:
2084
2447
  goto st2;
2085
2448
  goto st0;
2086
2449
  tr2:
2087
- #line 55 "edn_parser.rl"
2450
+ #line 54 "edn_parser.rl"
2088
2451
  {
2089
2452
  std::stringstream s;
2090
2453
  s << "unterminated " << EDN_TYPE;
@@ -2092,30 +2455,36 @@ tr2:
2092
2455
  p--; {p++; cs = 0; goto _out;}
2093
2456
  }
2094
2457
  goto st0;
2095
- #line 2096 "edn_parser.cc"
2458
+ #line 2459 "edn_parser.cc"
2096
2459
  st0:
2097
2460
  cs = 0;
2098
2461
  goto _out;
2099
2462
  tr3:
2100
- #line 23 "edn_parser.rl"
2463
+ #line 24 "edn_parser.rl"
2101
2464
  { line_number++; }
2102
2465
  goto st2;
2103
2466
  tr4:
2104
- #line 530 "edn_parser.rl"
2105
- {
2106
- Rice::Object v;
2107
- const char *np = parse_value(p, pe, v);
2467
+ #line 544 "edn_parser.rl"
2468
+ {
2469
+ // reads an item within a sequence (vector, list, map, or
2470
+ // set). Regardless of the sequence type, an array of the
2471
+ // items is built. Once done, the sequence parser will convert
2472
+ // if needed
2473
+ Rice::Object e;
2474
+ const char *np = parse_value(p, pe, e);
2108
2475
  if (np == NULL) {
2109
2476
  p--; {p++; cs = 2; goto _out;}
2110
2477
  } else {
2111
2478
  // if there's an entry in the discard list, the current
2112
- // object is not meant to be kept
2479
+ // object is not meant to be kept due to a #_ so don't
2480
+ // push it into the list of elements
2113
2481
  if (!discard.empty()) {
2114
2482
  discard.pop();
2115
2483
  }
2116
2484
  else {
2117
- // otherwise we add it to the sequence
2118
- arr.push(v);
2485
+ // otherwise we add it to the list of elements for the
2486
+ // corresponding container
2487
+ elems.push(e);
2119
2488
  }
2120
2489
  {p = (( np))-1;}
2121
2490
  }
@@ -2125,7 +2494,7 @@ st2:
2125
2494
  if ( ++p == pe )
2126
2495
  goto _test_eof2;
2127
2496
  case 2:
2128
- #line 2129 "edn_parser.cc"
2497
+ #line 2498 "edn_parser.cc"
2129
2498
  switch( (*p) ) {
2130
2499
  case 10: goto tr3;
2131
2500
  case 32: goto st2;
@@ -2158,14 +2527,14 @@ case 3:
2158
2527
  goto tr3;
2159
2528
  goto st3;
2160
2529
  tr6:
2161
- #line 553 "edn_parser.rl"
2530
+ #line 61 "edn_parser.rl"
2162
2531
  { p--; {p++; cs = 4; goto _out;} }
2163
2532
  goto st4;
2164
2533
  st4:
2165
2534
  if ( ++p == pe )
2166
2535
  goto _test_eof4;
2167
2536
  case 4:
2168
- #line 2169 "edn_parser.cc"
2537
+ #line 2538 "edn_parser.cc"
2169
2538
  goto st0;
2170
2539
  }
2171
2540
  _test_eof2: cs = 2; goto _test_eof;
@@ -2178,7 +2547,7 @@ case 4:
2178
2547
  switch ( cs ) {
2179
2548
  case 2:
2180
2549
  case 3:
2181
- #line 55 "edn_parser.rl"
2550
+ #line 54 "edn_parser.rl"
2182
2551
  {
2183
2552
  std::stringstream s;
2184
2553
  s << "unterminated " << EDN_TYPE;
@@ -2186,17 +2555,18 @@ case 4:
2186
2555
  p--; {p++; cs = 0; goto _out;}
2187
2556
  }
2188
2557
  break;
2189
- #line 2190 "edn_parser.cc"
2558
+ #line 2559 "edn_parser.cc"
2190
2559
  }
2191
2560
  }
2192
2561
 
2193
2562
  _out: {}
2194
2563
  }
2195
2564
 
2196
- #line 674 "edn_parser.rl"
2565
+ #line 806 "edn_parser.rl"
2197
2566
 
2198
2567
  if (cs >= EDN_set_first_final) {
2199
- o = Parser::make_ruby_set(arr);
2568
+ // all elements collected; now convert to a set
2569
+ o = Parser::make_ruby_set(elems);
2200
2570
  return p + 1;
2201
2571
  }
2202
2572
  else if (cs == EDN_set_error) {
@@ -2210,188 +2580,153 @@ case 4:
2210
2580
 
2211
2581
 
2212
2582
  // ============================================================
2213
- // hash parsing
2583
+ // discard - consume the discard token and parse the next value to
2584
+ // discard. TODO: perhaps optimize this so no object data is built
2585
+ // by defining a new machine(s) to consume items within container
2586
+ // delimiters
2214
2587
  //
2215
2588
 
2216
- #line 2217 "edn_parser.cc"
2217
- static const int EDN_map_start = 1;
2218
- static const int EDN_map_first_final = 4;
2219
- static const int EDN_map_error = 0;
2589
+ #line 2590 "edn_parser.cc"
2590
+ static const int EDN_discard_start = 1;
2591
+ static const int EDN_discard_first_final = 4;
2592
+ static const int EDN_discard_error = 0;
2220
2593
 
2221
- static const int EDN_map_en_main = 1;
2594
+ static const int EDN_discard_en_main = 1;
2222
2595
 
2223
2596
 
2224
- #line 709 "edn_parser.rl"
2597
+ #line 853 "edn_parser.rl"
2225
2598
 
2226
2599
 
2227
2600
 
2228
- const char* edn::Parser::parse_map(const char *p, const char *pe, Rice::Object& o)
2601
+ const char* edn::Parser::parse_discard(const char *p, const char *pe)
2229
2602
  {
2230
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
2231
- static const char* EDN_TYPE = "map";
2232
- Rice::Array arr;
2233
2603
  int cs;
2604
+ Rice::Object o;
2234
2605
 
2235
2606
 
2236
- #line 2237 "edn_parser.cc"
2607
+ #line 2608 "edn_parser.cc"
2237
2608
  {
2238
- cs = EDN_map_start;
2609
+ cs = EDN_discard_start;
2239
2610
  }
2240
2611
 
2241
- #line 720 "edn_parser.rl"
2612
+ #line 862 "edn_parser.rl"
2242
2613
 
2243
- #line 2244 "edn_parser.cc"
2614
+ #line 2615 "edn_parser.cc"
2244
2615
  {
2245
2616
  if ( p == pe )
2246
2617
  goto _test_eof;
2247
2618
  switch ( cs )
2248
2619
  {
2249
2620
  case 1:
2250
- if ( (*p) == 123 )
2621
+ if ( (*p) == 95 )
2251
2622
  goto st2;
2252
2623
  goto st0;
2253
- tr2:
2254
- #line 55 "edn_parser.rl"
2255
- {
2256
- std::stringstream s;
2257
- s << "unterminated " << EDN_TYPE;
2258
- error(__FUNCTION__, s.str());
2259
- p--; {p++; cs = 0; goto _out;}
2260
- }
2261
- goto st0;
2262
- #line 2263 "edn_parser.cc"
2263
2624
  st0:
2264
2625
  cs = 0;
2265
2626
  goto _out;
2266
- tr3:
2267
- #line 23 "edn_parser.rl"
2627
+ tr2:
2628
+ #line 24 "edn_parser.rl"
2268
2629
  { line_number++; }
2269
2630
  goto st2;
2270
- tr4:
2271
- #line 530 "edn_parser.rl"
2272
- {
2273
- Rice::Object v;
2274
- const char *np = parse_value(p, pe, v);
2275
- if (np == NULL) {
2276
- p--; {p++; cs = 2; goto _out;}
2277
- } else {
2278
- // if there's an entry in the discard list, the current
2279
- // object is not meant to be kept
2280
- if (!discard.empty()) {
2281
- discard.pop();
2282
- }
2283
- else {
2284
- // otherwise we add it to the sequence
2285
- arr.push(v);
2286
- }
2287
- {p = (( np))-1;}
2288
- }
2289
- }
2290
- goto st2;
2291
2631
  st2:
2292
2632
  if ( ++p == pe )
2293
2633
  goto _test_eof2;
2294
2634
  case 2:
2295
- #line 2296 "edn_parser.cc"
2635
+ #line 2636 "edn_parser.cc"
2296
2636
  switch( (*p) ) {
2297
- case 10: goto tr3;
2637
+ case 10: goto tr2;
2298
2638
  case 32: goto st2;
2299
- case 40: goto tr4;
2639
+ case 40: goto tr3;
2300
2640
  case 44: goto st2;
2301
2641
  case 59: goto st3;
2302
- case 95: goto tr4;
2303
- case 125: goto tr6;
2642
+ case 95: goto tr3;
2304
2643
  }
2305
2644
  if ( (*p) < 42 ) {
2306
2645
  if ( (*p) > 13 ) {
2307
2646
  if ( 33 <= (*p) && (*p) <= 38 )
2308
- goto tr4;
2647
+ goto tr3;
2309
2648
  } else if ( (*p) >= 9 )
2310
2649
  goto st2;
2311
2650
  } else if ( (*p) > 63 ) {
2312
2651
  if ( (*p) > 92 ) {
2313
2652
  if ( 97 <= (*p) && (*p) <= 123 )
2314
- goto tr4;
2653
+ goto tr3;
2315
2654
  } else if ( (*p) >= 65 )
2316
- goto tr4;
2655
+ goto tr3;
2317
2656
  } else
2318
- goto tr4;
2319
- goto tr2;
2320
- st3:
2321
- if ( ++p == pe )
2322
- goto _test_eof3;
2323
- case 3:
2324
- if ( (*p) == 10 )
2325
2657
  goto tr3;
2326
- goto st3;
2327
- tr6:
2328
- #line 553 "edn_parser.rl"
2658
+ goto st0;
2659
+ tr3:
2660
+ #line 836 "edn_parser.rl"
2661
+ {
2662
+ const char *np = parse_value(p, pe, o);
2663
+ if (np) {
2664
+ // this token is to be discard it so store it in the
2665
+ // discard stack - we really don't need to save it so this
2666
+ // could be simplified
2667
+ discard.push(o);
2668
+ {p = (( np))-1;}
2669
+ } else {
2670
+ p--; {p++; cs = 4; goto _out;}
2671
+ }
2672
+ }
2673
+ #line 61 "edn_parser.rl"
2329
2674
  { p--; {p++; cs = 4; goto _out;} }
2330
2675
  goto st4;
2331
2676
  st4:
2332
2677
  if ( ++p == pe )
2333
2678
  goto _test_eof4;
2334
2679
  case 4:
2335
- #line 2336 "edn_parser.cc"
2680
+ #line 2681 "edn_parser.cc"
2336
2681
  goto st0;
2682
+ st3:
2683
+ if ( ++p == pe )
2684
+ goto _test_eof3;
2685
+ case 3:
2686
+ if ( (*p) == 10 )
2687
+ goto tr2;
2688
+ goto st3;
2337
2689
  }
2338
2690
  _test_eof2: cs = 2; goto _test_eof;
2339
- _test_eof3: cs = 3; goto _test_eof;
2340
2691
  _test_eof4: cs = 4; goto _test_eof;
2692
+ _test_eof3: cs = 3; goto _test_eof;
2341
2693
 
2342
2694
  _test_eof: {}
2343
- if ( p == eof )
2344
- {
2345
- switch ( cs ) {
2346
- case 2:
2347
- case 3:
2348
- #line 55 "edn_parser.rl"
2349
- {
2350
- std::stringstream s;
2351
- s << "unterminated " << EDN_TYPE;
2352
- error(__FUNCTION__, s.str());
2353
- p--; {p++; cs = 0; goto _out;}
2354
- }
2355
- break;
2356
- #line 2357 "edn_parser.cc"
2357
- }
2358
- }
2359
-
2360
2695
  _out: {}
2361
2696
  }
2362
2697
 
2363
- #line 721 "edn_parser.rl"
2364
-
2365
- if (cs >= EDN_map_first_final) {
2366
-
2367
- if ((arr.size() % 2) != 0) {
2368
- error(__FUNCTION__, "odd number of elements in map");
2369
- return pe;
2370
- }
2371
-
2372
- Rice::Hash map;
2373
- while (arr.size())
2374
- {
2375
- Rice::Object k = arr.shift();
2376
- map[k] = arr.shift();
2377
- }
2698
+ #line 863 "edn_parser.rl"
2378
2699
 
2379
- o = map;
2700
+ if (cs >= EDN_discard_first_final) {
2380
2701
  return p + 1;
2381
2702
  }
2382
- else if (cs == EDN_map_error) {
2703
+ else if (cs == EDN_discard_error) {
2704
+ error(__FUNCTION__, *p);
2383
2705
  return pe;
2384
2706
  }
2385
- else if (cs == EDN_map_en_main) {} // silence ragel warning
2707
+ else if (cs == EDN_discard_en_main) {} // silence ragel warning
2708
+
2386
2709
  return NULL;
2387
2710
  }
2388
2711
 
2389
2712
 
2713
+
2390
2714
  // ============================================================
2391
- // tagged element parsing - #uuid, #inst, #{, #_
2715
+ // tagged element parsing - #uuid, #inst, #{, #user/tag
2716
+ //
2717
+ // Current implementation expects a symbol followed by a value to
2718
+ // match it against and does not check validity of uuid or rfc3339
2719
+ // date characters.
2720
+ //
2721
+ // TODO:
2722
+ // 1. need to check if we must support discard shenanigans such as
2723
+ //
2724
+ // #symbol #_ discard data
2725
+ //
2726
+ // 2. add parse checks for uuid and inst for better error reporting
2392
2727
  //
2393
2728
 
2394
- #line 2395 "edn_parser.cc"
2729
+ #line 2730 "edn_parser.cc"
2395
2730
  static const int EDN_tagged_start = 1;
2396
2731
  static const int EDN_tagged_first_final = 6;
2397
2732
  static const int EDN_tagged_error = 0;
@@ -2399,27 +2734,26 @@ static const int EDN_tagged_error = 0;
2399
2734
  static const int EDN_tagged_en_main = 1;
2400
2735
 
2401
2736
 
2402
- #line 771 "edn_parser.rl"
2737
+ #line 914 "edn_parser.rl"
2403
2738
 
2404
2739
 
2405
2740
 
2406
2741
  const char* edn::Parser::parse_tagged(const char *p, const char *pe, Rice::Object& o)
2407
2742
  {
2408
- // std::cerr << __FUNCTION__ << " p '" << p << "'" << std::endl;
2409
2743
  std::string sym_name;
2410
- Rice::Object object;
2744
+ Rice::Object data;
2411
2745
 
2412
2746
  int cs;
2413
2747
 
2414
2748
 
2415
- #line 2416 "edn_parser.cc"
2749
+ #line 2750 "edn_parser.cc"
2416
2750
  {
2417
2751
  cs = EDN_tagged_start;
2418
2752
  }
2419
2753
 
2420
- #line 783 "edn_parser.rl"
2754
+ #line 925 "edn_parser.rl"
2421
2755
 
2422
- #line 2423 "edn_parser.cc"
2756
+ #line 2757 "edn_parser.cc"
2423
2757
  {
2424
2758
  if ( p == pe )
2425
2759
  goto _test_eof;
@@ -2436,8 +2770,9 @@ st0:
2436
2770
  cs = 0;
2437
2771
  goto _out;
2438
2772
  tr0:
2439
- #line 759 "edn_parser.rl"
2773
+ #line 901 "edn_parser.rl"
2440
2774
  {
2775
+ // parses the symbol portion of the pair
2441
2776
  const char *np = parse_symbol(p, pe, sym_name);
2442
2777
  if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else { {p = (( np))-1;} }
2443
2778
  }
@@ -2446,7 +2781,7 @@ st2:
2446
2781
  if ( ++p == pe )
2447
2782
  goto _test_eof2;
2448
2783
  case 2:
2449
- #line 2450 "edn_parser.cc"
2784
+ #line 2785 "edn_parser.cc"
2450
2785
  switch( (*p) ) {
2451
2786
  case 10: goto tr3;
2452
2787
  case 32: goto st3;
@@ -2483,14 +2818,14 @@ case 2:
2483
2818
  goto tr5;
2484
2819
  goto st0;
2485
2820
  tr3:
2486
- #line 23 "edn_parser.rl"
2821
+ #line 24 "edn_parser.rl"
2487
2822
  { line_number++; }
2488
2823
  goto st3;
2489
2824
  st3:
2490
2825
  if ( ++p == pe )
2491
2826
  goto _test_eof3;
2492
2827
  case 3:
2493
- #line 2494 "edn_parser.cc"
2828
+ #line 2829 "edn_parser.cc"
2494
2829
  switch( (*p) ) {
2495
2830
  case 10: goto tr3;
2496
2831
  case 32: goto st3;
@@ -2515,19 +2850,20 @@ case 3:
2515
2850
  goto tr4;
2516
2851
  goto st0;
2517
2852
  tr4:
2518
- #line 763 "edn_parser.rl"
2853
+ #line 906 "edn_parser.rl"
2519
2854
  {
2520
- const char *np = parse_value(p, pe, object);
2855
+ // parses the value portion
2856
+ const char *np = parse_value(p, pe, data);
2521
2857
  if (np == NULL) { p--; {p++; cs = 6; goto _out;} } else { {p = (( np))-1;} }
2522
2858
  }
2523
- #line 768 "edn_parser.rl"
2859
+ #line 61 "edn_parser.rl"
2524
2860
  { p--; {p++; cs = 6; goto _out;} }
2525
2861
  goto st6;
2526
2862
  st6:
2527
2863
  if ( ++p == pe )
2528
2864
  goto _test_eof6;
2529
2865
  case 6:
2530
- #line 2531 "edn_parser.cc"
2866
+ #line 2867 "edn_parser.cc"
2531
2867
  goto st0;
2532
2868
  st4:
2533
2869
  if ( ++p == pe )
@@ -2537,19 +2873,20 @@ case 4:
2537
2873
  goto tr3;
2538
2874
  goto st4;
2539
2875
  tr5:
2540
- #line 763 "edn_parser.rl"
2876
+ #line 906 "edn_parser.rl"
2541
2877
  {
2542
- const char *np = parse_value(p, pe, object);
2878
+ // parses the value portion
2879
+ const char *np = parse_value(p, pe, data);
2543
2880
  if (np == NULL) { p--; {p++; cs = 7; goto _out;} } else { {p = (( np))-1;} }
2544
2881
  }
2545
- #line 768 "edn_parser.rl"
2882
+ #line 61 "edn_parser.rl"
2546
2883
  { p--; {p++; cs = 7; goto _out;} }
2547
2884
  goto st7;
2548
2885
  st7:
2549
2886
  if ( ++p == pe )
2550
2887
  goto _test_eof7;
2551
2888
  case 7:
2552
- #line 2553 "edn_parser.cc"
2889
+ #line 2890 "edn_parser.cc"
2553
2890
  switch( (*p) ) {
2554
2891
  case 10: goto tr3;
2555
2892
  case 32: goto st3;
@@ -2586,19 +2923,20 @@ case 7:
2586
2923
  goto tr5;
2587
2924
  goto st0;
2588
2925
  tr6:
2589
- #line 763 "edn_parser.rl"
2926
+ #line 906 "edn_parser.rl"
2590
2927
  {
2591
- const char *np = parse_value(p, pe, object);
2928
+ // parses the value portion
2929
+ const char *np = parse_value(p, pe, data);
2592
2930
  if (np == NULL) { p--; {p++; cs = 8; goto _out;} } else { {p = (( np))-1;} }
2593
2931
  }
2594
- #line 768 "edn_parser.rl"
2932
+ #line 61 "edn_parser.rl"
2595
2933
  { p--; {p++; cs = 8; goto _out;} }
2596
2934
  goto st8;
2597
2935
  st8:
2598
2936
  if ( ++p == pe )
2599
2937
  goto _test_eof8;
2600
2938
  case 8:
2601
- #line 2602 "edn_parser.cc"
2939
+ #line 2940 "edn_parser.cc"
2602
2940
  if ( (*p) > 90 ) {
2603
2941
  if ( 97 <= (*p) && (*p) <= 122 )
2604
2942
  goto st5;
@@ -2645,19 +2983,20 @@ case 5:
2645
2983
  goto tr8;
2646
2984
  goto st0;
2647
2985
  tr8:
2648
- #line 763 "edn_parser.rl"
2986
+ #line 906 "edn_parser.rl"
2649
2987
  {
2650
- const char *np = parse_value(p, pe, object);
2988
+ // parses the value portion
2989
+ const char *np = parse_value(p, pe, data);
2651
2990
  if (np == NULL) { p--; {p++; cs = 9; goto _out;} } else { {p = (( np))-1;} }
2652
2991
  }
2653
- #line 768 "edn_parser.rl"
2992
+ #line 61 "edn_parser.rl"
2654
2993
  { p--; {p++; cs = 9; goto _out;} }
2655
2994
  goto st9;
2656
2995
  st9:
2657
2996
  if ( ++p == pe )
2658
2997
  goto _test_eof9;
2659
2998
  case 9:
2660
- #line 2661 "edn_parser.cc"
2999
+ #line 3000 "edn_parser.cc"
2661
3000
  switch( (*p) ) {
2662
3001
  case 10: goto tr3;
2663
3002
  case 32: goto st3;
@@ -2707,11 +3046,19 @@ case 9:
2707
3046
  _out: {}
2708
3047
  }
2709
3048
 
2710
- #line 784 "edn_parser.rl"
3049
+ #line 926 "edn_parser.rl"
2711
3050
 
2712
3051
  if (cs >= EDN_tagged_first_final) {
2713
- //std::cerr << __FUNCTION__ << " parse symbol name as '" << sym_name << "', value is: " << object << std::endl;
2714
- o = Parser::tagged_element(sym_name, object);
3052
+ //std::cerr << __FUNCTION__ << " parse symbol name as '" << sym_name << "', value is: " << data << std::endl;
3053
+
3054
+ try {
3055
+ // tagged_element makes a call to ruby which may throw an
3056
+ // exception when parsing the data
3057
+ o = Parser::tagged_element(sym_name, data);
3058
+ } catch (Rice::Exception& e) {
3059
+ error(__FUNCTION__, e.message().str());
3060
+ return pe;
3061
+ }
2715
3062
  return p + 1;
2716
3063
  }
2717
3064
  else if (cs == EDN_tagged_error) {
@@ -2722,250 +3069,25 @@ case 9:
2722
3069
  }
2723
3070
 
2724
3071
 
2725
- // ============================================================
2726
- // discard
2727
- //
2728
-
2729
- #line 2730 "edn_parser.cc"
2730
- static const int EDN_discard_start = 1;
2731
- static const int EDN_discard_first_final = 4;
2732
- static const int EDN_discard_error = 0;
2733
-
2734
- static const int EDN_discard_en_main = 1;
2735
-
2736
-
2737
- #line 821 "edn_parser.rl"
2738
-
2739
-
2740
-
2741
- const char* edn::Parser::parse_discard(const char *p, const char *pe)
2742
- {
2743
- //std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
2744
- int cs;
2745
- Rice::Object o;
2746
-
2747
-
2748
- #line 2749 "edn_parser.cc"
2749
- {
2750
- cs = EDN_discard_start;
2751
- }
2752
-
2753
- #line 831 "edn_parser.rl"
2754
-
2755
- #line 2756 "edn_parser.cc"
2756
- {
2757
- if ( p == pe )
2758
- goto _test_eof;
2759
- switch ( cs )
2760
- {
2761
- case 1:
2762
- if ( (*p) == 95 )
2763
- goto st2;
2764
- goto st0;
2765
- st0:
2766
- cs = 0;
2767
- goto _out;
2768
- tr2:
2769
- #line 23 "edn_parser.rl"
2770
- { line_number++; }
2771
- goto st2;
2772
- st2:
2773
- if ( ++p == pe )
2774
- goto _test_eof2;
2775
- case 2:
2776
- #line 2777 "edn_parser.cc"
2777
- switch( (*p) ) {
2778
- case 10: goto tr2;
2779
- case 32: goto st2;
2780
- case 40: goto tr3;
2781
- case 44: goto st2;
2782
- case 59: goto st3;
2783
- case 95: goto tr3;
2784
- }
2785
- if ( (*p) < 42 ) {
2786
- if ( (*p) > 13 ) {
2787
- if ( 33 <= (*p) && (*p) <= 38 )
2788
- goto tr3;
2789
- } else if ( (*p) >= 9 )
2790
- goto st2;
2791
- } else if ( (*p) > 63 ) {
2792
- if ( (*p) > 92 ) {
2793
- if ( 97 <= (*p) && (*p) <= 123 )
2794
- goto tr3;
2795
- } else if ( (*p) >= 65 )
2796
- goto tr3;
2797
- } else
2798
- goto tr3;
2799
- goto st0;
2800
- tr3:
2801
- #line 809 "edn_parser.rl"
2802
- {
2803
- const char *np = parse_value(p, pe, o);
2804
- if (np == NULL) { p--; {p++; cs = 4; goto _out;} } else { discard.push(o); {p = (( np))-1;} }
2805
- }
2806
- #line 814 "edn_parser.rl"
2807
- {
2808
- p--; {p++; cs = 4; goto _out;}
2809
- }
2810
- goto st4;
2811
- st4:
2812
- if ( ++p == pe )
2813
- goto _test_eof4;
2814
- case 4:
2815
- #line 2816 "edn_parser.cc"
2816
- goto st0;
2817
- st3:
2818
- if ( ++p == pe )
2819
- goto _test_eof3;
2820
- case 3:
2821
- if ( (*p) == 10 )
2822
- goto tr2;
2823
- goto st3;
2824
- }
2825
- _test_eof2: cs = 2; goto _test_eof;
2826
- _test_eof4: cs = 4; goto _test_eof;
2827
- _test_eof3: cs = 3; goto _test_eof;
2828
-
2829
- _test_eof: {}
2830
- _out: {}
2831
- }
2832
-
2833
- #line 832 "edn_parser.rl"
2834
-
2835
- if (cs >= EDN_discard_first_final) {
2836
- return p + 1;
2837
- }
2838
- else if (cs == EDN_discard_error) {
2839
- error(__FUNCTION__, *p);
2840
- return pe;
2841
- }
2842
- else if (cs == EDN_discard_en_main) {} // silence ragel warning
2843
-
2844
- return NULL;
2845
- }
2846
-
2847
-
2848
-
2849
- // ============================================================
2850
- // dispatch
2851
- //
2852
-
2853
- #line 2854 "edn_parser.cc"
2854
- static const int EDN_dispatch_start = 1;
2855
- static const int EDN_dispatch_first_final = 2;
2856
- static const int EDN_dispatch_error = 0;
2857
-
2858
- static const int EDN_dispatch_en_main = 1;
2859
-
2860
-
2861
- #line 878 "edn_parser.rl"
2862
-
2863
-
2864
-
2865
- const char* edn::Parser::parse_dispatch(const char *p, const char *pe, Rice::Object& o)
2866
- {
2867
- // std::cerr << __FUNCTION__ << " - p: '" << p << "'" << std::endl;
2868
- int cs;
2869
-
2870
-
2871
- #line 2872 "edn_parser.cc"
2872
- {
2873
- cs = EDN_dispatch_start;
2874
- }
2875
-
2876
- #line 887 "edn_parser.rl"
2877
-
2878
- #line 2879 "edn_parser.cc"
2879
- {
2880
- if ( p == pe )
2881
- goto _test_eof;
2882
- switch ( cs )
2883
- {
2884
- case 1:
2885
- switch( (*p) ) {
2886
- case 95: goto tr2;
2887
- case 123: goto tr3;
2888
- }
2889
- if ( (*p) > 90 ) {
2890
- if ( 97 <= (*p) && (*p) <= 122 )
2891
- goto tr0;
2892
- } else if ( (*p) >= 65 )
2893
- goto tr0;
2894
- goto st0;
2895
- st0:
2896
- cs = 0;
2897
- goto _out;
2898
- tr0:
2899
- #line 866 "edn_parser.rl"
2900
- {
2901
- const char *np = parse_tagged(p, pe, o);
2902
- if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
2903
- }
2904
- #line 871 "edn_parser.rl"
2905
- { p--; {p++; cs = 2; goto _out;} }
2906
- goto st2;
2907
- tr2:
2908
- #line 856 "edn_parser.rl"
2909
- {
2910
- const char *np = parse_discard(p, pe);
2911
- if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
2912
- }
2913
- #line 871 "edn_parser.rl"
2914
- { p--; {p++; cs = 2; goto _out;} }
2915
- goto st2;
2916
- tr3:
2917
- #line 861 "edn_parser.rl"
2918
- {
2919
- const char *np = parse_set(p, pe, o);
2920
- if (np == NULL) { p--; {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
2921
- }
2922
- #line 871 "edn_parser.rl"
2923
- { p--; {p++; cs = 2; goto _out;} }
2924
- goto st2;
2925
- st2:
2926
- if ( ++p == pe )
2927
- goto _test_eof2;
2928
- case 2:
2929
- #line 2930 "edn_parser.cc"
2930
- goto st0;
2931
- }
2932
- _test_eof2: cs = 2; goto _test_eof;
2933
-
2934
- _test_eof: {}
2935
- _out: {}
2936
- }
2937
-
2938
- #line 888 "edn_parser.rl"
2939
-
2940
- if (cs >= EDN_dispatch_first_final) {
2941
- return p + 1;
2942
- }
2943
- else if (cs == EDN_dispatch_error) {
2944
- error(__FUNCTION__, *p);
2945
- return pe;
2946
- }
2947
- else if (cs == EDN_dispatch_en_main) {} // silence ragel warning
2948
3072
 
2949
- return NULL;
2950
- }
2951
3073
 
2952
3074
  // ============================================================
2953
3075
  // main parsing machine
2954
3076
  //
2955
3077
 
2956
- #line 2957 "edn_parser.cc"
3078
+ #line 3079 "edn_parser.cc"
2957
3079
  static const int EDN_start = 2;
2958
3080
  static const int EDN_error = 0;
2959
3081
 
2960
3082
  static const int EDN_en_main = 2;
2961
3083
 
2962
3084
 
2963
- #line 921 "edn_parser.rl"
3085
+ #line 969 "edn_parser.rl"
2964
3086
 
2965
3087
 
2966
3088
  //
2967
- //
2968
- //
3089
+ // TODO: Currently using a sequence to handle cases with a discard
3090
+ // but EDN's Reader allows token by token parsing
2969
3091
  Rice::Object edn::Parser::parse(const char* buf, std::size_t len)
2970
3092
  {
2971
3093
  int cs;
@@ -2980,28 +3102,28 @@ Rice::Object edn::Parser::parse(const char* buf, std::size_t len)
2980
3102
  discard.pop();
2981
3103
 
2982
3104
 
2983
- #line 2984 "edn_parser.cc"
3105
+ #line 3106 "edn_parser.cc"
2984
3106
  {
2985
3107
  cs = EDN_start;
2986
3108
  }
2987
3109
 
2988
- #line 940 "edn_parser.rl"
3110
+ #line 988 "edn_parser.rl"
2989
3111
  p = &buf[0];
2990
3112
  pe = p + len;
2991
3113
  eof = pe; // eof defined in Parser class
2992
3114
 
2993
- #line 2994 "edn_parser.cc"
3115
+ #line 3116 "edn_parser.cc"
2994
3116
  {
2995
3117
  if ( p == pe )
2996
3118
  goto _test_eof;
2997
3119
  switch ( cs )
2998
3120
  {
2999
3121
  tr1:
3000
- #line 23 "edn_parser.rl"
3122
+ #line 24 "edn_parser.rl"
3001
3123
  { line_number++; }
3002
3124
  goto st2;
3003
3125
  tr4:
3004
- #line 910 "edn_parser.rl"
3126
+ #line 959 "edn_parser.rl"
3005
3127
  {
3006
3128
  const char* np = parse_value(p, pe, result);
3007
3129
  if (np == NULL) { {p = (( pe))-1;} {p++; cs = 2; goto _out;} } else {p = (( np))-1;}
@@ -3011,7 +3133,7 @@ st2:
3011
3133
  if ( ++p == pe )
3012
3134
  goto _test_eof2;
3013
3135
  case 2:
3014
- #line 3015 "edn_parser.cc"
3136
+ #line 3137 "edn_parser.cc"
3015
3137
  switch( (*p) ) {
3016
3138
  case 10: goto tr1;
3017
3139
  case 32: goto st2;
@@ -3053,7 +3175,7 @@ case 1:
3053
3175
  _out: {}
3054
3176
  }
3055
3177
 
3056
- #line 944 "edn_parser.rl"
3178
+ #line 992 "edn_parser.rl"
3057
3179
 
3058
3180
  if (cs == EDN_error) {
3059
3181
  error(__FUNCTION__, *p);