lgierth-rack-mount 0.6.13

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/LICENSE +20 -0
  2. data/README.rdoc +36 -0
  3. data/lib/rack/mount.rb +32 -0
  4. data/lib/rack/mount/analysis/frequency.rb +60 -0
  5. data/lib/rack/mount/analysis/histogram.rb +74 -0
  6. data/lib/rack/mount/analysis/splitting.rb +159 -0
  7. data/lib/rack/mount/code_generation.rb +117 -0
  8. data/lib/rack/mount/generatable_regexp.rb +210 -0
  9. data/lib/rack/mount/multimap.rb +53 -0
  10. data/lib/rack/mount/prefix.rb +36 -0
  11. data/lib/rack/mount/regexp_with_named_groups.rb +69 -0
  12. data/lib/rack/mount/route.rb +130 -0
  13. data/lib/rack/mount/route_set.rb +420 -0
  14. data/lib/rack/mount/strexp.rb +68 -0
  15. data/lib/rack/mount/strexp/parser.rb +160 -0
  16. data/lib/rack/mount/strexp/parser.y +34 -0
  17. data/lib/rack/mount/strexp/tokenizer.rb +83 -0
  18. data/lib/rack/mount/strexp/tokenizer.rex +12 -0
  19. data/lib/rack/mount/utils.rb +162 -0
  20. data/lib/rack/mount/vendor/multimap/multimap.rb +569 -0
  21. data/lib/rack/mount/vendor/multimap/multiset.rb +185 -0
  22. data/lib/rack/mount/vendor/multimap/nested_multimap.rb +158 -0
  23. data/lib/rack/mount/vendor/regin/regin.rb +75 -0
  24. data/lib/rack/mount/vendor/regin/regin/alternation.rb +40 -0
  25. data/lib/rack/mount/vendor/regin/regin/anchor.rb +4 -0
  26. data/lib/rack/mount/vendor/regin/regin/atom.rb +54 -0
  27. data/lib/rack/mount/vendor/regin/regin/character.rb +51 -0
  28. data/lib/rack/mount/vendor/regin/regin/character_class.rb +50 -0
  29. data/lib/rack/mount/vendor/regin/regin/collection.rb +77 -0
  30. data/lib/rack/mount/vendor/regin/regin/expression.rb +126 -0
  31. data/lib/rack/mount/vendor/regin/regin/group.rb +85 -0
  32. data/lib/rack/mount/vendor/regin/regin/options.rb +55 -0
  33. data/lib/rack/mount/vendor/regin/regin/parser.rb +520 -0
  34. data/lib/rack/mount/vendor/regin/regin/tokenizer.rb +246 -0
  35. data/lib/rack/mount/vendor/regin/regin/version.rb +3 -0
  36. data/lib/rack/mount/version.rb +3 -0
  37. metadata +140 -0
@@ -0,0 +1,55 @@
1
+ module Regin
2
+ class Options
3
+ def self.from_int(flags)
4
+ multiline = flags & Regexp::MULTILINE != 0
5
+ ignorecase = flags & Regexp::IGNORECASE != 0
6
+ extended = flags & Regexp::EXTENDED != 0
7
+
8
+ new(multiline, ignorecase, extended)
9
+ end
10
+
11
+ attr_reader :multiline, :ignorecase, :extended
12
+
13
+ def initialize(*args)
14
+ if args.first.is_a?(Hash)
15
+ @multiline = args[0][:multiline]
16
+ @ignorecase = args[0][:ignorecase]
17
+ @extended = args[0][:extended]
18
+ else
19
+ @multiline = args[0]
20
+ @ignorecase = args[1]
21
+ @extended = args[2]
22
+ end
23
+ end
24
+
25
+ def any?(explicit = false)
26
+ if explicit
27
+ !multiline.nil? || !ignorecase.nil? || !extended.nil?
28
+ else
29
+ multiline || ignorecase || extended
30
+ end
31
+ end
32
+
33
+ def to_h(explicit = false)
34
+ if explicit
35
+ options = {}
36
+ options[:multiline] = multiline unless multiline.nil?
37
+ options[:ignorecase] = ignorecase unless ignorecase.nil?
38
+ options[:extended] = extended unless extended.nil?
39
+ options
40
+ else
41
+ { :multiline => multiline,
42
+ :ignorecase => ignorecase,
43
+ :extended => extended }
44
+ end
45
+ end
46
+
47
+ def to_i
48
+ flag = 0
49
+ flag |= Regexp::MULTILINE if multiline
50
+ flag |= Regexp::IGNORECASE if ignorecase
51
+ flag |= Regexp::EXTENDED if extended
52
+ flag
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,520 @@
1
+ #
2
+ # DO NOT MODIFY!!!!
3
+ # This file is automatically generated by Racc 1.4.6
4
+ # from Racc grammer file "".
5
+ #
6
+
7
+ require 'racc/parser.rb'
8
+ module Regin
9
+ class Parser < Racc::Parser #:nodoc: all
10
+
11
+ def self.parse_regexp(regexp)
12
+ options = Options.from_int(regexp.options)
13
+
14
+ parser = new
15
+ parser.options_stack << options.to_h
16
+
17
+ expression = parser.scan_str(regexp.source)
18
+ expression = expression.dup(options.to_h) if options.any?
19
+ expression
20
+ end
21
+
22
+ attr_accessor :options_stack
23
+
24
+ def initialize
25
+ @capture_index = 0
26
+ @capture_index_stack = []
27
+ @options_stack = []
28
+ end
29
+
30
+ ##### State transition tables begin ###
31
+
32
+ racc_action_table = [
33
+ 45, 47, 67, 69, 56, 57, 58, 59, 60, 61,
34
+ 62, 63, 64, 66, 68, 55, 53, 83, 46, 48,
35
+ 49, 74, 44, 46, 48, 49, 4, 54, 16, 7,
36
+ 9, 11, 13, 18, 19, 20, 4, 3, 5, 7,
37
+ 9, 11, 13, 46, 48, 49, 4, 3, 5, 7,
38
+ 9, 11, 13, 46, 48, 49, 4, 3, 5, 7,
39
+ 9, 11, 13, 46, 48, 49, 4, 3, 5, 7,
40
+ 9, 11, 13, 26, 29, 27, 4, 3, 5, 7,
41
+ 9, 11, 13, 46, 48, 49, 4, 3, 5, 7,
42
+ 9, 11, 13, 46, 48, 49, 4, 3, 5, 7,
43
+ 9, 11, 13, 77, 21, 70, 21, 3, 5, 39,
44
+ 28, 25, 21, 37, 21, 79, 23, 39, 80, 25,
45
+ 75, 46, 48, 49, 46, 48, 49, 52, 32, 33,
46
+ 85, 35, 87, 41, 36 ]
47
+
48
+ racc_action_check = [
49
+ 29, 29, 36, 36, 36, 36, 36, 36, 36, 36,
50
+ 36, 36, 36, 36, 36, 36, 34, 76, 76, 76,
51
+ 76, 50, 29, 29, 29, 29, 27, 34, 1, 27,
52
+ 27, 27, 27, 1, 1, 1, 45, 27, 27, 45,
53
+ 45, 45, 45, 75, 75, 75, 0, 45, 45, 0,
54
+ 0, 0, 0, 71, 71, 71, 47, 0, 0, 47,
55
+ 47, 47, 47, 78, 78, 78, 13, 47, 47, 13,
56
+ 13, 13, 13, 8, 13, 10, 14, 13, 13, 14,
57
+ 14, 14, 14, 82, 82, 82, 74, 14, 14, 74,
58
+ 74, 74, 74, 44, 44, 44, 28, 74, 74, 28,
59
+ 28, 28, 28, 65, 40, 40, 23, 28, 28, 40,
60
+ 12, 23, 22, 22, 4, 72, 4, 22, 73, 4,
61
+ 51, 51, 51, 51, 83, 83, 83, 30, 18, 19,
62
+ 77, 20, 81, 26, 21 ]
63
+
64
+ racc_action_pointer = [
65
+ 43, 17, nil, nil, 111, nil, nil, nil, 73, nil,
66
+ 73, nil, 108, 63, 73, nil, nil, nil, 117, 118,
67
+ 123, 122, 109, 103, nil, nil, 133, 23, 93, -12,
68
+ 117, nil, nil, nil, 8, nil, -18, nil, nil, nil,
69
+ 101, nil, nil, nil, 58, 33, nil, 53, nil, nil,
70
+ 9, 86, nil, nil, nil, nil, nil, nil, nil, nil,
71
+ nil, nil, nil, nil, nil, 91, nil, nil, nil, nil,
72
+ nil, 18, 105, 108, 83, 8, -17, 126, 28, nil,
73
+ nil, 122, 48, 89, nil, nil, nil, nil, nil, nil ]
74
+
75
+ racc_action_default = [
76
+ -57, -9, -10, -21, -57, -22, -15, -13, -57, -14,
77
+ -1, -16, -2, -57, -5, -7, -25, -8, -23, -24,
78
+ -57, -57, -57, -57, -33, -34, -57, -57, -57, -57,
79
+ -57, -6, -26, -27, -57, -30, -57, -11, -31, -32,
80
+ -57, 90, -3, -4, -57, -57, -54, -57, -55, -56,
81
+ -57, -57, -17, -29, -28, -49, -38, -39, -40, -41,
82
+ -42, -43, -44, -45, -46, -57, -47, -36, -48, -37,
83
+ -12, -57, -57, -57, -57, -57, -57, -57, -57, -19,
84
+ -20, -57, -57, -57, -53, -35, -50, -18, -51, -52 ]
85
+
86
+ racc_goto_table = [
87
+ 8, 22, 51, 38, 42, 43, 34, 31, 17, 65,
88
+ 50, nil, nil, 30, nil, nil, nil, 71, nil, nil,
89
+ 40, 38, nil, nil, 76, nil, nil, nil, nil, nil,
90
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
91
+ nil, nil, nil, nil, 78, 72, nil, 73, 82, 84,
92
+ nil, 86, nil, nil, nil, 88, 89, nil, nil, nil,
93
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
94
+ nil, nil, nil, nil, 81 ]
95
+
96
+ racc_goto_check = [
97
+ 1, 9, 15, 13, 3, 3, 12, 5, 7, 14,
98
+ 11, nil, nil, 1, nil, nil, nil, 15, nil, nil,
99
+ 9, 13, nil, nil, 15, nil, nil, nil, nil, nil,
100
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
101
+ nil, nil, nil, nil, 15, 1, nil, 1, 15, 15,
102
+ nil, 15, nil, nil, nil, 15, 15, nil, nil, nil,
103
+ nil, nil, nil, nil, nil, nil, nil, nil, nil, nil,
104
+ nil, nil, nil, nil, 1 ]
105
+
106
+ racc_goto_pointer = [
107
+ nil, 0, nil, -23, nil, -7, nil, 7, nil, -3,
108
+ nil, -19, -14, -19, -27, -27 ]
109
+
110
+ racc_goto_default = [
111
+ nil, nil, 10, 12, 14, 15, 1, nil, 2, nil,
112
+ 6, nil, nil, 24, nil, nil ]
113
+
114
+ racc_reduce_table = [
115
+ 0, 0, :racc_error,
116
+ 1, 39, :_reduce_1,
117
+ 1, 39, :_reduce_none,
118
+ 3, 40, :_reduce_3,
119
+ 3, 40, :_reduce_4,
120
+ 1, 41, :_reduce_5,
121
+ 2, 42, :_reduce_6,
122
+ 1, 42, :_reduce_7,
123
+ 2, 43, :_reduce_8,
124
+ 1, 43, :_reduce_none,
125
+ 1, 44, :_reduce_none,
126
+ 3, 44, :_reduce_11,
127
+ 4, 44, :_reduce_12,
128
+ 1, 44, :_reduce_13,
129
+ 1, 44, :_reduce_14,
130
+ 1, 44, :_reduce_15,
131
+ 1, 44, :_reduce_16,
132
+ 3, 46, :_reduce_17,
133
+ 6, 46, :_reduce_18,
134
+ 5, 46, :_reduce_19,
135
+ 5, 46, :_reduce_20,
136
+ 1, 48, :_reduce_none,
137
+ 1, 48, :_reduce_none,
138
+ 1, 45, :_reduce_none,
139
+ 1, 45, :_reduce_none,
140
+ 1, 45, :_reduce_none,
141
+ 2, 45, :_reduce_26,
142
+ 2, 45, :_reduce_27,
143
+ 3, 45, :_reduce_28,
144
+ 2, 50, :_reduce_29,
145
+ 1, 50, :_reduce_none,
146
+ 2, 47, :_reduce_31,
147
+ 2, 47, :_reduce_32,
148
+ 1, 47, :_reduce_none,
149
+ 1, 47, :_reduce_none,
150
+ 5, 51, :_reduce_35,
151
+ 1, 52, :_reduce_none,
152
+ 1, 52, :_reduce_none,
153
+ 1, 52, :_reduce_none,
154
+ 1, 52, :_reduce_none,
155
+ 1, 52, :_reduce_none,
156
+ 1, 52, :_reduce_none,
157
+ 1, 52, :_reduce_none,
158
+ 1, 52, :_reduce_none,
159
+ 1, 52, :_reduce_none,
160
+ 1, 52, :_reduce_none,
161
+ 1, 52, :_reduce_none,
162
+ 1, 52, :_reduce_none,
163
+ 1, 52, :_reduce_none,
164
+ 1, 52, :_reduce_none,
165
+ 4, 49, :_reduce_50,
166
+ 4, 49, :_reduce_51,
167
+ 4, 49, :_reduce_52,
168
+ 3, 49, :_reduce_53,
169
+ 1, 53, :_reduce_54,
170
+ 1, 53, :_reduce_55,
171
+ 1, 53, :_reduce_56 ]
172
+
173
+ racc_reduce_n = 57
174
+
175
+ racc_shift_n = 90
176
+
177
+ racc_token_table = {
178
+ false => 0,
179
+ :error => 1,
180
+ :BAR => 2,
181
+ :LBRACK => 3,
182
+ :RBRACK => 4,
183
+ :NEGATE => 5,
184
+ :CCLASS => 6,
185
+ :DOT => 7,
186
+ :CHAR => 8,
187
+ :LPAREN => 9,
188
+ :RPAREN => 10,
189
+ :QMARK => 11,
190
+ :COLON => 12,
191
+ :NAME => 13,
192
+ :L_ANCHOR => 14,
193
+ :R_ANCHOR => 15,
194
+ :STAR => 16,
195
+ :PLUS => 17,
196
+ :LCURLY => 18,
197
+ :RCURLY => 19,
198
+ "alnum" => 20,
199
+ "alpha" => 21,
200
+ "ascii" => 22,
201
+ "blank" => 23,
202
+ "cntrl" => 24,
203
+ "digit" => 25,
204
+ "graph" => 26,
205
+ "lower" => 27,
206
+ "print" => 28,
207
+ "punct" => 29,
208
+ "space" => 30,
209
+ "upper" => 31,
210
+ "word" => 32,
211
+ "xdigit" => 33,
212
+ :MINUS => 34,
213
+ :MULTILINE => 35,
214
+ :IGNORECASE => 36,
215
+ :EXTENDED => 37 }
216
+
217
+ racc_nt_base = 38
218
+
219
+ racc_use_result_var = true
220
+
221
+ Racc_arg = [
222
+ racc_action_table,
223
+ racc_action_check,
224
+ racc_action_default,
225
+ racc_action_pointer,
226
+ racc_goto_table,
227
+ racc_goto_check,
228
+ racc_goto_default,
229
+ racc_goto_pointer,
230
+ racc_nt_base,
231
+ racc_reduce_table,
232
+ racc_token_table,
233
+ racc_shift_n,
234
+ racc_reduce_n,
235
+ racc_use_result_var ]
236
+
237
+ Racc_token_to_s_table = [
238
+ "$end",
239
+ "error",
240
+ "BAR",
241
+ "LBRACK",
242
+ "RBRACK",
243
+ "NEGATE",
244
+ "CCLASS",
245
+ "DOT",
246
+ "CHAR",
247
+ "LPAREN",
248
+ "RPAREN",
249
+ "QMARK",
250
+ "COLON",
251
+ "NAME",
252
+ "L_ANCHOR",
253
+ "R_ANCHOR",
254
+ "STAR",
255
+ "PLUS",
256
+ "LCURLY",
257
+ "RCURLY",
258
+ "\"alnum\"",
259
+ "\"alpha\"",
260
+ "\"ascii\"",
261
+ "\"blank\"",
262
+ "\"cntrl\"",
263
+ "\"digit\"",
264
+ "\"graph\"",
265
+ "\"lower\"",
266
+ "\"print\"",
267
+ "\"punct\"",
268
+ "\"space\"",
269
+ "\"upper\"",
270
+ "\"word\"",
271
+ "\"xdigit\"",
272
+ "MINUS",
273
+ "MULTILINE",
274
+ "IGNORECASE",
275
+ "EXTENDED",
276
+ "$start",
277
+ "expression",
278
+ "alternation",
279
+ "subexpression",
280
+ "expression_ary",
281
+ "quantified_atom",
282
+ "atom",
283
+ "quantifier",
284
+ "group",
285
+ "bracket_expression",
286
+ "anchor",
287
+ "options",
288
+ "quantifier_char",
289
+ "posix_bracket_expression",
290
+ "posix_bracket_type",
291
+ "modifier" ]
292
+
293
+ Racc_debug_parser = false
294
+
295
+ ##### State transition tables end #####
296
+
297
+ # reduce 0 omitted
298
+
299
+ def _reduce_1(val, _values, result)
300
+ result = Expression.new(val[0])
301
+ result
302
+ end
303
+
304
+ # reduce 2 omitted
305
+
306
+ def _reduce_3(val, _values, result)
307
+ result = val[0] + [val[2]]
308
+ result
309
+ end
310
+
311
+ def _reduce_4(val, _values, result)
312
+ result = Alternation.new(val[0], val[2])
313
+ result
314
+ end
315
+
316
+ def _reduce_5(val, _values, result)
317
+ result = Expression.new(val[0])
318
+ result
319
+ end
320
+
321
+ def _reduce_6(val, _values, result)
322
+ result = val[0] + [val[1]]
323
+ result
324
+ end
325
+
326
+ def _reduce_7(val, _values, result)
327
+ result = [val[0]]
328
+ result
329
+ end
330
+
331
+ def _reduce_8(val, _values, result)
332
+ result = val[0].dup(:quantifier => val[1])
333
+ result
334
+ end
335
+
336
+ # reduce 9 omitted
337
+
338
+ # reduce 10 omitted
339
+
340
+ def _reduce_11(val, _values, result)
341
+ result = CharacterClass.new(val[1])
342
+ result
343
+ end
344
+
345
+ def _reduce_12(val, _values, result)
346
+ result = CharacterClass.new(val[2], :negate => true)
347
+ result
348
+ end
349
+
350
+ def _reduce_13(val, _values, result)
351
+ result = CharacterClass.new(val[0])
352
+ result
353
+ end
354
+
355
+ def _reduce_14(val, _values, result)
356
+ result = CharacterClass.new('.')
357
+ result
358
+ end
359
+
360
+ def _reduce_15(val, _values, result)
361
+ result = Anchor.new(val[0])
362
+ result
363
+ end
364
+
365
+ def _reduce_16(val, _values, result)
366
+ result = Character.new(val[0])
367
+ result
368
+ end
369
+
370
+ def _reduce_17(val, _values, result)
371
+ result = Group.new(val[1], :index => @capture_index_stack.pop)
372
+
373
+ result
374
+ end
375
+
376
+ def _reduce_18(val, _values, result)
377
+ result = Group.new(val[4], val[2].merge(:capture => false))
378
+ @options_stack.pop
379
+
380
+ result
381
+ end
382
+
383
+ def _reduce_19(val, _values, result)
384
+ result = Group.new(val[3], :capture => false);
385
+
386
+ result
387
+ end
388
+
389
+ def _reduce_20(val, _values, result)
390
+ result = Group.new(val[3], :name => val[2], :index => @capture_index_stack.pop);
391
+
392
+ result
393
+ end
394
+
395
+ # reduce 21 omitted
396
+
397
+ # reduce 22 omitted
398
+
399
+ # reduce 23 omitted
400
+
401
+ # reduce 24 omitted
402
+
403
+ # reduce 25 omitted
404
+
405
+ def _reduce_26(val, _values, result)
406
+ result = val.join
407
+ result
408
+ end
409
+
410
+ def _reduce_27(val, _values, result)
411
+ result = val.join
412
+ result
413
+ end
414
+
415
+ def _reduce_28(val, _values, result)
416
+ result = val.join
417
+ result
418
+ end
419
+
420
+ def _reduce_29(val, _values, result)
421
+ result = val.join
422
+ result
423
+ end
424
+
425
+ # reduce 30 omitted
426
+
427
+ def _reduce_31(val, _values, result)
428
+ result = val.join
429
+ result
430
+ end
431
+
432
+ def _reduce_32(val, _values, result)
433
+ result = val.join
434
+ result
435
+ end
436
+
437
+ # reduce 33 omitted
438
+
439
+ # reduce 34 omitted
440
+
441
+ def _reduce_35(val, _values, result)
442
+ result = val.join
443
+ result
444
+ end
445
+
446
+ # reduce 36 omitted
447
+
448
+ # reduce 37 omitted
449
+
450
+ # reduce 38 omitted
451
+
452
+ # reduce 39 omitted
453
+
454
+ # reduce 40 omitted
455
+
456
+ # reduce 41 omitted
457
+
458
+ # reduce 42 omitted
459
+
460
+ # reduce 43 omitted
461
+
462
+ # reduce 44 omitted
463
+
464
+ # reduce 45 omitted
465
+
466
+ # reduce 46 omitted
467
+
468
+ # reduce 47 omitted
469
+
470
+ # reduce 48 omitted
471
+
472
+ # reduce 49 omitted
473
+
474
+ def _reduce_50(val, _values, result)
475
+ @options_stack << result = { val[1] => false, val[2] => false, val[3] => false }
476
+
477
+ result
478
+ end
479
+
480
+ def _reduce_51(val, _values, result)
481
+ @options_stack << result = { val[0] => true, val[2] => false, val[3] => false }
482
+
483
+ result
484
+ end
485
+
486
+ def _reduce_52(val, _values, result)
487
+ @options_stack << result = { val[0] => true, val[1] => true, val[3] => false }
488
+
489
+ result
490
+ end
491
+
492
+ def _reduce_53(val, _values, result)
493
+ @options_stack << result = { val[0] => true, val[1] => true, val[2] => true }
494
+
495
+ result
496
+ end
497
+
498
+ def _reduce_54(val, _values, result)
499
+ result = :multiline
500
+ result
501
+ end
502
+
503
+ def _reduce_55(val, _values, result)
504
+ result = :ignorecase
505
+ result
506
+ end
507
+
508
+ def _reduce_56(val, _values, result)
509
+ result = :extended
510
+ result
511
+ end
512
+
513
+ def _reduce_none(val, _values, result)
514
+ val[0]
515
+ end
516
+
517
+ end # class Parser
518
+ end # module Regin
519
+
520
+ require 'regin/tokenizer'