ruby_parser 3.18.1 → 3.19.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/ruby_parser.yy CHANGED
@@ -767,8 +767,7 @@ rule
767
767
 
768
768
  cpath: tCOLON3 cname
769
769
  {
770
- _, (name, line) = val
771
- result = s(:colon3, name.to_sym).line line
770
+ result = wrap :colon3, val[1]
772
771
  }
773
772
  | cname
774
773
  {
@@ -793,9 +792,7 @@ rule
793
792
 
794
793
  fitem: fname
795
794
  {
796
- (id, line), = val
797
-
798
- result = s(:lit, id.to_sym).line line
795
+ result = wrap :lit, val[0]
799
796
  }
800
797
  | symbol
801
798
 
@@ -864,9 +861,9 @@ rule
864
861
  }
865
862
  | tCOLON3 tCONSTANT tOP_ASGN arg_rhs
866
863
  {
867
- _, (lhs, line), op, rhs = val
864
+ _, lhs, op, rhs = val
868
865
 
869
- lhs = s(:colon3, lhs.to_sym).line line
866
+ lhs = wrap :colon3, lhs
870
867
  result = new_const_op_asgn [lhs, op, rhs]
871
868
  }
872
869
  | backref tOP_ASGN arg_rhs
@@ -1336,9 +1333,7 @@ rule
1336
1333
  }
1337
1334
  | tCOLON3 tCONSTANT
1338
1335
  {
1339
- _, (id, line) = val
1340
-
1341
- result = s(:colon3, id.to_sym).line line
1336
+ result = wrap :colon3, val[1]
1342
1337
  }
1343
1338
  | tLBRACK { result = lexer.lineno } aref_args tRBRACK
1344
1339
  {
@@ -1846,8 +1841,7 @@ opt_block_args_tail: tCOMMA block_args_tail
1846
1841
 
1847
1842
  bvar: tIDENTIFIER
1848
1843
  {
1849
- (id, line), = val
1850
- result = s(:shadow, id.to_sym).line line
1844
+ result = wrap :shadow, val[0]
1851
1845
  }
1852
1846
  | f_bad_arg
1853
1847
 
@@ -2458,9 +2452,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2458
2452
 
2459
2453
  p_kw_label: tLABEL
2460
2454
  {
2461
- (id, line), = val
2462
-
2463
- result = s(:lit, id.to_sym).line line
2455
+ result = wrap :lit, val[0]
2464
2456
  }
2465
2457
 
2466
2458
  p_kwrest: kwrest_mark tIDENTIFIER
@@ -2552,26 +2544,20 @@ opt_block_args_tail: tCOMMA block_args_tail
2552
2544
 
2553
2545
  p_variable: tIDENTIFIER
2554
2546
  {
2555
- (id, line), = val
2556
-
2557
2547
  # TODO: error_duplicate_pattern_variable(p, $1, &@1);
2558
2548
  # TODO: assignable(p, $1, 0, &@$);
2559
- result = s(:lvar, id.to_sym).line line
2549
+ result = wrap :lvar, val[0]
2560
2550
  }
2561
2551
 
2562
2552
  p_var_ref: tCARET tIDENTIFIER
2563
2553
  {
2564
- _, (id, line) = val
2565
-
2566
2554
  # TODO: check id against env for lvar or dvar
2567
-
2568
- result = s(:lvar, id.to_sym).line line
2555
+ result = wrap :lvar, val[1]
2569
2556
  }
2570
2557
 
2571
2558
  p_const: tCOLON3 cname
2572
2559
  {
2573
- _, (id, line) = val
2574
- result = s(:colon3, id.to_sym).line line
2560
+ result = wrap :colon3, val[1]
2575
2561
  }
2576
2562
  | p_const tCOLON2 cname
2577
2563
  {
@@ -2583,8 +2569,7 @@ opt_block_args_tail: tCOMMA block_args_tail
2583
2569
  | tCONSTANT
2584
2570
  {
2585
2571
  # TODO $$ = gettable(p, $1, &@$);
2586
- (id, line), = val
2587
- result = s(:const, id.to_sym).line line
2572
+ result = wrap :const, val[0]
2588
2573
  }
2589
2574
  ######################################################################
2590
2575
  #endif
@@ -2871,18 +2856,15 @@ regexp_contents: none
2871
2856
 
2872
2857
  string_dvar: tGVAR
2873
2858
  {
2874
- (id, line), = val
2875
- result = s(:gvar, id.to_sym).line line
2859
+ result = wrap :gvar, val[0]
2876
2860
  }
2877
2861
  | tIVAR
2878
2862
  {
2879
- (id, line), = val
2880
- result = s(:ivar, id.to_sym).line line
2863
+ result = wrap :ivar, val[0]
2881
2864
  }
2882
2865
  | tCVAR
2883
2866
  {
2884
- (id, line), = val
2885
- result = s(:cvar, id.to_sym).line line
2867
+ result = wrap :cvar, val[0]
2886
2868
  }
2887
2869
  | backref
2888
2870
 
@@ -2891,17 +2873,13 @@ regexp_contents: none
2891
2873
 
2892
2874
  ssym: tSYMBEG sym
2893
2875
  {
2894
- _, (id, line) = val
2895
-
2896
2876
  lexer.lex_state = EXPR_END
2897
- result = s(:lit, id.to_sym).line line
2877
+ result = wrap :lit, val[1]
2898
2878
  }
2899
2879
  | tSYMBOL
2900
2880
  {
2901
- (id, line), = val
2902
-
2903
2881
  lexer.lex_state = EXPR_END
2904
- result = s(:lit, id.to_sym).line line
2882
+ result = wrap :lit, val[0]
2905
2883
  }
2906
2884
 
2907
2885
  sym: fname | tIVAR | tGVAR | tCVAR
@@ -3422,10 +3400,10 @@ keyword_variable: kNIL { result = s(:nil).line lexer.lineno }
3422
3400
  }
3423
3401
  | tLABEL arg_value
3424
3402
  {
3425
- (label, line), arg = val
3403
+ label, arg = val
3426
3404
 
3427
- lit = s(:lit, label.to_sym).line line
3428
- result = s(:array, lit, arg).line line
3405
+ lit = wrap :lit, label
3406
+ result = s(:array, lit, arg).line lit.line
3429
3407
  }
3430
3408
  #if V >= 22
3431
3409
  | tSTRING_BEG string_contents tLABEL_END arg_value
@@ -30,7 +30,7 @@ class Sexp
30
30
  end
31
31
 
32
32
  module RubyParserStuff
33
- VERSION = "3.18.1"
33
+ VERSION = "3.19.0"
34
34
 
35
35
  attr_accessor :lexer, :in_def, :in_single, :file
36
36
  attr_accessor :in_kwarg
@@ -978,6 +978,45 @@ module RubyParserStuff
978
978
  [result, in_def]
979
979
  end
980
980
 
981
+ def new_endless_defn val
982
+ (name, line, in_def), args, _, body, _, resbody = val
983
+
984
+ result =
985
+ if resbody then
986
+ s(:defn, name, args,
987
+ new_rescue(body,
988
+ new_resbody(s(:array).line(line),
989
+ resbody))).line line
990
+ else
991
+ s(:defn, name, args, body).line line
992
+ end
993
+
994
+ local_pop in_def
995
+ endless_method_name result
996
+
997
+ result
998
+ end
999
+
1000
+ def new_endless_defs val
1001
+ (recv, (name, line, in_def)), args, _, body, _, resbody = val
1002
+
1003
+ result =
1004
+ if resbody then
1005
+ s(:defs, recv, name, args,
1006
+ new_rescue(body,
1007
+ new_resbody(s(:array).line(line),
1008
+ resbody))).line line
1009
+ else
1010
+ s(:defs, recv, name, args, body).line(line)
1011
+ end
1012
+
1013
+ self.in_single -= 1
1014
+ local_pop in_def
1015
+ endless_method_name result
1016
+
1017
+ result
1018
+ end
1019
+
981
1020
  def new_defs val
982
1021
  _, recv, (name, line), in_def, args, body, _ = val
983
1022
 
@@ -1613,6 +1652,12 @@ module RubyParserStuff
1613
1652
 
1614
1653
  alias remove_whitespace_width whitespace_width
1615
1654
 
1655
+ def wrap type, node
1656
+ value, line = node
1657
+ value = value.to_sym if value.respond_to? :to_sym
1658
+ s(type, value).line line
1659
+ end
1660
+
1616
1661
  class Keyword
1617
1662
  include RubyLexer::State::Values
1618
1663
 
@@ -3541,6 +3541,8 @@ module TestRubyParserShared20Plus
3541
3541
  end
3542
3542
 
3543
3543
  def test_regexp_esc_C_slash
3544
+ skip "https://bugs.ruby-lang.org/issues/18449" if RUBY_VERSION == "3.1.0"
3545
+
3544
3546
  rb = "/\\cC\\d/"
3545
3547
  pt = s(:lit, /\cC\d/)
3546
3548
 
@@ -5306,6 +5308,110 @@ module TestRubyParserShared30Plus
5306
5308
  end
5307
5309
  end
5308
5310
 
5311
+ module TestRubyParserShared31Plus
5312
+ include TestRubyParserShared30Plus
5313
+
5314
+ def test_assoc__bare
5315
+ rb = "{ y: }"
5316
+ pt = s(:hash, s(:lit, :y), nil)
5317
+
5318
+ assert_parse rb, pt
5319
+ end
5320
+
5321
+ def test_block_arg__bare
5322
+ rb = "def x(&); end"
5323
+ pt = s(:defn, :x, s(:args, :&).line(1),
5324
+ s(:nil).line(1)).line(1)
5325
+
5326
+ assert_parse rb, pt
5327
+ end
5328
+
5329
+ def test_case_in_carat_parens
5330
+ processor.env[:a] = :lvar
5331
+
5332
+ rb = "[^(a)]"
5333
+ pt = s(:array_pat, nil,
5334
+ s(:lvar, :a).line(2)).line(2)
5335
+
5336
+ assert_case_in rb, pt
5337
+ end
5338
+
5339
+ def test_case_in_carat_nonlocal_vars
5340
+ processor.env[:a] = :lvar
5341
+
5342
+ rb = "[^@a, ^$b, ^@@c]"
5343
+ pt = s(:array_pat,
5344
+ nil,
5345
+ s(:ivar, :@a).line(2),
5346
+ s(:gvar, :$b).line(2),
5347
+ s(:cvar, :@@c).line(2)).line(2)
5348
+
5349
+ assert_case_in rb, pt
5350
+ end
5351
+
5352
+ def test_case_in_quoted_label
5353
+ rb = " \"b\": "
5354
+ pt = s(:hash_pat, nil, s(:lit, :b).line(2), nil).line(2)
5355
+
5356
+ assert_case_in rb, pt
5357
+ end
5358
+
5359
+ def test_call_block_arg_named
5360
+ processor.env[:blk] = :lvar
5361
+ rb = "x(&blk)"
5362
+ pt = s(:call, nil, :x,
5363
+ s(:block_pass, s(:lvar, :blk).line(1)).line(1)).line(1)
5364
+
5365
+ assert_parse rb, pt
5366
+ end
5367
+
5368
+ def test_call_block_arg_unnamed
5369
+ rb = "x(&)"
5370
+ pt = s(:call, nil, :x,
5371
+ s(:block_pass).line(1)).line(1)
5372
+
5373
+ assert_parse rb, pt
5374
+ end
5375
+
5376
+ def test_defn_endless_command
5377
+ rb = "def some_method = other_method 42"
5378
+ pt = s(:defn, :some_method, s(:args).line(1),
5379
+ s(:call, nil, :other_method, s(:lit, 42).line(1)).line(1)).line(1)
5380
+
5381
+ assert_parse rb, pt
5382
+ end
5383
+
5384
+ def test_defn_endless_command_rescue
5385
+ rb = "def some_method = other_method 42 rescue 24"
5386
+ pt = s(:defn, :some_method, s(:args).line(1),
5387
+ s(:rescue,
5388
+ s(:call, nil, :other_method, s(:lit, 42).line(1)).line(1),
5389
+ s(:resbody, s(:array).line(1),
5390
+ s(:lit, 24).line(1)).line(1)).line(1)).line(1)
5391
+
5392
+ assert_parse rb, pt
5393
+ end
5394
+
5395
+ def test_defs_endless_command
5396
+ rb = "def x.some_method = other_method 42"
5397
+ pt = s(:defs, s(:call, nil, :x).line(1), :some_method, s(:args).line(1),
5398
+ s(:call, nil, :other_method, s(:lit, 42).line(1)).line(1)).line(1)
5399
+
5400
+ assert_parse rb, pt
5401
+ end
5402
+
5403
+ def test_defs_endless_command_rescue
5404
+ rb = "def x.some_method = other_method 42 rescue 24"
5405
+ pt = s(:defs, s(:call, nil, :x).line(1), :some_method, s(:args).line(1),
5406
+ s(:rescue,
5407
+ s(:call, nil, :other_method, s(:lit, 42).line(1)).line(1),
5408
+ s(:resbody, s(:array).line(1),
5409
+ s(:lit, 24).line(1)).line(1)).line(1)).line(1)
5410
+
5411
+ assert_parse rb, pt
5412
+ end
5413
+ end
5414
+
5309
5415
  class Minitest::Test
5310
5416
  def skip s = "blah"
5311
5417
  warn "ignoring skip for %s: %s" % [name, s]
@@ -5641,6 +5747,16 @@ class TestRubyParserV30 < RubyParserTestCase
5641
5747
  end
5642
5748
  end
5643
5749
 
5750
+ class TestRubyParserV31 < RubyParserTestCase
5751
+ include TestRubyParserShared31Plus
5752
+
5753
+ def setup
5754
+ super
5755
+
5756
+ self.processor = RubyParser::V31.new
5757
+ end
5758
+ end
5759
+
5644
5760
  RubyParser::VERSIONS.each do |klass|
5645
5761
  v = klass.version
5646
5762
  describe "block args arity #{v}" do
data.tar.gz.sig CHANGED
Binary file
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.18.1
4
+ version: 3.19.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIDPjCCAiagAwIBAgIBBTANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
13
+ MIIDPjCCAiagAwIBAgIBBjANBgkqhkiG9w0BAQsFADBFMRMwEQYDVQQDDApyeWFu
14
14
  ZC1ydWJ5MRkwFwYKCZImiZPyLGQ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ho5OX6YMqg4KdxehfSLqqTZGoeV78qwf/jpPQZKTf+W9gUSJh
27
+ zsWpo4K50MP+QtdSbKXZwjAafpQ8hK0MnnZ/aeCsW9ov5vdXpYbf3dpg6ADXRGE7
28
+ lQY2y1tJ5/chqu6h7dQmnm2ABUqx9O+JcN9hbCYoA5i/EeubUEtFIh2w3SpO6YfB
29
+ JFmxn4h9YO/pVdB962BdBNNDia0kgIjI3ENnkLq0dKpYU3+F3KhEuTksLO0L6X/V
30
+ YsuyUzsMz6GQA4khyaMgKNSD
31
31
  -----END CERTIFICATE-----
32
- date: 2021-11-10 00:00:00.000000000 Z
32
+ date: 2022-03-30 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.22'
122
+ version: '3.23'
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.22'
129
+ version: '3.23'
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
@@ -155,6 +155,9 @@ description: |-
155
155
  * 1.9 parser is at 99.9940% accuracy, 4.013 sigma
156
156
  * 2.0 parser is at 99.9939% accuracy, 4.008 sigma
157
157
  * 2.6 parser is at 99.9972% accuracy, 4.191 sigma
158
+ * 3.0 parser has a 100% parse rate.
159
+ * Tested against 2,672,412 unique ruby files across 167k gems.
160
+ * As do all the others now, basically.
158
161
  email:
159
162
  - ryand-ruby@zenspider.com
160
163
  executables:
@@ -199,6 +202,8 @@ files:
199
202
  - lib/ruby27_parser.y
200
203
  - lib/ruby30_parser.rb
201
204
  - lib/ruby30_parser.y
205
+ - lib/ruby31_parser.rb
206
+ - lib/ruby31_parser.y
202
207
  - lib/ruby3_parser.yy
203
208
  - lib/ruby_lexer.rb
204
209
  - lib/ruby_lexer.rex
@@ -238,7 +243,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
238
243
  - !ruby/object:Gem::Version
239
244
  version: '0'
240
245
  requirements: []
241
- rubygems_version: 3.2.16
246
+ rubygems_version: 3.3.3
242
247
  signing_key:
243
248
  specification_version: 4
244
249
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which
metadata.gz.sig CHANGED
Binary file