ruby_parser 3.9.0 → 3.10.0

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
  SHA1:
3
- metadata.gz: db3aec0f342263aec6c4bc598f2af937d889219b
4
- data.tar.gz: 0a7300cfcb5109443168aa3432eefb0b103a07a1
3
+ metadata.gz: 2f40dfeee0e474212f0bfb56c32bfa6ac2c15345
4
+ data.tar.gz: 3b138c15fc4ccea9cdaeb78a29d735b4ce044075
5
5
  SHA512:
6
- metadata.gz: c26c726384052dc9ea43d9cb29f982ed03768458c1ff0e64a515026c721be346f009ead616d18c499d449fbf9a6c23234a4c637afb14cf28fb74035a33a743db
7
- data.tar.gz: 4f3d570afe84856c5275be5a9eaf9277168a89db5bd3dea605cc86cf8c38492d9ee0b5ec2d32c3413124c068ff57e24a5241d8474463e15018376328fff024ec
6
+ metadata.gz: eab6b5f51918c84302a104d5f9f6957c4848478a2a52c63a013e50dde8e447d88f384721c699a5fdb2e104fa260c3cfc8ab4af135fccc0a320a09ebc2e876917
7
+ data.tar.gz: 9dd361bb654390734c54292fe533291c583a202ffde25b417e133abc03cc96b143a0df5669aa4158c4b0938a3aa782d727452778648681eb6b3a2e2495b8358a
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/History.rdoc CHANGED
@@ -1,3 +1,20 @@
1
+ === 3.10.0 / 2017-07-17
2
+
3
+ * 4 minor enhancements:
4
+
5
+ * Added support for 'squiggly heredocs' (indented content). (jjoos)
6
+ * Bumped oedipus_lex to ~> 2.5.
7
+ * Bumped sexp_processor to ~> 4.9.
8
+ * Made STRICT_SEXP=1 safe: converted indexed sexps to semantic calls where needed.
9
+
10
+ * 5 bug fixes:
11
+
12
+ * Clear and restore cmdarg stack around defs args and body. (presidentbeef)
13
+ * Conditionalize use of sexp_body= to make it compatible w/ sexp_processor 4.9.0
14
+ * Fix up line numbers in strings with newlines and `#`. (presidentbeef)
15
+ * Fixed line numbers of resbodies.
16
+ * Fixed some tracking of lexical state. Fixes bug #249.
17
+
1
18
  === 3.9.0 / 2017-04-13
2
19
 
3
20
  * 1 major enhancement:
data/Rakefile CHANGED
@@ -23,9 +23,9 @@ Hoe.spec "ruby_parser" do
23
23
 
24
24
  license "MIT"
25
25
 
26
- dependency "sexp_processor", "~> 4.1"
26
+ dependency "sexp_processor", "~> 4.9"
27
27
  dependency "rake", "< 11", :developer
28
- dependency "oedipus_lex", "~> 2.1", :developer
28
+ dependency "oedipus_lex", "~> 2.5", :developer
29
29
 
30
30
  if plugin? :perforce then # generated files
31
31
  V1_2.each do |n|
data/lib/rp_extensions.rb CHANGED
@@ -38,6 +38,10 @@ class String
38
38
  # reduces tIDENTIFIER.
39
39
 
40
40
  attr_accessor :lineno
41
+
42
+ def clean_caller
43
+ self.sub(File.dirname(__FILE__), ".").sub(/:in.*/, "")
44
+ end if $DEBUG
41
45
  end
42
46
 
43
47
  require "sexp"
@@ -66,7 +70,7 @@ class Sexp
66
70
  end
67
71
 
68
72
  def block_pass?
69
- any? { |s| Sexp === s && s[0] == :block_pass }
73
+ any? { |s| Sexp === s && s.sexp_type == :block_pass }
70
74
  end
71
75
 
72
76
  alias :node_type :sexp_type
data/lib/ruby18_parser.rb CHANGED
@@ -3825,7 +3825,7 @@ end
3825
3825
 
3826
3826
  def _reduce_177(val, _values, result)
3827
3827
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
3828
- val[2][0] = :arglist if val[2]
3828
+ val[2].sexp_type = :arglist if val[2]
3829
3829
 
3830
3830
  result
3831
3831
  end
@@ -3937,7 +3937,7 @@ def _reduce_193(val, _values, result)
3937
3937
  end
3938
3938
 
3939
3939
  def _reduce_194(val, _values, result)
3940
- if val[1][0] == :lit then
3940
+ if val[1].sexp_type == :lit then
3941
3941
  result = val[1]
3942
3942
  else
3943
3943
  result = new_call val[1], :"+@"
@@ -4723,13 +4723,18 @@ def _reduce_322(val, _values, result)
4723
4723
  self.in_single += 1
4724
4724
  self.env.extend
4725
4725
  lexer.lex_state = :expr_end # force for args
4726
+ result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
4727
+ lexer.cmdarg.stack.replace [false]
4726
4728
 
4727
4729
  result
4728
4730
  end
4729
4731
 
4730
4732
  def _reduce_323(val, _values, result)
4733
+ line, cmdarg = val[5]
4731
4734
  result = new_defs val
4735
+ result[3].line line
4732
4736
 
4737
+ lexer.cmdarg.stack.replace cmdarg
4733
4738
  self.env.unextend
4734
4739
  self.in_single -= 1
4735
4740
  self.lexer.comments # we don't care about comments in the body
@@ -5082,10 +5087,11 @@ end
5082
5087
  # reduce 385 omitted
5083
5088
 
5084
5089
  def _reduce_386(val, _values, result)
5085
- klasses, var, body, rest = val[1], val[2], val[4], val[5]
5090
+ (_, line), klasses, var, _, body, rest = val
5086
5091
 
5087
5092
  klasses ||= s(:array)
5088
5093
  klasses << new_assign(var, s(:gvar, :"$!")) if var
5094
+ klasses.line line
5089
5095
 
5090
5096
  result = new_resbody(klasses, body)
5091
5097
  result << rest if rest # UGH, rewritten above
@@ -5142,7 +5148,7 @@ end
5142
5148
  # reduce 397 omitted
5143
5149
 
5144
5150
  def _reduce_398(val, _values, result)
5145
- val[0] = s(:dstr, val[0].value) if val[0][0] == :evstr
5151
+ val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
5146
5152
  result = val[0]
5147
5153
 
5148
5154
  result
@@ -5312,7 +5318,7 @@ def _reduce_423(val, _values, result)
5312
5318
 
5313
5319
  case stmt
5314
5320
  when Sexp then
5315
- case stmt[0]
5321
+ case stmt.sexp_type
5316
5322
  when :str, :dstr, :evstr then
5317
5323
  result = stmt
5318
5324
  else
@@ -5372,9 +5378,9 @@ def _reduce_434(val, _values, result)
5372
5378
  yyerror "empty symbol literal" if
5373
5379
  result.nil? or result.empty?
5374
5380
 
5375
- case result[0]
5381
+ case result.sexp_type
5376
5382
  when :dstr then
5377
- result[0] = :dsym
5383
+ result.sexp_type = :dsym
5378
5384
  when :str then
5379
5385
  result = s(:lit, result.last.to_sym)
5380
5386
  else
@@ -5679,7 +5685,7 @@ end
5679
5685
  def _reduce_490(val, _values, result)
5680
5686
  result = val[2]
5681
5687
  yyerror "Can't define single method for literals." if
5682
- result[0] == :lit
5688
+ result.sexp_type == :lit
5683
5689
 
5684
5690
  result
5685
5691
  end
@@ -5710,7 +5716,7 @@ end
5710
5716
 
5711
5717
  def _reduce_495(val, _values, result)
5712
5718
  list = val[0].dup
5713
- more = val[2][1..-1]
5719
+ more = val[2].sexp_body
5714
5720
  list.push(*more) unless more.empty?
5715
5721
  result = list
5716
5722
 
data/lib/ruby18_parser.y CHANGED
@@ -521,7 +521,7 @@ rule
521
521
  | primary_value tLBRACK2 aref_args tRBRACK tOP_ASGN arg
522
522
  {
523
523
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
524
- val[2][0] = :arglist if val[2]
524
+ val[2].sexp_type = :arglist if val[2]
525
525
  }
526
526
  | primary_value tDOT tIDENTIFIER tOP_ASGN arg
527
527
  {
@@ -599,7 +599,7 @@ rule
599
599
  }
600
600
  | tUPLUS arg
601
601
  {
602
- if val[1][0] == :lit then
602
+ if val[1].sexp_type == :lit then
603
603
  result = val[1]
604
604
  else
605
605
  result = new_call val[1], :"+@"
@@ -1158,11 +1158,16 @@ rule
1158
1158
  self.in_single += 1
1159
1159
  self.env.extend
1160
1160
  lexer.lex_state = :expr_end # force for args
1161
+ result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
1162
+ lexer.cmdarg.stack.replace [false]
1161
1163
  }
1162
1164
  f_arglist bodystmt kEND
1163
1165
  {
1166
+ line, cmdarg = val[5]
1164
1167
  result = new_defs val
1168
+ result[3].line line
1165
1169
 
1170
+ lexer.cmdarg.stack.replace cmdarg
1166
1171
  self.env.unextend
1167
1172
  self.in_single -= 1
1168
1173
  self.lexer.comments # we don't care about comments in the body
@@ -1417,10 +1422,11 @@ rule
1417
1422
 
1418
1423
  opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1419
1424
  {
1420
- klasses, var, body, rest = val[1], val[2], val[4], val[5]
1425
+ (_, line), klasses, var, _, body, rest = val
1421
1426
 
1422
1427
  klasses ||= s(:array)
1423
1428
  klasses << new_assign(var, s(:gvar, :"$!")) if var
1429
+ klasses.line line
1424
1430
 
1425
1431
  result = new_resbody(klasses, body)
1426
1432
  result << rest if rest # UGH, rewritten above
@@ -1459,7 +1465,7 @@ rule
1459
1465
 
1460
1466
  strings: string
1461
1467
  {
1462
- val[0] = s(:dstr, val[0].value) if val[0][0] == :evstr
1468
+ val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
1463
1469
  result = val[0]
1464
1470
  }
1465
1471
 
@@ -1593,7 +1599,7 @@ xstring_contents: none
1593
1599
 
1594
1600
  case stmt
1595
1601
  when Sexp then
1596
- case stmt[0]
1602
+ case stmt.sexp_type
1597
1603
  when :str, :dstr, :evstr then
1598
1604
  result = stmt
1599
1605
  else
@@ -1631,9 +1637,9 @@ xstring_contents: none
1631
1637
  yyerror "empty symbol literal" if
1632
1638
  result.nil? or result.empty?
1633
1639
 
1634
- case result[0]
1640
+ case result.sexp_type
1635
1641
  when :dstr then
1636
- result[0] = :dsym
1642
+ result.sexp_type = :dsym
1637
1643
  when :str then
1638
1644
  result = s(:lit, result.last.to_sym)
1639
1645
  else
@@ -1838,7 +1844,7 @@ xstring_contents: none
1838
1844
  {
1839
1845
  result = val[2]
1840
1846
  yyerror "Can't define single method for literals." if
1841
- result[0] == :lit
1847
+ result.sexp_type == :lit
1842
1848
  }
1843
1849
 
1844
1850
  assoc_list: none # [!nil]
@@ -1862,7 +1868,7 @@ xstring_contents: none
1862
1868
  | assocs tCOMMA assoc
1863
1869
  {
1864
1870
  list = val[0].dup
1865
- more = val[2][1..-1]
1871
+ more = val[2].sexp_body
1866
1872
  list.push(*more) unless more.empty?
1867
1873
  result = list
1868
1874
  }
data/lib/ruby19_parser.rb CHANGED
@@ -3580,7 +3580,7 @@ end
3580
3580
 
3581
3581
  def _reduce_77(val, _values, result)
3582
3582
  ary = list_append val[0], s(:splat, val[2])
3583
- ary.concat val[4][1..-1]
3583
+ ary.concat val[4].sexp_body
3584
3584
  result = s(:masgn, ary)
3585
3585
 
3586
3586
  result
@@ -3594,7 +3594,7 @@ end
3594
3594
 
3595
3595
  def _reduce_79(val, _values, result)
3596
3596
  ary = list_append val[0], s(:splat)
3597
- ary.concat val[3][1..-1]
3597
+ ary.concat val[3].sexp_body
3598
3598
  result = s(:masgn, ary)
3599
3599
 
3600
3600
  result
@@ -3608,7 +3608,7 @@ end
3608
3608
 
3609
3609
  def _reduce_81(val, _values, result)
3610
3610
  ary = s(:array, s(:splat, val[1]))
3611
- ary.concat val[3][1..-1]
3611
+ ary.concat val[3].sexp_body
3612
3612
  result = s(:masgn, ary)
3613
3613
 
3614
3614
  result
@@ -3622,7 +3622,7 @@ end
3622
3622
 
3623
3623
  def _reduce_83(val, _values, result)
3624
3624
  ary = s(:array, s(:splat))
3625
- ary.concat val[2][1..-1]
3625
+ ary.concat val[2].sexp_body
3626
3626
  result = s(:masgn, ary)
3627
3627
 
3628
3628
  result
@@ -4025,7 +4025,7 @@ def _reduce_198(val, _values, result)
4025
4025
  end
4026
4026
 
4027
4027
  def _reduce_199(val, _values, result)
4028
- val[2][0] = :arglist if val[2]
4028
+ val[2].sexp_type = :arglist if val[2]
4029
4029
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
4030
4030
 
4031
4031
  result
@@ -4337,7 +4337,7 @@ def _reduce_250(val, _values, result)
4337
4337
  end
4338
4338
 
4339
4339
  def _reduce_251(val, _values, result)
4340
- result = val[0] << s(:hash, *val[2][1..-1]) # TODO: self.args
4340
+ result = val[0] << s(:hash, *val[2].sexp_body) # TODO: self.args
4341
4341
 
4342
4342
  result
4343
4343
  end
@@ -4798,15 +4798,18 @@ def _reduce_326(val, _values, result)
4798
4798
  self.in_single += 1
4799
4799
  self.env.extend
4800
4800
  lexer.lex_state = :expr_end # force for args
4801
- result = lexer.lineno
4801
+ result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
4802
+ lexer.cmdarg.stack.replace [false]
4802
4803
 
4803
4804
  result
4804
4805
  end
4805
4806
 
4806
4807
  def _reduce_327(val, _values, result)
4808
+ line, cmdarg = val[5]
4807
4809
  result = new_defs val
4808
- result[3].line val[5]
4810
+ result[3].line line
4809
4811
 
4812
+ lexer.cmdarg.stack.replace cmdarg
4810
4813
  self.env.unextend
4811
4814
  self.in_single -= 1
4812
4815
  self.lexer.comments # we don't care about comments in the body
@@ -5357,10 +5360,11 @@ end
5357
5360
  # reduce 425 omitted
5358
5361
 
5359
5362
  def _reduce_426(val, _values, result)
5360
- _, klasses, var, _, body, rest = val
5363
+ (_, line), klasses, var, _, body, rest = val
5361
5364
 
5362
5365
  klasses ||= s(:array)
5363
5366
  klasses << new_assign(var, s(:gvar, :"$!")) if var
5367
+ klasses.line line
5364
5368
 
5365
5369
  result = new_resbody(klasses, body)
5366
5370
  result << rest if rest # UGH, rewritten above
@@ -5415,7 +5419,7 @@ end
5415
5419
  # reduce 437 omitted
5416
5420
 
5417
5421
  def _reduce_438(val, _values, result)
5418
- val[0] = s(:dstr, val[0].value) if val[0][0] == :evstr
5422
+ val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
5419
5423
  result = val[0]
5420
5424
 
5421
5425
  result
@@ -5597,7 +5601,7 @@ def _reduce_465(val, _values, result)
5597
5601
 
5598
5602
  case stmt
5599
5603
  when Sexp then
5600
- case stmt[0]
5604
+ case stmt.sexp_type
5601
5605
  when :str, :dstr, :evstr then
5602
5606
  result = stmt
5603
5607
  else
@@ -5656,9 +5660,9 @@ def _reduce_476(val, _values, result)
5656
5660
 
5657
5661
  result ||= s(:str, "")
5658
5662
 
5659
- case result[0]
5663
+ case result.sexp_type
5660
5664
  when :dstr then
5661
- result[0] = :dsym
5665
+ result.sexp_type = :dsym
5662
5666
  when :str then
5663
5667
  result = s(:lit, result.last.intern)
5664
5668
  else
@@ -6066,7 +6070,7 @@ end
6066
6070
  def _reduce_547(val, _values, result)
6067
6071
  result = val[2]
6068
6072
  yyerror "Can't define single method for literals." if
6069
- result[0] == :lit
6073
+ result.sexp_type == :lit
6070
6074
 
6071
6075
  result
6072
6076
  end
@@ -6087,7 +6091,7 @@ end
6087
6091
 
6088
6092
  def _reduce_551(val, _values, result)
6089
6093
  list = val[0].dup
6090
- more = val[2][1..-1]
6094
+ more = val[2].sexp_body
6091
6095
  list.push(*more) unless more.empty?
6092
6096
  result = list
6093
6097
 
data/lib/ruby19_parser.y CHANGED
@@ -357,7 +357,7 @@ rule
357
357
  | mlhs_head tSTAR mlhs_node tCOMMA mlhs_post
358
358
  {
359
359
  ary = list_append val[0], s(:splat, val[2])
360
- ary.concat val[4][1..-1]
360
+ ary.concat val[4].sexp_body
361
361
  result = s(:masgn, ary)
362
362
  }
363
363
  | mlhs_head tSTAR
@@ -367,7 +367,7 @@ rule
367
367
  | mlhs_head tSTAR tCOMMA mlhs_post
368
368
  {
369
369
  ary = list_append val[0], s(:splat)
370
- ary.concat val[3][1..-1]
370
+ ary.concat val[3].sexp_body
371
371
  result = s(:masgn, ary)
372
372
  }
373
373
  | tSTAR mlhs_node
@@ -377,7 +377,7 @@ rule
377
377
  | tSTAR mlhs_node tCOMMA mlhs_post
378
378
  {
379
379
  ary = s(:array, s(:splat, val[1]))
380
- ary.concat val[3][1..-1]
380
+ ary.concat val[3].sexp_body
381
381
  result = s(:masgn, ary)
382
382
  }
383
383
  | tSTAR
@@ -387,7 +387,7 @@ rule
387
387
  | tSTAR tCOMMA mlhs_post
388
388
  {
389
389
  ary = s(:array, s(:splat))
390
- ary.concat val[2][1..-1]
390
+ ary.concat val[2].sexp_body
391
391
  result = s(:masgn, ary)
392
392
  }
393
393
 
@@ -591,7 +591,7 @@ rule
591
591
  }
592
592
  | primary_value tLBRACK2 opt_call_args rbracket tOP_ASGN arg
593
593
  {
594
- val[2][0] = :arglist if val[2]
594
+ val[2].sexp_type = :arglist if val[2]
595
595
  result = s(:op_asgn1, val[0], val[2], val[4].to_sym, val[5])
596
596
  }
597
597
  | primary_value tDOT tIDENTIFIER tOP_ASGN arg
@@ -808,7 +808,7 @@ rule
808
808
  }
809
809
  | args tCOMMA assocs tCOMMA
810
810
  {
811
- result = val[0] << s(:hash, *val[2][1..-1]) # TODO: self.args
811
+ result = val[0] << s(:hash, *val[2].sexp_body) # TODO: self.args
812
812
  }
813
813
  | assocs tCOMMA
814
814
  {
@@ -1136,13 +1136,16 @@ rule
1136
1136
  self.in_single += 1
1137
1137
  self.env.extend
1138
1138
  lexer.lex_state = :expr_end # force for args
1139
- result = lexer.lineno
1139
+ result = [lexer.lineno, self.lexer.cmdarg.stack.dup]
1140
+ lexer.cmdarg.stack.replace [false]
1140
1141
  }
1141
1142
  f_arglist bodystmt kEND
1142
1143
  {
1144
+ line, cmdarg = val[5]
1143
1145
  result = new_defs val
1144
- result[3].line val[5]
1146
+ result[3].line line
1145
1147
 
1148
+ lexer.cmdarg.stack.replace cmdarg
1146
1149
  self.env.unextend
1147
1150
  self.in_single -= 1
1148
1151
  self.lexer.comments # we don't care about comments in the body
@@ -1543,10 +1546,11 @@ rule
1543
1546
 
1544
1547
  opt_rescue: kRESCUE exc_list exc_var then compstmt opt_rescue
1545
1548
  {
1546
- _, klasses, var, _, body, rest = val
1549
+ (_, line), klasses, var, _, body, rest = val
1547
1550
 
1548
1551
  klasses ||= s(:array)
1549
1552
  klasses << new_assign(var, s(:gvar, :"$!")) if var
1553
+ klasses.line line
1550
1554
 
1551
1555
  result = new_resbody(klasses, body)
1552
1556
  result << rest if rest # UGH, rewritten above
@@ -1583,7 +1587,7 @@ rule
1583
1587
 
1584
1588
  strings: string
1585
1589
  {
1586
- val[0] = s(:dstr, val[0].value) if val[0][0] == :evstr
1590
+ val[0] = s(:dstr, val[0].value) if val[0].sexp_type == :evstr
1587
1591
  result = val[0]
1588
1592
  }
1589
1593
 
@@ -1726,7 +1730,7 @@ regexp_contents: none
1726
1730
 
1727
1731
  case stmt
1728
1732
  when Sexp then
1729
- case stmt[0]
1733
+ case stmt.sexp_type
1730
1734
  when :str, :dstr, :evstr then
1731
1735
  result = stmt
1732
1736
  else
@@ -1763,9 +1767,9 @@ regexp_contents: none
1763
1767
 
1764
1768
  result ||= s(:str, "")
1765
1769
 
1766
- case result[0]
1770
+ case result.sexp_type
1767
1771
  when :dstr then
1768
- result[0] = :dsym
1772
+ result.sexp_type = :dsym
1769
1773
  when :str then
1770
1774
  result = s(:lit, result.last.intern)
1771
1775
  else
@@ -2050,7 +2054,7 @@ keyword_variable: kNIL { result = s(:nil) }
2050
2054
  {
2051
2055
  result = val[2]
2052
2056
  yyerror "Can't define single method for literals." if
2053
- result[0] == :lit
2057
+ result.sexp_type == :lit
2054
2058
  }
2055
2059
 
2056
2060
  assoc_list: none # [!nil]
@@ -2066,7 +2070,7 @@ keyword_variable: kNIL { result = s(:nil) }
2066
2070
  | assocs tCOMMA assoc
2067
2071
  {
2068
2072
  list = val[0].dup
2069
- more = val[2][1..-1]
2073
+ more = val[2].sexp_body
2070
2074
  list.push(*more) unless more.empty?
2071
2075
  result = list
2072
2076
  }