sourcify-0.5.0/0000755000175000017500000000000011755746006012410 5ustar gwolfgwolfsourcify-0.5.0/lib/0000755000175000017500000000000011755746006013156 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/0000755000175000017500000000000011755746006015021 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/proc/0000755000175000017500000000000011755746006015764 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/proc/parser.rb0000644000175000017500000000305611755746006017611 0ustar gwolfgwolfSourcify.require_rb('proc', 'scanner') %w{normalizer code_scanner source_code converter}.each do |file| Sourcify.require_rb('proc', 'parser', file) end module Sourcify module Proc class Parser #:nodoc:all IS_19x = RUBY_VERSION.include?('1.9.') def initialize(_proc) @arity, @source_code = _proc.arity, SourceCode.new(*_proc.source_location(false)) raise CannotHandleCreatedOnTheFlyProcError unless @source_code.file raise CannotParseEvalCodeError if @source_code.file == '(eval)' @binding = _proc.binding # this must come after the above check end def source(opts) (@sources ||= {})[opts.hash] ||= Converter.to_code(sexp(opts)) end def sexp(opts) (@sexps ||= {})[opts.hash] ||= ( raw_code = ("\n" * @source_code.line) + extracted_source(opts) raw_sexp = Converter.to_sexp(raw_code, @source_code.file) sexp = Normalizer.process(raw_sexp, @binding) opts[:strip_enclosure] ? Sexp.from_array(sexp.to_a.last) : sexp ) end def raw_source(opts) raw_code = extracted_source(opts).strip opts[:strip_enclosure] ? raw_code.sub(/^proc\s*(\{|do)\s*(\|[^\|]+\|)?(.*)(\}|end)$/m, '\3').strip : raw_code end private def extracted_source(opts) CodeScanner.process(@source_code, opts) do |code| begin eval(code).arity == @arity rescue Exception raise ParserInternalError end end end end end end sourcify-0.5.0/lib/sourcify/proc/scanner.rb0000644000175000017500000016035711755746006017756 0ustar gwolfgwolf # line 1 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" Sourcify.require_rb('proc', 'scanner', 'extensions') module Sourcify module Proc module Scanner #:nodoc:all # line 471 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" class << self attr_accessor :_proc_scanner_actions private :_proc_scanner_actions, :_proc_scanner_actions= end self._proc_scanner_actions = [ 0, 1, 0, 1, 2, 1, 3, 1, 4, 1, 5, 1, 6, 1, 7, 1, 8, 1, 9, 1, 10, 1, 11, 1, 13, 1, 15, 1, 16, 1, 17, 1, 20, 1, 21, 1, 22, 1, 23, 1, 24, 1, 25, 1, 26, 1, 27, 1, 28, 1, 29, 1, 30, 1, 31, 1, 32, 1, 33, 1, 34, 1, 35, 1, 36, 1, 37, 1, 38, 1, 39, 1, 40, 1, 41, 1, 42, 1, 43, 1, 44, 1, 45, 1, 46, 1, 47, 1, 48, 1, 49, 1, 50, 1, 51, 1, 52, 1, 53, 1, 54, 1, 55, 1, 56, 1, 57, 1, 58, 1, 59, 1, 60, 1, 61, 1, 62, 1, 63, 1, 64, 1, 65, 1, 66, 1, 67, 1, 68, 1, 69, 1, 70, 1, 71, 1, 72, 1, 73, 1, 74, 1, 75, 1, 76, 1, 77, 1, 78, 1, 79, 1, 80, 1, 81, 1, 82, 1, 83, 1, 88, 1, 89, 1, 90, 1, 91, 1, 92, 1, 93, 1, 94, 1, 95, 1, 96, 1, 97, 1, 98, 1, 99, 1, 100, 1, 101, 1, 102, 1, 103, 1, 104, 1, 105, 1, 106, 1, 107, 1, 108, 1, 109, 1, 110, 1, 111, 1, 112, 1, 113, 2, 0, 1, 2, 3, 12, 2, 3, 14, 2, 3, 18, 2, 3, 19, 2, 3, 84, 2, 3, 85, 2, 3, 86, 2, 3, 87 ] class << self attr_accessor :_proc_scanner_key_offsets private :_proc_scanner_key_offsets, :_proc_scanner_key_offsets= end self._proc_scanner_key_offsets = [ 0, 0, 1, 2, 3, 4, 5, 6, 7, 11, 19, 24, 35, 36, 37, 41, 51, 58, 62, 63, 64, 65, 72, 73, 74, 75, 76, 77, 89, 94, 95, 96, 97, 98, 105, 106, 107, 108, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 121, 123, 125, 127, 128, 129, 157, 185, 187, 188, 189, 191, 193, 195, 196, 197, 199, 201, 203, 204, 205, 207, 209, 211, 212, 213, 215, 217, 219, 220, 221, 223, 225, 227, 228, 229, 231, 233, 235, 236, 237, 239, 241, 243, 244, 245, 247, 249, 251, 252, 253, 255, 257, 259, 260, 261, 263, 265, 267, 268, 269, 271, 273, 275, 276, 277, 279, 281, 283, 284, 285, 287, 289, 291, 292, 293, 295, 297, 299, 300, 301, 303, 305, 307, 308, 309, 311, 313, 315, 316, 317, 319, 321, 323, 324, 325, 327, 329, 331, 332, 333, 335, 337, 339, 340, 341, 343, 345, 347, 348, 349, 351, 353, 355, 356, 358, 360, 361, 362, 364, 365, 366, 368, 370, 372, 373, 374, 376, 378, 380, 381, 382, 384, 386, 388, 389, 390, 392, 394, 396, 397, 398, 400, 402, 404, 405, 406, 408, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 466, 470, 471, 476, 484, 491, 492, 493, 501, 502, 503, 511, 520, 529, 538, 547, 556, 565, 577, 581, 582, 584, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 608, 642, 644, 646, 648, 650, 652, 654, 656, 658, 660, 662, 664, 666, 668, 670, 672, 674, 676, 678, 680, 682, 684, 686, 687, 689, 691, 693, 695, 697, 699, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, 727, 728 ] class << self attr_accessor :_proc_scanner_trans_keys private :_proc_scanner_trans_keys, :_proc_scanner_trans_keys= end self._proc_scanner_trans_keys = [ 98, 101, 103, 105, 110, 10, 58, 65, 90, 97, 122, 34, 39, 45, 95, 65, 90, 97, 122, 95, 65, 90, 97, 122, 10, 34, 39, 58, 95, 48, 57, 65, 90, 97, 122, 10, 58, 65, 90, 97, 122, 10, 34, 39, 95, 48, 57, 65, 90, 97, 122, 34, 39, 95, 65, 90, 97, 122, 65, 90, 97, 122, 103, 105, 110, 95, 48, 57, 65, 90, 97, 122, 115, 101, 97, 115, 115, 9, 32, 60, 95, 11, 13, 48, 57, 65, 90, 97, 122, 9, 32, 60, 11, 13, 60, 10, 102, 114, 95, 48, 57, 65, 90, 97, 122, 100, 117, 108, 108, 116, 101, 115, 115, 105, 108, 105, 108, 101, 10, 10, 61, 10, 101, 10, 110, 10, 100, 10, 10, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 63, 64, 91, 92, 94, 95, 96, 123, 124, 126, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 63, 64, 91, 92, 94, 95, 96, 123, 124, 126, 33, 92, 33, 33, 33, 92, 33, 92, 34, 92, 34, 34, 34, 92, 34, 92, 35, 92, 35, 35, 35, 92, 35, 92, 36, 92, 36, 36, 36, 92, 36, 92, 37, 92, 37, 37, 37, 92, 37, 92, 38, 92, 38, 38, 38, 92, 38, 92, 39, 92, 39, 39, 39, 92, 39, 92, 41, 92, 41, 41, 41, 92, 41, 92, 42, 92, 42, 42, 42, 92, 42, 92, 43, 92, 43, 43, 43, 92, 43, 92, 44, 92, 44, 44, 44, 92, 44, 92, 45, 92, 45, 45, 45, 92, 45, 92, 46, 92, 46, 46, 46, 92, 46, 92, 47, 92, 47, 47, 47, 92, 47, 92, 58, 92, 58, 58, 58, 92, 58, 92, 59, 92, 59, 59, 59, 92, 59, 92, 62, 92, 62, 62, 62, 92, 62, 92, 61, 92, 61, 61, 61, 92, 61, 92, 63, 92, 63, 63, 63, 92, 63, 92, 64, 92, 64, 64, 64, 92, 64, 92, 92, 93, 93, 93, 92, 93, 92, 93, 41, 92, 92, 41, 92, 41, 92, 92, 92, 92, 94, 94, 94, 92, 94, 92, 94, 92, 95, 95, 95, 92, 95, 92, 95, 92, 96, 96, 96, 92, 96, 92, 96, 92, 125, 125, 125, 92, 125, 92, 125, 92, 124, 124, 124, 92, 124, 92, 124, 92, 126, 126, 126, 92, 126, 92, 126, 34, 39, 47, 96, 126, 33, 64, 35, 36, 37, 94, 38, 42, 45, 95, 43, 61, 62, 124, 58, 59, 44, 46, 63, 125, 93, 41, 92, 10, 32, 34, 35, 37, 39, 40, 44, 47, 58, 59, 60, 61, 92, 96, 100, 101, 116, 123, 125, 9, 13, 48, 57, 65, 90, 95, 122, 9, 32, 11, 13, 61, 95, 65, 90, 97, 122, 58, 95, 48, 57, 65, 90, 97, 122, 95, 48, 57, 65, 90, 97, 122, 60, 62, 58, 95, 48, 57, 65, 90, 97, 122, 58, 10, 58, 95, 48, 57, 65, 90, 97, 122, 58, 95, 111, 48, 57, 65, 90, 97, 122, 58, 95, 110, 48, 57, 65, 90, 97, 122, 58, 95, 100, 48, 57, 65, 90, 97, 122, 58, 95, 104, 48, 57, 65, 90, 97, 122, 58, 95, 101, 48, 57, 65, 90, 97, 122, 58, 95, 110, 48, 57, 65, 90, 97, 122, 9, 32, 98, 99, 100, 102, 105, 109, 117, 119, 11, 13, 9, 32, 11, 13, 101, 97, 108, 9, 32, 60, 11, 13, 10, 60, 101, 111, 102, 111, 110, 104, 10, 10, 10, 10, 10, 10, 34, 37, 39, 47, 96, 33, 34, 35, 36, 37, 38, 39, 40, 42, 43, 44, 45, 46, 47, 58, 59, 60, 61, 63, 64, 81, 87, 91, 92, 94, 95, 96, 113, 114, 119, 120, 123, 124, 126, 33, 92, 34, 92, 35, 92, 36, 92, 37, 92, 38, 92, 39, 92, 41, 92, 42, 92, 43, 92, 44, 92, 45, 92, 46, 92, 47, 92, 58, 92, 59, 92, 62, 92, 61, 92, 63, 92, 64, 92, 92, 93, 41, 92, 92, 92, 94, 92, 95, 92, 96, 92, 125, 92, 124, 92, 126, 39, 92, 34, 39, 47, 96, 126, 33, 64, 35, 36, 37, 94, 38, 42, 45, 95, 43, 61, 62, 124, 58, 59, 44, 46, 63, 125, 93, 41, 92, 0 ] class << self attr_accessor :_proc_scanner_single_lengths private :_proc_scanner_single_lengths, :_proc_scanner_single_lengths= end self._proc_scanner_single_lengths = [ 0, 1, 1, 1, 1, 1, 1, 1, 0, 4, 1, 5, 1, 1, 0, 4, 3, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 4, 3, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 28, 28, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 2, 1, 1, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 20, 2, 1, 1, 2, 1, 1, 1, 2, 1, 1, 2, 3, 3, 3, 3, 3, 3, 10, 2, 1, 2, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 5, 34, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] class << self attr_accessor :_proc_scanner_range_lengths private :_proc_scanner_range_lengths, :_proc_scanner_range_lengths= end self._proc_scanner_range_lengths = [ 0, 0, 0, 0, 0, 0, 0, 0, 2, 2, 2, 3, 0, 0, 2, 3, 2, 2, 0, 0, 0, 3, 0, 0, 0, 0, 0, 4, 1, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 4, 1, 0, 2, 3, 3, 0, 0, 3, 0, 0, 3, 3, 3, 3, 3, 3, 3, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] class << self attr_accessor :_proc_scanner_index_offsets private :_proc_scanner_index_offsets, :_proc_scanner_index_offsets= end self._proc_scanner_index_offsets = [ 0, 0, 2, 4, 6, 8, 10, 12, 14, 17, 24, 28, 37, 39, 41, 44, 52, 58, 61, 63, 65, 67, 72, 74, 76, 78, 80, 82, 91, 96, 98, 100, 102, 104, 109, 111, 113, 115, 118, 120, 122, 124, 126, 128, 130, 132, 134, 136, 139, 142, 145, 148, 150, 152, 181, 210, 213, 215, 217, 220, 223, 226, 228, 230, 233, 236, 239, 241, 243, 246, 249, 252, 254, 256, 259, 262, 265, 267, 269, 272, 275, 278, 280, 282, 285, 288, 291, 293, 295, 298, 301, 304, 306, 308, 311, 314, 317, 319, 321, 324, 327, 330, 332, 334, 337, 340, 343, 345, 347, 350, 353, 356, 358, 360, 363, 366, 369, 371, 373, 376, 379, 382, 384, 386, 389, 392, 395, 397, 399, 402, 405, 408, 410, 412, 415, 418, 421, 423, 425, 428, 431, 434, 436, 438, 441, 444, 447, 449, 451, 454, 457, 460, 462, 464, 467, 470, 473, 475, 477, 480, 483, 486, 488, 491, 494, 496, 498, 501, 503, 505, 508, 511, 514, 516, 518, 521, 524, 527, 529, 531, 534, 537, 540, 542, 544, 547, 550, 553, 555, 557, 560, 563, 566, 568, 570, 573, 576, 578, 580, 582, 584, 586, 588, 590, 592, 594, 596, 598, 600, 602, 604, 606, 608, 610, 612, 614, 616, 618, 620, 622, 624, 626, 628, 630, 632, 657, 661, 663, 667, 673, 678, 680, 682, 688, 690, 692, 698, 705, 712, 719, 726, 733, 740, 752, 756, 758, 761, 766, 768, 770, 772, 774, 776, 778, 780, 782, 784, 786, 788, 790, 792, 794, 800, 835, 838, 841, 844, 847, 850, 853, 856, 859, 862, 865, 868, 871, 874, 877, 880, 883, 886, 889, 892, 895, 898, 901, 903, 906, 909, 912, 915, 918, 921, 924, 926, 928, 930, 932, 934, 936, 938, 940, 942, 944, 946, 948, 950, 952, 954, 956, 958, 960, 962, 964, 966, 968, 970, 972, 974, 976, 978 ] class << self attr_accessor :_proc_scanner_indicies private :_proc_scanner_indicies, :_proc_scanner_indicies= end self._proc_scanner_indicies = [ 1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 5, 8, 7, 9, 9, 7, 11, 11, 12, 14, 13, 14, 10, 14, 13, 14, 10, 15, 16, 16, 17, 13, 13, 13, 13, 10, 15, 10, 18, 10, 13, 13, 10, 15, 16, 16, 14, 14, 14, 14, 10, 11, 11, 14, 13, 14, 10, 20, 20, 19, 22, 21, 23, 21, 24, 21, 21, 21, 21, 21, 25, 26, 21, 24, 21, 27, 21, 28, 21, 29, 21, 30, 30, 31, 21, 30, 21, 21, 21, 25, 33, 33, 34, 33, 32, 35, 32, 32, 36, 24, 21, 37, 21, 21, 21, 21, 21, 38, 39, 21, 40, 21, 26, 21, 41, 42, 21, 43, 21, 44, 21, 24, 21, 45, 21, 37, 21, 46, 21, 47, 21, 37, 21, 50, 49, 50, 51, 49, 50, 52, 49, 50, 53, 49, 50, 54, 49, 56, 55, 58, 57, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 59, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 59, 116, 117, 88, 119, 118, 116, 118, 116, 122, 121, 119, 122, 121, 116, 123, 89, 125, 124, 116, 124, 116, 127, 126, 125, 127, 126, 116, 128, 90, 130, 129, 116, 129, 116, 132, 131, 130, 132, 131, 116, 133, 91, 135, 134, 116, 134, 116, 137, 136, 135, 137, 136, 116, 138, 92, 140, 139, 116, 139, 116, 142, 141, 140, 142, 141, 116, 143, 93, 145, 144, 116, 144, 116, 147, 146, 145, 147, 146, 116, 149, 94, 151, 150, 116, 150, 116, 153, 152, 151, 153, 152, 116, 154, 95, 156, 155, 116, 155, 116, 158, 157, 156, 158, 157, 116, 159, 96, 161, 160, 116, 160, 116, 163, 162, 161, 163, 162, 116, 164, 97, 166, 165, 116, 165, 116, 168, 167, 166, 168, 167, 116, 169, 98, 171, 170, 116, 170, 116, 173, 172, 171, 173, 172, 116, 174, 99, 176, 175, 116, 175, 116, 178, 177, 176, 178, 177, 116, 179, 100, 181, 180, 116, 180, 116, 183, 182, 181, 183, 182, 116, 184, 101, 186, 185, 116, 185, 116, 188, 187, 186, 188, 187, 116, 189, 102, 191, 190, 116, 190, 116, 193, 192, 191, 193, 192, 116, 194, 103, 196, 195, 116, 195, 116, 198, 197, 196, 198, 197, 116, 199, 104, 201, 200, 116, 200, 116, 203, 202, 201, 203, 202, 116, 204, 105, 206, 205, 116, 205, 116, 208, 207, 206, 208, 207, 116, 209, 106, 211, 210, 116, 210, 116, 213, 212, 211, 213, 212, 116, 214, 107, 216, 215, 116, 215, 116, 218, 217, 216, 218, 217, 219, 116, 108, 221, 220, 116, 220, 223, 116, 222, 223, 221, 222, 224, 225, 109, 116, 224, 120, 227, 226, 120, 228, 226, 230, 229, 225, 229, 231, 116, 110, 233, 232, 116, 232, 235, 116, 234, 235, 233, 234, 236, 116, 111, 238, 237, 116, 237, 240, 116, 239, 240, 238, 239, 241, 116, 112, 243, 242, 116, 242, 245, 116, 244, 245, 243, 244, 246, 116, 113, 248, 247, 116, 247, 250, 116, 249, 250, 248, 249, 251, 116, 114, 253, 252, 116, 252, 255, 116, 254, 255, 253, 254, 256, 116, 115, 258, 257, 116, 257, 260, 116, 259, 260, 258, 259, 262, 261, 264, 263, 266, 265, 268, 267, 270, 269, 272, 271, 274, 273, 276, 275, 278, 277, 280, 279, 282, 281, 284, 283, 286, 285, 288, 287, 290, 289, 292, 291, 294, 293, 296, 295, 298, 297, 300, 299, 302, 301, 304, 303, 306, 305, 308, 307, 310, 309, 312, 311, 314, 313, 316, 315, 319, 318, 320, 321, 320, 320, 322, 322, 323, 325, 322, 326, 327, 328, 320, 330, 331, 332, 333, 334, 318, 324, 20, 329, 317, 318, 318, 318, 335, 337, 336, 339, 9, 339, 338, 341, 9, 9, 9, 9, 340, 339, 339, 339, 339, 340, 342, 338, 344, 343, 346, 20, 20, 20, 20, 345, 348, 347, 349, 338, 351, 329, 329, 329, 329, 350, 351, 329, 353, 329, 329, 329, 352, 351, 329, 354, 329, 329, 329, 352, 351, 329, 355, 329, 329, 329, 352, 351, 329, 356, 329, 329, 329, 352, 351, 329, 357, 329, 329, 329, 352, 351, 329, 358, 329, 329, 329, 352, 360, 360, 361, 362, 363, 364, 365, 366, 367, 368, 360, 359, 360, 360, 360, 369, 371, 370, 372, 373, 370, 33, 33, 34, 33, 374, 374, 36, 35, 374, 375, 370, 376, 370, 24, 370, 377, 370, 378, 370, 379, 370, 58, 380, 381, 380, 50, 49, 50, 54, 56, 55, 383, 57, 61, 385, 386, 73, 84, 384, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 388, 388, 80, 81, 82, 83, 84, 389, 388, 389, 388, 85, 86, 87, 387, 116, 122, 121, 116, 127, 126, 116, 132, 131, 116, 137, 136, 116, 142, 141, 116, 147, 146, 116, 153, 152, 116, 158, 157, 116, 163, 162, 116, 168, 167, 116, 173, 172, 116, 178, 177, 116, 183, 182, 116, 188, 187, 116, 193, 192, 116, 198, 197, 116, 203, 202, 116, 208, 207, 116, 213, 212, 116, 218, 217, 223, 116, 222, 390, 228, 226, 230, 229, 235, 116, 234, 240, 116, 239, 245, 116, 244, 250, 116, 249, 255, 116, 254, 260, 116, 259, 116, 149, 94, 262, 261, 264, 263, 266, 265, 268, 267, 270, 269, 272, 271, 274, 273, 276, 275, 278, 277, 280, 279, 282, 281, 284, 283, 286, 285, 288, 287, 290, 289, 292, 291, 294, 293, 296, 295, 298, 297, 300, 299, 302, 301, 304, 303, 306, 305, 308, 307, 310, 309, 312, 311, 314, 313, 316, 315, 0 ] class << self attr_accessor :_proc_scanner_trans_targs private :_proc_scanner_trans_targs, :_proc_scanner_trans_targs= end self._proc_scanner_trans_targs = [ 224, 2, 3, 4, 5, 6, 224, 224, 8, 228, 224, 10, 16, 11, 15, 224, 12, 13, 14, 224, 232, 242, 19, 20, 21, 242, 23, 25, 26, 27, 246, 248, 242, 28, 29, 30, 247, 33, 242, 35, 36, 38, 41, 39, 40, 42, 44, 45, 257, 46, 47, 48, 49, 50, 258, 51, 52, 260, 0, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 261, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 110, 115, 120, 125, 130, 135, 140, 145, 150, 155, 160, 166, 171, 176, 181, 186, 191, 261, 56, 57, 263, 261, 58, 59, 61, 62, 264, 63, 64, 66, 67, 265, 68, 69, 71, 72, 266, 73, 74, 76, 77, 267, 78, 79, 81, 82, 268, 83, 84, 261, 86, 87, 269, 88, 89, 91, 92, 270, 93, 94, 96, 97, 271, 98, 99, 101, 102, 272, 103, 104, 106, 107, 273, 108, 109, 111, 112, 274, 113, 114, 116, 117, 275, 118, 119, 121, 122, 276, 123, 124, 126, 127, 277, 128, 129, 131, 132, 278, 133, 134, 136, 137, 279, 138, 139, 141, 142, 280, 143, 144, 146, 147, 281, 148, 149, 151, 152, 282, 153, 154, 156, 157, 283, 158, 159, 161, 284, 162, 163, 164, 165, 285, 167, 168, 286, 169, 170, 172, 173, 287, 174, 175, 177, 178, 288, 179, 180, 182, 183, 289, 184, 185, 187, 188, 290, 189, 190, 192, 193, 291, 194, 195, 196, 293, 197, 294, 198, 295, 199, 296, 200, 297, 201, 298, 202, 299, 203, 300, 204, 301, 205, 302, 206, 303, 207, 304, 208, 305, 209, 306, 210, 307, 211, 308, 212, 309, 213, 310, 214, 311, 215, 312, 216, 313, 217, 314, 218, 315, 219, 316, 220, 317, 221, 318, 222, 319, 223, 320, 224, 225, 226, 224, 224, 224, 224, 224, 227, 230, 231, 234, 235, 236, 237, 239, 224, 224, 224, 224, 1, 224, 229, 224, 7, 9, 224, 224, 224, 233, 224, 17, 224, 224, 224, 224, 235, 238, 235, 240, 241, 235, 242, 243, 244, 245, 249, 250, 251, 252, 253, 254, 242, 242, 18, 22, 24, 242, 31, 32, 34, 37, 43, 256, 255, 257, 259, 261, 262, 292, 261, 53, 54, 261, 261 ] class << self attr_accessor :_proc_scanner_trans_actions private :_proc_scanner_trans_actions, :_proc_scanner_trans_actions= end self._proc_scanner_trans_actions = [ 203, 0, 0, 0, 0, 0, 171, 205, 0, 5, 207, 0, 0, 0, 0, 173, 0, 0, 0, 201, 0, 21, 0, 0, 0, 9, 0, 0, 0, 0, 5, 5, 19, 0, 0, 0, 0, 0, 7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 27, 0, 0, 0, 0, 0, 217, 0, 0, 0, 0, 99, 43, 33, 47, 49, 51, 55, 35, 85, 57, 63, 75, 59, 77, 37, 71, 73, 67, 65, 79, 45, 83, 87, 53, 61, 39, 81, 69, 41, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 31, 0, 0, 5, 97, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 101, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 0, 5, 0, 0, 0, 103, 0, 105, 0, 107, 0, 109, 0, 111, 0, 113, 0, 115, 0, 117, 0, 119, 0, 121, 0, 123, 0, 125, 0, 127, 0, 129, 0, 131, 0, 133, 0, 135, 0, 137, 0, 139, 0, 141, 0, 143, 0, 145, 0, 147, 0, 149, 0, 151, 0, 153, 0, 155, 0, 157, 183, 0, 5, 175, 169, 167, 177, 181, 0, 5, 0, 0, 235, 0, 0, 0, 159, 161, 197, 187, 0, 199, 0, 195, 0, 0, 189, 163, 193, 5, 185, 0, 179, 209, 165, 191, 226, 0, 229, 0, 0, 232, 11, 0, 5, 5, 5, 5, 5, 5, 5, 5, 15, 17, 0, 0, 0, 13, 0, 0, 0, 0, 0, 214, 23, 25, 29, 89, 223, 220, 95, 0, 0, 91, 93 ] class << self attr_accessor :_proc_scanner_to_state_actions private :_proc_scanner_to_state_actions, :_proc_scanner_to_state_actions= end self._proc_scanner_to_state_actions = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 211, 0, 211, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 ] class << self attr_accessor :_proc_scanner_from_state_actions private :_proc_scanner_from_state_actions, :_proc_scanner_from_state_actions= end self._proc_scanner_from_state_actions = [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 0, 3, 0, 3, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ] class << self attr_accessor :_proc_scanner_eof_trans private :_proc_scanner_eof_trans, :_proc_scanner_eof_trans= end self._proc_scanner_eof_trans = [ 0, 1, 1, 1, 1, 1, 1, 8, 8, 11, 11, 11, 11, 11, 11, 11, 11, 20, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 33, 33, 33, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 49, 49, 49, 49, 49, 0, 0, 60, 60, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 149, 149, 149, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 121, 121, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 60, 60, 60, 121, 121, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 336, 337, 339, 341, 341, 339, 344, 346, 348, 339, 351, 353, 353, 353, 353, 353, 353, 0, 370, 371, 371, 375, 375, 375, 371, 371, 371, 371, 371, 371, 0, 382, 0, 383, 0, 384, 0, 388, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 391, 392, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] class << self attr_accessor :proc_scanner_start end self.proc_scanner_start = 224; class << self attr_accessor :proc_scanner_first_final end self.proc_scanner_first_final = 224; class << self attr_accessor :proc_scanner_error end self.proc_scanner_error = 0; class << self attr_accessor :proc_scanner_en_new_statement end self.proc_scanner_en_new_statement = 242; class << self attr_accessor :proc_scanner_en_per_line_comment end self.proc_scanner_en_per_line_comment = 255; class << self attr_accessor :proc_scanner_en_block_comment end self.proc_scanner_en_block_comment = 257; class << self attr_accessor :proc_scanner_en_heredoc end self.proc_scanner_en_heredoc = 259; class << self attr_accessor :proc_scanner_en_string end self.proc_scanner_en_string = 261; class << self attr_accessor :proc_scanner_en_dstring1 end self.proc_scanner_en_dstring1 = 293; class << self attr_accessor :proc_scanner_en_dstring2 end self.proc_scanner_en_dstring2 = 294; class << self attr_accessor :proc_scanner_en_dstring3 end self.proc_scanner_en_dstring3 = 295; class << self attr_accessor :proc_scanner_en_dstring4 end self.proc_scanner_en_dstring4 = 296; class << self attr_accessor :proc_scanner_en_dstring5 end self.proc_scanner_en_dstring5 = 297; class << self attr_accessor :proc_scanner_en_dstring6 end self.proc_scanner_en_dstring6 = 298; class << self attr_accessor :proc_scanner_en_dstring7 end self.proc_scanner_en_dstring7 = 299; class << self attr_accessor :proc_scanner_en_dstring8 end self.proc_scanner_en_dstring8 = 300; class << self attr_accessor :proc_scanner_en_dstring9 end self.proc_scanner_en_dstring9 = 301; class << self attr_accessor :proc_scanner_en_dstring10 end self.proc_scanner_en_dstring10 = 302; class << self attr_accessor :proc_scanner_en_dstring11 end self.proc_scanner_en_dstring11 = 303; class << self attr_accessor :proc_scanner_en_dstring12 end self.proc_scanner_en_dstring12 = 304; class << self attr_accessor :proc_scanner_en_dstring13 end self.proc_scanner_en_dstring13 = 305; class << self attr_accessor :proc_scanner_en_dstring14 end self.proc_scanner_en_dstring14 = 306; class << self attr_accessor :proc_scanner_en_dstring15 end self.proc_scanner_en_dstring15 = 307; class << self attr_accessor :proc_scanner_en_dstring16 end self.proc_scanner_en_dstring16 = 308; class << self attr_accessor :proc_scanner_en_dstring17 end self.proc_scanner_en_dstring17 = 309; class << self attr_accessor :proc_scanner_en_dstring18 end self.proc_scanner_en_dstring18 = 310; class << self attr_accessor :proc_scanner_en_dstring19 end self.proc_scanner_en_dstring19 = 311; class << self attr_accessor :proc_scanner_en_dstring20 end self.proc_scanner_en_dstring20 = 312; class << self attr_accessor :proc_scanner_en_dstring21 end self.proc_scanner_en_dstring21 = 313; class << self attr_accessor :proc_scanner_en_dstring22 end self.proc_scanner_en_dstring22 = 314; class << self attr_accessor :proc_scanner_en_dstring23 end self.proc_scanner_en_dstring23 = 315; class << self attr_accessor :proc_scanner_en_dstring24 end self.proc_scanner_en_dstring24 = 316; class << self attr_accessor :proc_scanner_en_dstring25 end self.proc_scanner_en_dstring25 = 317; class << self attr_accessor :proc_scanner_en_dstring26 end self.proc_scanner_en_dstring26 = 318; class << self attr_accessor :proc_scanner_en_dstring27 end self.proc_scanner_en_dstring27 = 319; class << self attr_accessor :proc_scanner_en_dstring28 end self.proc_scanner_en_dstring28 = 320; class << self attr_accessor :proc_scanner_en_main end self.proc_scanner_en_main = 224; # line 473 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" extend Scanner::Extensions def self.execute! data = @data eof = data.length # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" begin p ||= 0 pe ||= data.length cs = proc_scanner_start ts = nil te = nil act = 0 end # line 480 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" begin _klen, _trans, _keys, _acts, _nacts = nil _goto_level = 0 _resume = 10 _eof_trans = 15 _again = 20 _test_eof = 30 _out = 40 while true _trigger_goto = false if _goto_level <= 0 if p == pe _goto_level = _test_eof next end if cs == 0 _goto_level = _out next end end if _goto_level <= _resume _acts = _proc_scanner_from_state_actions[cs] _nacts = _proc_scanner_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _proc_scanner_actions[_acts - 1] when 2 then # line 1 "NONE" begin ts = p end # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" end # from state action switch end if _trigger_goto next end _keys = _proc_scanner_key_offsets[cs] _trans = _proc_scanner_index_offsets[cs] _klen = _proc_scanner_single_lengths[cs] _break_match = false begin if _klen > 0 _lower = _keys _upper = _keys + _klen - 1 loop do break if _upper < _lower _mid = _lower + ( (_upper - _lower) >> 1 ) if data[p] < _proc_scanner_trans_keys[_mid] _upper = _mid - 1 elsif data[p] > _proc_scanner_trans_keys[_mid] _lower = _mid + 1 else _trans += (_mid - _keys) _break_match = true break end end # loop break if _break_match _keys += _klen _trans += _klen end _klen = _proc_scanner_range_lengths[cs] if _klen > 0 _lower = _keys _upper = _keys + (_klen << 1) - 2 loop do break if _upper < _lower _mid = _lower + (((_upper-_lower) >> 1) & ~1) if data[p] < _proc_scanner_trans_keys[_mid] _upper = _mid - 2 elsif data[p] > _proc_scanner_trans_keys[_mid+1] _lower = _mid + 2 else _trans += ((_mid - _keys) >> 1) _break_match = true break end end # loop break if _break_match _trans += _klen end end while false _trans = _proc_scanner_indicies[_trans] end if _goto_level <= _eof_trans cs = _proc_scanner_trans_targs[_trans] if _proc_scanner_trans_actions[_trans] != 0 _acts = _proc_scanner_trans_actions[_trans] _nacts = _proc_scanner_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _proc_scanner_actions[_acts - 1] when 3 then # line 1 "NONE" begin te = p+1 end when 4 then # line 47 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:kw_do_alias2, ts, te) increment_counter(:do_end, 0..1) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 5 then # line 56 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:kw_do_alias1, ts, te) increment_counter(:do_end, 1) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 6 then # line 63 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin p = p - 1; begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 7 then # line 56 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:kw_do_alias1, ts, te) increment_counter(:do_end, 1) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 8 then # line 62 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:space, ts, te) end end when 9 then # line 63 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin p = p - 1; begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 10 then # line 56 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:kw_do_alias1, ts, te) increment_counter(:do_end, 1) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 11 then # line 63 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin p = p - 1; begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 12 then # line 69 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 5; end when 13 then # line 1 "NONE" begin case act when 0 then begin begin cs = 0 _trigger_goto = true _goto_level = _again break end end when 5 then begin begin p = ((te))-1; end push(:comment, ts.pred, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 14 then # line 77 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 6; end when 15 then # line 77 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin unless push_comment(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 16 then # line 1 "NONE" begin case act when 0 then begin begin cs = 0 _trigger_goto = true _goto_level = _again break end end when 6 then begin begin p = ((te))-1; end unless push_comment(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end end when 17 then # line 86 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin unless push_heredoc(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 18 then # line 142 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 10; end when 19 then # line 171 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 37; end when 20 then # line 135 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:sstring, ts, te); begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 21 then # line 141 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 293 _trigger_goto = true _goto_level = _again break end end end when 22 then # line 142 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 294 _trigger_goto = true _goto_level = _again break end end end when 23 then # line 143 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 295 _trigger_goto = true _goto_level = _again break end end end when 24 then # line 144 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 296 _trigger_goto = true _goto_level = _again break end end end when 25 then # line 145 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 297 _trigger_goto = true _goto_level = _again break end end end when 26 then # line 146 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 298 _trigger_goto = true _goto_level = _again break end end end when 27 then # line 147 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 299 _trigger_goto = true _goto_level = _again break end end end when 28 then # line 148 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 300 _trigger_goto = true _goto_level = _again break end end end when 29 then # line 149 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 301 _trigger_goto = true _goto_level = _again break end end end when 30 then # line 150 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 302 _trigger_goto = true _goto_level = _again break end end end when 31 then # line 151 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 303 _trigger_goto = true _goto_level = _again break end end end when 32 then # line 152 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 304 _trigger_goto = true _goto_level = _again break end end end when 33 then # line 153 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 305 _trigger_goto = true _goto_level = _again break end end end when 34 then # line 154 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 306 _trigger_goto = true _goto_level = _again break end end end when 35 then # line 155 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 307 _trigger_goto = true _goto_level = _again break end end end when 36 then # line 156 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 308 _trigger_goto = true _goto_level = _again break end end end when 37 then # line 157 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 309 _trigger_goto = true _goto_level = _again break end end end when 38 then # line 158 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 310 _trigger_goto = true _goto_level = _again break end end end when 39 then # line 159 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 311 _trigger_goto = true _goto_level = _again break end end end when 40 then # line 160 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 312 _trigger_goto = true _goto_level = _again break end end end when 41 then # line 161 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 313 _trigger_goto = true _goto_level = _again break end end end when 42 then # line 162 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 314 _trigger_goto = true _goto_level = _again break end end end when 43 then # line 163 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 315 _trigger_goto = true _goto_level = _again break end end end when 44 then # line 164 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 316 _trigger_goto = true _goto_level = _again break end end end when 45 then # line 165 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 317 _trigger_goto = true _goto_level = _again break end end end when 46 then # line 166 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 318 _trigger_goto = true _goto_level = _again break end end end when 47 then # line 167 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 319 _trigger_goto = true _goto_level = _again break end end end when 48 then # line 168 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_dstring(ts, te); begin cs = 320 _trigger_goto = true _goto_level = _again break end end end when 49 then # line 171 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:any, ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 50 then # line 135 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:sstring, ts, te); begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 51 then # line 142 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push_dstring(ts, te); begin cs = 294 _trigger_goto = true _goto_level = _again break end end end when 52 then # line 171 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:any, ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 53 then # line 135 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:sstring, ts, te); begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 54 then # line 171 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:any, ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end when 55 then # line 1 "NONE" begin case act when 10 then begin begin p = ((te))-1; end push_dstring(ts, te); begin cs = 294 _trigger_goto = true _goto_level = _again break end end when 37 then begin begin p = ((te))-1; end push(:any, ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 56 then # line 179 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 57 then # line 186 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 58 then # line 193 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 59 then # line 200 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 60 then # line 207 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 61 then # line 214 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 62 then # line 221 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 63 then # line 228 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 64 then # line 235 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 65 then # line 242 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 66 then # line 249 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 67 then # line 256 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 68 then # line 263 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 69 then # line 270 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 70 then # line 277 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 71 then # line 284 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 72 then # line 291 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 73 then # line 298 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 74 then # line 305 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 75 then # line 312 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 76 then # line 319 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 77 then # line 326 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 78 then # line 333 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 79 then # line 340 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 80 then # line 347 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 81 then # line 354 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 82 then # line 361 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 83 then # line 368 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin unless push_dstring(ts, te) begin cs = 224 _trigger_goto = true _goto_level = _again break end end end end when 84 then # line 380 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 66; end when 85 then # line 386 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 67; end when 86 then # line 421 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 73; end when 87 then # line 460 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin act = 79; end when 88 then # line 393 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:lbrace, ts, te) increment_counter(:brace) end end when 89 then # line 398 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:rbrace, ts, te) decrement_counter(:brace) end end when 90 then # line 403 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:assoc, ts, te) fix_counter_false_start(:brace) end end when 91 then # line 408 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_label(ts, te) fix_counter_false_start(:brace) end end when 92 then # line 421 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:newline_alias, ts, te) begin cs = 242 _trigger_goto = true _goto_level = _again break end end end when 93 then # line 428 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin begin cs = 255 _trigger_goto = true _goto_level = _again break end end end when 94 then # line 432 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_comment(ts, te) increment_lineno begin cs = 257 _trigger_goto = true _goto_level = _again break end end end when 95 then # line 440 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push_heredoc(ts, te) increment_lineno begin cs = 259 _trigger_goto = true _goto_level = _again break end end end when 96 then # line 446 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin p = p - 1; begin cs = 261 _trigger_goto = true _goto_level = _again break end end end when 97 then # line 450 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin if preceded_with?(:char, :digit, :var, :const, :symbol, :dstring, :sstring, ')', ']', '}') push(:op, ts, te) else p = p - 1; begin cs = 261 _trigger_goto = true _goto_level = _again break end end end end when 98 then # line 461 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:bslash, ts, te) end end when 99 then # line 465 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:digit, ts, te) end end when 100 then # line 467 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p+1 begin push(:any, ts, te) end end when 101 then # line 408 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push_label(ts, te) fix_counter_false_start(:brace) end end when 102 then # line 415 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:newline, ts, te) increment_lineno begin cs = 242 _trigger_goto = true _goto_level = _again break end end end when 103 then # line 421 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:newline_alias, ts, te) begin cs = 242 _trigger_goto = true _goto_level = _again break end end end when 104 then # line 460 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:var, ts, te) end end when 105 then # line 462 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:const, ts, te) end end when 106 then # line 463 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:symbol, ts, te) end end when 107 then # line 464 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:space, ts, te) end end when 108 then # line 467 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin te = p p = p - 1; begin push(:any, ts, te) end end when 109 then # line 408 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push_label(ts, te) fix_counter_false_start(:brace) end end when 110 then # line 415 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:newline, ts, te) increment_lineno begin cs = 242 _trigger_goto = true _goto_level = _again break end end end when 111 then # line 463 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:symbol, ts, te) end end when 112 then # line 467 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" begin begin p = ((te))-1; end begin push(:any, ts, te) end end when 113 then # line 1 "NONE" begin case act when 66 then begin begin p = ((te))-1; end push(:kw_do, ts, te) increment_counter(:do_end) begin cs = 242 _trigger_goto = true _goto_level = _again break end end when 67 then begin begin p = ((te))-1; end push(:kw_end, ts, te) decrement_counter(:do_end) end when 73 then begin begin p = ((te))-1; end push(:newline_alias, ts, te) begin cs = 242 _trigger_goto = true _goto_level = _again break end end when 79 then begin begin p = ((te))-1; end push(:var, ts, te) end end end # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" end # action switch end end if _trigger_goto next end end if _goto_level <= _again _acts = _proc_scanner_to_state_actions[cs] _nacts = _proc_scanner_actions[_acts] _acts += 1 while _nacts > 0 _nacts -= 1 _acts += 1 case _proc_scanner_actions[_acts - 1] when 0 then # line 1 "NONE" begin ts = nil; end when 1 then # line 1 "NONE" begin act = 0 end # line 2 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rb" end # to state action switch end if _trigger_goto next end if cs == 0 _goto_level = _out next end p += 1 if p != pe _goto_level = _resume next end end if _goto_level <= _test_eof if p == eof if _proc_scanner_eof_trans[cs] > 0 _trans = _proc_scanner_eof_trans[cs] - 1; _goto_level = _eof_trans next; end end end if _goto_level <= _out break end end end # line 481 "/home/ty.archlinux/dev/ty/sourcify/spec/../lib/sourcify/proc/scanner.rl" end end end end sourcify-0.5.0/lib/sourcify/proc/scanner.rl0000644000175000017500000002713711755746006017766 0ustar gwolfgwolfSourcify.require_rb('proc', 'scanner', 'extensions') module Sourcify module Proc module Scanner #:nodoc:all %%{ machine proc_scanner; kw_class = 'class'; kw_module = 'module'; kw_def = 'def'; kw_begin = 'begin'; kw_case = 'case'; kw_if = 'if'; kw_unless = 'unless'; kw_do = 'do'; kw_then = 'then'; kw_for = 'for'; kw_while = 'while'; kw_until = 'until'; kw_end = 'end'; vchar = alnum | '_'; const = upper . vchar* . ('::' . alpha . vchar*)*; var = (lower | '_') . vchar*; meth = (alpha | '_') . vchar*; symbol = ':' . (var | const); assoc = '=>'; assgn = '='; comma = ','; label = (var | const) . ':'; lparen = '('; rparen = ')'; lbrace = '{'; rbrace = '}'; smcolon = ';'; newline = '\n'; bslash = '\\' . newline; ospaces = space* -- newline; mspaces = space+ -- newline; ## MACHINE >> New statement new_statement := |* (kw_for | kw_while | kw_until) . ^vchar => { push(:kw_do_alias2, ts, te) increment_counter(:do_end, 0..1) fgoto main; }; ( ((kw_class | kw_module | kw_def | kw_begin | kw_case | kw_if | kw_unless) . ^vchar) | (kw_class . ospaces . '<<' . ospaces . ^newline+) ) => { push(:kw_do_alias1, ts, te) increment_counter(:do_end, 1) fgoto main; }; ospaces => { push(:space, ts, te) }; any => { fhold; fgoto main; }; *|; ## MACHINE >> One-liner comment per_line_comment := |* ^newline* => { push(:comment, ts.pred, te) fgoto main; }; *|; ## MACHINE >> Block comment block_comment := |* any* . newline . '=end' . ospaces . ^newline* => { unless push_comment(ts, te) fgoto main; end }; *|; ## MACHINE >> Heredoc heredoc := |* ^newline* . newline . ospaces . ^newline+ => { unless push_heredoc(ts, te) fgoto main; end }; *|; ## MACHINE >> String string := |* sqm = '%q' | '%w'; dqm = '%Q' | '%W' | '%x' | '%r' | '%'; ## == Single quote strings sqs1 = "'" . ([^\']* | ([^\'\\]*[\\][\'][^\']*)*) . '\\\\'* . "'"; sqs2 = '~' . ([^\~]* | ([^\~\\]*[\\][\~][^\~]*)*) . '\\\\'* . '~'; sqs3 = '`' . ([^\`]* | ([^\`\\]*[\\][\`][^\`]*)*) . '\\\\'* . '`'; sqs4 = '!' . ([^\!]* | ([^\!\\]*[\\][\!][^\!]*)*) . '\\\\'* . '!'; sqs5 = '@' . ([^\@]* | ([^\@\\]*[\\][\@][^\@]*)*) . '\\\\'* . '@'; sqs6 = '#' . ([^\#]* | ([^\#\\]*[\\][\#][^\#]*)*) . '\\\\'* . '#'; sqs7 = '$' . ([^\$]* | ([^\$\\]*[\\][\$][^\$]*)*) . '\\\\'* . '$'; sqs8 = '%' . ([^\%]* | ([^\%\\]*[\\][\%][^\%]*)*) . '\\\\'* . '%'; sqs9 = '^' . ([^\^]* | ([^\^\\]*[\\][\^][^\^]*)*) . '\\\\'* . '^'; sqs10 = '&' . ([^\&]* | ([^\&\\]*[\\][\&][^\&]*)*) . '\\\\'* . '&'; sqs11 = '*' . ([^\*]* | ([^\*\\]*[\\][\*][^\*]*)*) . '\\\\'* . '*'; sqs12 = '-' . ([^\-]* | ([^\-\\]*[\\][\-][^\-]*)*) . '\\\\'* . '-'; sqs13 = '_' . ([^\_]* | ([^\_\\]*[\\][\_][^\_]*)*) . '\\\\'* . '_'; sqs14 = '+' . ([^\+]* | ([^\+\\]*[\\][\+][^\+]*)*) . '\\\\'* . '+'; sqs15 = '=' . ([^\=]* | ([^\=\\]*[\\][\=][^\=]*)*) . '\\\\'* . '='; sqs16 = '<' . ([^\>]* | ([^\>\\]*[\\][\>][^\>]*)*) . '\\\\'* . '>'; sqs17 = '|' . ([^\|]* | ([^\|\\]*[\\][\|][^\|]*)*) . '\\\\'* . '|'; sqs18 = ':' . ([^\:]* | ([^\:\\]*[\\][\:][^\:]*)*) . '\\\\'* . ':'; sqs19 = ';' . ([^\;]* | ([^\;\\]*[\\][\;][^\;]*)*) . '\\\\'* . ';'; sqs20 = '"' . ([^\"]* | ([^\"\\]*[\\][\"][^\"]*)*) . '\\\\'* . '"'; sqs21 = ',' . ([^\,]* | ([^\,\\]*[\\][\,][^\,]*)*) . '\\\\'* . ','; sqs22 = '.' . ([^\.]* | ([^\.\\]*[\\][\.][^\.]*)*) . '\\\\'* . '.'; sqs23 = '?' . ([^\?]* | ([^\?\\]*[\\][\?][^\?]*)*) . '\\\\'* . '?'; sqs24 = '/' . ([^\/]* | ([^\/\\]*[\\][\/][^\/]*)*) . '\\\\'* . '/'; sqs25 = '{' . ([^\}]* | ([^\}\\]*[\\][\}][^\}]*)*) . '\\\\'* . '}'; sqs26 = '[' . ([^\]]* | ([^\]\\]*[\\][\]][^\]]*)*) . '\\\\'* . ']'; sqs27 = '(' . ([^\)]* | ([^\)\\]*[\\][\)][^\)]*)*) . '\\\\'* . ')'; sqs28 = '\\' . ([^\\]* | ([^\)]*[\\][\\][^\\]*)*) . '\\'; ( sqs1 | sqm . sqs1 | sqm . sqs2 | sqm . sqs3 | sqm . sqs4 | sqm . sqs5 | sqm . sqs6 | sqm . sqs7 | sqm . sqs8 | sqm . sqs9 | sqm . sqs10 | sqm . sqs11 | sqm . sqs12 | sqm . sqs13 | sqm . sqs14 | sqm . sqs15 | sqm . sqs16 | sqm . sqs17 | sqm . sqs18 | sqm . sqs19 | sqm . sqs20 | sqm . sqs21 | sqm . sqs22 | sqm . sqs23 | sqm . sqs24 | sqm . sqs25 | sqm . sqs26 | sqm . sqs27 | sqm . sqs28 ) => { push(:sstring, ts, te); fgoto main; }; ## == Double quote strings (dqm . '"') | '"' => { push_dstring(ts, te); fgoto dstring1; }; (dqm . "'") | "'" => { push_dstring(ts, te); fgoto dstring2; }; (dqm . '/') | '/' => { push_dstring(ts, te); fgoto dstring3; }; (dqm . '`') | '`' => { push_dstring(ts, te); fgoto dstring4; }; dqm . '~' => { push_dstring(ts, te); fgoto dstring5; }; dqm . '!' => { push_dstring(ts, te); fgoto dstring6; }; dqm . '@' => { push_dstring(ts, te); fgoto dstring7; }; dqm . '#' => { push_dstring(ts, te); fgoto dstring8; }; dqm . '$' => { push_dstring(ts, te); fgoto dstring9; }; dqm . '%' => { push_dstring(ts, te); fgoto dstring10; }; dqm . '^' => { push_dstring(ts, te); fgoto dstring11; }; dqm . '&' => { push_dstring(ts, te); fgoto dstring12; }; dqm . '*' => { push_dstring(ts, te); fgoto dstring13; }; dqm . '-' => { push_dstring(ts, te); fgoto dstring14; }; dqm . '_' => { push_dstring(ts, te); fgoto dstring15; }; dqm . '+' => { push_dstring(ts, te); fgoto dstring16; }; dqm . '=' => { push_dstring(ts, te); fgoto dstring17; }; dqm . '<' => { push_dstring(ts, te); fgoto dstring18; }; dqm . '|' => { push_dstring(ts, te); fgoto dstring19; }; dqm . ':' => { push_dstring(ts, te); fgoto dstring20; }; dqm . ';' => { push_dstring(ts, te); fgoto dstring21; }; dqm . ',' => { push_dstring(ts, te); fgoto dstring22; }; dqm . '.' => { push_dstring(ts, te); fgoto dstring23; }; dqm . '?' => { push_dstring(ts, te); fgoto dstring24; }; dqm . '{' => { push_dstring(ts, te); fgoto dstring25; }; dqm . '[' => { push_dstring(ts, te); fgoto dstring26; }; dqm . '(' => { push_dstring(ts, te); fgoto dstring27; }; dqm . '\\' => { push_dstring(ts, te); fgoto dstring28; }; ## == Anything accidentally caught any => { push(:any, ts, te) fgoto main; }; *|; ## MACHINES >> Double quote strings dstring1 := |* [^\"]*[\"] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring2 := |* [^\']*[\'] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring3 := |* [^\/]*[\/] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring4 := |* [^\`]*[\`] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring5 := |* [^\~]*[\~] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring6 := |* [^\!]*[\!] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring7 := |* [^\@]*[\@] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring8 := |* [^\#]*[\#] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring9 := |* [^\$]*[\$] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring10 := |* [^\%]*[\%] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring11 := |* [^\^]*[\^] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring12 := |* [^\&]*[\&] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring13 := |* [^\*]*[\*] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring14 := |* [^\-]*[\-] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring15 := |* [^\_]*[\_] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring16 := |* [^\+]*[\+] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring17 := |* [^\=]*[\=] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring18 := |* [^\>]*[\>] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring19 := |* [^\|]*[\|] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring20 := |* [^\:]*[\:] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring21 := |* [^\;]*[\;] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring22 := |* [^\,]*[\,] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring23 := |* [^\.]*[\.] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring24 := |* [^\?]*[\?] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring25 := |* [^\}]*[\}] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring26 := |* [^\]]*[\]] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring27 := |* [^\)]*[\)] => { unless push_dstring(ts, te) fgoto main; end }; *|; dstring28 := |* [^\\]*[\\] => { unless push_dstring(ts, te) fgoto main; end }; *|; ## MACHINE >> Main main := |* ## == Start/end of do..end block kw_do => { push(:kw_do, ts, te) increment_counter(:do_end) fgoto new_statement; }; kw_end => { push(:kw_end, ts, te) decrement_counter(:do_end) }; ## == Start/end of {...} block lbrace => { push(:lbrace, ts, te) increment_counter(:brace) }; rbrace => { push(:rbrace, ts, te) decrement_counter(:brace) }; assoc => { push(:assoc, ts, te) fix_counter_false_start(:brace) }; label => { push_label(ts, te) fix_counter_false_start(:brace) }; ## == New statement newline => { push(:newline, ts, te) increment_lineno fgoto new_statement; }; smcolon | lparen | assgn | kw_then | comma => { push(:newline_alias, ts, te) fgoto new_statement; }; ## == Comment '#' => { fgoto per_line_comment; }; newline . '=begin' . ospaces . (ospaces . ^newline+)* . newline => { push_comment(ts, te) increment_lineno fgoto block_comment; }; ## == Strings ('<<' | '<<-') . ["']? . (const | var) . ["']? . newline => { push_heredoc(ts, te) increment_lineno fgoto heredoc; }; ('"' | "'" | '`' | '%') => { fhold; fgoto string; }; '/' => { if preceded_with?(:char, :digit, :var, :const, :symbol, :dstring, :sstring, ')', ']', '}') push(:op, ts, te) else fhold; fgoto string; end }; ## == Misc var => { push(:var, ts, te) }; bslash => { push(:bslash, ts, te) }; const => { push(:const, ts, te) }; symbol => { push(:symbol, ts, te) }; mspaces => { push(:space, ts, te) }; [0-9] => { push(:digit, ts, te) }; lower => { push(:char, ts, te) }; any => { push(:any, ts, te) }; *|; }%% %% write data; extend Scanner::Extensions def self.execute! data = @data eof = data.length %% write init; %% write exec; end end end end sourcify-0.5.0/lib/sourcify/proc/scanner/0000755000175000017500000000000011755746006017415 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/proc/scanner/counter.rb0000644000175000017500000000150311755746006021420 0ustar gwolfgwolfmodule Sourcify module Proc module Scanner #:nodoc:all class Counter attr_reader :counts def initialize @counts = [0,0] end def started? @counts.any?(&:nonzero?) end def just_started? @counts.any?{|count| count == 1 } end def balanced? @counts.any?(&:zero?) end def decrement (0..1).each{|i| @counts[i] -= 1 unless @counts[i].zero? } end def increment(val = 1) if val.is_a?(Range) @counts[0] += val.first @counts[1] += val.last else (0..1).each{|i| @counts[i] += 1 } end end end class DoEndBlockCounter < Counter; end class BraceBlockCounter < Counter; end end end end sourcify-0.5.0/lib/sourcify/proc/scanner/heredoc.rb0000644000175000017500000000077111755746006021360 0ustar gwolfgwolfmodule Sourcify module Proc module Scanner #:nodoc:all class Heredoc < Struct.new(:tag, :indented) def <<(content) (@contents ||= []) << content end def to_s @contents.join end def closed?(sealer) return false unless sealer == "\n" parts = @contents[-1].split("\n") return true if parts[-1] == tag indented && parts[-1].sub(/^\s*(.*)$/,'\1') == tag end end end end end sourcify-0.5.0/lib/sourcify/proc/scanner/dstring.rb0000644000175000017500000000262111755746006021415 0ustar gwolfgwolfmodule Sourcify module Proc module Scanner #:nodoc:all class DString < Struct.new(:tag) # To suppress 'warning: Object#type is deprecated; use Object#class' when # evaluating string attr_reader :type def <<(content) (@contents ||= []) << content end def to_s @contents.join end def closed? evaluable? && parsable? end private CLOSING_TAGS = {'(' => ')', '[' => ']', '<' => '>', '{' => '}'} def evaluable? @contents[-1][-1].chr == end_tag end def parsable? begin Parser::Converter.to_sexp <<-SOURCIFIED_HEREDOKIE.strip #{safe_contents} SOURCIFIED_HEREDOKIE rescue Exception true end end def safe_contents # NOTE: %x & ` strings are dangerous to eval cos they execute shell commands, # thus we convert them to normal strings 1st to_s.gsub(/(%x)(\W|\_)/, '%Q\2').gsub(/.{0,2}(`)/) do |s| s =~ /^(%Q|%W|%r|%x|.?%|.?\\)/ ? s : s.sub(/`$/,'%Q`') end end def start_tag @start_tag ||= tag[-1].chr end def end_tag @end_tag ||= (CLOSING_TAGS[start_tag] || start_tag) end end end end end sourcify-0.5.0/lib/sourcify/proc/scanner/extensions.rb0000644000175000017500000001166611755746006022153 0ustar gwolfgwolf%w{heredoc comment dstring counter}.each do |f| Sourcify.require_rb('proc', 'scanner', f) end module Sourcify module Proc module Scanner #:nodoc:all module Extensions class Escape < Exception; end RUBY_PARSER = RubyParser.new def process(data, opts={}) begin @start_pattern = opts[:start_pattern] || /.*/ @body_matcher = opts[:body_matcher] || lambda{|_| true } @stop_on_newline = opts[:stop_on_newline] @results, @data = [], data.unpack("c*") reset_attributes execute! rescue Escape @results end end def data_frag(range) @data[range].pack('c*') end def push(key, ts, te) @tokens << [key, data_frag(ts .. te.pred)] end def push_dstring(ts, te) data = data_frag(ts .. te.pred) @dstring ||= DString.new(data[%r{^("|`|/|%(?:Q|W|r|x|)(?:\W|_))},1]) @dstring << data return true unless @dstring.closed? @tokens << [:dstring, @dstring.to_s] @dstring = nil end def push_comment(ts, te) data = data_frag(ts .. te.pred) @comment ||= Comment.new @comment << data return true unless @comment.closed? @tokens << [:comment, @comment.to_s] @comment = nil end def push_heredoc(ts, te) data = data_frag(ts .. te.pred) unless @heredoc indented, tag = data.match(/\<\<(\-?)['"]?(\w+)['"]?$/)[1..3] @heredoc = Heredoc.new(tag, !indented.empty?) end @heredoc << data return true unless @heredoc.closed?(data_frag(te .. te)) @tokens << [:heredoc, @heredoc.to_s] @heredoc = nil end def push_label(ts, te) # NOTE: 1.9.* supports label key, which RubyParser cannot handle, thus # conversion is needed. data = data_frag(ts .. te.pred) @tokens << [:symbol, data.sub(/^(.*)\:$/, ':\1')] @tokens << [:space, ' '] @tokens << [:assoc, '=>'] end def preceded_with?(*args) begin prev_token = @tokens[-1][0] == :space ? @tokens[-2] : @tokens[-1] !([args].flatten & prev_token).empty? rescue end end def increment_lineno @lineno += 1 if @stop_on_newline || !@results.empty? || (@results.empty? && @rejecting_block) raise Escape end end def increment_counter(key, count = 1) return if other_counter(key).started? unless (counter = this_counter(key)).started? return if (@rejecting_block = codified_tokens !~ @start_pattern) @false_start_backup = @tokens.dup if key == :brace offset_attributes end counter.increment(count) end def decrement_counter(key) return unless (counter = this_counter(key)).started? counter.decrement construct_result_code if counter.balanced? end def fix_counter_false_start(key) return unless this_counter(key).just_started? return unless really_false_started? reset_attributes @tokens, @false_start_backup = @false_start_backup.dup, nil if @false_start_backup end def other_counter(type) {:do_end => @brace_counter, :brace => @do_end_counter}[type] end def this_counter(type) {:brace => @brace_counter, :do_end => @do_end_counter}[type] end def construct_result_code code = <<-SOURCIFIED_HEREDOKIE.strip proc #{codified_tokens} SOURCIFIED_HEREDOKIE begin if safe_eval(code) && @body_matcher.call(code) @results << code raise Escape if @stop_on_newline or @lineno != 1 reset_attributes end rescue Exception raise if $!.is_a?(Escape) end end def codified_tokens @tokens.map(&:last).join end def reset_attributes @tokens = [] @lineno = 1 @heredoc, @dstring, @comment = nil @do_end_counter = DoEndBlockCounter.new @brace_counter = BraceBlockCounter.new @rejecting_block = false end def really_false_started? safe_eval(<<-SOURCIFIED_HEREDOKIE.strip #{codified_tokens} 1} SOURCIFIED_HEREDOKIE ) && true end def offset_attributes @lineno = 1 # Fixing JRuby's lineno bug (see http://jira.codehaus.org/browse/JRUBY-5014) unless @tokens.empty? last = @tokens[-1] @tokens.clear @tokens << last end end def safe_eval(string) Parser::Converter.to_sexp(string) end end end end end sourcify-0.5.0/lib/sourcify/proc/scanner/comment.rb0000644000175000017500000000051311755746006021403 0ustar gwolfgwolfmodule Sourcify module Proc module Scanner #:nodoc:all class Comment def <<(content) (@contents ||= []) << content end def to_s @contents.join end def closed? @contents[-1].split("\n")[-1].strip == '=end' end end end end end sourcify-0.5.0/lib/sourcify/proc/methods.rb0000644000175000017500000000016611755746006017757 0ustar gwolfgwolf%w{source_location to_source to_sexp to_raw_source}.each do |file| Sourcify.require_rb('proc', 'methods', file) end sourcify-0.5.0/lib/sourcify/proc/methods/0000755000175000017500000000000011755746006017427 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/proc/methods/source_location.rb0000644000175000017500000000374311755746006023153 0ustar gwolfgwolfmodule Sourcify module Proc module Methods #:nodoc:all module SourceLocation def self.included(base) base.class_eval do # Case (1): the family of 1.9.* behaves slightly differently for created on # the fly proc, eg. 1.9.2 does yield meaningful Proc#source_location for procs # created from Method#to_proc. Since it is not possible to derive the same # behaviour for other rubies, we stick to the less performant behaviour. if lambda{}.respond_to?(:source_location) alias_method :__pre_sourcified_source_location, :source_location def source_location(get_original = true) if get_original __pre_sourcified_source_location elsif !@created_on_the_fly __pre_sourcified_source_location end end # Case (2): okko, we are on rubies that don't support Proc#source_location .. else def source_location(get_original = true) unless @created_on_the_fly @source_location ||= ( file, line = /^#$/.match(inspect)[1..2] [file, line.to_i] ) end end end # HACK to make it real easy to determine if a proc is created on the fly # (eg. Method#to_proc & Symbol#to_proc). attr_writer :created_on_the_fly [::Method, ::Symbol].each do |klass| begin klass.class_eval do alias_method :__pre_sourcified_to_proc, :to_proc def to_proc (_proc = __pre_sourcified_to_proc).created_on_the_fly = true _proc end end rescue NameError end end end end end end end end sourcify-0.5.0/lib/sourcify/proc/methods/to_sexp.rb0000644000175000017500000000233211755746006021435 0ustar gwolfgwolfmodule Sourcify module Proc module Methods #:nodoc:all module ToSexp def self.included(base) base.class_eval do ref_proc = lambda {} # Case 1: we already have Proc#to_sexp (eg. provided by ParseTree) available, # we override it to ensure it handles the extra args .. if ref_proc.respond_to?(:to_sexp) alias_method :__pre_sourcified_to_sexp, :to_sexp def to_sexp(opts = {}, &body_matcher) sexp, flag = __pre_sourcified_to_sexp, opts[:strip_enclosure] Marshal.load(Marshal.dump( # need a deep copy cos the caller may reset the sexp (@sourcified_sexps ||= {})[flag] ||= flag ? Sexp.from_array(sexp.to_a.last) : sexp )) end # Case 2: okko, we have to implement our own Proc#to_sexp ... else Sourcify.require_rb('proc', 'parser') def to_sexp(opts = {}, &body_matcher) (@sourcified_parser ||= Parser.new(self)). sexp(opts.merge(:body_matcher => body_matcher)) end end end end end end end end sourcify-0.5.0/lib/sourcify/proc/methods/to_raw_source.rb0000644000175000017500000000070511755746006022631 0ustar gwolfgwolfmodule Sourcify module Proc module Methods #:nodoc:all module ToRawSource def self.included(base) base.class_eval do Sourcify.require_rb('proc', 'parser') def to_raw_source(opts = {}, &body_matcher) (@sourcified_parser ||= Parser.new(self)). raw_source(opts.merge(:body_matcher => body_matcher)) end end end end end end end sourcify-0.5.0/lib/sourcify/proc/methods/to_source.rb0000644000175000017500000000311011755746006021751 0ustar gwolfgwolfmodule Sourcify module Proc module Methods #:nodoc:all module ToSource def self.included(base) base.class_eval do ref_proc = lambda {} # Case 1: the current ruby already implements Proc#to_source, # we override it to ensure it handles the extra args .. if ref_proc.respond_to?(:to_source) alias_method :__pre_sourcified_to_source, :to_source def to_source(opts = {}, &body_matcher) flag = opts[:strip_enclosure] (@sourcified_sources ||= {})[flag] ||= flag ? Ruby2Ruby.new.process(to_sexp(opts, &body_matcher)) : __pre_sourcified_to_source end # Case 2: we have Proc#to_ruby (eg. provided by ParseTree) available, # we have a wrapper round it to ensure it handles the extra args .. elsif ref_proc.respond_to?(:to_ruby) def to_source(opts = {}, &body_matcher) flag = opts[:strip_enclosure] (@sourcified_sources ||= {})[flag] ||= flag ? Ruby2Ruby.new.process(to_sexp(opts, &body_matcher)) : to_ruby end # Case 3: okko, we have to implement our own Proc#to_source ... else Sourcify.require_rb('proc', 'parser') def to_source(opts = {}, &body_matcher) (@sourcified_parser ||= Parser.new(self)). source(opts.merge(:body_matcher => body_matcher)) end end end end end end end end sourcify-0.5.0/lib/sourcify/proc/parser/0000755000175000017500000000000011755746006017260 5ustar gwolfgwolfsourcify-0.5.0/lib/sourcify/proc/parser/code_scanner.rb0000644000175000017500000000242611755746006022234 0ustar gwolfgwolfmodule Sourcify module Proc class Parser #:nodoc:all class CodeScanner class << self def process(source_code, opts, &matcher) results = rscan(source_code.to_s, { :start_pattern => scan_pattern_hint(opts[:attached_to]), :body_matcher => opts[:body_matcher], :ignore_nested => opts[:ignore_nested], :stop_on_newline => false, }).flatten.select(&matcher) case results.size when 0 then raise NoMatchingProcError when 1 then results[0] else raise MultipleMatchingProcsPerLineError end end def scan_pattern_hint(val) case val when Regexp then val when String, Symbol then /^(?:.*?\W|)#{val}(?:\W)/ when nil then /.*/ else raise TypeError end end def rscan(str, opts) results = Scanner.process(str, opts) || [] return results if opts[:ignore_nested] results.map do |outer| inner = rscan(outer.sub(/^proc\s*(do|\{)/,''), opts.merge(:stop_on_newline => true)) [outer, inner] end end end end end end end sourcify-0.5.0/lib/sourcify/proc/parser/normalizer.rb0000644000175000017500000000215311755746006021770 0ustar gwolfgwolfmodule Sourcify module Proc class Parser #:nodoc:all class Normalizer class << self def process(sexp, binding) @binding = binding Sexp.from_array(fix_no_arg_method_calls(sexp.to_a)) end def fix_no_arg_method_calls(array) return array if [:class, :sclass, :defn, :module].include?(array[0]) array.map do |e| if e.is_a?(Array) no_arg_method_call?(e) or fix_no_arg_method_calls(e) else e end end end def no_arg_method_call?(e) if like_no_arg_method_call?(e) bounded_var?(var = e[2]) ? [:lvar, var] : e end end def like_no_arg_method_call?(e) e.size == 4 && e[0..1] == [:call, nil] && e[3] == [:arglist] && (var = e[2]).is_a?(Symbol) end def bounded_var?(var) lvar = (@q ||= (IS_19x ? ":%s" : "'%s'")) % var @binding.has_local_variable?(lvar) end end end end end end sourcify-0.5.0/lib/sourcify/proc/parser/converter.rb0000644000175000017500000000124711755746006021620 0ustar gwolfgwolfmodule Sourcify module Proc class Parser #:nodoc:all class Converter class << self RUBY_PARSER = RubyParser.new RUBY_2_RUBY = Ruby2Ruby.new def to_sexp(code, file = nil) retried = false begin RUBY_PARSER.reset (retried ? RubyParser.new : RUBY_PARSER).parse(*[code, file].compact) rescue Racc::ParseError, SyntaxError return nil if retried retried = true; retry end end def to_code(sexp) RUBY_2_RUBY.process(Sexp.from_array(sexp.to_a)) end end end end end end sourcify-0.5.0/lib/sourcify/proc/parser/source_code.rb0000644000175000017500000000137111755746006022101 0ustar gwolfgwolfmodule Sourcify module Proc class Parser #:nodoc:all class SourceCode < Struct.new(:file, :line) def line super.pred end def to_s case file when /\(irb\)/ then from_irb_to_s else from_file_to_s end end def from_file_to_s File.open(file, 'r') do |fh| fh.extend(File::Tail).forward(line) fh.readlines.join end end def from_irb_to_s # Really owe it to Florian Groß's solution @ http://rubyquiz.com/quiz38.html ... # anyway, note that we use *line.succ* instead of *line* here. IRB.CurrentContext.io.line(line.succ .. -1).join end end end end end sourcify-0.5.0/lib/sourcify/version.rb0000644000175000017500000000005011755746006017026 0ustar gwolfgwolfmodule Sourcify VERSION = "0.5.0" end sourcify-0.5.0/lib/sourcify/facets.rb0000644000175000017500000000101511755746006016610 0ustar gwolfgwolfif RUBY_VERSION.include?('1.8.6') unless 1.respond_to?(:pred) class Integer def pred self - 1 end end end unless :a.respond_to?(:to_proc) class Symbol def to_proc Proc.new{|*args| args.shift.__send__(self, *args)} end end end end unless binding.respond_to?(:has_local_variable?) class Binding def has_local_variable?(name) check_str = "local_variables.include?(#{name})" self.eval(check_str) rescue eval(check_str, self) end end end sourcify-0.5.0/lib/sourcify/proc.rb0000644000175000017500000001366211755746006016321 0ustar gwolfgwolfmodule Sourcify class MultipleMatchingProcsPerLineError < Exception; end class NoMatchingProcError < Exception; end class ParserInternalError < Exception; end class CannotParseEvalCodeError < Exception; end class CannotHandleCreatedOnTheFlyProcError < Exception; end module Proc def self.included(base) #:nodoc: base.class_eval do Sourcify.require_rb('proc', 'methods') include Methods::SourceLocation include Methods::ToRawSource include Methods::ToSource include Methods::ToSexp end end module Stubs ### # Returns the ruby source filename and line number containing this proc. # # # /tmp/test.rb # x = lambda { 1 } # x.source_location # >> ["/tmp/test.rb", 2] # # When proc is not defined in ruby (i.e. native), or when the proc is created using # Method#to_proc or Symbol#to_proc, nil is returned. # # class AA # class << self # def m1; 1; end # def m2(&block); block; end # end # end # # AA.method(:m1).to_proc.source_location # >> nil # AA.m2(&:m1).source_location # >> nil # # For 1.9.2, the proc obtained using Method#to_proc by default yields info pointing # to where the method is located. Sourcify respects this builtin implementation and # assumes you usually want it. It is possible to get info that is consistent with all # other rubies by passing in +get_original+ as false: # # # /tmp/test.rb # class AA # def m; 1; end # end # # x = AA.new.method(:m).to_proc # x.source_location # >> ["/tmp/test.rb", 2] # x.source_location(false) # >> nil # def source_location(get_original = true) # NOTE: this is a stub for the actual one in Methods::SourceLocation end ### # Returns the code representation of this proc. Unlike Proc#to_raw_source, the # returned code retains only the functional aspects, fluff like comments are # stripped off. # # lambda do |i| # i+1 # (blah) # end.to_source # # >> "proc {|i| i+1 }" # # The following options are supported: # # * +:strip_enclosure+ when set to true, strips the enclosing "proc { ... }" to get # just the meat within. # # lambda {|i| i+1 }.to_source(:strip_enclosure => true) # # >> "i+2" # # (this option is effective regardless of presence of ParseTree) # # * +:attached_to+ is useful to avoid the nasty # Sourcify::MultipleMatchingProcsPerLineError (as a result of ambiguities when doing # static code analysis), it declares the condition that must be met prior grabbing # the code block: # # x = lambda { proc { :blah } } # # x.to_source # # >> Sourcify::MultipleMatchingProcsPerLineError # # x.to_source(:attached_to => :lambda) # # >> "proc { proc { :blah } }" # # Sometimes more control is needed: # # # We want to ignore everything associated with ignore # def ignore(&block); block; end # x = lambda { ignore { :blah } } # # x.to_source # # >> Sourcify::MultipleMatchingProcsPerLineError # # x.to_source(:attached_to => /^(.*\W|)(lambda|proc)\W/) # # >> "proc { ignore { :blah } }" # # (this option is effective ONLY when ParseTree is not available) # # * +:ignore_nested+ is useful when only the outermost proc matters and we want to # ignore all other nested proc(s): # # x = lambda { lambda { :blah } } # # x.to_source # # >> Sourcify::MultipleMatchingProcsPerLineError # # x.to_source(:ignore_nested => true) # # >> "proc { lambda { :blah } }" # # However, since code scanning stops at the outermost proc, beware of the following: # # x = lambda {|_| lambda { lambda { :blah } } }.call(nil) # # x.to_source # # >> "proc { lambda { :blah } }" # # x.to_source(:ignore_nested => true) # # >> Sourcify::NoMatchingProcError # # (this option is effective ONLY when ParseTree is not available) # # When in static code analysis (non-ParseTree) mode, it is even possible to # specify how the proc body should look like by passing in a code block: # # x, y = lambda { def secret; 1; end }, lambda { :blah } # # x.to_source # # >> Sourcify::MultipleMatchingProcsPerLineError # # x.to_source{|body| body =~ /^(.*\W|)def\W/ } # # >> "proc { def secret; 1; end }" # def to_source(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToSource end ### # Returns the S-expression representation of this proc. # # lambda {|i| i+1 }.to_sexp # # >> s(:iter, # # >> s(:call, nil, :proc, s(:arglist)), # # >> s(:lasgn, :i), # # >> s(:call, s(:lvar, :i), :+, s(:arglist, s(:lit, 1)))) # # (pls see #to_source for options/arguments supported) # def to_sexp(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToSexp end ### # Returns the raw code enclosed within this proc. # # lambda do |i| # i+1 # (blah) # end.to_source # # >> "proc do |i| # # >> i+1 # (blah) # # >> end" # # NOTE: The options supported are the same as those for Proc#to_source. # def to_raw_source(opts={}, &body_matcher) # NOTE: this is a stub for the actual one in Methods::ToRawSource end end end end Proc.class_eval do include Sourcify::Proc end sourcify-0.5.0/lib/sourcify.rb0000644000175000017500000000112011755746006015340 0ustar gwolfgwolfrequire 'rubygems' require 'ruby2ruby' require 'sexp_processor' require 'ruby_parser' require 'file/tail' begin require 'parse_tree' require 'parse_tree_extensions' rescue LoadError # ParseTree is now optional for all supported rubies :) end module Sourcify #:nodoc: class << self def require_rb(*args) require root(*args) end def root(*args) @root ||= File.join(File.dirname(File.expand_path(__FILE__)), 'sourcify') File.join(@root, *args) end end end Sourcify.require_rb('facets') Sourcify.require_rb('version') Sourcify.require_rb('proc') sourcify-0.5.0/spec/0000755000175000017500000000000011755746006013342 5ustar gwolfgwolfsourcify-0.5.0/spec/proc/0000755000175000017500000000000011755746006014305 5ustar gwolfgwolfsourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb0000644000175000017500000000110411755746006026577 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested method)" do should 'handle simple' do ( lambda do def aa; x = 1; end end ).should.be having_source(%Q\ proc do def aa; x = 1; end end \) end should 'handle nested' do ( lambda do def aa def bb; x = 2; end end end ).should.be having_source(%Q\ proc do def aa def bb; x = 2; end end end \) end end sourcify-0.5.0/spec/proc/to_source_variables_spec.rb0000644000175000017500000000122211755746006021673 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source (variables)" do should 'handle non var' do lambda { x }.should.be having_source(%|proc { x }|) end should 'handle local var' do x = 'lx' lambda { x }.should.be having_source(%|proc { x }|) end should 'handle instance var' do @x = 'ix' lambda { @x }.should.be having_source(%|proc { @x }|) end should 'handle class var' do @@x = 'cx' lambda { @@x }.should.be having_source(%|proc { @@x }|) end should 'handle global var' do $x = 'gx' lambda { $x }.should.be having_source(%|proc { $x }|) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb0000644000175000017500000000623411755746006026463 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested until block)" do should 'handle w do' do ( lambda do until true do @x1 = 1 end end ).should.be having_source(%Q\ proc do until true do @x1 = 1 end end \) end should 'handle w \ do' do ( lambda do until true \ do @x1 = 2 end end ).should.be having_source(%Q\ proc do until true do @x1 = 2 end end \) end should 'handle wo do (w newline)' do ( lambda do until true @x1 = 3 end end ).should.be having_source(%Q\ proc do until true @x1 = 3 end end \) end should 'handle wo do (w semicolon)' do ( lambda do until true; @x1 = 4; end end ).should.be having_source(%Q\ proc do until true @x1 = 4 end end \) end should 'handle nested wo do within w do' do ( lambda do until true do until true; @x1 = 5; end end end ).should.be having_source(%Q\ proc do until true do until true @x1 = 5 end end end \) end should 'handle nested wo do within wo do' do ( lambda do until true until true; @x1 = 6; end end end ).should.be having_source(%Q\ proc do until true until true @x1 = 6 end end end \) end should 'handle nested w do within wo do' do ( lambda do until true until true do @x1 = 7 end end end ).should.be having_source(%Q\ proc do until true until true @x1 = 7 end end end \) end should 'handle nested w do within w do' do ( lambda do until true do until true do @x1 = 8 end end end ).should.be having_source(%Q\ proc do until true until true @x1 = 8 end end end \) end should 'handle simple modifier' do ( lambda do @x1 = 9 until true end ).should.be having_source(%Q\ proc do @x1 = 9 until true end \) end should 'handle block within modifier' do ( lambda do @x1 = 10 until ( until true do @x1 = 10 end ) end ).should.be having_source(%Q\ proc do @x1 = 10 until ( until true do @x1 = 10 end ) end \) end should 'handle modifier within block' do ( lambda do until true @x1 = 11 until true end end ).should.be having_source(%Q\ proc do until true @x1 = 11 until true end end \) end should 'handle modifier w trailing backslash' do ( lambda do @x1 = 9 \ until true end ).should.be having_source(%Q\ proc do @x1 = 9 until true end \) end end ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rbsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.0000644000175000017500000000151111755746006033532 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified body matcher & single match' do matcher = lambda {|code| code =~ /^(.*\W|)def\W/ } should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { def aa; end } b3.should.be having_source('proc { def aa; end }', &matcher) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = lambda { def bb; end; lambda { @x2+3 } } b2.should.be having_source('proc { def bb; end; lambda { @x2+3 } }', &matcher) end should 'handle multi level nesting on same line' do b2 = (lambda {|a| lambda { def cc; end; lambda { @x3+3 } } }).call(1) b2.should.be having_source('proc { def cc; end; lambda { @x3+3 } }', &matcher) end end sourcify-0.5.0/spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb0000644000175000017500000000153611755746006030020 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source from multi blocks w single match' do expected = 'proc { @x%s }' should 'skip non-matching (all do...end blocks)' do ( b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end; b2 ).should.be having_source(expected%1) end should 'skip non-matching (all {...} blocks)' do ( b1 = lambda {|a| @x2 }; b2 = lambda { @x2 }; b2 ).should.be having_source(expected%2) end should 'skip non-matching (mixed {...} with do...end blocks)' do ( b1 = lambda {|a| @x3 }; b2 = lambda do @x3 end; b2 ).should.be having_source(expected%3) end should 'skip non-matching (mixed do...end with {...} blocks)' do ( b1 = lambda do |a| @x4 end; b2 = lambda { @x4 }; b2 ).should.be having_source(expected%4) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb0000644000175000017500000000114111755746006026404 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested begin)" do should 'handle simple' do ( lambda do begin @x1 = 1 end end ).should.be having_source(%Q\ proc do begin @x1 = 1 end end \) end should 'handle nested' do ( lambda do begin @x1 = 1 begin @x2 = 2 end end end ).should.be having_source(%Q\ proc do begin @x1 = 1 begin @x2 = 2 end end end \) end end sourcify-0.5.0/spec/proc/19x_extras.rb0000644000175000017500000000071011755746006016637 0ustar gwolfgwolfshared 'Proc#to_source from { ... } block (1.9.*)' do should 'handle simple (w label keys)' do ( lambda { {a: 1, b: 2} } ).should.be having_source(%Q\ proc do {:a => 1, :b => 2} end \) end should 'handle nested (w label keys)' do ( lambda { {a: 1, b: {c: 3}} } ).should.be having_source(%Q\ proc do {:a => 1, :b => {:c => 3}} end \) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb0000644000175000017500000000304211755746006026633 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested unless)" do should 'handle simple block' do ( lambda do unless @x1 then @x1 = 1 end end ).should.be having_source(%Q\ proc do unless @x1 then @x1 = 1 end end \) end should 'handle nested block' do ( lambda do unless @x1 unless @x2 then @x2 = 1 end end end ).should.be having_source(%Q\ proc do unless @x1 unless @x2 then @x2 = 1 end end end \) end should 'handle simple modifier' do ( lambda do @x1 = 1 unless true end ).should.be having_source(%Q\ proc do @x1 = 1 unless true end \) end should 'handle block within modifier' do ( lambda do @x1 = 1 unless (unless @x1 then true end) end ).should.be having_source(%Q\ proc do @x1 = 1 unless (unless @x1 then true end) end \) end should 'handle modifier within block' do ( lambda do unless @x1 @x1 = 1 unless @x2 end end ).should.be having_source(%Q\ proc do unless @x1 @x1 = 1 unless @x2 end end \) end should 'handle modifier w trailing backslash' do ( lambda do @x1 = 1 \ unless true end ).should.be having_source(%Q\ proc do @x1 = 1 unless true end \) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb0000644000175000017500000000124611755746006026241 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested case)" do should 'handle simple' do ( lambda do case @x1 when true then false end end ).should.be having_source(%Q\ proc do case @x1 when true then false end end \) end should 'handle nested' do ( lambda do case @x1 when true case @x2 when false then true end end end ).should.be having_source(%Q\ proc do case @x1 when true case @x2 when false then true end end end \) end end sourcify-0.5.0/spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb0000644000175000017500000000165711755746006030351 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from { ... } block (wo nesting complication)" do expected = 'proc { @x%s }' should 'handle watever(..) { ... }' do ( watever(:a, :b, {:c => 1}) { @x1 } ).should.be having_source(expected%1) end should 'handle watever(..) \ { ... }' do ( watever(:a, :b, {:c => 1}) \ { @x2 } ).should.be having_source(expected%2) end should 'handle watever { ... }' do ( watever { @x3 } ).should.be having_source(expected%3) end should 'handle watever \ { ... }' do ( watever \ { @x4 } ).should.be having_source(expected%4) end should 'handle lambda { ... }' do ( lambda { @x5 } ).should.be having_source(expected%5) end should 'handle lambda \ { ... }' do ( lambda \ { @x6 } ).should.be having_source(expected%6) end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb0000644000175000017500000000270611755746006033037 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:attached_to => ...} & no match' do options = {:attached_to => :forever} if has_parsetree? should 'handle no nesting on same line' do b1 = lambda do |a| @x1+1 end; b2 = lambda do @x1+2 end; b3 = lambda do @x1+3 end b2.should.be having_source('proc { @x1+2 }', options) end should 'handle single level nesting on same line' do b1 = lambda do |a| @x2+1 end; b2 = lambda do lambda do @x2+2 end end b2.should.be having_source('proc { lambda { @x2+2 } }', options) end should 'handle multi level nesting on same line' do b2 = (lambda do |a| lambda do lambda do @x3 end end end).call(1) b2.should.be having_source('proc { lambda { @x3 } }', options) end else error = Sourcify::NoMatchingProcError should "raise #{error} w no nesting on same line" do b1 = lambda {|a| @x }; b2 = watever { @x }; b3 = lambda { @x } lambda { b2.to_source(options) }.should.raise(error) end should "raise #{error} w single level nesting on same line" do b1 = lambda {|a| @x }; b2 = watever { lambda { @x } } lambda { b2.to_source(options) }.should.raise(error) end should "raise #{error} w multi level nesting on same line" do b2 = (lambda {|a| watever { lambda { @x } } }).call(1) lambda { b2.to_source(options) }.should.raise(error) end end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb0000644000175000017500000000262711755746006026437 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested class)" do should 'handle simple' do ( lambda do class AA def aa @x1 = 1 end end end ).should.be having_source(%Q\ proc do class AA def aa @x1 = 1 end end end \) end should 'handle inheritance' do ( lambda do class AA < Object def aa @x1 = 1 end end end ).should.be having_source(%Q\ proc do class AA < Object def aa @x1 = 1 end end end \) end should 'handle singleton' do ( lambda do class << 'AA' def aa @x1 = 1 end end end ).should.be having_source(%Q\ proc do class << 'AA' def aa @x1 = 1 end end end \) end should 'handle nested' do ( lambda do class AA class BB def bb @x1 = 1 end end end end ).should.be having_source(%Q\ proc do class AA class BB def bb @x1 = 1 end end end end \) end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb0000644000175000017500000000271611755746006033221 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified body matcher & no match' do matcher = lambda {|code| code =~ /^(.*\W|)def\W/ } if has_parsetree? should 'handle no nesting on same line' do b1 = lambda do |a| @x1+1 end; b2 = lambda do @x1+2 end; b3 = lambda do @x1+3 end b2.should.be having_source('proc { @x1+2 }', &matcher) end should 'handle single level nesting on same line' do b1 = lambda do |a| @x2+1 end; b2 = lambda do lambda do @x2+2 end end b2.should.be having_source('proc { lambda { @x2+2 } }', &matcher) end should 'handle multi level nesting on same line' do b2 = (lambda do |a| lambda do lambda do @x3 end end end).call(1) b2.should.be having_source('proc { lambda { @x3 } }', &matcher) end else error = Sourcify::NoMatchingProcError should "raise #{error} w no nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(&matcher) }.should.raise(error) end should "raise #{error} w single level nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } } lambda { b2.to_source(&matcher) }.should.raise(error) end should "raise #{error} w multi level nesting on same line" do b2 = (lambda {|a| lambda { lambda { @x } } }).call(1) lambda { b2.to_source(&matcher) }.should.raise(error) end end end sourcify-0.5.0/spec/proc/to_source_w_specified_strip_enclosure_spec.rb0000644000175000017500000000142711755746006025513 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:strip_enclosure => ...}' do describe '>> w true' do options = {:strip_enclosure => true} should 'strip enclosing proc wo arg' do lambda { a+b }.should.be having_source('a+b', options) end should 'strip enclosing proc w arg' do lambda {|a| a+b }.should.be having_source('a+b', options) end end describe '>> w false' do options = {:strip_enclosure => false} should 'not strip enclosing proc wo arg' do lambda { a+b }.should.be having_source('proc { a+b }', options) end should 'not strip enclosing proc w arg' do lambda {|a| a+b }.should.be having_source('proc {|a| a+b }', options) end end end sourcify-0.5.0/spec/proc/spec_helper.rb0000644000175000017500000000012111755746006017115 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), '..', 'spec_helper') ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rbsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.r0000644000175000017500000000266611755746006033562 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:attached_to => ...} & single match' do options = {:attached_to => :lambda} if has_parsetree? should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_source('proc { @x1+2 }', options) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } } b2.should.be having_source('proc { lambda { @x2+2 } }', options) end should 'handle multi level nesting on same line' do b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1) b2.should.be having_source('proc { lambda { @x3 } }', options) end else error = Sourcify::MultipleMatchingProcsPerLineError should "raise #{error} w no nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(options) }.should.raise(error) end should "raise #{error} w single level nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } } lambda { b2.to_source(options) }.should.raise(error) end should "raise #{error} w multi level nesting on same line" do b2 = (lambda {|a| lambda { lambda { @x } } }).call(1) lambda { b2.to_source(options) }.should.raise(error) end end end sourcify-0.5.0/spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb0000644000175000017500000000246411755746006030025 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_sexp w specified {:attached_to => ...}' do # NOTE: We just want enough specs to show that handling of :attached_to # works for Proc#to_sexp as well. options = {:attached_to => /^.*?(\W|)watever(\W)/} should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = watever { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, s(:ivar, :@x1), :+, s(:arglist, s(:lit, 2)))), options ) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = watever { lambda { @x2+2 } } b2.should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:call, s(:ivar, :@x2), :+, s(:arglist, s(:lit, 2))))), options ) end should 'handle multi level nesting on same line' do b2 = (lambda {|a| watever { lambda { @x3 } } }).call(1) b2.should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:iter, s(:call, nil, :lambda, s(:arglist)), nil, s(:ivar, :@x3))), options ) end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb0000644000175000017500000000562311755746006030346 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:attached_to => ...}' do unless has_parsetree? err1 = Sourcify::MultipleMatchingProcsPerLineError err2 = Sourcify::NoMatchingProcError describe '>> w :attached_to as regexp' do should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => /^(?:.*?\W|)lambda(?:\W)/) }.should.raise(err1) end should "raise Sourcify::NoMatchingProcError for no match" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => /^(?:.*?\W|)proc(?:\W)/) }.should.raise(err2) end should "handle for single match" do b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 } b2.should.be having_source('proc { @x2 }', :attached_to => /^(?:.*?\W|)proc(?:\W)/) end end describe '>> w :attached_to as string' do should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => 'lambda') }.should.raise(err1) end should "raise Sourcify::NoMatchingProcError for no match" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => 'proc') }.should.raise(err2) end should "handle for single match" do b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 } b2.should.be having_source('proc { @x2 }', :attached_to => 'proc') end end describe '>> w :attached_to as symbol' do should "raise Sourcify::MultipleMatchingProcsPerLineError for multiple matches" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => :lambda) }.should.raise(err1) end should "raise Sourcify::NoMatchingProcError for no match" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source(:attached_to => :proc) }.should.raise(err2) end should "handle for single match" do b1 = lambda {|a| @x1 }; b2 = proc { @x2 }; b3 = lambda { @x3 } b2.should.be having_source('proc { @x2 }', :attached_to => :proc) end end describe '>> w false start as a result of preceding hash' do option = {:attached_to => :watever} aa = :aa should 'handle for do ... end block' do x = watever({aa => 1, :bb => 3}) do :blah end x.should.be having_source('proc { :blah }', option) end should 'handle for { ... } block' do x = watever({aa => 1, :bb => 3}) { :blah } x.should.be having_source('proc { :blah }', option) end end end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb0000644000175000017500000000251711755746006026523 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source from multi blocks w many matches' do if has_parsetree? should "handle w no nesting on same line" do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_source('proc { @x1+2 }') end should "handle w single level nesting on same line" do b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } } b2.should.be having_source('proc { lambda { @x2+2 } }') end should "handle w multi level nesting on same line" do b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1) b2.should.be having_source('proc { lambda { @x3 } }') end else error = Sourcify::MultipleMatchingProcsPerLineError should "raise #{error} w no nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { @x }; b3 = lambda { @x } lambda { b2.to_source }.should.raise(error) end should "raise #{error} w single level nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { lambda { @x } } lambda { b2.to_source }.should.raise(error) end should "raise #{error} w multi level nesting on same line" do b2 = (lambda {|a| lambda { lambda { @x } } }).call(1) lambda { b2.to_source }.should.raise(error) end end end sourcify-0.5.0/spec/proc/created_on_the_fly_proc_spec.rb0000644000175000017500000000444311755746006022511 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Created on the fly proc" do unless has_parsetree? klass = Class.new do def test(&block); block ; end def blah; 1+2; end end describe 'Blah#to_proc raising Sourcify::CannotHandleCreatedOnTheFlyProcError' do should "raise when created by :to_proc" do lambda { x, y = klass.new.method(:test).to_proc, lambda { 1+2 } x.to_source }.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError) end should "not raise even with prepending #to_proc on the same line" do x, y = klass.new.method(:test).to_proc, lambda { 1+2 } y.to_source.should.not.be.nil end should "not raise even with appending #to_proc on the same line" do x, y = lambda { 1+2 }, klass.new.method(:test).to_proc x.to_source.should.not.be.nil end should "not raise even with nested #to_proc on the same line" do x = lambda { klass.new.method(:test).to_proc } x.to_source.should.not.be.nil end should "not raise with nested #to_proc on diff line" do ( lambda do klass.new.method(:test).to_proc end ).to_source.should.not.be.nil end end describe '&:blah raising Sourcify::CannotHandleCreatedOnTheFlyProcError' do should "raise when created by &:blah" do lambda { x, y = klass.new.test(&:blah), lambda { 1+2 } x.to_source }.should.raise(Sourcify::CannotHandleCreatedOnTheFlyProcError) end should "not raise even with prepending &:blah on the same line" do x, y = klass.new.test(&:blah), lambda { 1+2 } y.to_source.should.not.be.nil end should "not raise even with appending &:blah on the same line" do x, y = lambda { 1+2 }, klass.new.test(&:blah) x.to_source.should.not.be.nil end should "not raise even with nested &:blah on the same line" do x = lambda { klass.new.test(&:blah) } x.to_source.should.not.be.nil end should "not raise with nested &:blah on diff line" do ( lambda do klass.new.test(&:blah) end ).to_source.should.not.be.nil end end end end sourcify-0.5.0/spec/proc/to_raw_source_spec.rb0000644000175000017500000000102411755746006020514 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_raw_source" do should 'retain comments' do ( lambda do a = 1 # i should stay !! end ).should.be having_raw_source(%( proc do a = 1 # i should stay !! end )) end should 'retain last nil statement' do ( lambda do a = 1 nil end ).should.be having_raw_source(%( proc do a = 1 nil end )) end end sourcify-0.5.0/spec/proc/to_sexp_variables_spec.rb0000644000175000017500000000753011755746006021362 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_sexp (variables)" do should 'handle non var' do expected = s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, nil, :x, s(:arglist))) lambda { x }.should.be having_sexp(expected) end should 'handle local var' do x, expected = 'lx', s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:lvar, :x)) lambda { x }.should.be having_sexp(expected) end should 'handle instance var' do @x, expected = 'ix', s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:ivar, :@x)) lambda { @x }.should.be having_sexp(expected) end should 'handle class var' do @@x, expected = 'cx', s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:cvar, :@@x)) lambda { @@x }.should.be having_sexp(expected) end should 'handle global var' do $x, expected = 'gx', s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:gvar, :$x)) lambda { $x }.should.be having_sexp(expected) end should 'handle class_eval scoped local var' do ( x = 1 lambda { Object.class_eval {|x| y = x } } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:iter, s(:call, s(:const, :Object), :class_eval, s(:arglist)), s(:lasgn, :x), s(:lasgn, :y, s(:lvar, :x)))) ) end should 'handle instance_eval scoped local var' do ( x = 1 lambda { 'aa'.instance_eval {|x| y = x } } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:iter, s(:call, s(:str, "aa"), :instance_eval, s(:arglist)), s(:lasgn, :x), s(:lasgn, :y, s(:lvar, :x)))) ) end should 'handle define_method scoped local var' do ( x = 1 lambda { Object.send(:define_method, :aa) {|x| y = x } } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:iter, s(:call, s(:const, :Object), :send, s(:arglist, s(:lit, :define_method), s(:lit, :aa))), s(:lasgn, :x), s(:lasgn, :y, s(:lvar, :x)))) ) end should 'not handle class scoped local var (simple)' do ( x = 1 lambda { class AA ; y = x ; end } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:class, :AA, nil, s(:scope, s(:lasgn, :y, s(:call, nil, :x, s(:arglist)))))) ) end should 'not handle class scoped local var (w inheritance)' do ( x = 1 lambda { class AA < Object; y = x ; end } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:class, :AA, s(:const, :Object), s(:scope, s(:lasgn, :y, s(:call, nil, :x, s(:arglist)))))) ) end should 'not handle class scoped local var (w singleton)' do ( x = 1 lambda { class << 'AA'; y = x ; end } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:sclass, s(:str, "AA"), s(:scope, s(:lasgn, :y, s(:call, nil, :x, s(:arglist)))))) ) end should 'not handle module scoped local var' do ( x = 1 lambda { module AA ; y = x ; end } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:module, :AA, s(:scope, s(:lasgn, :y, s(:call, nil, :x, s(:arglist)))))) ) end should 'not handle method scoped local var' do ( x = 1 lambda { def aa ; y = x ; end } ).should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:defn, :aa, s(:args), s(:scope, s(:block, s(:lasgn, :y, s(:call, nil, :x, s(:arglist))))))) ) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb0000644000175000017500000000146211755746006026613 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested module)" do should 'handle simple' do ( lambda do module AA def aa @x1 = 1 end end end ).should.be having_source(%Q\ proc do module AA def aa @x1 = 1 end end end \) end should 'handle nested' do ( lambda do module AA module BB def bb @x1 = 1 end end end end ).should.be having_source(%Q\ proc do module AA module BB def bb @x1 = 1 end end end end \) end end ././@LongLink0000000000000000000000000000014600000000000011566 Lustar rootrootsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rbsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.r0000644000175000017500000000140011755746006033530 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:attached_to => ...} & single match' do options = {:attached_to => :watever} should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = watever { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_source('proc { @x1+2 }', options) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = watever { lambda { @x2+2 } } b2.should.be having_source('proc { lambda { @x2+2 } }', options) end should 'handle multi level nesting on same line' do b2 = (lambda {|a| watever { lambda { @x3 } } }).call(1) b2.should.be having_source('proc { lambda { @x3 } }', options) end end sourcify-0.5.0/spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb0000644000175000017500000000246411755746006026366 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_raw_source w specified {:strip_enclosure => ...}' do describe '>> w true' do options = {:strip_enclosure => true} should 'strip enclosing proc wo arg' do ( lambda do a = 1 # i should stay !! end ).should.be having_raw_source(%( a = 1 # i should stay !! ), options) end should 'strip enclosing proc w arg' do ( lambda do |a| a = 1 # i should stay !! end ).should.be having_raw_source(%( a = 1 # i should stay !! ), options) end end describe '>> w false' do options = {:strip_enclosure => false} should 'not strip enclosing proc wo arg' do ( lambda do a = 1 # i should stay !! end ).should.be having_raw_source(%( proc do a = 1 # i should stay !! end ), options) end should 'not strip enclosing proc w arg' do ( lambda do |a| a = 1 # i should stay !! end ).should.be having_raw_source(%( proc do |a| a = 1 # i should stay !! end ), options) end end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb0000644000175000017500000000124411755746006026504 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source from multi blocks w single match' do should 'skip non-matching w no nesting on same line' do b1 = lambda do |a| @x1 end; b2 = lambda do @x1 end b2.should.be having_source('proc { @x1 }') end should 'skip non-matching w single level nesting on same line' do b2 = (lambda {|a| lambda { @x2 } }).call(1) b2.should.be having_source('proc { @x2 }') end should 'skip non-matching w multi level nesting on same line' do b2 = (lambda {|a| lambda {|a| b2 = lambda { @x3 } } }).call(1).call(1) b2.should.be having_source('proc { @x3 }') end end sourcify-0.5.0/spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb0000644000175000017500000000210011755746006026227 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from { ... } block (w nested hash)" do should 'handle simple' do ( lambda { {:a => 1, :b => 2} } ).should.be having_source(%Q\ proc do {:a => 1, :b => 2} end \) end should 'handle nested' do ( lambda { {:a => 1, :b => {:c => 3}} } ).should.be having_source(%Q\ proc do {:a => 1, :b => {:c => 3}} end \) end should 'handle method w only hash args' do ( lambda { test :a => 2 } ).should.be having_source(%Q\ proc do test(:a => 2) end \) end should 'handle method w mixed args' do ( lambda { test 1, :a => 2 } ).should.be having_source(%Q\ proc do test(1, :a => 2) end \) end if RUBY_VERSION.include?('1.9.') require File.join(File.expand_path(File.dirname(__FILE__)), '19x_extras') behaves_like 'Proc#to_source from { ... } block (1.9.*)' end end sourcify-0.5.0/spec/proc/to_source_magic_file_var_spec.rb0000644000175000017500000000630211755746006022656 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source (magic var __FILE__)" do should 'handle single standalone' do lambda { __FILE__ }.should.be having_source(%(proc { "#{__FILE__}" })) end should 'handle multiple standalones' do lambda { [ __FILE__, __FILE__, __FILE__ ] }.should.be having_source(%Q( proc do [ "#{__FILE__}", "#{__FILE__}", "#{__FILE__}" ] end )) end should 'handle single interpolation' do lambda { "#{__FILE__}" }.should.be having_source(%(proc { "#{__FILE__}" })) end should 'handle multiple interpolation (separate)' do lambda { [ "#{__FILE__}", "#{__FILE__}", "#{__FILE__}" ] }.should.be having_source(%Q( proc do [ "#{__FILE__}", "#{__FILE__}", "#{__FILE__}" ] end )) end should 'handle multiple interpolation (together)' do lambda { < ...}' do describe '>> w true' do options = {:strip_enclosure => true} should 'strip enclosing proc wo arg' do lambda { a+b }.should.be having_sexp( s(:call, s(:call, nil, :a, s(:arglist)), :+, s(:arglist, s(:call, nil, :b, s(:arglist)))), options ) end should 'strip enclosing proc w arg' do lambda {|a| a+b }.should.be having_sexp( s(:call, s(:lvar, :a), :+, s(:arglist, s(:call, nil, :b, s(:arglist)))), options ) end end describe '>> w false' do options = {:strip_enclosure => false} should 'not strip enclosing proc wo arg' do lambda { a+b }.should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:call, s(:call, nil, :a, s(:arglist)), :+, s(:arglist, s(:call, nil, :b, s(:arglist))))), options ) end should 'not strip enclosing proc w arg' do lambda {|a| a+b }.should.be having_sexp( s(:iter, s(:call, nil, :proc, s(:arglist)), s(:lasgn, :a), s(:call, s(:lvar, :a), :+, s(:arglist, s(:call, nil, :b, s(:arglist))))), options ) end end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb0000644000175000017500000000173211755746006030353 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (wo nesting complication)" do expected = 'proc { @x%s }' should 'handle watever(..) do ... end' do ( watever(:a, :b, {:c => 1}) do @x1 end ).should.be having_source(expected%1) end should 'handle watever(..) \ do ... end' do ( watever(:a, :b, {:c => 1}) \ do @x2 end ).should.be having_source(expected%2) end should 'handle watever do ... end' do ( watever do @x3 end ).should.be having_source(expected%3) end should 'handle watever \ do ... end' do ( watever \ do @x4 end ).should.be having_source(expected%4) end should 'handle lambda do ... end' do ( lambda do @x5 end ).should.be having_source(expected%5) end should 'handle lambda \ do ... end' do ( lambda \ do @x6 end ).should.be having_source(expected%6) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb0000644000175000017500000000272611755746006025730 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested if)" do should 'handle simple block' do ( lambda do if @x1 then @x1 = 1 end end ).should.be having_source(%Q\ proc do if @x1 then @x1 = 1 end end \) end should 'handle nested block' do ( lambda do if @x1 if @x2 then @x2 = 1 end end end ).should.be having_source(%Q\ proc do if @x1 if @x2 then @x2 = 1 end end end \) end should 'handle simple modifier' do ( lambda do @x1 = 1 if true end ).should.be having_source(%Q\ proc do @x1 = 1 if true end \) end should 'handle block within modifier' do ( lambda do @x1 = 1 if (if @x1 then true end) end ).should.be having_source(%Q\ proc do @x1 = 1 if (if @x1 then true end) end \) end should 'handle modifier w trailing backslash' do ( lambda do @x1 = 1 \ if true end ).should.be having_source(%Q\ proc do @x1 = 1 if true end \) end should 'handle modifier within block' do ( lambda do if @x1 @x1 = 1 if @x2 end end ).should.be having_source(%Q\ proc do if @x1 @x1 = 1 if @x2 end end \) end end ././@LongLink0000000000000000000000000000014700000000000011567 Lustar rootrootsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rbsourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.0000644000175000017500000000275711755746006033562 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:attached_to => ...} & single match' do matcher = lambda {|code| code =~ /^(.*\W|)def\W/ } if has_parsetree? should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_source('proc { @x1+2 }', &matcher) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } } b2.should.be having_source('proc { lambda { @x2+2 } }', &matcher) end should 'handle multi level nesting on same line' do b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1) b2.should.be having_source('proc { lambda { @x3 } }', &matcher) end else error = Sourcify::MultipleMatchingProcsPerLineError should "raise #{error} w no nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { def a1; end }; b3 = lambda { def a2; end } lambda { b2.to_source(&matcher) }.should.raise(error) end should "raise #{error} w single level nesting on same line" do b1 = lambda {|a| @x }; b2 = lambda { lambda { def bb; end } } lambda { b2.to_source(&matcher) }.should.raise(error) end should "raise #{error} w multi level nesting on same line" do b2 = (lambda {|a| lambda { lambda { def cc; end } } }).call(1) lambda { b2.to_source(&matcher) }.should.raise(error) end end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb0000644000175000017500000000113211755746006027722 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested do ... end block)" do should 'handle simple' do ( lambda do lambda do @x1 = 1 end end ).should.be having_source(%Q\ proc do lambda { @x1 = 1 } end \) end should 'handle nested' do ( lambda do lambda do lambda do @x1 = 1 end end end ).should.be having_source(%Q\ proc do lambda do lambda { @x1 = 1 } end end \) end end sourcify-0.5.0/spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb0000644000175000017500000000437111755746006026116 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Proc#to_source from do ... end block (w nested for block)" do should 'handle w do' do ( lambda do for x1 in [1,2] do x1 end end ).should.be having_source(%Q\ proc do for x1 in [1,2] do x1 end end \) end should 'handle w \ do' do ( lambda do for x2 in [1,2] \ do x2 end end ).should.be having_source(%Q\ proc do for x2 in [1,2] do x2 end end \) end should 'handle wo do (w newline)' do ( lambda do for x3 in [1,2] x3 end end ).should.be having_source(%Q\ proc do for x3 in [1,2] x3 end end \) end should 'handle wo do (w semicolon)' do ( lambda do for x4 in [1,2]; x4; end end ).should.be having_source(%Q\ proc do for x4 in [1,2] x4 end end \) end should 'handle nested wo do within w do' do ( lambda do for x1 in [1,2] do for x2 in [1,2] x2 end end end ).should.be having_source(%Q\ proc do for x1 in [1,2] do for x2 in [1,2] x2 end end end \) end should 'handle nested wo do within wo do' do ( lambda do for x1 in [2,3] for x2 in [2,3] x2 end end end ).should.be having_source(%Q\ proc do for x1 in [2,3] do for x2 in [2,3] x2 end end end \) end should 'handle nested w do within wo do' do ( lambda do for x1 in [3,4] for x2 in [3,4] do x2 end end end ).should.be having_source(%Q\ proc do for x1 in [3,4] for x2 in [3,4] do x2 end end end \) end should 'handle nested w do within w do' do ( lambda do for x1 in [4,5] \ do for x2 in [4,5] do x2 end end end ).should.be having_source(%Q\ proc do for x1 in [4,5] for x2 in [4,5] do x2 end end end \) end end sourcify-0.5.0/spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb0000644000175000017500000000307111755746006030707 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe 'Proc#to_source w specified {:ignore_nested => ...}' do options = {:ignore_nested => true} if has_parsetree? should 'handle no nesting on same line' do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 } b2.should.be having_source('proc { @x1+2 }', options) end should 'handle single level nesting on same line' do b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+2 } } b2.should.be having_source('proc { lambda { @x2+2 } }', options) end should 'handle multi level nesting on same line (w outermost having diff arity)' do b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1) b2.should.be having_source('proc { lambda { @x3 } }', options) end else should "raise Sourcify::MultipleMatchingProcsPerLineError w no nesting on same line" do b1 = lambda {|a| @x1+1 }; b2 = lambda { @x1+2 }; b3 = lambda { @x1+3 } lambda { b2.to_source(options) }.should.raise(Sourcify::MultipleMatchingProcsPerLineError) end should "handle w single level nesting on same line" do b1 = lambda {|a| @x2+1 }; b2 = lambda { lambda { @x2+3 } } b2.should.be having_source('proc { lambda { @x2+3 } }', options) end should "raise Sourcify::NoMatchingProcError w multi level nesting on same line (w outermost having diff arity)" do b2 = (lambda {|a| lambda { lambda { @x3 } } }).call(1) lambda { b2.to_source(options) }.should.raise(Sourcify::NoMatchingProcError) end end end sourcify-0.5.0/spec/proc/others_spec.rb0000644000175000017500000000247711755746006017162 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') describe "Misc" do should 'handle accessing #to_sexp after #to_source' do (s_proc = lambda { :test }).to_source s_proc.should.be having_sexp(s(:iter, s(:call, nil, :proc, s(:arglist)), nil, s(:lit, :test))) end should 'handle accessing #to_source after #to_sexp' do (s_proc = lambda { :test }).to_sexp s_proc.should.be having_source('proc { :test }') end should "handle proc with '/' char" do (lambda { @x1/2 }).should.be having_source('proc { @x1/2 }') end should "handle lexer bug in missing trailing chars after '=>' operator" do # This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765 { __LINE__ => lambda { :test } }.values.last.should.be having_source('proc { :test }') end should "handle lexer bug in missing trailing chars after '=>' operator" do # This example addresses bug @ http://redmine.ruby-lang.org/issues/show/3765 { __LINE__ => lambda do :test end }.values.last.should.be having_source('proc { :test }') end unless has_parsetree? should "raise Sourcify::CannotParseEvalCodeError when proc is created from eval" do lambda { eval("proc {:test }").to_source }.should. raise(Sourcify::CannotParseEvalCodeError) end end end sourcify-0.5.0/spec/dump_object_space_procs.rb0000644000175000017500000000463011755746006020546 0ustar gwolfgwolfrequire File.join(File.dirname(File.expand_path(__FILE__)), '..', 'lib', 'sourcify') require 'benchmark' require 'pp' if RUBY_PLATFORM =~ /java/i require 'jruby' JRuby.objectspace = true reload! rescue nil end DUMPED_OBJECT_SPACE_PROCS = {:max => nil, :done => 0} DUMP_OBJECT_SPACE_PROCS_ERRORS = [] class STOP_DUMPING_OBJECT_SPACE_PROCS < Exception; end def dump_object_space_procs(debug = false) # Determine working dir name = [ RUBY_DESCRIPTION =~ /enterprise/i ? 'ree' : (RUBY_PLATFORM =~ /java/i ? 'jruby' : 'mri'), RUBY_VERSION, Object.const_defined?(:ParseTree) ? 'parsetree' : nil ].compact.join('~') dump_dir = File.join(File.dirname(File.expand_path(__FILE__)), '..', 'tmp', name) Dir.mkdir(dump_dir) unless File.exists?(dump_dir) puts '', '== NOTE: dump files can be found at %s' % dump_dir # Core processing ObjectSpace.each_object(Proc).to_a.select{|o| o.source_location }. group_by{|o| o.source_location[0] }.each do |ofile, objs| nfile = File.join(dump_dir, ofile.gsub('/','~')) File.open(nfile,'w') do |f| objs.sort_by{|o| o.source_location[1] }.map do |o| DUMPED_OBJECT_SPACE_PROCS[:done] += 1 begin data = { :location => o.source_location, :sexp => o.to_sexp, :source => o.to_source } f.puts(data.pretty_inspect) print '.' rescue Exception data = { :location => o.source_location, :error => $!.inspect } DUMP_OBJECT_SPACE_PROCS_ERRORS << data f.puts(data.pretty_inspect) pp(data) if debug print 'x' ensure raise STOP_DUMPING_OBJECT_SPACE_PROCS \ if DUMPED_OBJECT_SPACE_PROCS.values.uniq.size == 1 end end end end end # Dumping in action figures = Benchmark.measure do begin dump_object_space_procs rescue STOP_DUMPING_OBJECT_SPACE_PROCS end end # Printout the failures/passes unless DUMP_OBJECT_SPACE_PROCS_ERRORS.empty? puts '', '== OOPS, we have some erorrs :(' DUMP_OBJECT_SPACE_PROCS_ERRORS.each_with_index do |e, i| print "#{i}). %s" % e.pretty_inspect end else puts '', '== YEAH, no errors :)' end # Printout the benchmark results puts '', '== Benchmark results for processing %s procs:' % DUMPED_OBJECT_SPACE_PROCS[:done], figures.to_s, '' # __END__ sourcify-0.5.0/spec/proc_scanner/0000755000175000017500000000000011755746006016016 5ustar gwolfgwolfsourcify-0.5.0/spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb0000644000175000017500000000547211755746006026420 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe 'Double quote strings (wo interpolation)' do %w{~ ` ! @ # $ % ^ & * _ - + = | \\ ; : ' " , . ? /}.map{|w| [w,w] }.concat( [%w{( )}, %w{[ ]}, %w({ }), %w{< >}] ).each do |q1,q2| ['Q', 'W', 'x', 'r', ''].each do |t| should "handle %#{t}#{q1}...#{q2} (wo escape (single))" do process(" xx; %#{t}#{q1}hello#{q2} ").should.include([:dstring, "%#{t}#{q1}hello#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (wo escape (multiple))" do tokens = process(" xx; %#{t}#{q1}hello#{q2} %#{t}#{q1}world#{q2} ") tokens.should.include([:dstring, "%#{t}#{q1}hello#{q2}"]) tokens.should.include([:dstring, "%#{t}#{q1}world#{q2}"]) end # NOTE: We are skipping '\\' cos %Q\hel\\o\ is always raise SyntaxError no matter # how many backslashes we add unless q1 == '\\' should "handle %#{t}#{q1}...#{q2} (w escape (single))" do process(" xx; %#{t}#{q1}hel\\#{q2}lo#{q2} ").should. include([:dstring, "%#{t}#{q1}hel\\#{q2}lo#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (w escape (multiple))" do process(" xx; %#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2} ").should. include([:dstring, "%#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2}"]) end should "handle %#{t}#{q1}\\\\#{q2}" do process(" xx; %#{t}#{q1}\\\\#{q2} %#{t}#{q2}lo#{q2} ").should. include([:dstring, "%#{t}#{q1}\\\\#{q2}"]) end should "handle %#{t}#{q1}#{q2}" do process(" xx; %#{t}#{q1}#{q2} %#{t}#{q2}lo#{q2} ").should. include([:dstring, "%#{t}#{q1}#{q2}"]) end end end end %w{" / `}.each do |q| should "handle #{q}...#{q} (wo escape (single))" do process(%Q( xx; #{q}hello#{q} )).should.include([:dstring, %Q(#{q}hello#{q})]) end should "handle #{q}...#{q} (wo escape & multiple)" do tokens = process(%Q( xx; #{q}hello#{q} ; #{q}world#{q} )) tokens.should.include([:dstring, %Q(#{q}hello#{q})]) tokens.should.include([:dstring, %Q(#{q}world#{q})]) end should "handle #{q}...#{q} (w escape (single))" do process(%Q( xx; #{q}hel\\#{q}lo#{q} )).should.include([:dstring, %Q(#{q}hel\\#{q}lo#{q})]) end should "handle #{q}...#{q} (w escape (multiple))" do process(%Q( xx; #{q}h\\#{q}el\\#{q}lo#{q} )).should. include([:dstring, %Q(#{q}h\\#{q}el\\#{q}lo#{q})]) end should "handle #{q}\\\\#{q}" do process(%Q( aa; #{q}\\\\#{q} cc #{q}dd#{q} )).should.include([:dstring, "#{q}\\\\#{q}"]) end should "handle #{q}#{q}" do process(%Q( aa; #{q}#{q} cc #{q}dd#{q} )).should.include([:dstring, "#{q}#{q}"]) end end end end sourcify-0.5.0/spec/proc_scanner/heredoc_spec.rb0000644000175000017500000000600111755746006020763 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe "Heredoc (wo indent)" do %w{X "X" 'X'}.each do |tag| should "handle <<#{tag}\\n .. \\nX\\n" do process(%Q( s <<#{tag} aa X )).should.include([:heredoc, "<<#{tag}\n aa \nX"]) end should "not handle <<#{tag} \\n .. \\nX\\n" do process(%Q( s << #{tag} aa X )).should.not.include([:heredoc, "<<#{tag} \n aa \nX"]) end should "not handle <<#{tag}\\n .. \\n X\\n" do process(%Q( s <<#{tag} aa X )).should.not.include([:heredoc, "<<#{tag} \n aa \n X"]) end should "not handle <<#{tag}\\n .. \\nX \\n" do process(%Q( s <<#{tag} aa X )).should.not.include([:heredoc, "<<#{tag} \n aa \nX "]) end should "not handle class <<#{tag}\\n .. \\nX \\n" do process(%Q( class <<#{tag} aa X )).should.not.include([:heredoc, "<<#{tag}\n aa \nX"]) end should "handle xclass <<#{tag}\\n .. \\nX \\n" do process(%Q( xclass <<#{tag} aa X )).should.include([:heredoc, "<<#{tag}\n aa \nX"]) end should "handle classx <<#{tag}\\n .. \\nX \\n" do process(%Q( classx <<#{tag} aa X )).should.include([:heredoc, "<<#{tag}\n aa \nX"]) end should "handle <<#{tag}\\n .. \\nX \\n" do process(%Q( <<#{tag} aa X )).should.include([:heredoc, "<<#{tag}\n aa \nX"]) end end end describe "Heredoc (w indent)" do %w{X "X" 'X'}.each do |tag| should "handle <<-#{tag}\\n .. \\nX\\n" do process(%Q( s <<-#{tag} aa X )).should.include([:heredoc, "<<-#{tag}\n aa \nX"]) end should "handle <<-#{tag}\\n .. \\n X\\n" do process(%Q( s <<-#{tag} aa X )).should.include([:heredoc, "<<-#{tag}\n aa \n X"]) end should "not handle <<-#{tag} \\n .. \\nX\\n" do process(%Q( s <<-#{tag} aa X )).should.not.include([:heredoc, "<<-#{tag} \n aa \n X"]) end should "not handle <<-#{tag}\\n .. \\nX \\n" do process(%Q( s <<-#{tag} aa X )).should.not.include([:heredoc, "<<-#{tag}\n aa \nX "]) end should "not handle class <<-#{tag}\\n .. \\nX \\n" do process(%Q( class <<-#{tag} aa X )).should.not.include([:heredoc, "<<-#{tag}\n aa \nX"]) end should "handle xclass <<-#{tag}\\n .. \\nX \\n" do process(%Q( xclass <<-#{tag} aa X )).should.include([:heredoc, "<<-#{tag}\n aa \nX"]) end should "handle classx <<-#{tag}\\n .. \\nX \\n" do process(%Q( classx <<-#{tag} aa X )).should.include([:heredoc, "<<-#{tag}\n aa \nX"]) end should "handle <<-#{tag}\\n .. \\nX \\n" do process(%Q( <<-#{tag} aa X )).should.include([:heredoc, "<<-#{tag}\n aa \nX"]) end end end end sourcify-0.5.0/spec/proc_scanner/double_quote_str_w_interpolation_spec.rb0000644000175000017500000000472711755746006026243 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe 'Double quote strings (w interpolation)' do # NOTE: we skip %Q#...# cos %Q#..#{..}..# is invalid syntax. %w{~ ` ! @ $ % ^ & * _ - + = | ; : ' " , . ? / \\}.map{|w| [w,w] }.concat( [%w{( )}, %w{[ ]}, %w({ }), %w{< >}] ).each do |q1,q2| ['Q', 'W', 'x', 'r', ''].each do |t| should "handle %#{t}#{q1}...#{q2} (wo nesting (single))" do process(" xx; %#{t}#{q1}h\#{%#{t}#{q1}ell#{q2}}o#{q2} "). should.include([:dstring, "%#{t}#{q1}h\#{%#{t}#{q1}ell#{q2}}o#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (wo nesting (multiple))" do tokens = process(" xx; %#{t}#{q1}h\#{%#{t}#{q1}ell#{q2}}o#{q2} %#{t}#{q1}w\#{%#{t}#{q1}orl#{q2}}d#{q2} ") tokens.should.include([:dstring, "%#{t}#{q1}h\#{%#{t}#{q1}ell#{q2}}o#{q2}"]) tokens.should.include([:dstring, "%#{t}#{q1}w\#{%#{t}#{q1}orl#{q2}}d#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (w nesting (single))" do process(" xx; %#{t}#{q1}h\#{%#{t}#{q1}e\#{%#{t}#{q1}l#{q2}}l#{q2}}o#{q2} "). should.include([:dstring, "%#{t}#{q1}h\#{%#{t}#{q1}e\#{%#{t}#{q1}l#{q2}}l#{q2}}o#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (w nesting (multiple))" do tokens = process(" xx; " + "%#{t}#{q1}h\#{%#{t}#{q1}e\#{%#{t}#{q1}l#{q2}}l#{q2}}o#{q2} " + "%#{t}#{q1}w\#{%#{t}#{q1}o\#{%#{t}#{q1}r#{q2}}l#{q2}}d#{q2} " ) tokens.should.include([:dstring, "%#{t}#{q1}h\#{%#{t}#{q1}e\#{%#{t}#{q1}l#{q2}}l#{q2}}o#{q2}"]) tokens.should.include([:dstring, "%#{t}#{q1}w\#{%#{t}#{q1}o\#{%#{t}#{q1}r#{q2}}l#{q2}}d#{q2}"]) end end end %w{" / `}.each do |q| should "handle #{q}...#{q} (wo escape (single))" do process(%Q( xx; #{q}hello#{q} )).should.include([:dstring, %Q(#{q}hello#{q})]) end should "handle #{q}...#{q} (wo escape & multiple)" do tokens = process(%Q( xx; #{q}hello#{q} ; #{q}world#{q} )) tokens.should.include([:dstring, %Q(#{q}hello#{q})]) tokens.should.include([:dstring, %Q(#{q}world#{q})]) end should "handle #{q}...#{q} (w escape (single))" do process(%Q( xx; #{q}hel\\#{q}lo#{q} )).should. include([:dstring, %Q(#{q}hel\\#{q}lo#{q})]) end should "handle #{q}...#{q} (w escape (multiple))" do process(%Q( xx; #{q}h\\#{q}el\\#{q}lo#{q} )).should.include([:dstring, %Q(#{q}h\\#{q}el\\#{q}lo#{q})]) end end end end sourcify-0.5.0/spec/proc_scanner/double_colons_spec.rb0000644000175000017500000000051611755746006022206 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe "Double colons" do should "handle A::B as :const" do process(" A::B ").should.include([:const, 'A::B']) end should "handle A::aa as :const" do process(" A::aa ").should.include([:const, 'A::aa']) end end end sourcify-0.5.0/spec/proc_scanner/spec_helper.rb0000644000175000017500000000140111755746006020630 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), '..', 'spec_helper') module Sourcify::Proc::Scanner class << self ; attr_reader :tokens ; end class << self ; attr_reader :do_end_counter ; end end def process(data) Sourcify::Proc::Scanner.process(data) Sourcify::Proc::Scanner.tokens end def do_end_counter(data) Sourcify::Proc::Scanner.process(data) Sourcify::Proc::Scanner.do_end_counter.counts end shared 'has started do...end counter' do before do Sourcify::Proc::Scanner::DoEndBlockCounter.class_eval do alias_method :orig_started?, :started? def started?; true; end end end after do Sourcify::Proc::Scanner::DoEndBlockCounter.class_eval do alias_method :started?, :orig_started? end end end sourcify-0.5.0/spec/proc_scanner/per_line_comment_spec.rb0000644000175000017500000000104211755746006022671 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe "Per line comment (# ...)" do should 'handle start of line' do process(<}] ).each do |q1,q2| %w{q w}.each do |t| should "handle %#{t}#{q1}...#{q2} (wo escape (single))" do process(" xx %#{t}#{q1}hello#{q2} ").should.include([:sstring, "%#{t}#{q1}hello#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (wo escape (multiple))" do tokens = process(" xx %#{t}#{q1}hello#{q2} %#{t}#{q1}world#{q2} ") tokens.should.include([:sstring, "%#{t}#{q1}hello#{q2}"]) tokens.should.include([:sstring, "%#{t}#{q1}world#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (w escape (single))" do process(" xx %#{t}#{q1}hel\\#{q2}lo#{q2} ").should. include([:sstring, "%#{t}#{q1}hel\\#{q2}lo#{q2}"]) end should "handle %#{t}#{q1}...#{q2} (w escape (multiple))" do process(" xx %#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2} ").should. include([:sstring, "%#{t}#{q1}h\\#{q2}el\\#{q2}lo#{q2}"]) end # NOTE: We are skipping '\\' cos %q\\\\ is always raise SyntaxError no matter # how many backslashes we add unless q1 == '\\' should "handle %#{t}#{q1}\\\\#{q2}" do process(" xx %#{t}#{q1}\\\\#{q2} %#{t}#{q2}lo#{q2} ").should. include([:sstring, "%#{t}#{q1}\\\\#{q2}"]) end end should "handle %#{t}#{q1}#{q2}" do process(" xx %#{t}#{q1}#{q2} %#{t}#{q2}lo#{q2} ").should. include([:sstring, "%#{t}#{q1}#{q2}"]) end end end should "handle '...' (wo escape (single))" do process(" xx 'hello' ").should.include([:sstring, "'hello'"]) end should "handle '...' (wo escape (multiple))" do tokens = process(" xx 'hello' 'world' ") tokens.should.include([:sstring, "'hello'"]) tokens.should.include([:sstring, "'world'"]) end should "handle '...' (w escape (single))" do process(" xx 'hel\\'lo' ").should.include([:sstring, "'hel\\'lo'"]) end should "handle '...' (w escape (multiple))" do process(" xx 'h\\'el\\'lo' ").should.include([:sstring, "'h\\'el\\'lo'"]) end should "handle '\\\\'" do process(%q( aa '\\\\' cc 'dd' )).should.include([:sstring, "'\\\\'"]) end should "handle ''" do process(%q( aa '' cc 'dd' )).should.include([:sstring, "''"]) end end end sourcify-0.5.0/spec/proc_scanner/slash_operator_spec.rb0000644000175000017500000000362011755746006022403 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe "Shash operator" do should 'handle w preceding variable' do process(%Q(a / b)).should.include([:op, '/']) end should 'handle w preceding constant' do process(%Q(A / b)).should.include([:op, '/']) end should 'handle w preceding symbol' do process(%Q(:a / b)).should.include([:op, '/']) end should 'handle w preceding digit' do process(%Q(0 / b)).should.include([:op, '/']) end should 'handle w preceding a~f' do process(%Q(0xa / b)).should.include([:op, '/']) process(%Q(0xb / b)).should.include([:op, '/']) process(%Q(0xc / b)).should.include([:op, '/']) process(%Q(0xd / b)).should.include([:op, '/']) process(%Q(0xe / b)).should.include([:op, '/']) process(%Q(0xf / b)).should.include([:op, '/']) end should 'handle w preceding dstring' do process(%Q("a" / b)).should.include([:op, '/']) end should 'handle w preceding sstring' do process(%Q('a' / b)).should.include([:op, '/']) end should "handle w preceding ')' char" do process(%Q{) / b}).should.include([:op, '/']) end should "handle w preceding ']' char" do process(%Q(] / b)).should.include([:op, '/']) end should "handle w preceding '}' char" do process(%Q(} / b)).should.include([:op, '/']) end should "not handle w preceding newline" do process(%Q( / b / )).should.not.include([:op, '/']) end should "not handle w preceding ';' char" do process(%Q(; / b /)).should.not.include([:op, '/']) end should "not handle w preceding '(' char" do process(%Q{( / b /}).should.not.include([:op, '/']) end should "not handle w preceding '{' char" do process(%Q({ / b /)).should.not.include([:op, '/']) end should "not handle w preceding '[' char" do process(%Q([ / b /)).should.not.include([:op, '/']) end end end sourcify-0.5.0/spec/proc_scanner/kw_do_alias1_spec.rb0000644000175000017500000000327711755746006021723 0ustar gwolfgwolfrequire File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper') unless has_parsetree? describe "Keyword do alias #1 (incrementing do...end counter by 1)" do behaves_like 'has started do...end counter' %w{class def module begin case module if unless}.each do |kw| %w{_ x 1}.each do |c| should "not increment counter with ... (#{kw}#{c} ...)" do do_end_counter(< $stdout.string, :stderr => $stderr.string} ensure $stdin, $stdout, $stderr = $o_stdin, $o_stdout, $o_stderr end end def irb_exec(stdin_str) # See http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support & # http://tyenglog.heroku.com/2010/9/how-to-test-irb-specific-support-2- sourcify_rb = File.join(File.expand_path(File.dirname(__FILE__)), '..', 'lib', 'sourcify.rb') irb_feedback = /^ => / values = %x(echo "#{stdin_str}" | irb -r #{sourcify_rb}).split("\n"). grep(irb_feedback).map{|s| eval(s.sub(irb_feedback,'').strip) } # IRB behaves slightly differently in 1.9.2 for appending newline (values[-1].nil? && RUBY_VERSION.include?('1.9.2')) ? values[0 .. -2] : values end # /////////////////////////////////////////////////////////// # Regenerate ragel-based scanner # /////////////////////////////////////////////////////////// unless has_parsetree? ragel_dir = File.join(File.dirname(__FILE__), '..', 'lib', 'sourcify', 'proc') ragel_file = File.join(ragel_dir, 'scanner.rl') ruby_file = File.join(ragel_dir, 'scanner.rb') File.delete(ruby_file) rescue nil system("ragel -R #{ragel_file}") begin require File.join(ragel_dir, 'scanner.rb') rescue LoadError raise $! end end sourcify-0.5.0/spec/run_spec.sh0000755000175000017500000000023011755746006015512 0ustar gwolfgwolf#!/bin/bash echo '' echo `gem env | grep 'INSTALLATION DIRECTORY' | sed 's/.*\/\(.*\)/\1:/'` rm -rf ~/.ruby_inline/*ParseTree* bacon spec/**/*_spec.rb sourcify-0.5.0/HISTORY.txt0000644000175000017500000000606311755746006014317 0ustar gwolfgwolf=== 0.5.0 (May 2, 2011) * adds Proc#to_raw_source that supports extracting of raw code, as it is written in the source code (see issue#9), it supports all options that are already supported by Proc#to_source. * MRI-1.8.6 now supports both ParseTree & static-scanner mode * out with infinity_test (due to unresolvable & unexpected consistent failure in running specs for jruby-1.6.1 & always running ParseTree mode specs in static-scanner mode), use homebaked rake tasks (spec:parsetree, spec:static & spec:all) to acheive testing of different rubies in different modes * removd dependency on jeweler, & use bundler instead to handle dependency & also have our own handcrafted gemspec file === 0.4.2 (Feb 06, 2011) * fixes Sourcify::NoMatchingProcError when inline proc contains hashes (issue#7) [#ngty] * uses RubyParser#parse to eval correctness of code instead of Kernel#eval [#ngty] === 0.4.1 (Jan 29, 2011) * fixes Sourcify::NoMatchingProcError when if/unless/until/while modifier follows a trailing backslash (see issue#5) [#ngty] === 0.4.0 (Oct 15, 2010) * adds Proc#to_source(:strip_enclosure => ...) (& the Proc#to_sexp equivalent) to ease stripping of enclosing 'proc {|params| ... }', returning only the inner code body '...' [#ngty] * adds Proc#to_source(:attached_to => ..., :ignore_nested => ..., &body_matcher) (& the Proc#to_sexp equivalent) to narrow down code scanning, avoiding unnecessary Sourcify::MultipleMatchingProcsPerLineError, useful for libs that can anticipate how the proc should look like [#ngty] * adds support for running in MRI-1.9.2 [#ngty] * fixes '/' operator always treated as start of regexp [#ngty & #seamusabshere] === 0.3.0 (Sep 23, 2010) * Proc#to_source & friends now work in IRB as well [#ngty] === 0.2.3 (Sep 15, 2010) * since (static) code scanner doesn't run in 1.8.6, we enforce ParseTree mode for 1.8.6 [#ngty] === 0.2.2 (Sep 15, 2010) * fixed failure to run on MRI-1.8.6 [#ngty] === 0.2.1 (Sep 14, 2010) * introduced hack to ensure procs generated by Symbol#to_proc & Method#to_proc behaves exactly the same way under 1.8.*, 1.9.* & JRuby ~> always throwing CannotHandleCreatedOnTheFlyProcError [#ngty] * minor cleaning up of ragel scanner [#ngty] === 0.2.0 (Sep 10, 2010) * use home-baked ragel-based scanner for scanning for proc code [#ngty] * renamed Sourcify::LexerInternalError to Sourcify::ParserInternalError since we are not using any lexer anymore [#ngty] * introduces CannotParseEvalCodeError, CannotParseIrbCodeError & CannotHandleCreatedOnTheFlyProcError to handle procs that there is no way to extract code from [#ngty] * tested against well known projects (eg. spree & redmine) to show that it is indeed working [#ngty] === 0.1.2 (Aug 30, 2010) * introduced throwing of Sourcify::LexerInternalError when parser cannot handle incorrectly lexed code fragments [#ngty] * fixed bug in lexing keyword literals (represented as Symbol) [#ngty] === 0.1.1 (Aug 30, 2010) * fixed empty return for Proc#to_sexp after calling of Proc#to_source [#ngty] === 0.1.0 (Aug 28, 2010) * 1st gem release !! [#ngty] sourcify-0.5.0/LICENSE0000644000175000017500000000203511755746006013415 0ustar gwolfgwolfCopyright (c) 2009 NgTzeYang Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. sourcify-0.5.0/Rakefile0000644000175000017500000000462711755746006014066 0ustar gwolfgwolfrequire 'rubygems' require 'rake' require 'bundler' Bundler::GemHelper.install_tasks SPEC_SCRIPT = File.expand_path('../spec/run_spec.sh', __FILE__) task :default => :spec RUBIES = { :parsetree => [ 'ruby-1.8.6-p420@sourcify-parsetree', 'ruby-1.8.7-p334@sourcify-parsetree', 'ree-1.8.7-2011.03@sourcify-parsetree' ], :static => [ 'ruby-1.8.6-p420@sourcify', 'ruby-1.8.7-p334@sourcify', 'ree-1.8.7-2011.03@sourcify', 'jruby-1.6.1@sourcify', 'ruby-1.9.1-p378@sourcify', 'ruby-1.9.2-p180@sourcify', ] } # /////////////////////////////////////////////////////////// # Running Specs # /////////////////////////////////////////////////////////// desc "Run all specs" task :spec do |t| system SPEC_SCRIPT end desc "Run specs in all rubies (both ParseTree & static scanner modes)" task :'spec:all' do system 'export MUTE_BACON=true; rvm ' + RUBIES.values.flatten.join(',') + ' exec ' + SPEC_SCRIPT end desc "Run specs in rubies supporting ParseTree mode" task :'spec:parsetree' do system 'export MUTE_BACON=true; rvm ' + RUBIES[:parsetree].join(',') + ' exec ' + SPEC_SCRIPT end desc "Run specs in rubies supporting static scanner mode" task :'spec:static' do system 'export MUTE_BACON=true; rvm ' + RUBIES[:static].join(',') + ' exec ' + SPEC_SCRIPT end # /////////////////////////////////////////////////////////// # Benchmarking # /////////////////////////////////////////////////////////// desc "Benchmarking" task :benchmark, :task, :times do |t, args| times, task = (args.times || 5).to_i.method(:times), args.task title = " ~ Benchmark Results for Task :#{task} ~ " results = [%w{nth}, %w{user}, %w{system}, %w{total}, %w{real}] # Running benchmarking & collecting results require 'benchmark' times.call do |i| result = Benchmark.measure{ Rake::Task[task].execute }.to_s user, system, total, real = result.match(/^\s*(\d+\.\d+)\s+(\d+\.\d+)\s+(\d+\.\d+)\s+\(\s*(\d+\.\d+)\)$/)[1..-1] ["##{i.succ}", user, system, total, real].each_with_index{|val, j| results[j] << val } end # Formatting benchmarking results formatted_results = results.map do |rs| width = rs.map(&:to_s).map(&:size).max rs.map{|r| ' ' + r.ljust(width, ' ') } end.transpose.map{|row| row.join } # Showdown .. printout line = '=' * ([title.size, formatted_results.map(&:size).max].max + 2) puts [line, title, formatted_results.join("\n"), line].join("\n\n") end sourcify-0.5.0/.document0000644000175000017500000000007411755746006014230 0ustar gwolfgwolfREADME.rdoc lib/**/*.rb bin/* features/**/*.feature LICENSE sourcify-0.5.0/.gitignore0000644000175000017500000000024311755746006014377 0ustar gwolfgwolf## MAC OS .DS_Store ## TEXTMATE *.tmproj tmtags ## EMACS *~ \#* .\#* ## VIM *.swp ## PROJECT::GENERAL coverage rdoc pkg Gemfile.lock ## PROJECT::SPECIFIC tmp sourcify-0.5.0/VERSION0000644000175000017500000000000511755746006013453 0ustar gwolfgwolf0.4.2sourcify-0.5.0/sourcify.gemspec0000644000175000017500000000202311755746006015615 0ustar gwolfgwolf# -*- encoding: utf-8 -*- $:.push File.expand_path("../lib", __FILE__) require "sourcify/version" Gem::Specification.new do |s| s.name = "sourcify" s.version = Sourcify::VERSION s.platform = Gem::Platform::RUBY s.authors = ["NgTzeYang"] s.email = ["ngty77@gmail.com"] s.homepage = "http://github.com/ngty/sourcify" s.summary = %q{Workarounds before ruby-core officially supports Proc#to_source (& friends)} s.description = %q{} s.add_dependency 'ruby2ruby', '>= 1.2.5' s.add_dependency 'sexp_processor', '>= 3.0.5' s.add_dependency 'ruby_parser', '>= 2.0.5' s.add_dependency 'file-tail', '>= 1.0.5' s.add_development_dependency 'bacon' # ParseTree (better performance + dynamic goodness, but not supported on java & 1.9.*), # optional for any 1.8.*. #s.add_dependency "ParseTree", ">= 3.0.6" s.extra_rdoc_files = ["README.rdoc"] s.files = `git ls-files`.split("\n") s.test_files = `git ls-files -- spec/*`.split("\n") s.require_paths = ["lib"] end sourcify-0.5.0/.rvmrc0000644000175000017500000000003411755746006013537 0ustar gwolfgwolfrvm use 1.9.2-p180@sourcify sourcify-0.5.0/README.rdoc0000644000175000017500000002006411755746006014220 0ustar gwolfgwolf= Sourcify ParseTree[http://github.com/seattlerb/parsetree] is great, it accesses the runtime AST (abstract syntax tree) and makes it possible to convert any object to ruby code & S-expression, BUT ParseTree doesn't work for 1.9.* & JRuby. RubyParser[http://github.com/seattlerb/ruby_parser] is great, and it works for any rubies (of course, not 100% compatible for 1.8.7 & 1.9.* syntax yet), BUT it works only with static code. I truely enjoy using the above tools, but with my other projects, the absence of ParseTree on the different rubies is forcing me to hand-baked my own solution each time to extract the proc code i need at runtime. This is frustrating, the solution for each of them is never perfect, and i'm reinventing the wheel each time just to address a particular pattern of usage (using regexp kungfu). Enough is enough, and now we have Sourcify, a unified solution to extract proc code. When ParseTree is available, it simply works as a thin wrapper round it, otherwise, it uses a home-baked ragel-generated scanner to extract the proc code. Further processing with RubyParser & Ruby2Ruby to ensure 100% with ParseTree (yup, there is no denying that i really like ParseTree). == Installing It The religiously standard way: $ gem install ParseTree sourcify Or on 1.9.* or JRuby: $ gem install ruby_parser file-tail sourcify == Using It Sourcify adds 4 methods to Proc: === 1. Proc#to_source Returns the code representation of the proc: require 'sourcify' lambda { x + y }.to_source # >> "proc { (x + y) }" proc { x + y }.to_source # >> "proc { (x + y) }" Like it or not, a lambda is represented as a proc when converted to source (exactly the same way as ParseTree). It is possible to only extract the body of the proc by passing in {:strip_enclosure => true}: lambda { x + y }.to_source(:strip_enclosure => true) # >> "(x + y)" lambda {|i| i + 2 }.to_source(:strip_enclosure => true) # >> "(i + 2)" === 2. Proc#to_sexp Returns the S-expression of the proc: require 'sourcify' x = 1 lambda { x + y }.to_sexp # >> s(:iter, # >> s(:call, nil, :proc, s(:arglist)), # >> nil, # >> s(:call, s(:lvar, :x), :+, s(:arglist, s(:call, nil, :y, s(:arglist))))) To extract only the body of the proc: lambda { x + y }.to_sexp(:strip_enclosure => true) # >> s(:call, s(:lvar, :x), :+, s(:arglist, s(:call, nil, :y, s(:arglist))))) === 3. Proc#to_raw_source Unlike Proc#to_source, which returns code that retains only functional aspects, fetching of raw source returns the raw code enclosed within the proc, including fluff like comments: lambda do |i| i+1 # (blah) end.to_source # >> "proc do |i| # >> i+1 # (blah) # >> end" NOTE: This is extracting of raw code, it relies on static code scanning (even when running in ParseTree mode), the gotchas for static code scanning always apply. === 4. Proc#source_location By default, this is only available on 1.9.*, it is added (as a bonus) to provide consistency under 1.8.*: # /tmp/test.rb require 'sourcify' lambda { x + y }.source_location # >> ["/tmp/test.rb", 5] == Performance Performance is embarassing for now, benchmarking results for processing 500 procs (in the ObjectSpace of an average rails project) yiels the following: ruby user system total real ruby-1.8.7-p299 (w ParseTree) 10.270000 0.010000 10.280000 ( 10.311430) ruby-1.8.7-p299 (static scanner) 14.120000 0.080000 14.200000 ( 14.283817) ruby-1.9.1-p376 (static scanner) 17.380000 0.050000 17.430000 ( 17.405966) jruby-1.5.2 (static scanner) 21.318000 0.000000 21.318000 ( 21.318000) Since i'm still pretty new to ragel[http://www.complang.org/ragel], the code scanner will probably become better & faster as my knowlegde & skills with ragel improve. Also, instead of generating a pure ruby scanner, we can generate native code (eg. C or java, or whatever) instead. As i'm a C & java noob, this will probably take some time to realize. == Gotchas Nothing beats ParseTree's ability to access the runtime AST, it is a very powerful feature. The scanner-based (static) implementation suffer the following gotchas: === 1. The source code is everything Since static code analysis is involved, the subject code needs to physically exist within a file, meaning Proc#source_location must return the expected *[file, lineno]*, the following will not work: def test eval('lambda { x + y }') end test.source_location # >> ["(eval)", 1] test.to_source # >> Sourcify::CannotParseEvalCodeError The same applies to *Blah#to_proc* & *&:blah*: klass = Class.new do def aa(&block); block ; end def bb; 1+2; end end klass.new.method(:bb).to_proc.to_source # >> Sourcify::CannotHandleCreatedOnTheFlyProcError klass.new.aa(&:bb).to_source # >> Sourcify::CannotHandleCreatedOnTheFlyProcError === 2. Multiple matching procs per line error Sometimes, we may have multiple procs on a line, Sourcify can handle this as long as the subject proc has arity that is unique from others: # Yup, this works as expected :) b1 = lambda {|a| a+1 }; b2 = lambda { 1+2 } b2.to_source # >> proc { (1 + 2) } # Nope, this won't work :( b1 = lambda { 1+2 }; b2 = lambda { 2+3 } b2.to_source # >> raises Sourcify::MultipleMatchingProcsPerLineError As observed, the above does not work when there are multiple procs having the same arity, on the same line. Furthermore, this bug[http://redmine.ruby-lang.org/issues/show/574] under 1.8.* affects the accuracy of this approach. To better narrow down the scanning, try: * passing in the {:attached_to => ...} option x = lambda { proc { :blah } } x.to_source # >> Sourcify::MultipleMatchingProcsPerLineError x.to_source(:attached_to => :lambda) # >> "proc { proc { :blah } }" * passing in the {:ignore_nested => ...} option x = lambda { lambda { :blah } } x.to_source # >> Sourcify::MultipleMatchingProcsPerLineError x.to_source(:ignore_nested => true) # >> "proc { lambda { :blah } }" * attaching a body matcher proc x, y = lambda { def secret; 1; end }, lambda { :blah } x.to_source # >> Sourcify::MultipleMatchingProcsPerLineError x.to_source{|body| body =~ /^(.*\W|)def\W/ } # >> 'proc { def secret; 1; end }' Pls refer to the rdoc for more details. === 3. Occasional Racc::ParseError Under the hood, sourcify relies on RubyParser to yield s-expression, and since RubyParser does not yet fully handle 1.8.7 & 1.9.* syntax, you will get a nasty Racc::ParseError when you have any code that is not compatible with 1.8.6. == Is it really working ?? Sourcify spec suite currently passes in the following rubies: * MRI-1.8.*, REE-1.8.7 (both ParseTree & static scanner modes) * JRuby-1.6.*, MRI-1.9.* (static scanner ONLY) Besides its own spec suite, sourcify has also been tested to handle: ObjectSpace.each_object(Proc) {|o| puts o.to_source } For projects: * Spree[http://github.com/railsdog/spree] * Redmine[http://github.com/edavis10/redmine] (TODO: the more the merrier) == Projects using it Projects using sourcify include: * wrong[http://github.com/sconover/wrong] * ruote[http://ruote.rubyforge.org/] * dm-ambition[https://github.com/dkubb/dm-ambition] == Additional Resources Sourcify is heavily inspired by many ideas gathered from the ruby community: * http://www.justskins.com/forums/breaking-ruby-code-into-117453.html * http://rubyquiz.com/quiz38.html (Florian Groß's solution) * http://svenfuchs.com/2009/07/05/using-ruby-1-9-ripper.html The sad fact that Proc#to_source wouldn't be available in the near future: * http://redmine.ruby-lang.org/issues/show/2080 == Note on Patches/Pull Requests * Fork the project. * Make your feature addition or bug fix. * Add tests for it. This is important so I don't break it in a future version unintentionally. * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull) * Send me a pull request. Bonus points for topic branches. == Copyright Copyright (c) 2010 NgTzeYang. See LICENSE for details. sourcify-0.5.0/Gemfile0000644000175000017500000000013511755746006013702 0ustar gwolfgwolfsource "http://rubygems.org" # Specify your gem's dependencies in sourcify.gemspec gemspec sourcify-0.5.0/metadata.yml0000644000175000017500000002260611755746006014721 0ustar gwolfgwolf--- !ruby/object:Gem::Specification name: sourcify version: !ruby/object:Gem::Version version: 0.5.0 prerelease: platform: ruby authors: - NgTzeYang autorequire: bindir: bin cert_chain: [] date: 2011-05-02 00:00:00.000000000 +08:00 default_executable: dependencies: - !ruby/object:Gem::Dependency name: ruby2ruby requirement: &19360780 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.2.5 type: :runtime prerelease: false version_requirements: *19360780 - !ruby/object:Gem::Dependency name: sexp_processor requirement: &19360280 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 3.0.5 type: :runtime prerelease: false version_requirements: *19360280 - !ruby/object:Gem::Dependency name: ruby_parser requirement: &19359820 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 2.0.5 type: :runtime prerelease: false version_requirements: *19359820 - !ruby/object:Gem::Dependency name: file-tail requirement: &19359360 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: 1.0.5 type: :runtime prerelease: false version_requirements: *19359360 - !ruby/object:Gem::Dependency name: bacon requirement: &19358980 !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' type: :development prerelease: false version_requirements: *19358980 description: '' email: - ngty77@gmail.com executables: [] extensions: [] extra_rdoc_files: - README.rdoc files: - .document - .gitignore - .rvmrc - Gemfile - HISTORY.txt - LICENSE - README.rdoc - Rakefile - VERSION - lib/sourcify.rb - lib/sourcify/facets.rb - lib/sourcify/proc.rb - lib/sourcify/proc/methods.rb - lib/sourcify/proc/methods/source_location.rb - lib/sourcify/proc/methods/to_raw_source.rb - lib/sourcify/proc/methods/to_sexp.rb - lib/sourcify/proc/methods/to_source.rb - lib/sourcify/proc/parser.rb - lib/sourcify/proc/parser/code_scanner.rb - lib/sourcify/proc/parser/converter.rb - lib/sourcify/proc/parser/normalizer.rb - lib/sourcify/proc/parser/source_code.rb - lib/sourcify/proc/scanner.rb - lib/sourcify/proc/scanner.rl - lib/sourcify/proc/scanner/comment.rb - lib/sourcify/proc/scanner/counter.rb - lib/sourcify/proc/scanner/dstring.rb - lib/sourcify/proc/scanner/extensions.rb - lib/sourcify/proc/scanner/heredoc.rb - lib/sourcify/version.rb - sourcify.gemspec - spec/dump_object_space_procs.rb - spec/proc/19x_extras.rb - spec/proc/created_on_the_fly_proc_spec.rb - spec/proc/others_spec.rb - spec/proc/readme - spec/proc/spec_helper.rb - spec/proc/to_raw_source_spec.rb - spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb - spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb - spec/proc/to_sexp_variables_spec.rb - spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb - spec/proc/to_sexp_within_irb_spec.rb - spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb - spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb - spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb - spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb - spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb - spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb - spec/proc/to_source_magic_file_var_spec.rb - spec/proc/to_source_magic_line_var_spec.rb - spec/proc/to_source_variables_spec.rb - spec/proc/to_source_w_specified_strip_enclosure_spec.rb - spec/proc/to_source_within_irb_spec.rb - spec/proc_scanner/block_comment_spec.rb - spec/proc_scanner/double_colons_spec.rb - spec/proc_scanner/double_quote_str_w_interpolation_spec.rb - spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb - spec/proc_scanner/heredoc_spec.rb - spec/proc_scanner/kw_do_alias1_spec.rb - spec/proc_scanner/kw_do_alias2_spec.rb - spec/proc_scanner/per_line_comment_spec.rb - spec/proc_scanner/single_quote_str_spec.rb - spec/proc_scanner/slash_operator_spec.rb - spec/proc_scanner/spec_helper.rb - spec/run_spec.sh - spec/spec_helper.rb has_rdoc: true homepage: http://github.com/ngty/sourcify licenses: [] post_install_message: rdoc_options: [] require_paths: - lib required_ruby_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' required_rubygems_version: !ruby/object:Gem::Requirement none: false requirements: - - ! '>=' - !ruby/object:Gem::Version version: '0' requirements: [] rubyforge_project: rubygems_version: 1.6.1 signing_key: specification_version: 3 summary: Workarounds before ruby-core officially supports Proc#to_source (& friends) test_files: - spec/dump_object_space_procs.rb - spec/proc/19x_extras.rb - spec/proc/created_on_the_fly_proc_spec.rb - spec/proc/others_spec.rb - spec/proc/readme - spec/proc/spec_helper.rb - spec/proc/to_raw_source_spec.rb - spec/proc/to_raw_source_w_specified_strip_enclosure_spec.rb - spec/proc/to_sexp_from_multi_blocks_w_specified_attached_to_spec.rb - spec/proc/to_sexp_variables_spec.rb - spec/proc/to_sexp_w_specified_strip_enclosure_spec.rb - spec/proc/to_sexp_within_irb_spec.rb - spec/proc/to_source_from_braced_block_w_nested_braced_block_spec.rb - spec/proc/to_source_from_braced_block_w_nested_hash_spec.rb - spec/proc/to_source_from_braced_block_wo_nesting_complication_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_begin_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_case_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_class_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_do_end_block_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_for_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_if_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_literal_keyword_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_method_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_module_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_unless_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_until_spec.rb - spec/proc/to_source_from_do_end_block_w_nested_while_spec.rb - spec/proc/to_source_from_do_end_block_wo_nesting_complication_spec.rb - spec/proc/to_source_from_multi_blocks_w_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_no_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_and_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_attached_to_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_many_matches_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_no_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_body_matcher_and_single_match_spec.rb - spec/proc/to_source_from_multi_blocks_w_specified_ignore_nested_spec.rb - spec/proc/to_source_from_multi_do_end_blocks_w_single_match_spec.rb - spec/proc/to_source_magic_file_var_spec.rb - spec/proc/to_source_magic_line_var_spec.rb - spec/proc/to_source_variables_spec.rb - spec/proc/to_source_w_specified_strip_enclosure_spec.rb - spec/proc/to_source_within_irb_spec.rb - spec/proc_scanner/block_comment_spec.rb - spec/proc_scanner/double_colons_spec.rb - spec/proc_scanner/double_quote_str_w_interpolation_spec.rb - spec/proc_scanner/double_quote_str_wo_interpolation_spec.rb - spec/proc_scanner/heredoc_spec.rb - spec/proc_scanner/kw_do_alias1_spec.rb - spec/proc_scanner/kw_do_alias2_spec.rb - spec/proc_scanner/per_line_comment_spec.rb - spec/proc_scanner/single_quote_str_spec.rb - spec/proc_scanner/slash_operator_spec.rb - spec/proc_scanner/spec_helper.rb - spec/run_spec.sh - spec/spec_helper.rb