ruby_parser 3.19.0 → 3.19.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5e8b4b78bfb538253820b4ff34d49ebf7a91f9722c0ecfb63e3dadb3067530cb
4
- data.tar.gz: e8e6e9cc42513094304d79a10fb4802706b10cb147084683c5dd3315c2ecde9a
3
+ metadata.gz: 82ff82f1d9693451e0d2f740f5e7a9cbeaa31034bee66ffa61486bc0f930d60b
4
+ data.tar.gz: 15d8b71b9533534ffaa4184e50f0e5a795e4a7f190bf13a55858f59b17c1ed99
5
5
  SHA512:
6
- metadata.gz: dd72b30995fbc5ad74f04dedc341572d03b73b962ddd2dd3ecd255c8d1babe1b4e190b780588b846f2c8b8942327ac4a50bda0e8401d02037299f9b16965e69b
7
- data.tar.gz: 5793d0f9bf5e11f56db8eb5b53fd4b603664e72818b4bc43a3bfb61cf3c4a0c61f9ecee3757350a684271ae9e0c434782ef739ef0f075b3897fa338bcd2680c5
6
+ metadata.gz: 78332be9c05d511d05f1c47977c74390658fcc00fc412009dba172d0e53c0e698b8e28c4803c4969720f2d2d29ed3fc891be2a990618098ae0cf04d00ad28e9f
7
+ data.tar.gz: 72f7e1c089bc80662ea2eb8c8056d7bb3bf84ff27224c2d450ffde94abd2fb5ba2317d1405a880bebb2c91ac34bcb7023685065f1a8b2e69f62ed8f6b0362e77
checksums.yaml.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,20 @@
1
+ === 3.19.2 / 2022-12-03
2
+
3
+ * 5 bug fixes:
4
+
5
+ * Fixed bug parsing array patterns using %w, %i, etc.
6
+ * Fixed dedenting when heredoc has only empty line and interpolation. (mvz)
7
+ * Fixed dsym unescaping. (mvz)
8
+ * Fixed vars in pattern matching that should be lasgn, not lvar.
9
+ * find_pat mid-patterns are now splatted inline, not wrapped in an array_pat.
10
+
11
+ === 3.19.1 / 2022-04-05
12
+
13
+ * 2 bug fixes:
14
+
15
+ * Added comments to endless defn and defs. (mvz)
16
+ * Fixed endless method bug handling attrset names.
17
+
1
18
  === 3.19.0 / 2022-03-29
2
19
 
3
20
  * 1 major enhancement:
data/Rakefile CHANGED
@@ -12,6 +12,7 @@ Hoe.add_include_dirs "lib"
12
12
  Hoe.add_include_dirs "../../sexp_processor/dev/lib"
13
13
  Hoe.add_include_dirs "../../minitest/dev/lib"
14
14
  Hoe.add_include_dirs "../../oedipus_lex/dev/lib"
15
+ Hoe.add_include_dirs "../../ruby2ruby/dev/lib"
15
16
 
16
17
  V2 = %w[20 21 22 23 24 25 26 27]
17
18
  V3 = %w[30 31]
data/gauntlet.md CHANGED
@@ -42,8 +42,7 @@ using `unpack_gems.rb`.
42
42
  ... waaaait ...
43
43
  % DIR=gauntlet.$(today).(all|new).noindex
44
44
  % mv hashed.noindex $DIR
45
- % tar c $DIR | zstd -5 -T0 --long > archives/$DIR.tar.zst
46
- % tar vc -T <(fd . $DIR | sort) | zstd -5 -T0 --long > archives/$DIR.tar.zst
45
+ % tar vc -T <(fd -tf . $DIR | sort) | zstd -5 -T0 --long > archives/$DIR.tar.zst ; say done
47
46
  % ./bin/sync.sh
48
47
  ```
49
48
 
@@ -66,8 +65,8 @@ Unpacking, validating, SHA'ing everything is disk and CPU intensive.
66
65
  The `.noindex` extension stops spotlight from indexing the continous
67
66
  churn of files being unpacked and moved and saves time.
68
67
 
69
- Finally, I rename and archive it all up (currently using lrztar, but
70
- I'm not in love with it).
68
+ Finally, I rename and archive it all up (currently using zstd to
69
+ compress).
71
70
 
72
71
  ### Stats
73
72
 
@@ -75,7 +74,7 @@ I'm not in love with it).
75
74
  9696 % find gauntlet.$(today).noindex -type f | lc
76
75
  561270
77
76
  3.5G gauntlet.2021-08-06.noindex
78
- 239M gauntlet.2021-08-06.noindex.tar.lrz
77
+ 239M gauntlet.2021-08-06.noindex.tar.zst
79
78
  ```
80
79
 
81
80
  So I wind up with a little over half a million unique ruby files to
@@ -86,7 +85,7 @@ parse. It's about 3.5g but compresses very nicely down to 240m
86
85
  Assuming you're starting from scratch, unpack the archive once:
87
86
 
88
87
  ```
89
- % lrzuntar gauntlet.$(today).noindex.lrz
88
+ % zstdcat gauntlet.$(today).noindex.tar.zst | tar x
90
89
  ```
91
90
 
92
91
  Then, either run a single process (easier to read):
@@ -98,7 +97,7 @@ Then, either run a single process (easier to read):
98
97
  Or max out your machine using xargs (note the `-P 16` and choose accordingly):
99
98
 
100
99
  ```
101
- % ls -d gauntlet/*.noindex/?/? | xargs -n 1 -P 16 ./gauntlet/bin/gauntlet.rb
100
+ % ls -d gauntlet/*.noindex/?/? | time xargs -n 1 -P 16 ./gauntlet/bin/gauntlet.rb
102
101
  ```
103
102
 
104
103
  In another terminal I usually monitor the progress like so:
data/lib/ruby27_parser.rb CHANGED
@@ -7722,10 +7722,10 @@ racc_reduce_table = [
7722
7722
  1, 364, :_reduce_none,
7723
7723
  1, 364, :_reduce_none,
7724
7724
  1, 364, :_reduce_none,
7725
- 1, 364, :_reduce_none,
7726
- 1, 364, :_reduce_none,
7727
- 1, 364, :_reduce_none,
7728
- 1, 364, :_reduce_none,
7725
+ 1, 364, :_reduce_548,
7726
+ 1, 364, :_reduce_549,
7727
+ 1, 364, :_reduce_550,
7728
+ 1, 364, :_reduce_551,
7729
7729
  1, 364, :_reduce_552,
7730
7730
  1, 364, :_reduce_none,
7731
7731
  1, 344, :_reduce_554,
@@ -11813,13 +11813,29 @@ end
11813
11813
 
11814
11814
  # reduce 547 omitted
11815
11815
 
11816
- # reduce 548 omitted
11816
+ def _reduce_548(val, _values, result)
11817
+ result = ary_to_pat val[0]
11818
+
11819
+ result
11820
+ end
11821
+
11822
+ def _reduce_549(val, _values, result)
11823
+ result = ary_to_pat val[0]
11817
11824
 
11818
- # reduce 549 omitted
11825
+ result
11826
+ end
11827
+
11828
+ def _reduce_550(val, _values, result)
11829
+ result = ary_to_pat val[0]
11830
+
11831
+ result
11832
+ end
11819
11833
 
11820
- # reduce 550 omitted
11834
+ def _reduce_551(val, _values, result)
11835
+ result = ary_to_pat val[0]
11821
11836
 
11822
- # reduce 551 omitted
11837
+ result
11838
+ end
11823
11839
 
11824
11840
  def _reduce_552(val, _values, result)
11825
11841
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -11835,7 +11851,7 @@ end
11835
11851
  def _reduce_554(val, _values, result)
11836
11852
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
11837
11853
  # TODO: assignable(p, $1, 0, &@$);
11838
- result = wrap :lvar, val[0]
11854
+ result = wrap :lasgn, val[0]
11839
11855
 
11840
11856
  result
11841
11857
  end
data/lib/ruby27_parser.y CHANGED
@@ -2453,9 +2453,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2453
2453
  | xstring
2454
2454
  | regexp
2455
2455
  | words
2456
+ {
2457
+ result = ary_to_pat val[0]
2458
+ }
2456
2459
  | qwords
2460
+ {
2461
+ result = ary_to_pat val[0]
2462
+ }
2457
2463
  | symbols
2464
+ {
2465
+ result = ary_to_pat val[0]
2466
+ }
2458
2467
  | qsymbols
2468
+ {
2469
+ result = ary_to_pat val[0]
2470
+ }
2459
2471
  | keyword_variable
2460
2472
  {
2461
2473
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -2469,7 +2481,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2469
2481
  {
2470
2482
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2471
2483
  # TODO: assignable(p, $1, 0, &@$);
2472
- result = wrap :lvar, val[0]
2484
+ result = wrap :lasgn, val[0]
2473
2485
  }
2474
2486
 
2475
2487
  p_var_ref: tCARET tIDENTIFIER
data/lib/ruby30_parser.rb CHANGED
@@ -7841,10 +7841,10 @@ racc_reduce_table = [
7841
7841
  1, 371, :_reduce_none,
7842
7842
  1, 371, :_reduce_none,
7843
7843
  1, 371, :_reduce_none,
7844
- 1, 371, :_reduce_none,
7845
- 1, 371, :_reduce_none,
7846
- 1, 371, :_reduce_none,
7847
- 1, 371, :_reduce_none,
7844
+ 1, 371, :_reduce_561,
7845
+ 1, 371, :_reduce_562,
7846
+ 1, 371, :_reduce_563,
7847
+ 1, 371, :_reduce_564,
7848
7848
  1, 371, :_reduce_565,
7849
7849
  1, 371, :_reduce_none,
7850
7850
  1, 350, :_reduce_567,
@@ -12038,13 +12038,29 @@ end
12038
12038
 
12039
12039
  # reduce 560 omitted
12040
12040
 
12041
- # reduce 561 omitted
12041
+ def _reduce_561(val, _values, result)
12042
+ result = ary_to_pat val[0]
12043
+
12044
+ result
12045
+ end
12046
+
12047
+ def _reduce_562(val, _values, result)
12048
+ result = ary_to_pat val[0]
12042
12049
 
12043
- # reduce 562 omitted
12050
+ result
12051
+ end
12052
+
12053
+ def _reduce_563(val, _values, result)
12054
+ result = ary_to_pat val[0]
12055
+
12056
+ result
12057
+ end
12044
12058
 
12045
- # reduce 563 omitted
12059
+ def _reduce_564(val, _values, result)
12060
+ result = ary_to_pat val[0]
12046
12061
 
12047
- # reduce 564 omitted
12062
+ result
12063
+ end
12048
12064
 
12049
12065
  def _reduce_565(val, _values, result)
12050
12066
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -12060,7 +12076,7 @@ end
12060
12076
  def _reduce_567(val, _values, result)
12061
12077
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
12062
12078
  # TODO: assignable(p, $1, 0, &@$);
12063
- result = wrap :lvar, val[0]
12079
+ result = wrap :lasgn, val[0]
12064
12080
 
12065
12081
  result
12066
12082
  end
data/lib/ruby30_parser.y CHANGED
@@ -2534,9 +2534,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2534
2534
  | xstring
2535
2535
  | regexp
2536
2536
  | words
2537
+ {
2538
+ result = ary_to_pat val[0]
2539
+ }
2537
2540
  | qwords
2541
+ {
2542
+ result = ary_to_pat val[0]
2543
+ }
2538
2544
  | symbols
2545
+ {
2546
+ result = ary_to_pat val[0]
2547
+ }
2539
2548
  | qsymbols
2549
+ {
2550
+ result = ary_to_pat val[0]
2551
+ }
2540
2552
  | keyword_variable
2541
2553
  {
2542
2554
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -2550,7 +2562,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2550
2562
  {
2551
2563
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2552
2564
  # TODO: assignable(p, $1, 0, &@$);
2553
- result = wrap :lvar, val[0]
2565
+ result = wrap :lasgn, val[0]
2554
2566
  }
2555
2567
 
2556
2568
  p_var_ref: tCARET tIDENTIFIER
data/lib/ruby31_parser.rb CHANGED
@@ -8153,10 +8153,10 @@ racc_reduce_table = [
8153
8153
  1, 373, :_reduce_none,
8154
8154
  1, 373, :_reduce_none,
8155
8155
  1, 373, :_reduce_none,
8156
- 1, 373, :_reduce_none,
8157
- 1, 373, :_reduce_none,
8158
- 1, 373, :_reduce_none,
8159
- 1, 373, :_reduce_none,
8156
+ 1, 373, :_reduce_569,
8157
+ 1, 373, :_reduce_570,
8158
+ 1, 373, :_reduce_571,
8159
+ 1, 373, :_reduce_572,
8160
8160
  1, 373, :_reduce_573,
8161
8161
  1, 373, :_reduce_none,
8162
8162
  1, 351, :_reduce_575,
@@ -12399,13 +12399,29 @@ end
12399
12399
 
12400
12400
  # reduce 568 omitted
12401
12401
 
12402
- # reduce 569 omitted
12402
+ def _reduce_569(val, _values, result)
12403
+ result = ary_to_pat val[0]
12404
+
12405
+ result
12406
+ end
12407
+
12408
+ def _reduce_570(val, _values, result)
12409
+ result = ary_to_pat val[0]
12403
12410
 
12404
- # reduce 570 omitted
12411
+ result
12412
+ end
12413
+
12414
+ def _reduce_571(val, _values, result)
12415
+ result = ary_to_pat val[0]
12416
+
12417
+ result
12418
+ end
12405
12419
 
12406
- # reduce 571 omitted
12420
+ def _reduce_572(val, _values, result)
12421
+ result = ary_to_pat val[0]
12407
12422
 
12408
- # reduce 572 omitted
12423
+ result
12424
+ end
12409
12425
 
12410
12426
  def _reduce_573(val, _values, result)
12411
12427
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -12421,7 +12437,7 @@ end
12421
12437
  def _reduce_575(val, _values, result)
12422
12438
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
12423
12439
  # TODO: assignable(p, $1, 0, &@$);
12424
- result = wrap :lvar, val[0]
12440
+ result = wrap :lasgn, val[0]
12425
12441
 
12426
12442
  result
12427
12443
  end
data/lib/ruby31_parser.y CHANGED
@@ -2562,9 +2562,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2562
2562
  | xstring
2563
2563
  | regexp
2564
2564
  | words
2565
+ {
2566
+ result = ary_to_pat val[0]
2567
+ }
2565
2568
  | qwords
2569
+ {
2570
+ result = ary_to_pat val[0]
2571
+ }
2566
2572
  | symbols
2573
+ {
2574
+ result = ary_to_pat val[0]
2575
+ }
2567
2576
  | qsymbols
2577
+ {
2578
+ result = ary_to_pat val[0]
2579
+ }
2568
2580
  | keyword_variable
2569
2581
  {
2570
2582
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -2578,7 +2590,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2578
2590
  {
2579
2591
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2580
2592
  # TODO: assignable(p, $1, 0, &@$);
2581
- result = wrap :lvar, val[0]
2593
+ result = wrap :lasgn, val[0]
2582
2594
  }
2583
2595
 
2584
2596
  p_var_ref: tCARET tIDENTIFIER
data/lib/ruby3_parser.yy CHANGED
@@ -2591,9 +2591,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2591
2591
  | xstring
2592
2592
  | regexp
2593
2593
  | words
2594
+ {
2595
+ result = ary_to_pat val[0]
2596
+ }
2594
2597
  | qwords
2598
+ {
2599
+ result = ary_to_pat val[0]
2600
+ }
2595
2601
  | symbols
2602
+ {
2603
+ result = ary_to_pat val[0]
2604
+ }
2596
2605
  | qsymbols
2606
+ {
2607
+ result = ary_to_pat val[0]
2608
+ }
2597
2609
  | keyword_variable
2598
2610
  {
2599
2611
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -2607,7 +2619,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2607
2619
  {
2608
2620
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2609
2621
  # TODO: assignable(p, $1, 0, &@$);
2610
- result = wrap :lvar, val[0]
2622
+ result = wrap :lasgn, val[0]
2611
2623
  }
2612
2624
 
2613
2625
  p_var_ref: tCARET tIDENTIFIER
data/lib/ruby_lexer.rb CHANGED
@@ -232,7 +232,7 @@ class RubyLexer
232
232
  content = match[1]
233
233
 
234
234
  if text =~ check then
235
- content.gsub(ESC) { unescape $1 }
235
+ unescape_string content
236
236
  else
237
237
  content.gsub(/\\\\/, "\\").gsub(/\\\'/, "'")
238
238
  end
@@ -590,9 +590,7 @@ class RubyLexer
590
590
  orig_line = lineno
591
591
  self.lineno += text.count("\n")
592
592
 
593
- str = text[1..-2]
594
- .gsub(ESC) { unescape($1).b.force_encoding Encoding::UTF_8 }
595
- str = str.b unless str.valid_encoding?
593
+ str = unescape_string text[1..-2]
596
594
 
597
595
  result EXPR_END, :tSTRING, str, orig_line
598
596
  end
@@ -817,6 +815,15 @@ class RubyLexer
817
815
  end
818
816
  end
819
817
 
818
+ def unescape_string str
819
+ str = str.gsub(ESC) { unescape($1).b.force_encoding Encoding::UTF_8 }
820
+ if str.valid_encoding?
821
+ str
822
+ else
823
+ str.b
824
+ end
825
+ end
826
+
820
827
  def unescape s
821
828
  r = ESCAPES[s]
822
829
 
data/lib/ruby_parser.yy CHANGED
@@ -2530,9 +2530,21 @@ opt_block_args_tail: tCOMMA block_args_tail
2530
2530
  | xstring
2531
2531
  | regexp
2532
2532
  | words
2533
+ {
2534
+ result = ary_to_pat val[0]
2535
+ }
2533
2536
  | qwords
2537
+ {
2538
+ result = ary_to_pat val[0]
2539
+ }
2534
2540
  | symbols
2541
+ {
2542
+ result = ary_to_pat val[0]
2543
+ }
2535
2544
  | qsymbols
2545
+ {
2546
+ result = ary_to_pat val[0]
2547
+ }
2536
2548
  | keyword_variable
2537
2549
  {
2538
2550
  # TODO? if (!($$ = gettable(p, $1, &@$))) $$ = NEW_BEGIN(0, &@$);
@@ -2546,7 +2558,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2546
2558
  {
2547
2559
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2548
2560
  # TODO: assignable(p, $1, 0, &@$);
2549
- result = wrap :lvar, val[0]
2561
+ result = wrap :lasgn, val[0]
2550
2562
  }
2551
2563
 
2552
2564
  p_var_ref: tCARET tIDENTIFIER
@@ -30,7 +30,7 @@ class Sexp
30
30
  end
31
31
 
32
32
  module RubyParserStuff
33
- VERSION = "3.19.0"
33
+ VERSION = "3.19.2"
34
34
 
35
35
  attr_accessor :lexer, :in_def, :in_single, :file
36
36
  attr_accessor :in_kwarg
@@ -218,11 +218,15 @@ module RubyParserStuff
218
218
  self.args args
219
219
  end
220
220
 
221
+ def attrset_id? id
222
+ id =~ /^\[\]=$|^\w+=$/
223
+ end
224
+
221
225
  def endless_method_name defn_or_defs
222
226
  name = defn_or_defs[1]
223
227
  name = defn_or_defs[2] unless Symbol === name
224
228
 
225
- if name.end_with? "=" then
229
+ if attrset_id? name then
226
230
  yyerror "setter method cannot be defined in an endless method definition"
227
231
  end
228
232
 
@@ -467,7 +471,7 @@ module RubyParserStuff
467
471
  end
468
472
  else
469
473
  warn "unprocessed: %p" % [s]
470
- end.map { |l| whitespace_width l.chomp }
474
+ end.map { |l| whitespace_width l }
471
475
  }.compact.min
472
476
  end
473
477
 
@@ -727,6 +731,13 @@ module RubyParserStuff
727
731
  result
728
732
  end
729
733
 
734
+ def ary_to_pat ary
735
+ pat = ary.dup
736
+ pat.sexp_type = :array_TAIL
737
+
738
+ new_array_pattern nil, nil, pat, ary.line
739
+ end
740
+
730
741
  def new_array_pattern const, pre_arg, arypat, loc
731
742
  result = s(:array_pat, const).line loc
732
743
  result << pre_arg if pre_arg
@@ -994,6 +1005,8 @@ module RubyParserStuff
994
1005
  local_pop in_def
995
1006
  endless_method_name result
996
1007
 
1008
+ result.comments = self.comments.pop
1009
+
997
1010
  result
998
1011
  end
999
1012
 
@@ -1014,6 +1027,8 @@ module RubyParserStuff
1014
1027
  local_pop in_def
1015
1028
  endless_method_name result
1016
1029
 
1030
+ result.comments = self.comments.pop
1031
+
1017
1032
  result
1018
1033
  end
1019
1034
 
@@ -1058,9 +1073,9 @@ module RubyParserStuff
1058
1073
  lhs_id = "*#{lhs_id}".to_sym
1059
1074
  rhs_id = "*#{rhs_id}".to_sym
1060
1075
 
1061
- mid.sexp_type = :array_pat # HACK?
1076
+ raise "BAD?" unless mid.sexp_type == :array_TAIL
1062
1077
 
1063
- s(:find_pat_TAIL, lhs_id, mid, rhs_id).line line
1078
+ s(:find_pat_TAIL, lhs_id, *mid.sexp_body, rhs_id).line line
1064
1079
  end
1065
1080
 
1066
1081
  def new_for expr, var, body
@@ -1643,7 +1658,7 @@ module RubyParserStuff
1643
1658
 
1644
1659
  if remove_width then
1645
1660
  line[idx..-1]
1646
- elsif line[idx].nil?
1661
+ elsif line[idx] == "\n"
1647
1662
  nil
1648
1663
  else
1649
1664
  col
@@ -3009,6 +3009,19 @@ class TestRubyLexer < Minitest::Test
3009
3009
  :tSTRING_END, "\"", EXPR_LIT)
3010
3010
  end
3011
3011
 
3012
+ def test_yylex_symbol_double_escape_octal
3013
+ setup_lexer ":\"Variet\\303\\240\""
3014
+
3015
+ adv = @lex.next_token
3016
+ act_token, act_value = adv
3017
+ act_value = act_value.first
3018
+
3019
+ assert_equal :tSYMBOL, act_token
3020
+ assert_match EXPR_LIT, @lex.lex_state
3021
+ # Force comparison of encodings
3022
+ assert_equal "Varietà", act_value
3023
+ end
3024
+
3012
3025
  def test_yylex_symbol_single
3013
3026
  assert_lex3(":'symbol'",
3014
3027
  nil,
@@ -826,6 +826,13 @@ module TestRubyParserShared
826
826
  assert_parse rb, pt
827
827
  end
828
828
 
829
+ def test_dsym_esc_to_sym
830
+ rb = ':"Variet\303\240"'
831
+ pt = s(:lit, :Varietà)
832
+
833
+ assert_parse rb, pt
834
+ end
835
+
829
836
  def test_empty
830
837
  refute_parse ""
831
838
  end
@@ -3541,10 +3548,8 @@ module TestRubyParserShared20Plus
3541
3548
  end
3542
3549
 
3543
3550
  def test_regexp_esc_C_slash
3544
- skip "https://bugs.ruby-lang.org/issues/18449" if RUBY_VERSION == "3.1.0"
3545
-
3546
3551
  rb = "/\\cC\\d/"
3547
- pt = s(:lit, /\cC\d/)
3552
+ pt = s(:lit, Regexp.new('\cC\d')) # https://bugs.ruby-lang.org/issues/18449
3548
3553
 
3549
3554
  assert_parse rb, pt
3550
3555
  end
@@ -4270,6 +4275,21 @@ module TestRubyParserShared23Plus
4270
4275
  assert_parse rb, pt
4271
4276
  end
4272
4277
 
4278
+ def test_heredoc_squiggly_blank_line_plus_interpolation
4279
+ rb = "a = foo(<<~EOF.chop)\n\n #\{bar}baz\n EOF"
4280
+ pt = s(:lasgn, :a,
4281
+ s(:call,
4282
+ nil,
4283
+ :foo,
4284
+ s(:call,
4285
+ s(:dstr, "\n",
4286
+ s(:evstr, s(:call, nil, :bar).line(3)).line(3),
4287
+ s(:str, "baz\n").line(3)).line(1),
4288
+ :chop).line(1)).line(1)).line(1)
4289
+
4290
+ assert_parse rb, pt
4291
+ end
4292
+
4273
4293
  def test_integer_with_if_modifier
4274
4294
  rb = "1_234if true"
4275
4295
  pt = s(:if, s(:true), s(:lit, 1234), nil)
@@ -4553,8 +4573,8 @@ module TestPatternMatching
4553
4573
  pt = s(:array_pat,
4554
4574
  nil,
4555
4575
  s(:lit, :a).line(2),
4556
- s(:lvar, :b).line(2),
4557
- s(:lvar, :c).line(2),
4576
+ s(:lasgn, :b).line(2),
4577
+ s(:lasgn, :c).line(2),
4558
4578
  s(:array_pat,
4559
4579
  nil,
4560
4580
  s(:lit, :d).line(2),
@@ -4647,19 +4667,19 @@ module TestPatternMatching
4647
4667
  end
4648
4668
 
4649
4669
  def test_case_in_78
4650
- assert_case_in "%W[a b]", s(:array, s(:str, "a").line(2), s(:str, "b").line(2)).line(2)
4670
+ assert_case_in "%W[a b]", s(:array_pat, nil, s(:str, "a").line(2), s(:str, "b").line(2)).line(2)
4651
4671
  end
4652
4672
 
4653
4673
  def test_case_in_79
4654
- assert_case_in "%w[a b]", s(:array, s(:str, "a").line(2), s(:str, "b").line(2)).line(2)
4674
+ assert_case_in "%w[a b]", s(:array_pat, nil, s(:str, "a").line(2), s(:str, "b").line(2)).line(2)
4655
4675
  end
4656
4676
 
4657
4677
  def test_case_in_80
4658
- assert_case_in "%I[a b]", s(:array, s(:lit, :a).line(2), s(:lit, :b).line(2)).line(2)
4678
+ assert_case_in "%I[a b]", s(:array_pat, nil, s(:lit, :a).line(2), s(:lit, :b).line(2)).line(2)
4659
4679
  end
4660
4680
 
4661
4681
  def test_case_in_81
4662
- assert_case_in "%i[a b]", s(:array, s(:lit, :a).line(2), s(:lit, :b).line(2)).line(2)
4682
+ assert_case_in "%i[a b]", s(:array_pat, nil, s(:lit, :a).line(2), s(:lit, :b).line(2)).line(2)
4663
4683
  end
4664
4684
 
4665
4685
  def test_case_in_83
@@ -4667,7 +4687,7 @@ module TestPatternMatching
4667
4687
  pt = s(:array_pat, nil,
4668
4688
  s(:iter, s(:lambda).line(2), s(:args, :b).line(2),
4669
4689
  s(:true).line(2)).line(2),
4670
- s(:lvar, :c).line(2)).line(2)
4690
+ s(:lasgn, :c).line(2)).line(2)
4671
4691
 
4672
4692
  assert_case_in rb, pt
4673
4693
  end
@@ -4677,7 +4697,7 @@ module TestPatternMatching
4677
4697
  pt = s(:array_pat, nil,
4678
4698
  s(:array_pat, nil,
4679
4699
  s(:lit, :b).line(2),
4680
- s(:lvar, :c).line(2)).line(2),
4700
+ s(:lasgn, :c).line(2)).line(2),
4681
4701
  s(:array_pat,
4682
4702
  nil,
4683
4703
  s(:lit, :d).line(2),
@@ -4723,7 +4743,7 @@ module TestPatternMatching
4723
4743
  s(:in,
4724
4744
  s(:array_pat,
4725
4745
  s(:const, :B).line(2),
4726
- s(:lvar, :c).line(2)).line(2),
4746
+ s(:lasgn, :c).line(2)).line(2),
4727
4747
  s(:lit, :d).line(3)).line(2),
4728
4748
  nil)
4729
4749
 
@@ -4736,7 +4756,7 @@ module TestPatternMatching
4736
4756
  s(:in,
4737
4757
  s(:array_pat,
4738
4758
  s(:const, s(:colon2, s(:const, :B).line(2), :C).line(2)).line(2),
4739
- s(:lvar, :d).line(2)).line(2),
4759
+ s(:lasgn, :d).line(2)).line(2),
4740
4760
  s(:lit, :e).line(3)).line(2),
4741
4761
  nil)
4742
4762
 
@@ -4841,7 +4861,7 @@ module TestPatternMatching
4841
4861
  s(:hash_pat,
4842
4862
  nil,
4843
4863
  s(:lit, :b).line(2),
4844
- s(:lvar, :c).line(2),
4864
+ s(:lasgn, :c).line(2),
4845
4865
  s(:kwrest, :"**rest").line(2)).line(2),
4846
4866
  s(:lit, :d).line(2)).line(2),
4847
4867
  nil)
@@ -4934,12 +4954,12 @@ module TestPatternMatching
4934
4954
  end
4935
4955
 
4936
4956
  def test_parse_pattern_044
4937
- rb = <<~RUBY
4938
- case obj
4939
- in Object[]
4940
- true
4941
- end
4942
- RUBY
4957
+ rb = <<~RUBY
4958
+ case obj
4959
+ in Object[]
4960
+ true
4961
+ end
4962
+ RUBY
4943
4963
  pt = s(:case,
4944
4964
  s(:call, nil, :obj),
4945
4965
  s(:in, s(:array_pat, s(:const, :Object).line(2)).line(2),
@@ -5072,7 +5092,7 @@ module TestPatternMatching30
5072
5092
  s(:find_pat,
5073
5093
  s(:const, :Symbol).line(2),
5074
5094
  :"*lhs",
5075
- s(:array_pat, s(:lvar, :x).line(2)).line(2),
5095
+ s(:lasgn, :x).line(2),
5076
5096
  :"*rhs").line(2))
5077
5097
  end
5078
5098
 
@@ -5080,7 +5100,7 @@ module TestPatternMatching30
5080
5100
  assert_case_in("Symbol[*lhs, x, *rhs]",
5081
5101
  s(:find_pat, s(:const, :Symbol).line(2),
5082
5102
  :"*lhs",
5083
- s(:array_pat, s(:lvar, :x).line(2)).line(2),
5103
+ s(:lasgn, :x).line(2),
5084
5104
  :"*rhs").line(2))
5085
5105
  end
5086
5106
  end
@@ -5196,7 +5216,7 @@ module TestRubyParserShared30Plus
5196
5216
  rb = "42 => n"
5197
5217
  pt = s(:case,
5198
5218
  s(:lit, 42),
5199
- s(:in, s(:lvar, :n), nil), nil)
5219
+ s(:in, s(:lasgn, :n), nil), nil)
5200
5220
 
5201
5221
  assert_parse rb, pt
5202
5222
  end
@@ -5208,7 +5228,7 @@ module TestRubyParserShared30Plus
5208
5228
  s(:in,
5209
5229
  s(:find_pat, nil,
5210
5230
  :"*a",
5211
- s(:array_pat, s(:lit, :+).line(2)).line(2),
5231
+ s(:lit, :+).line(2),
5212
5232
  :"*b").line(2),
5213
5233
  nil).line(2),
5214
5234
  nil)
@@ -5223,7 +5243,7 @@ module TestRubyParserShared30Plus
5223
5243
  s(:in,
5224
5244
  s(:find_pat, nil,
5225
5245
  :*,
5226
- s(:array_pat, s(:lit, :b).line(2), s(:lvar, :c).line(2)).line(2),
5246
+ s(:lit, :b).line(2), s(:lasgn, :c).line(2),
5227
5247
  :*).line(2),
5228
5248
  nil).line(2),
5229
5249
  nil)
@@ -5272,6 +5292,15 @@ module TestRubyParserShared30Plus
5272
5292
  assert_parse rb, pt.deep_each { |s| s.line = 1 }
5273
5293
  end
5274
5294
 
5295
+ def test_defn_oneliner_comment
5296
+ p = RubyParser.new
5297
+ rb = "# blah\ndef exec(cmd) = system(cmd)"
5298
+ sexp = p.parse rb
5299
+
5300
+ assert_equal :defn, sexp.sexp_type
5301
+ assert_equal "# blah\n", sexp.comments
5302
+ end
5303
+
5275
5304
  def test_defs_oneliner
5276
5305
  rb = "def self.exec(cmd) = system(cmd)"
5277
5306
  pt = s(:defs, s(:self), :exec, s(:args, :cmd),
@@ -5295,17 +5324,54 @@ module TestRubyParserShared30Plus
5295
5324
  assert_parse rb, pt.deep_each { |s| s.line = 1 }
5296
5325
  end
5297
5326
 
5327
+ def test_defs_oneliner_comment
5328
+ p = RubyParser.new
5329
+ rb = "# blah\ndef self.exec(cmd) = system(cmd)"
5330
+ sexp = p.parse rb
5331
+
5332
+ assert_equal :defs, sexp.sexp_type
5333
+ assert_equal "# blah\n", sexp.comments
5334
+ end
5335
+
5298
5336
  def test_defn_oneliner_setter
5299
5337
  rb = "class X\n def x=(o) = 42\nend"
5300
5338
 
5301
5339
  assert_syntax_error rb, /setter method cannot be defined/
5340
+
5341
+ rb = "class X\n def []=(k, v) = 42\nend"
5342
+
5343
+ assert_syntax_error rb, /setter method cannot be defined/
5302
5344
  end
5303
5345
 
5304
5346
  def test_defs_oneliner_setter
5305
- rb = "class X\n def self.x= = 42\nend"
5347
+ rb = "class X\n def self.x=(o) = 42\nend"
5348
+
5349
+ assert_syntax_error rb, /setter method cannot be defined/
5350
+
5351
+ rb = "class X\n def self.[]=(k, v) = 42\nend"
5306
5352
 
5307
5353
  assert_syntax_error rb, /setter method cannot be defined/
5308
5354
  end
5355
+
5356
+ def test_defn_oneliner_eq2
5357
+ rb = "class X\n def ==(o) = 42\nend"
5358
+ pt = s(:class, :X, nil,
5359
+ s(:defn, :==, s(:args, :o).line(2),
5360
+ s(:lit, 42).line(2)).line(2)
5361
+ ).line(1)
5362
+
5363
+ assert_parse rb, pt
5364
+ end
5365
+
5366
+ def test_defs_oneliner_eq2
5367
+ rb = "class X\n def self.==(o) = 42\nend"
5368
+ pt = s(:class, :X, nil,
5369
+ s(:defs, s(:self).line(2), :==, s(:args, :o).line(2),
5370
+ s(:lit, 42).line(2)).line(2)
5371
+ ).line(1)
5372
+
5373
+ assert_parse rb, pt
5374
+ end
5309
5375
  end
5310
5376
 
5311
5377
  module TestRubyParserShared31Plus
@@ -5478,6 +5544,8 @@ class RubyParserTestCase < ParseTreeTestCase
5478
5544
 
5479
5545
  attr_accessor :assert_parse_ran
5480
5546
 
5547
+ require "ruby2ruby" if ENV["R2R"]
5548
+
5481
5549
  def assert_parse rb, pt
5482
5550
  self.processor.reset if assert_parse_ran # allows multiple calls
5483
5551
  self.assert_parse_ran = true
@@ -5488,6 +5556,10 @@ class RubyParserTestCase < ParseTreeTestCase
5488
5556
  pt.line ||= 1
5489
5557
 
5490
5558
  self.result = processor.parse rb, "(string)", timeout
5559
+
5560
+ # just try it for now:
5561
+ Ruby2Ruby.new.process(result.deep_clone) if ENV["R2R"]
5562
+
5491
5563
  assert_equal pt, result
5492
5564
  end
5493
5565
 
data.tar.gz.sig CHANGED
@@ -1,6 +1 @@
1
- #���ө
2
- D+� Ps4��@VHXhoSv�|Ý[�=�����U�w�F�@Ju��%�GS=��@p�;
3
- ��*A05Yx�&�q� �.�QQ:a>�0mZ���� �w�j�b���sA���*b�d��?3��4��x�Qw!���
4
- e�
5
- ��z*����� ��Pp��/���F~J{W:4
6
- �U�/ѯ5�,u �#ɓ���-
1
+ ��4i�L[�.�M���4�D=�EuƜK��� �OegE�WKʱ�Dwc}����lٷ�3P�WV�g�L�_���7v�]{�ؚH>n|���2Y��ZxM@oGz'Yq!���+����oۢ���U�mY����WAQ��^��1�gJ�t�Z[wp�>o�v2�q�h[��"��y/}l���j�߉� ]o�Qi/�[RԄ���b٢T��m^x{���9p�H�JjK.�eKz�B�ɹ�C6U8[$�L��9YV^��
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_parser
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.19.0
4
+ version: 3.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
30
  YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2022-03-30 00:00:00.000000000 Z
32
+ date: 2022-12-03 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -119,14 +119,14 @@ dependencies:
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '3.23'
122
+ version: '3.25'
123
123
  type: :development
124
124
  prerelease: false
125
125
  version_requirements: !ruby/object:Gem::Requirement
126
126
  requirements:
127
127
  - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: '3.23'
129
+ version: '3.25'
130
130
  description: |-
131
131
  ruby_parser (RP) is a ruby parser written in pure ruby (utilizing
132
132
  racc--which does by default use a C extension). It outputs
@@ -243,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
243
243
  - !ruby/object:Gem::Version
244
244
  version: '0'
245
245
  requirements: []
246
- rubygems_version: 3.3.3
246
+ rubygems_version: 3.3.12
247
247
  signing_key:
248
248
  specification_version: 4
249
249
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which
metadata.gz.sig CHANGED
Binary file