ruby2ruby 2.4.4 → 2.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/History.rdoc +22 -0
- data/Rakefile +18 -0
- data/lib/ruby2ruby.rb +162 -26
- data/test/test_ruby2ruby.rb +428 -125
- data.tar.gz.sig +0 -0
- metadata +18 -17
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ce3916335beb18e635634b93a85be8c88aaaab6029aea5ba5426b429cebbb2a6
|
4
|
+
data.tar.gz: e443e89cd7216bee0ae5d2fc8b182cafb94827357cb82d2b248cb19e2a26b6bd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 62655af018fce2402bb410d7606afb34f7a6f332c88fc74aca6ebf9faf5f37abd23d9827cfd5d5742d3240d89ae838f4ef7d28f92da7bc520c335467b89a448a
|
7
|
+
data.tar.gz: 637c87a736b4da72487c95bc8fa981d49ba9b57e3e8f48c2013ef52bbbcb09176c0abfae18b272cba551adcb5961bcad6e94fa38dee8352f154986861cf7e616
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
@@ -1,3 +1,25 @@
|
|
1
|
+
=== 2.5.1 / 2024-07-08
|
2
|
+
|
3
|
+
* 1 bug fix:
|
4
|
+
|
5
|
+
* Fix errors created when string literals are frozen. (byroot + zenspider)
|
6
|
+
|
7
|
+
=== 2.5.0 / 2022-10-04
|
8
|
+
|
9
|
+
* 5 minor enhancements:
|
10
|
+
|
11
|
+
* Added support for (most?) pattern matching.
|
12
|
+
* Added support for **kwrest.
|
13
|
+
* Added support for forward args (...), defn and call.
|
14
|
+
* Added support for preexe (BEGIN { ... }).
|
15
|
+
* Support ruby 3.1 hash shorthand syntax. (presidentbeef)
|
16
|
+
|
17
|
+
* 3 bug fixes:
|
18
|
+
|
19
|
+
* Fix generation of case w/ no else.
|
20
|
+
* Fixed a bug block shadow vars (they're grouped)
|
21
|
+
* Fixed find_pat up (after fixing a find_pat bug in ruby_parser).
|
22
|
+
|
1
23
|
=== 2.4.4 / 2019-09-24
|
2
24
|
|
3
25
|
* 1 bug fix:
|
data/Rakefile
CHANGED
@@ -79,6 +79,24 @@ task :debug => :isolate do
|
|
79
79
|
puts process(ruby, file)
|
80
80
|
end
|
81
81
|
|
82
|
+
task :parse => :isolate do
|
83
|
+
require "ruby_parser"
|
84
|
+
require "pp"
|
85
|
+
|
86
|
+
parser = RubyParser.for_current_ruby
|
87
|
+
|
88
|
+
file = ENV["F"]
|
89
|
+
ruby = ENV["R"]
|
90
|
+
|
91
|
+
if ruby then
|
92
|
+
file = "env"
|
93
|
+
else
|
94
|
+
ruby = File.read file
|
95
|
+
end
|
96
|
+
|
97
|
+
pp parser.process(ruby, file)
|
98
|
+
end
|
99
|
+
|
82
100
|
task :bugs do
|
83
101
|
sh "for f in bug*.rb ; do #{Gem.ruby} -S rake debug F=$f && rm $f ; done"
|
84
102
|
end
|
data/lib/ruby2ruby.rb
CHANGED
@@ -31,7 +31,7 @@ end
|
|
31
31
|
# Generate ruby code from a sexp.
|
32
32
|
|
33
33
|
class Ruby2Ruby < SexpProcessor
|
34
|
-
VERSION = "2.
|
34
|
+
VERSION = "2.5.1" # :nodoc:
|
35
35
|
|
36
36
|
# cutoff for one-liners
|
37
37
|
LINE_LENGTH = 78
|
@@ -134,8 +134,10 @@ class Ruby2Ruby < SexpProcessor
|
|
134
134
|
_, k, v = arg
|
135
135
|
"#{k}: #{process v}"
|
136
136
|
when :shadow then
|
137
|
-
shadow << arg
|
137
|
+
shadow << arg.sexp_body
|
138
138
|
next
|
139
|
+
when :forward_args then
|
140
|
+
"..."
|
139
141
|
else
|
140
142
|
raise "unknown arg type #{arg.first.inspect}"
|
141
143
|
end
|
@@ -322,9 +324,10 @@ class Ruby2Ruby < SexpProcessor
|
|
322
324
|
end
|
323
325
|
|
324
326
|
result.concat rest.map { |pt|
|
325
|
-
if pt and pt.sexp_type
|
327
|
+
if pt and %i[when in].include? pt.sexp_type
|
326
328
|
"#{process pt}"
|
327
329
|
else
|
330
|
+
next unless pt
|
328
331
|
code = indent process pt
|
329
332
|
code = indent("# do nothing") if code =~ /^\s*$/
|
330
333
|
"else\n#{code}"
|
@@ -333,7 +336,7 @@ class Ruby2Ruby < SexpProcessor
|
|
333
336
|
|
334
337
|
result << "end"
|
335
338
|
|
336
|
-
result.join "\n"
|
339
|
+
result.compact.join "\n"
|
337
340
|
end
|
338
341
|
|
339
342
|
def process_cdecl exp # :nodoc:
|
@@ -366,13 +369,26 @@ class Ruby2Ruby < SexpProcessor
|
|
366
369
|
def process_const exp # :nodoc:
|
367
370
|
_, name = exp
|
368
371
|
|
372
|
+
name = process name if Sexp === name
|
373
|
+
|
369
374
|
name.to_s
|
370
375
|
end
|
371
376
|
|
377
|
+
def __var name
|
378
|
+
case context[1]
|
379
|
+
when /_pat$/ then
|
380
|
+
"^#{name}"
|
381
|
+
when :in then
|
382
|
+
"^#{name}"
|
383
|
+
else
|
384
|
+
name.to_s
|
385
|
+
end
|
386
|
+
end
|
387
|
+
|
372
388
|
def process_cvar exp # :nodoc:
|
373
389
|
_, name = exp
|
374
390
|
|
375
|
-
name
|
391
|
+
__var name
|
376
392
|
end
|
377
393
|
|
378
394
|
def process_cvasgn exp # :nodoc:
|
@@ -459,7 +475,7 @@ class Ruby2Ruby < SexpProcessor
|
|
459
475
|
|
460
476
|
options = re_opt rest.pop if Integer === rest.last
|
461
477
|
|
462
|
-
"/"
|
478
|
+
"/" + util_dthing(:dregx, s(:dregx, str, *rest)) << "/#{options}"
|
463
479
|
end
|
464
480
|
|
465
481
|
def process_dregx_once(exp) # :nodoc:
|
@@ -486,7 +502,7 @@ class Ruby2Ruby < SexpProcessor
|
|
486
502
|
ens = process(ens) || "# do nothing"
|
487
503
|
ens = "begin\n#{ens}\nend\n" if ens =~ /(^|\n)rescue/
|
488
504
|
|
489
|
-
body.sub
|
505
|
+
body = body.sub(/\n\s*end\z/, "")
|
490
506
|
body = indent(body) unless body =~ /(^|\n)rescue/
|
491
507
|
|
492
508
|
"#{body}\nensure\n#{indent ens}"
|
@@ -528,6 +544,10 @@ class Ruby2Ruby < SexpProcessor
|
|
528
544
|
result.join "\n"
|
529
545
|
end
|
530
546
|
|
547
|
+
def process_forward_args exp
|
548
|
+
"..."
|
549
|
+
end
|
550
|
+
|
531
551
|
def process_gasgn exp # :nodoc:
|
532
552
|
process_iasgn exp
|
533
553
|
end
|
@@ -535,7 +555,7 @@ class Ruby2Ruby < SexpProcessor
|
|
535
555
|
def process_gvar exp # :nodoc:
|
536
556
|
_, name = exp
|
537
557
|
|
538
|
-
name
|
558
|
+
__var name
|
539
559
|
end
|
540
560
|
|
541
561
|
def process_hash(exp) # :nodoc:
|
@@ -544,6 +564,13 @@ class Ruby2Ruby < SexpProcessor
|
|
544
564
|
result = pairs.each_slice(2).map { |k, v|
|
545
565
|
if k.sexp_type == :kwsplat then
|
546
566
|
"%s" % process(k)
|
567
|
+
elsif v.nil?
|
568
|
+
# Shorthand hash syntax
|
569
|
+
unless k.sexp_type == :lit and k.value.is_a? Symbol
|
570
|
+
raise "Expected symbol for hash key, but got #{k.inspect}"
|
571
|
+
end
|
572
|
+
|
573
|
+
"#{k.value}:"
|
547
574
|
else
|
548
575
|
t = v.sexp_type
|
549
576
|
|
@@ -568,6 +595,89 @@ class Ruby2Ruby < SexpProcessor
|
|
568
595
|
end
|
569
596
|
end
|
570
597
|
|
598
|
+
def process_in exp # :nodoc:
|
599
|
+
_, lhs, *rhs = exp
|
600
|
+
|
601
|
+
cond = process lhs
|
602
|
+
body = rhs.compact.map { |sexp| indent process sexp }
|
603
|
+
|
604
|
+
body << indent("# do nothing") if body.empty?
|
605
|
+
body = body.join "\n"
|
606
|
+
|
607
|
+
"in #{cond} then\n#{body.chomp}"
|
608
|
+
end
|
609
|
+
|
610
|
+
def process_find_pat exp # :nodoc:
|
611
|
+
_, a, b, *c, d = exp
|
612
|
+
|
613
|
+
a = process a # might be nil
|
614
|
+
b = process b if Sexp === b
|
615
|
+
c = c.map { |sexp| process sexp }.join(", ")
|
616
|
+
d = process d if Sexp === d
|
617
|
+
|
618
|
+
"%s[%s, %s, %s]" % [a, b, c, d]
|
619
|
+
end
|
620
|
+
|
621
|
+
def process_array_pat exp # :nodoc:
|
622
|
+
_, const, *rest = exp
|
623
|
+
|
624
|
+
const = process const if const
|
625
|
+
|
626
|
+
rest = rest.map { |sexp|
|
627
|
+
case sexp
|
628
|
+
when Sexp
|
629
|
+
process sexp
|
630
|
+
else
|
631
|
+
sexp
|
632
|
+
end
|
633
|
+
}
|
634
|
+
|
635
|
+
"%s[%s]" % [const, rest.join(", ")]
|
636
|
+
end
|
637
|
+
|
638
|
+
def process_kwrest exp # :nodoc:
|
639
|
+
_, name = exp
|
640
|
+
|
641
|
+
name.to_s
|
642
|
+
end
|
643
|
+
|
644
|
+
def process_hash_pat exp # :nodoc:
|
645
|
+
_, const, *rest = exp
|
646
|
+
|
647
|
+
if const then
|
648
|
+
const = process const
|
649
|
+
kwrest = process rest.pop if rest.last && rest.last.sexp_type == :kwrest
|
650
|
+
|
651
|
+
rest = rest.each_slice(2).map { |k, v|
|
652
|
+
k = process(k).delete_prefix ":"
|
653
|
+
v = process v
|
654
|
+
|
655
|
+
"#{k}: #{v}".strip
|
656
|
+
}
|
657
|
+
|
658
|
+
rest << kwrest if kwrest
|
659
|
+
|
660
|
+
rest.empty? ? "%s[]" % const : "%s[%s]" % [const, rest.join(", ")]
|
661
|
+
else
|
662
|
+
kwrest = process rest.pop if rest.last && rest.last.sexp_type == :kwrest
|
663
|
+
|
664
|
+
rest = rest.each_slice(2).map { |k, v|
|
665
|
+
k = process(k).delete_prefix ":"
|
666
|
+
v = process v
|
667
|
+
|
668
|
+
"#{k}: #{v}".strip
|
669
|
+
}
|
670
|
+
|
671
|
+
rest << kwrest if kwrest
|
672
|
+
|
673
|
+
rest.empty? ? "{}" : "{ %s }" % [rest.join(", ")]
|
674
|
+
end
|
675
|
+
end
|
676
|
+
|
677
|
+
def process_preexe exp # :nodoc:
|
678
|
+
"BEGIN"
|
679
|
+
end
|
680
|
+
|
571
681
|
def process_if(exp) # :nodoc:
|
572
682
|
_, c, t, f = exp
|
573
683
|
|
@@ -589,11 +699,12 @@ class Ruby2Ruby < SexpProcessor
|
|
589
699
|
return r if r and (@indent + r).size < LINE_LENGTH and r !~ /\n/
|
590
700
|
end
|
591
701
|
|
592
|
-
r =
|
702
|
+
r = []
|
703
|
+
r << "if #{c} then\n#{indent(t)}\n"
|
593
704
|
r << "else\n#{indent(f)}\n" if f
|
594
705
|
r << "end"
|
595
706
|
|
596
|
-
r
|
707
|
+
r.join
|
597
708
|
elsif f
|
598
709
|
unless expand then
|
599
710
|
r = "#{f} unless #{c}"
|
@@ -610,6 +721,8 @@ class Ruby2Ruby < SexpProcessor
|
|
610
721
|
"->"
|
611
722
|
end
|
612
723
|
|
724
|
+
MUST_BE_CURLY = %w[ BEGIN END ]
|
725
|
+
|
613
726
|
def process_iter(exp) # :nodoc:
|
614
727
|
_, iter, args, body = exp
|
615
728
|
|
@@ -627,13 +740,13 @@ class Ruby2Ruby < SexpProcessor
|
|
627
740
|
" |#{process(args)[1..-2]}|"
|
628
741
|
end
|
629
742
|
|
630
|
-
b, e = if iter
|
743
|
+
b, e = if MUST_BE_CURLY.include? iter then
|
631
744
|
%w[ { } ]
|
632
745
|
else
|
633
746
|
%w[ do end ]
|
634
747
|
end
|
635
748
|
|
636
|
-
iter.sub
|
749
|
+
iter = iter.sub(/\(\)$/, "")
|
637
750
|
|
638
751
|
# REFACTOR: ugh
|
639
752
|
result = []
|
@@ -676,7 +789,8 @@ class Ruby2Ruby < SexpProcessor
|
|
676
789
|
|
677
790
|
def process_ivar(exp) # :nodoc:
|
678
791
|
_, name = exp
|
679
|
-
|
792
|
+
|
793
|
+
__var name
|
680
794
|
end
|
681
795
|
|
682
796
|
def process_kwsplat(exp)
|
@@ -687,9 +801,18 @@ class Ruby2Ruby < SexpProcessor
|
|
687
801
|
def process_lasgn(exp) # :nodoc:
|
688
802
|
_, name, value = exp
|
689
803
|
|
690
|
-
|
691
|
-
|
692
|
-
|
804
|
+
value = process value
|
805
|
+
|
806
|
+
if value then
|
807
|
+
"%s %s %s" % case context[1]
|
808
|
+
when /_pat$/ then
|
809
|
+
[value, "=>", name]
|
810
|
+
else
|
811
|
+
[name, "=", value]
|
812
|
+
end
|
813
|
+
else
|
814
|
+
"%s" % [name]
|
815
|
+
end
|
693
816
|
end
|
694
817
|
|
695
818
|
def process_lit exp # :nodoc:
|
@@ -704,7 +827,8 @@ class Ruby2Ruby < SexpProcessor
|
|
704
827
|
|
705
828
|
def process_lvar(exp) # :nodoc:
|
706
829
|
_, name = exp
|
707
|
-
|
830
|
+
|
831
|
+
__var name
|
708
832
|
end
|
709
833
|
|
710
834
|
def process_masgn(exp) # :nodoc:
|
@@ -793,12 +917,20 @@ class Ruby2Ruby < SexpProcessor
|
|
793
917
|
|
794
918
|
def process_op_asgn exp # :nodoc:
|
795
919
|
# [[:lvar, :x], [:call, nil, :z, [:lit, 1]], :y, :"||"]
|
796
|
-
_, lhs, rhs, index, op = exp
|
797
920
|
|
798
|
-
|
799
|
-
|
921
|
+
case exp.length
|
922
|
+
when 4
|
923
|
+
raise "NOT YET: op_asgn 4"
|
924
|
+
when 5
|
925
|
+
_, lhs, rhs, index, op = exp
|
926
|
+
|
927
|
+
lhs = process lhs
|
928
|
+
rhs = process rhs
|
800
929
|
|
801
|
-
|
930
|
+
"#{lhs}.#{index} #{op}= #{rhs}"
|
931
|
+
else
|
932
|
+
raise ArgumentError, "Don't know how to process this length: %p" % [exp]
|
933
|
+
end
|
802
934
|
end
|
803
935
|
|
804
936
|
def process_op_asgn1(exp) # :nodoc:
|
@@ -840,7 +972,15 @@ class Ruby2Ruby < SexpProcessor
|
|
840
972
|
def process_or(exp) # :nodoc:
|
841
973
|
_, lhs, rhs = exp
|
842
974
|
|
843
|
-
|
975
|
+
lhs = process lhs
|
976
|
+
rhs = process rhs
|
977
|
+
|
978
|
+
case context[1]
|
979
|
+
when :in then
|
980
|
+
"(#{lhs} | #{rhs})"
|
981
|
+
else
|
982
|
+
"(#{lhs} or #{rhs})"
|
983
|
+
end
|
844
984
|
end
|
845
985
|
|
846
986
|
def process_postexe(exp) # :nodoc:
|
@@ -1029,10 +1169,6 @@ class Ruby2Ruby < SexpProcessor
|
|
1029
1169
|
end
|
1030
1170
|
|
1031
1171
|
def process_when exp # :nodoc:
|
1032
|
-
s(:when, s(:array, s(:lit, 1)),
|
1033
|
-
s(:call, nil, :puts, s(:str, "something")),
|
1034
|
-
s(:lasgn, :result, s(:str, "red")))
|
1035
|
-
|
1036
1172
|
_, lhs, *rhs = exp
|
1037
1173
|
|
1038
1174
|
cond = process(lhs)[1..-2]
|
data/test/test_ruby2ruby.rb
CHANGED
@@ -42,6 +42,15 @@ class TestRuby2Ruby < R2RTestCase
|
|
42
42
|
@processor = Ruby2Ruby.new
|
43
43
|
end
|
44
44
|
|
45
|
+
# some things don't work in earlier rubies... oh well.
|
46
|
+
def skip30
|
47
|
+
skip unless RUBY_VERSION > "3.0"
|
48
|
+
end
|
49
|
+
|
50
|
+
def skip31
|
51
|
+
skip unless RUBY_VERSION > "3.1"
|
52
|
+
end
|
53
|
+
|
45
54
|
def do_not_check_sexp!
|
46
55
|
@check_sexp = false
|
47
56
|
end
|
@@ -100,8 +109,8 @@ class TestRuby2Ruby < R2RTestCase
|
|
100
109
|
end
|
101
110
|
|
102
111
|
def test_hash_parens_lvar
|
103
|
-
inn = s(:hash, s(:lit, :k), s(:lvar, :
|
104
|
-
out = "{ :k =>
|
112
|
+
inn = s(:hash, s(:lit, :k), s(:lvar, :a))
|
113
|
+
out = "{ :k => a }"
|
105
114
|
assert_parse inn, out
|
106
115
|
end
|
107
116
|
|
@@ -118,6 +127,23 @@ class TestRuby2Ruby < R2RTestCase
|
|
118
127
|
assert_parse inn, out
|
119
128
|
end
|
120
129
|
|
130
|
+
def test_hash_shorthand
|
131
|
+
inn = s(:hash, s(:lit, :k), nil)
|
132
|
+
out = '{ k: }'
|
133
|
+
|
134
|
+
assert_parse inn, out
|
135
|
+
end
|
136
|
+
|
137
|
+
def test_hash_shorthand_invalid_key_type
|
138
|
+
do_not_check_sexp!
|
139
|
+
|
140
|
+
inn = s(:hash, s(:str, 'k'), nil)
|
141
|
+
out = '{ k: }'
|
142
|
+
assert_raises do
|
143
|
+
assert_parse inn, out
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
121
147
|
def test_and_alias
|
122
148
|
inn = s(:and, s(:true), s(:alias, s(:lit, :a), s(:lit, :b)))
|
123
149
|
out = "true and (alias :a :b)"
|
@@ -351,15 +377,6 @@ class TestRuby2Ruby < R2RTestCase
|
|
351
377
|
assert_parse inn, out
|
352
378
|
end
|
353
379
|
|
354
|
-
def test_defn_kwargs
|
355
|
-
inn = s(:defn, :initialize,
|
356
|
-
s(:args, :arg, s(:kwarg, :keyword, s(:nil)), :"**args"),
|
357
|
-
s(:nil))
|
358
|
-
out = "def initialize(arg, keyword: nil, **args)\n # do nothing\nend"
|
359
|
-
|
360
|
-
assert_parse inn, out
|
361
|
-
end
|
362
|
-
|
363
380
|
def test_defn_kwargs2
|
364
381
|
inn = s(:defn, :initialize,
|
365
382
|
s(:args, :arg,
|
@@ -373,55 +390,34 @@ class TestRuby2Ruby < R2RTestCase
|
|
373
390
|
end
|
374
391
|
|
375
392
|
def test_call_self_index
|
376
|
-
assert_parse s(:call,
|
393
|
+
assert_parse s(:call, s(:self), :[], s(:lit, 42)), "self[42]"
|
377
394
|
end
|
378
395
|
|
379
396
|
def test_call_self_index_equals
|
380
397
|
assert_parse(s(:attrasgn, s(:self), :[]=, s(:lit, 42), s(:lit, 24)),
|
381
398
|
"self[42] = 24")
|
382
|
-
end
|
383
|
-
|
384
|
-
def test_call_self_index_equals_array
|
385
399
|
assert_parse(s(:attrasgn, s(:self), :[]=, s(:lit, 1), s(:lit, 2), s(:lit, 3)),
|
386
400
|
"self[1, 2] = 3")
|
387
401
|
end
|
388
402
|
|
389
|
-
def test_call_arglist_hash_first
|
390
|
-
inn = s(:call, nil, :method,
|
391
|
-
s(:hash, s(:lit, :a), s(:lit, 1)),
|
392
|
-
s(:call, nil, :b))
|
393
|
-
out = "method({ :a => 1 }, b)"
|
394
|
-
|
395
|
-
assert_parse inn, out
|
396
|
-
end
|
397
|
-
|
398
403
|
def test_call_arglist_hash_first_last
|
399
404
|
inn = s(:call, nil, :method,
|
400
405
|
s(:hash, s(:lit, :a), s(:lit, 1)),
|
401
|
-
s(:
|
406
|
+
s(:lvar, :b),
|
402
407
|
s(:hash, s(:lit, :c), s(:lit, 1)))
|
403
408
|
out = "method({ :a => 1 }, b, :c => 1)"
|
404
409
|
|
405
410
|
assert_parse inn, out
|
406
411
|
end
|
407
412
|
|
408
|
-
def test_call_arglist_hash_last
|
409
|
-
inn = s(:call, nil, :method,
|
410
|
-
s(:call, nil, :b),
|
411
|
-
s(:hash, s(:lit, :a), s(:lit, 1)))
|
412
|
-
out = "method(b, :a => 1)"
|
413
|
-
|
414
|
-
assert_parse inn, out
|
415
|
-
end
|
416
|
-
|
417
413
|
def test_call_arglist_if
|
418
414
|
inn = s(:call,
|
419
|
-
s(:
|
415
|
+
s(:lvar, :a),
|
420
416
|
:+,
|
421
417
|
s(:if,
|
422
|
-
s(:
|
423
|
-
s(:
|
424
|
-
s(:
|
418
|
+
s(:lvar, :b),
|
419
|
+
s(:lvar, :c),
|
420
|
+
s(:lvar, :d)))
|
425
421
|
|
426
422
|
out = "(a + (b ? (c) : (d)))"
|
427
423
|
assert_parse inn, out
|
@@ -443,12 +439,27 @@ class TestRuby2Ruby < R2RTestCase
|
|
443
439
|
assert_parse inn, out
|
444
440
|
end
|
445
441
|
|
442
|
+
def test_forward_args__defn
|
443
|
+
inn = s(:defn, :x, s(:args, :a, s(:forward_args)), s(:nil))
|
444
|
+
out = "def x(a, ...)\n # do nothing\nend"
|
445
|
+
|
446
|
+
assert_parse inn, out
|
447
|
+
end
|
448
|
+
|
449
|
+
def test_forward_args__call
|
450
|
+
skip31
|
451
|
+
|
452
|
+
inn = s(:defn, :x, s(:args, s(:forward_args)), s(:call, nil, :y, s(:forward_args)))
|
453
|
+
out = "def x(...)\n y(...)\nend"
|
454
|
+
|
455
|
+
assert_parse inn, out
|
456
|
+
end
|
457
|
+
|
446
458
|
def test_shadow_block_args
|
447
459
|
inn = s(:iter,
|
448
460
|
s(:call, nil, :a),
|
449
461
|
s(:args,
|
450
|
-
s(:shadow, :b)
|
451
|
-
s(:shadow, :c)))
|
462
|
+
s(:shadow, :b, :c)))
|
452
463
|
out = 'a { |; b, c| }'
|
453
464
|
|
454
465
|
assert_parse inn, out
|
@@ -481,19 +492,6 @@ class TestRuby2Ruby < R2RTestCase
|
|
481
492
|
assert_parse inn, out
|
482
493
|
end
|
483
494
|
|
484
|
-
def test_multiple_nested_masgn_block_arg
|
485
|
-
inn = s(:iter,
|
486
|
-
s(:call, nil, :a),
|
487
|
-
s(:args, :b,
|
488
|
-
s(:masgn,
|
489
|
-
s(:masgn, :c, :d),
|
490
|
-
:e,
|
491
|
-
s(:masgn, :f, :g))))
|
492
|
-
out = "a { |b, ((c, d), e, (f, g))| }"
|
493
|
-
|
494
|
-
assert_parse inn, out
|
495
|
-
end
|
496
|
-
|
497
495
|
def test_multiple_nested_masgn_array
|
498
496
|
inn = s(:masgn,
|
499
497
|
s(:array,
|
@@ -544,6 +542,13 @@ class TestRuby2Ruby < R2RTestCase
|
|
544
542
|
assert_parse inn, out
|
545
543
|
end
|
546
544
|
|
545
|
+
def test_preexe
|
546
|
+
inn = s(:iter, s(:preexe), 0, s(:block, s(:lit, 1), s(:lit, 2), s(:lit, 3)))
|
547
|
+
out = "BEGIN {\n 1\n 2\n 3\n}"
|
548
|
+
|
549
|
+
assert_parse inn, out
|
550
|
+
end
|
551
|
+
|
547
552
|
def test_safe_attrasgn
|
548
553
|
inn = s(:safe_attrasgn,
|
549
554
|
s(:call, nil, :x),
|
@@ -578,6 +583,8 @@ class TestRuby2Ruby < R2RTestCase
|
|
578
583
|
end
|
579
584
|
|
580
585
|
def test_safe_op_asgn
|
586
|
+
do_not_check_sexp! # TODO: fix!
|
587
|
+
|
581
588
|
inn = s(:safe_op_asgn,
|
582
589
|
s(:call, nil, :x),
|
583
590
|
s(:call, nil, :z, s(:lit, 1)),
|
@@ -611,38 +618,6 @@ class TestRuby2Ruby < R2RTestCase
|
|
611
618
|
assert_parse inn, out
|
612
619
|
end
|
613
620
|
|
614
|
-
def test_resbody_block
|
615
|
-
inn = s(:rescue,
|
616
|
-
s(:call, nil, :x1),
|
617
|
-
s(:resbody,
|
618
|
-
s(:array),
|
619
|
-
s(:call, nil, :x2),
|
620
|
-
s(:call, nil, :x3)))
|
621
|
-
|
622
|
-
out = "begin\n x1\nrescue\n x2\n x3\nend"
|
623
|
-
assert_parse inn, out
|
624
|
-
end
|
625
|
-
|
626
|
-
def test_resbody_short_with_begin_end
|
627
|
-
# "begin; blah; rescue; []; end"
|
628
|
-
inn = s(:rescue,
|
629
|
-
s(:call, nil, :blah),
|
630
|
-
s(:resbody, s(:array), s(:array)))
|
631
|
-
out = "blah rescue []"
|
632
|
-
assert_parse inn, out
|
633
|
-
end
|
634
|
-
|
635
|
-
def test_resbody_short_with_begin_end_multiple
|
636
|
-
# "begin; blah; rescue; []; end"
|
637
|
-
inn = s(:rescue,
|
638
|
-
s(:call, nil, :blah),
|
639
|
-
s(:resbody, s(:array),
|
640
|
-
s(:call, nil, :log),
|
641
|
-
s(:call, nil, :raise)))
|
642
|
-
out = "begin\n blah\nrescue\n log\n raise\nend"
|
643
|
-
assert_parse inn, out
|
644
|
-
end
|
645
|
-
|
646
621
|
def test_resbody_short_with_defn_multiple
|
647
622
|
inn = s(:defn,
|
648
623
|
:foo,
|
@@ -678,9 +653,7 @@ class TestRuby2Ruby < R2RTestCase
|
|
678
653
|
end
|
679
654
|
|
680
655
|
def test_call_binary_call_with_hash_arg
|
681
|
-
# if 42
|
682
|
-
# args << {:key => 24}
|
683
|
-
# end
|
656
|
+
# args << {:key => 24} if 42
|
684
657
|
|
685
658
|
inn = s(:if, s(:lit, 42),
|
686
659
|
s(:call, s(:call, nil, :args),
|
@@ -704,8 +677,8 @@ class TestRuby2Ruby < R2RTestCase
|
|
704
677
|
|
705
678
|
def test_binary_operators_with_multiple_arguments
|
706
679
|
Ruby2Ruby::BINARY.each do |op|
|
707
|
-
inn = s(:call, s(:lvar, :
|
708
|
-
out = "
|
680
|
+
inn = s(:call, s(:lvar, :a), op, s(:lit, 2), s(:lit, 3))
|
681
|
+
out = "a.#{op}(2, 3)"
|
709
682
|
assert_parse inn, out
|
710
683
|
end
|
711
684
|
end
|
@@ -722,6 +695,309 @@ class TestRuby2Ruby < R2RTestCase
|
|
722
695
|
assert_parse inn, out
|
723
696
|
end
|
724
697
|
|
698
|
+
def test_case_in_normal_01
|
699
|
+
assert_case_in "var", s(:lasgn, :var)
|
700
|
+
end
|
701
|
+
|
702
|
+
def test_case_in_normal_02
|
703
|
+
assert_case_in "^var", s(:lvar, :var)
|
704
|
+
end
|
705
|
+
|
706
|
+
def test_case_in_normal_04
|
707
|
+
assert_case_in "A if true", s(:if, s(:true), s(:const, :A), nil)
|
708
|
+
end
|
709
|
+
|
710
|
+
def test_case_in_normal_05
|
711
|
+
assert_case_in "A unless true", s(:if, s(:true), nil, s(:const, :A))
|
712
|
+
end
|
713
|
+
|
714
|
+
def test_case_in_normal_06
|
715
|
+
assert_case_in "A::B", s(:const, s(:colon2, s(:const, :A), :B))
|
716
|
+
end
|
717
|
+
|
718
|
+
def test_case_in_normal_07
|
719
|
+
assert_case_in "A | B", s(:or, s(:const, :A), s(:const, :B)), "(A | B)"
|
720
|
+
|
721
|
+
# TODO: assert_case_in "(A or B)", s(:const, s(:colon2, s(:colon3, :A), :B))
|
722
|
+
end
|
723
|
+
|
724
|
+
def test_case_in_normal_08
|
725
|
+
assert_case_in "::A::B", s(:const, s(:colon2, s(:colon3, :A), :B))
|
726
|
+
end
|
727
|
+
|
728
|
+
def test_case_in_normal_09
|
729
|
+
assert_case_in "A", s(:const, :A)
|
730
|
+
end
|
731
|
+
|
732
|
+
def test_case_in__array_pat_00
|
733
|
+
assert_case_in "Object[]", s(:array_pat, s(:const, :Object))
|
734
|
+
end
|
735
|
+
|
736
|
+
def test_case_in__array_pat_01
|
737
|
+
assert_case_in "[]", s(:array_pat)
|
738
|
+
end
|
739
|
+
|
740
|
+
def test_case_in__array_pat_02
|
741
|
+
assert_case_in "[*, ::NilClass]", s(:array_pat, nil, :*, s(:colon3, :NilClass))
|
742
|
+
end
|
743
|
+
|
744
|
+
def test_case_in__array_pat_03
|
745
|
+
assert_case_in "[*, :b, :c]", s(:array_pat, nil, :*, s(:lit, :b), s(:lit, :c))
|
746
|
+
end
|
747
|
+
|
748
|
+
def test_case_in__array_pat_04
|
749
|
+
assert_case_in "[[:b, ^c], [:d, ^e]]", s(:array_pat, nil, s(:array_pat, nil, s(:lit, :b), s(:lvar, :c)), s(:array_pat, nil, s(:lit, :d), s(:lvar, :e)))
|
750
|
+
end
|
751
|
+
|
752
|
+
def test_case_in__array_pat_06
|
753
|
+
assert_case_in "[A, *, B]", s(:array_pat, nil, s(:const, :A), :*, s(:const, :B))
|
754
|
+
end
|
755
|
+
|
756
|
+
def test_case_in__array_pat_07
|
757
|
+
assert_case_in "[-> (b) { true }, ^c]", s(:array_pat, nil, s(:iter, s(:lambda), s(:args, :b), s(:true)), s(:lvar, :c))
|
758
|
+
end
|
759
|
+
|
760
|
+
def test_case_in__array_pat_09
|
761
|
+
assert_case_in "[:a, ^b, ^c, [:d, *e, nil]]", s(:array_pat, nil, s(:lit, :a), s(:lvar, :b), s(:lvar, :c), s(:array_pat, nil, s(:lit, :d), :"*e", s(:nil)))
|
762
|
+
end
|
763
|
+
|
764
|
+
def test_case_in__array_pat_14
|
765
|
+
assert_case_in "A[*list]", s(:array_pat, s(:const, :A), :"*list")
|
766
|
+
end
|
767
|
+
|
768
|
+
def test_case_in__array_pat_15
|
769
|
+
assert_case_in "B[C => d]", s(:array_pat, s(:const, :B), s(:lasgn, :d, s(:const, :C)))
|
770
|
+
end
|
771
|
+
|
772
|
+
def test_case_in__array_pat_16
|
773
|
+
assert_case_in "B[^c]", s(:array_pat, s(:const, :B), s(:lvar, :c))
|
774
|
+
end
|
775
|
+
|
776
|
+
def test_case_in__array_pat_19
|
777
|
+
skip31
|
778
|
+
|
779
|
+
assert_case_in "[^@a, ^$b, ^@@c]", s(:array_pat, nil, s(:ivar, :@a), s(:gvar, :$b), s(:cvar, :@@c)) # HACK: really not sure about this one
|
780
|
+
end
|
781
|
+
|
782
|
+
def test_case_in__find_pat_1
|
783
|
+
skip30
|
784
|
+
|
785
|
+
assert_case_in "[*a, :+, *b]", s(:find_pat, nil, :"*a",
|
786
|
+
s(:lit, :+),
|
787
|
+
:"*b")
|
788
|
+
end
|
789
|
+
|
790
|
+
def test_case_in__find_pat_2
|
791
|
+
skip30
|
792
|
+
|
793
|
+
assert_case_in "[*, :b, ^c, *]", s(:find_pat, nil,
|
794
|
+
:*,
|
795
|
+
s(:lit, :b), s(:lvar, :c),
|
796
|
+
:*)
|
797
|
+
end
|
798
|
+
|
799
|
+
def test_case_in__find_pat_3
|
800
|
+
skip30
|
801
|
+
|
802
|
+
assert_case_in("Array(*b, n, { a: }, m, *a)",
|
803
|
+
s(:find_pat,
|
804
|
+
s(:const, :Array),
|
805
|
+
:"*b",
|
806
|
+
s(:lasgn, :n),
|
807
|
+
s(:hash_pat, nil, s(:lit, :a), nil),
|
808
|
+
s(:lasgn, :m),
|
809
|
+
:"*a"),
|
810
|
+
"Array[*b, n, { a: }, m, *a]")
|
811
|
+
end
|
812
|
+
|
813
|
+
def test_case_in__find_pat_4
|
814
|
+
skip30
|
815
|
+
|
816
|
+
assert_case_in("*b, n, { a: }, m, *a", s(:find_pat,
|
817
|
+
nil,
|
818
|
+
:"*b",
|
819
|
+
s(:lasgn, :n),
|
820
|
+
s(:hash_pat, nil, s(:lit, :a), nil),
|
821
|
+
s(:lasgn, :m),
|
822
|
+
:"*a"),
|
823
|
+
"[*b, n, { a: }, m, *a]")
|
824
|
+
end
|
825
|
+
|
826
|
+
def test_case_in__find_pat_5
|
827
|
+
skip30
|
828
|
+
|
829
|
+
assert_case_in("Array(*lhs, ^b, *rhs)", s(:find_pat,
|
830
|
+
s(:const, :Array),
|
831
|
+
:"*lhs",
|
832
|
+
s(:lvar, :b),
|
833
|
+
:"*rhs"),
|
834
|
+
"Array[*lhs, ^b, *rhs]")
|
835
|
+
end
|
836
|
+
|
837
|
+
def test_case_in__find_pat_6
|
838
|
+
assert_case_in("Array[*lhs, b, *rhs]", s(:find_pat,
|
839
|
+
s(:const, :Array),
|
840
|
+
:"*lhs",
|
841
|
+
s(:lasgn, :b),
|
842
|
+
:"*rhs"))
|
843
|
+
end
|
844
|
+
|
845
|
+
def test_case_in__find_pat_7
|
846
|
+
assert_case_in("Array[*lhs, :b, *rhs]", s(:find_pat,
|
847
|
+
s(:const, :Array),
|
848
|
+
:"*lhs",
|
849
|
+
s(:lit, :b),
|
850
|
+
:"*rhs"))
|
851
|
+
end
|
852
|
+
|
853
|
+
def test_case_in_10
|
854
|
+
assert_case_in("[nil, nil, nil]",
|
855
|
+
s(:array_pat,
|
856
|
+
nil,
|
857
|
+
s(:nil),
|
858
|
+
s(:nil),
|
859
|
+
s(:nil)))
|
860
|
+
end
|
861
|
+
|
862
|
+
def test_case_in_32_2
|
863
|
+
assert_case_in "1..3", s(:dot2, s(:lit, 1), s(:lit, 3)), "(1..3)"
|
864
|
+
end
|
865
|
+
|
866
|
+
def test_case_in_32_3
|
867
|
+
assert_case_in "1...3", s(:dot3, s(:lit, 1), s(:lit, 3)), "(1...3)"
|
868
|
+
end
|
869
|
+
|
870
|
+
def test_case_in_36
|
871
|
+
pt = s(:array_pat, nil,
|
872
|
+
s(:lit, :a), s(:lasgn, :b), s(:lvar, :d), :"*e", s(:nil))
|
873
|
+
|
874
|
+
assert_case_in "[:a, b, ^d, *e, nil]", pt
|
875
|
+
end
|
876
|
+
|
877
|
+
def test_case_in_42
|
878
|
+
rb = "case :a\nin [:b, *_] then\n nil\nend"
|
879
|
+
pt = s(:case, s(:lit, :a),
|
880
|
+
s(:in,
|
881
|
+
s(:array_pat,
|
882
|
+
nil,
|
883
|
+
s(:lit, :b),
|
884
|
+
:"*_",
|
885
|
+
),
|
886
|
+
s(:nil)),
|
887
|
+
nil)
|
888
|
+
|
889
|
+
assert_parse pt, rb
|
890
|
+
assert_variant pt, "case :a\nin :b, *_ then\n nil\nend"
|
891
|
+
end
|
892
|
+
|
893
|
+
def test_case_in_42_2
|
894
|
+
rb = "case :a\nin A[*list] then\n nil\nend"
|
895
|
+
pt = s(:case, s(:lit, :a),
|
896
|
+
s(:in,
|
897
|
+
s(:array_pat,
|
898
|
+
s(:const, :A),
|
899
|
+
:"*list"),
|
900
|
+
s(:nil)),
|
901
|
+
nil)
|
902
|
+
|
903
|
+
assert_parse pt, rb
|
904
|
+
assert_variant pt, "case :a\nin A(*list) then\n nil\nend"
|
905
|
+
end
|
906
|
+
|
907
|
+
def test_case_in_67
|
908
|
+
rb = "case :a\nin 1.. then nil\nend"
|
909
|
+
rb = "case :a\nin (1..) then\n nil\nend"
|
910
|
+
pt = s(:case,
|
911
|
+
s(:lit, :a),
|
912
|
+
s(:in, s(:dot2, s(:lit, 1), nil),
|
913
|
+
s(:nil)),
|
914
|
+
nil)
|
915
|
+
|
916
|
+
assert_parse pt, rb
|
917
|
+
end
|
918
|
+
|
919
|
+
def test_case_in_76
|
920
|
+
assert_case_in "`echo hi`", s(:xstr, "echo hi")
|
921
|
+
end
|
922
|
+
|
923
|
+
def test_case_in_77
|
924
|
+
assert_case_in "/regexp/", s(:lit, /regexp/)
|
925
|
+
end
|
926
|
+
|
927
|
+
def test_case_in_79
|
928
|
+
assert_case_in "%w[a b]", s(:array_pat, nil, s(:str, "a"), s(:str, "b")), "[\"a\", \"b\"]"
|
929
|
+
end
|
930
|
+
|
931
|
+
def test_case_in_80
|
932
|
+
assert_case_in "%I[a b]", s(:array_pat, nil, s(:lit, :a), s(:lit, :b)), "[:a, :b]"
|
933
|
+
end
|
934
|
+
|
935
|
+
def test_case_in_83
|
936
|
+
pt = s(:array_pat, nil,
|
937
|
+
s(:iter, s(:lambda), s(:args, :b),
|
938
|
+
s(:true)),
|
939
|
+
s(:lasgn, :c))
|
940
|
+
|
941
|
+
assert_case_in "[-> (b) { true }, c]", pt
|
942
|
+
end
|
943
|
+
|
944
|
+
def test_case_in_85
|
945
|
+
pt = s(:array_pat, nil,
|
946
|
+
s(:array_pat, nil,
|
947
|
+
s(:lit, :b),
|
948
|
+
s(:lasgn, :c)),
|
949
|
+
s(:array_pat,
|
950
|
+
nil,
|
951
|
+
s(:lit, :d),
|
952
|
+
s(:lvar, :e)),
|
953
|
+
)
|
954
|
+
|
955
|
+
assert_case_in "[[:b, c], [:d, ^e]]", pt
|
956
|
+
end
|
957
|
+
|
958
|
+
def test_case_in__hash_pat_00
|
959
|
+
assert_case_in "{}", s(:hash_pat, nil)
|
960
|
+
end
|
961
|
+
|
962
|
+
def test_case_in__hash_pat_01
|
963
|
+
assert_case_in "**nil", s(:hash_pat, nil, s(:kwrest, :"**nil")), "{ **nil }"
|
964
|
+
end
|
965
|
+
|
966
|
+
def test_case_in__hash_pat_03
|
967
|
+
assert_case_in "a:", s(:hash_pat, nil, s(:lit, :a), nil), "{ a: }"
|
968
|
+
end
|
969
|
+
|
970
|
+
def test_case_in__hash_pat_06
|
971
|
+
assert_case_in "a:1, **r",s(:hash_pat, nil, s(:lit, :a), s(:lit, 1), s(:kwrest, :"**r")), "{ a: 1, **r }"
|
972
|
+
end
|
973
|
+
|
974
|
+
def test_case_in__hash_pat_08
|
975
|
+
assert_case_in "{ b: [Hash, *] }", s(:hash_pat, nil, s(:lit, :b), s(:array_pat, nil, s(:const, :Hash), :*))
|
976
|
+
end
|
977
|
+
|
978
|
+
def test_case_in__hash_pat_09
|
979
|
+
assert_case_in("{ b: Integer => x, d: \"e\", f: }",
|
980
|
+
s(:hash_pat, nil,
|
981
|
+
s(:lit, :b), s(:lasgn, :x, s(:const, :Integer)),
|
982
|
+
s(:lit, :d), s(:str, "e"), s(:lit, :f), nil))
|
983
|
+
end
|
984
|
+
|
985
|
+
def test_case_in__hash_pat_10
|
986
|
+
assert_case_in "{ b: ^c, **r }", s(:hash_pat, nil, s(:lit, :b), s(:lvar, :c), s(:kwrest, :"**r"))
|
987
|
+
end
|
988
|
+
|
989
|
+
def test_case_in__hash_pat_11
|
990
|
+
assert_case_in "{ b: \"c\", d: \"e\" }", s(:hash_pat, nil, s(:lit, :b), s(:str, "c"), s(:lit, :d), s(:str, "e"))
|
991
|
+
end
|
992
|
+
|
993
|
+
def test_case_in__hash_pat_12
|
994
|
+
assert_case_in "{ b: true }", s(:hash_pat, nil, s(:lit, :b), s(:true))
|
995
|
+
end
|
996
|
+
|
997
|
+
def test_case_in__hash_pat_14
|
998
|
+
assert_case_in "Object[b: 1]", s(:hash_pat, s(:const, :Object), s(:lit, :b), s(:lit, 1))
|
999
|
+
end
|
1000
|
+
|
725
1001
|
def test_interpolation_and_escapes
|
726
1002
|
# log_entry = " \e[#{message_color}m#{message}\e[0m "
|
727
1003
|
inn = s(:lasgn, :log_entry,
|
@@ -756,12 +1032,6 @@ class TestRuby2Ruby < R2RTestCase
|
|
756
1032
|
assert_parse inn, out
|
757
1033
|
end
|
758
1034
|
|
759
|
-
def test_basic_ensure
|
760
|
-
inn = s(:ensure, s(:lit, 1), s(:lit, 2))
|
761
|
-
out = "begin\n 1\nensure\n 2\nend"
|
762
|
-
assert_parse inn, out
|
763
|
-
end
|
764
|
-
|
765
1035
|
def test_nested_ensure
|
766
1036
|
inn = s(:ensure, s(:lit, 1), s(:ensure, s(:lit, 2), s(:lit, 3)))
|
767
1037
|
out = "begin\n 1\nensure\n begin\n 2\n ensure\n 3\n end\nend"
|
@@ -775,18 +1045,18 @@ class TestRuby2Ruby < R2RTestCase
|
|
775
1045
|
end
|
776
1046
|
|
777
1047
|
def test_nested_rescue_exception
|
778
|
-
inn = s(:ensure,
|
1048
|
+
inn = s(:ensure,
|
1049
|
+
s(:lit, 1),
|
1050
|
+
s(:rescue, s(:lit, 2),
|
1051
|
+
s(:resbody, s(:array, s(:const, :Exception)),
|
1052
|
+
s(:lit, 3))))
|
779
1053
|
out = "begin\n 1\nensure\n begin\n 2\n rescue Exception\n 3\n end\nend"
|
780
1054
|
assert_parse inn, out
|
781
1055
|
end
|
782
1056
|
|
783
|
-
def test_nested_rescue_exception2
|
784
|
-
inn = s(:ensure, s(:rescue, s(:lit, 2), s(:resbody, s(:array, s(:const, :Exception)), s(:lit, 3))), s(:lit, 1))
|
785
|
-
out = "begin\n 2\nrescue Exception\n 3\nensure\n 1\nend"
|
786
|
-
assert_parse inn, out
|
787
|
-
end
|
788
|
-
|
789
1057
|
def test_op_asgn
|
1058
|
+
do_not_check_sexp! # TODO: fix!
|
1059
|
+
|
790
1060
|
inn = s(:op_asgn,
|
791
1061
|
s(:call, nil, :x),
|
792
1062
|
s(:call, nil, :z, s(:lit, 1)),
|
@@ -809,42 +1079,80 @@ class TestRuby2Ruby < R2RTestCase
|
|
809
1079
|
|
810
1080
|
def test_array_adds_parens_around_rescue
|
811
1081
|
inn = s(:array,
|
812
|
-
s(:
|
813
|
-
s(:rescue, s(:
|
1082
|
+
s(:lvar, :a),
|
1083
|
+
s(:rescue, s(:lvar, :b), s(:resbody, s(:array), s(:lvar, :c))))
|
814
1084
|
out = "[a, (b rescue c)]"
|
815
1085
|
|
816
1086
|
assert_parse inn, out
|
817
1087
|
end
|
818
1088
|
|
819
1089
|
def test_call_arglist_rescue
|
820
|
-
inn = s(:call,
|
821
|
-
nil,
|
822
|
-
:method,
|
1090
|
+
inn = s(:call, nil, :method,
|
823
1091
|
s(:rescue,
|
824
|
-
s(:
|
825
|
-
s(:resbody, s(:array), s(:
|
1092
|
+
s(:lvar, :a),
|
1093
|
+
s(:resbody, s(:array), s(:lvar, :b))))
|
826
1094
|
out = "method((a rescue b))"
|
827
1095
|
assert_parse inn, out
|
828
1096
|
end
|
829
1097
|
|
830
1098
|
def test_unless_vs_if_not
|
1099
|
+
do_not_check_sexp! # TODO: remove? dunno if that's possible w/ this one
|
1100
|
+
|
831
1101
|
rb1 = "a unless b"
|
832
1102
|
rb2 = "a if (not b)"
|
833
1103
|
rb3 = "a if ! b"
|
834
1104
|
|
835
|
-
assert_parse
|
1105
|
+
assert_parse ruby_parser.parse(rb1), rb1
|
836
1106
|
|
837
|
-
assert_parse
|
1107
|
+
assert_parse ruby_parser.parse(rb2), rb1
|
838
1108
|
|
839
|
-
assert_parse
|
1109
|
+
assert_parse ruby_parser.parse(rb3), rb1
|
840
1110
|
end
|
841
1111
|
|
842
|
-
def
|
843
|
-
|
844
|
-
@check_sexp
|
1112
|
+
def ruby_parser
|
1113
|
+
parser = RubyParser.latest
|
845
1114
|
|
1115
|
+
%i[a b c d].each do |v|
|
1116
|
+
parser.env[v] = :lvar
|
1117
|
+
end
|
1118
|
+
|
1119
|
+
parser
|
1120
|
+
end
|
1121
|
+
|
1122
|
+
def assert_parse sexp, expected_ruby, expected_eval = nil
|
846
1123
|
assert_equal expected_ruby, @processor.process(sexp), "sexp -> ruby"
|
847
1124
|
assert_equal expected_eval, eval(expected_ruby) if expected_eval
|
1125
|
+
assert_variant sexp, expected_ruby if @check_sexp
|
1126
|
+
end
|
1127
|
+
|
1128
|
+
def assert_variant sexp, expected_ruby
|
1129
|
+
assert_equal sexp, ruby_parser.process(expected_ruby), "ruby -> sexp"
|
1130
|
+
end
|
1131
|
+
|
1132
|
+
def assert_case_in lit, exp_pt, normal_lit = nil
|
1133
|
+
rb = "case :a\nin #{normal_lit || lit} then\n # do nothing\nend"
|
1134
|
+
|
1135
|
+
exp_pt.deep_each { |s| s.line ||= 2 }
|
1136
|
+
exp_pt.line ||= 2
|
1137
|
+
|
1138
|
+
# flunk "redundant: #{lit.inspect}" if normal_lit == lit
|
1139
|
+
# flunk "redundant: #{lit.inspect}" if normal_lit && normal_lit[1..-2] == lit
|
1140
|
+
normal_lit, lit = lit, lit[1..-2] if lit =~ /^\[.+\]$/ && !normal_lit
|
1141
|
+
|
1142
|
+
if ENV["VERBOSE_TEST"] then
|
1143
|
+
puts
|
1144
|
+
puts rb
|
1145
|
+
end
|
1146
|
+
|
1147
|
+
pt = s(:case, s(:lit, :a).line(1),
|
1148
|
+
s(:in, exp_pt, nil).line(2),
|
1149
|
+
nil).line(1)
|
1150
|
+
|
1151
|
+
if normal_lit then
|
1152
|
+
assert_variant pt, "case :a\nin #{lit} then\n # do nothing\nend"
|
1153
|
+
end
|
1154
|
+
|
1155
|
+
assert_parse pt, rb
|
848
1156
|
end
|
849
1157
|
|
850
1158
|
def util_thingy(type)
|
@@ -864,22 +1172,17 @@ end
|
|
864
1172
|
# s
|
865
1173
|
# t new 2 3
|
866
1174
|
|
867
|
-
tr2r = File.read(__FILE__).
|
1175
|
+
tr2r = File.read(__FILE__).lines[start + 1..__LINE__ - 2].join
|
868
1176
|
ir2r = File.read("lib/ruby2ruby.rb")
|
869
1177
|
|
870
1178
|
require "ruby_parser"
|
871
1179
|
|
872
|
-
def silent_eval ruby
|
873
|
-
old, $-w = $-w, nil
|
874
|
-
eval ruby
|
875
|
-
$-w = old
|
876
|
-
end
|
877
|
-
|
878
1180
|
def morph_and_eval src, from, to, processor
|
879
|
-
parser = RubyParser.
|
1181
|
+
parser = RubyParser.latest
|
880
1182
|
new_src = processor.new.process(parser.process(src.sub(from, to)))
|
881
1183
|
|
882
|
-
|
1184
|
+
eval new_src
|
1185
|
+
|
883
1186
|
new_src
|
884
1187
|
end
|
885
1188
|
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,18 +1,18 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby2ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Davis
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain:
|
11
11
|
- |
|
12
12
|
-----BEGIN CERTIFICATE-----
|
13
|
-
|
13
|
+
MIIDPjCCAiagAwIBAgIBCDANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
|
14
14
|
ZC1ydWJ5MRkwFwYKCZImiZPyLGQBGRYJemVuc3BpZGVyMRMwEQYKCZImiZPyLGQB
|
15
|
-
|
15
|
+
GRYDY29tMB4XDTI0MDEwMjIxMjEyM1oXDTI1MDEwMTIxMjEyM1owRTETMBEGA1UE
|
16
16
|
AwwKcnlhbmQtcnVieTEZMBcGCgmSJomT8ixkARkWCXplbnNwaWRlcjETMBEGCgmS
|
17
17
|
JomT8ixkARkWA2NvbTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALda
|
18
18
|
b9DCgK+627gPJkB6XfjZ1itoOQvpqH1EXScSaba9/S2VF22VYQbXU1xQXL/WzCkx
|
@@ -22,14 +22,14 @@ cert_chain:
|
|
22
22
|
qhtV7HJxNKuPj/JFH0D2cswvzznE/a5FOYO68g+YCuFi5L8wZuuM8zzdwjrWHqSV
|
23
23
|
gBEfoTEGr7Zii72cx+sCAwEAAaM5MDcwCQYDVR0TBAIwADALBgNVHQ8EBAMCBLAw
|
24
24
|
HQYDVR0OBBYEFEfFe9md/r/tj/Wmwpy+MI8d9k/hMA0GCSqGSIb3DQEBCwUAA4IB
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
25
|
+
AQCygvpmncmkiSs9r/Kceo4bBPDszhTv6iBi4LwMReqnFrpNLMOWJw7xi8x+3eL2
|
26
|
+
XS09ZPNOt2zm70KmFouBMgOysnDY4k2dE8uF6B8JbZOO8QfalW+CoNBliefOTcn2
|
27
|
+
bg5IOP7UoGM5lC174/cbDJrJnRG9bzig5FAP0mvsgA8zgTRXQzIUAZEo92D5K7p4
|
28
|
+
B4/O998ho6BSOgYBI9Yk1ttdCtti6Y+8N9+fZESsjtWMykA+WXWeGUScHqiU+gH8
|
29
|
+
S7043fq9EbQdBr2AXdj92+CDwuTfHI6/Hj5FVBDULufrJaan4xUgL70Hvc6pTTeW
|
30
|
+
deKfBjgVAq7EYHu1AczzlUly
|
31
31
|
-----END CERTIFICATE-----
|
32
|
-
date:
|
32
|
+
date: 2024-07-08 00:00:00.000000000 Z
|
33
33
|
dependencies:
|
34
34
|
- !ruby/object:Gem::Dependency
|
35
35
|
name: sexp_processor
|
@@ -85,14 +85,14 @@ dependencies:
|
|
85
85
|
requirements:
|
86
86
|
- - "~>"
|
87
87
|
- !ruby/object:Gem::Version
|
88
|
-
version: '
|
88
|
+
version: '4.2'
|
89
89
|
type: :development
|
90
90
|
prerelease: false
|
91
91
|
version_requirements: !ruby/object:Gem::Requirement
|
92
92
|
requirements:
|
93
93
|
- - "~>"
|
94
94
|
- !ruby/object:Gem::Version
|
95
|
-
version: '
|
95
|
+
version: '4.2'
|
96
96
|
description: |-
|
97
97
|
ruby2ruby provides a means of generating pure ruby code easily from
|
98
98
|
RubyParser compatible Sexps. This makes making dynamic language
|
@@ -118,8 +118,9 @@ files:
|
|
118
118
|
homepage: https://github.com/seattlerb/ruby2ruby
|
119
119
|
licenses:
|
120
120
|
- MIT
|
121
|
-
metadata:
|
122
|
-
|
121
|
+
metadata:
|
122
|
+
homepage_uri: https://github.com/seattlerb/ruby2ruby
|
123
|
+
post_install_message:
|
123
124
|
rdoc_options:
|
124
125
|
- "--main"
|
125
126
|
- README.rdoc
|
@@ -136,8 +137,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
136
137
|
- !ruby/object:Gem::Version
|
137
138
|
version: '0'
|
138
139
|
requirements: []
|
139
|
-
rubygems_version: 3.
|
140
|
-
signing_key:
|
140
|
+
rubygems_version: 3.5.14
|
141
|
+
signing_key:
|
141
142
|
specification_version: 4
|
142
143
|
summary: ruby2ruby provides a means of generating pure ruby code easily from RubyParser
|
143
144
|
compatible Sexps
|
metadata.gz.sig
CHANGED
Binary file
|