ruby_parser 3.15.1 → 3.16.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.
data/lib/ruby_lexer.rb CHANGED
@@ -25,6 +25,11 @@ class RubyLexer
25
25
 
26
26
  HAS_ENC = "".respond_to? :encoding
27
27
 
28
+ BTOKENS = {
29
+ ".." => :tBDOT2,
30
+ "..." => :tBDOT3,
31
+ }
32
+
28
33
  TOKENS = {
29
34
  "!" => :tBANG,
30
35
  "!=" => :tNEQ,
@@ -131,6 +136,10 @@ class RubyLexer
131
136
  ss.eos?
132
137
  end
133
138
 
139
+ def expr_beg?
140
+ lex_state =~ EXPR_BEG
141
+ end
142
+
134
143
  def expr_dot?
135
144
  lex_state =~ EXPR_DOT
136
145
  end
@@ -580,6 +589,12 @@ class RubyLexer
580
589
  end
581
590
  end
582
591
 
592
+ def process_dots text
593
+ tokens = ruby27plus? && expr_beg? ? BTOKENS : TOKENS
594
+
595
+ result EXPR_BEG, tokens[text], text
596
+ end
597
+
583
598
  def process_float text
584
599
  rb_compile_error "Invalid numeric format" if text =~ /__/
585
600
 
@@ -1136,6 +1151,10 @@ class RubyLexer
1136
1151
  parser.class.version <= 24
1137
1152
  end
1138
1153
 
1154
+ def ruby27plus?
1155
+ parser.class.version >= 27
1156
+ end
1157
+
1139
1158
  def scan re
1140
1159
  ss.scan re
1141
1160
  end
data/lib/ruby_lexer.rex CHANGED
@@ -48,7 +48,7 @@ rule
48
48
  | /\![=~]?/ { result :arg_state, TOKENS[text], text }
49
49
 
50
50
  : /\./
51
- | /\.\.\.?/ { result EXPR_BEG, TOKENS[text], text }
51
+ | /\.\.\.?/ process_dots
52
52
  | /\.\d/ { rb_compile_error "no .<digit> floating literal anymore put 0 before dot" }
53
53
  | /\./ { self.lex_state = EXPR_BEG; result EXPR_DOT, :tDOT, "." }
54
54
 
@@ -138,7 +138,7 @@ class RubyLexer
138
138
  when ss.match?(/\./) then
139
139
  case
140
140
  when text = ss.scan(/\.\.\.?/) then
141
- action { result EXPR_BEG, TOKENS[text], text }
141
+ process_dots text
142
142
  when ss.skip(/\.\d/) then
143
143
  action { rb_compile_error "no .<digit> floating literal anymore put 0 before dot" }
144
144
  when ss.skip(/\./) then
data/lib/ruby_parser.rb CHANGED
@@ -79,10 +79,12 @@ require "ruby24_parser"
79
79
  require "ruby25_parser"
80
80
  require "ruby26_parser"
81
81
  require "ruby27_parser"
82
+ require "ruby30_parser"
82
83
 
83
84
  class RubyParser # HACK
84
85
  VERSIONS.clear # also a HACK caused by racc namespace issues
85
86
 
87
+ class V30 < ::Ruby30Parser; end
86
88
  class V27 < ::Ruby27Parser; end
87
89
  class V26 < ::Ruby26Parser; end
88
90
  class V25 < ::Ruby25Parser; end
data/lib/ruby_parser.yy CHANGED
@@ -16,6 +16,8 @@ class Ruby25Parser
16
16
  class Ruby26Parser
17
17
  #elif V == 27
18
18
  class Ruby27Parser
19
+ #elif V == 30
20
+ class Ruby30Parser
19
21
  #else
20
22
  fail "version not specified or supported on code generation"
21
23
  #endif
@@ -46,6 +48,9 @@ token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
46
48
  #if V >= 23
47
49
  tLONELY
48
50
  #endif
51
+ #if V >= 26
52
+ tBDOT2 tBDOT3
53
+ #endif
49
54
 
50
55
  preclow
51
56
  nonassoc tLOWEST
@@ -57,7 +62,7 @@ preclow
57
62
  right tEQL tOP_ASGN
58
63
  left kRESCUE_MOD
59
64
  right tEH tCOLON
60
- nonassoc tDOT2 tDOT3
65
+ nonassoc tDOT2 tDOT3 tBDOT2 tBDOT3
61
66
  left tOROP
62
67
  left tANDOP
63
68
  nonassoc tCMP tEQ tEQQ tNEQ tMATCH tNMATCH
@@ -80,6 +85,9 @@ rule
80
85
  top_compstmt
81
86
  {
82
87
  result = new_compstmt val
88
+
89
+ lexer.cond.pop # local_pop
90
+ lexer.cmdarg.pop
83
91
  }
84
92
 
85
93
  top_compstmt: top_stmts opt_terms
@@ -856,6 +864,24 @@ rule
856
864
  result = s(:dot3, v1, v2).line v1.line
857
865
  }
858
866
  #endif
867
+
868
+ #if V >= 27
869
+ | tBDOT2 arg
870
+ {
871
+ _, v2, = val
872
+ v1 = nil
873
+
874
+ result = s(:dot2, v1, v2).line v2.line
875
+ }
876
+ | tBDOT3 arg
877
+ {
878
+ _, v2 = val
879
+ v1 = nil
880
+
881
+ result = s(:dot3, v1, v2).line v2.line
882
+ }
883
+ #endif
884
+
859
885
  | arg tPLUS arg
860
886
  {
861
887
  result = new_call val[0], :+, argl(val[2])
@@ -29,7 +29,7 @@ class Sexp
29
29
  end
30
30
 
31
31
  module RubyParserStuff
32
- VERSION = "3.15.1"
32
+ VERSION = "3.16.0"
33
33
 
34
34
  attr_accessor :lexer, :in_def, :in_single, :file
35
35
  attr_accessor :in_kwarg
@@ -115,7 +115,7 @@ module RubyParserStuff
115
115
  def initialize(options = {})
116
116
  super()
117
117
 
118
- v = self.class.name[/2\d/]
118
+ v = self.class.name[/[23]\d/]
119
119
  raise "Bad Class name #{self.class}" unless v
120
120
 
121
121
  self.lexer = RubyLexer.new v && v.to_i
@@ -478,6 +478,22 @@ class TestRubyLexer < Minitest::Test
478
478
  assert_lex3("!~", nil, :tNMATCH, "!~", EXPR_BEG)
479
479
  end
480
480
 
481
+ def test_yylex_bdot2
482
+ assert_lex3("..42",
483
+ nil, # TODO: s(:dot2, nil, s(:lit, 42)),
484
+
485
+ :tBDOT2, "..", EXPR_BEG,
486
+ :tINTEGER, 42, EXPR_END|EXPR_ENDARG)
487
+ end
488
+
489
+ def test_yylex_bdot3
490
+ assert_lex3("...42",
491
+ nil, # TODO: s(:dot2, nil, s(:lit, 42)),
492
+
493
+ :tBDOT3, "...", EXPR_BEG,
494
+ :tINTEGER, 42, EXPR_END|EXPR_ENDARG)
495
+ end
496
+
481
497
  def test_yylex_block_bug_1
482
498
  assert_lex3("a do end",
483
499
  s(:iter, s(:call, nil, :a), 0),
@@ -749,10 +765,26 @@ class TestRubyLexer < Minitest::Test
749
765
  end
750
766
 
751
767
  def test_yylex_dot2
768
+ assert_lex3("1..2",
769
+ s(:lit, 1..2),
770
+
771
+ :tINTEGER, 1, EXPR_END|EXPR_ENDARG,
772
+ :tDOT2, "..", EXPR_BEG,
773
+ :tINTEGER, 2, EXPR_END|EXPR_ENDARG)
774
+
775
+ self.lex_state = EXPR_END|EXPR_ENDARG
752
776
  assert_lex3("..", nil, :tDOT2, "..", EXPR_BEG)
753
777
  end
754
778
 
755
779
  def test_yylex_dot3
780
+ assert_lex3("1...2",
781
+ s(:lit, 1...2),
782
+
783
+ :tINTEGER, 1, EXPR_END|EXPR_ENDARG,
784
+ :tDOT3, "...", EXPR_BEG,
785
+ :tINTEGER, 2, EXPR_END|EXPR_ENDARG)
786
+
787
+ self.lex_state = EXPR_END|EXPR_ENDARG
756
788
  assert_lex3("...", nil, :tDOT3, "...", EXPR_BEG)
757
789
  end
758
790
 
@@ -3080,6 +3080,8 @@ module TestRubyParserShared19Plus
3080
3080
  end
3081
3081
 
3082
3082
  def test_motherfuckin_leading_dots
3083
+ skip if processor.class.version >= 27
3084
+
3083
3085
  rb = "a\n.b"
3084
3086
  pt = s(:call, s(:call, nil, :a), :b)
3085
3087
 
@@ -3087,6 +3089,8 @@ module TestRubyParserShared19Plus
3087
3089
  end
3088
3090
 
3089
3091
  def test_motherfuckin_leading_dots2
3092
+ skip if processor.class.version >= 27
3093
+
3090
3094
  rb = "a\n..b"
3091
3095
 
3092
3096
  assert_parse_error rb, '(string):2 :: parse error on value ".." (tDOT2)'
@@ -4136,6 +4140,10 @@ module TestRubyParserShared27Plus
4136
4140
  include TestRubyParserShared26Plus
4137
4141
  end
4138
4142
 
4143
+ module TestRubyParserShared30Plus
4144
+ include TestRubyParserShared27Plus
4145
+ end
4146
+
4139
4147
  class TestRubyParser < Minitest::Test
4140
4148
  def test_cls_version
4141
4149
  assert_equal 23, RubyParser::V23.version
@@ -4440,8 +4448,37 @@ class TestRubyParserV27 < RubyParserTestCase
4440
4448
 
4441
4449
  self.processor = RubyParser::V27.new
4442
4450
  end
4451
+
4452
+ def test_bdot2
4453
+ rb = "..10\n; ..a\n; c"
4454
+ pt = s(:block,
4455
+ s(:dot2, nil, s(:lit, 10).line(1)).line(1),
4456
+ s(:dot2, nil, s(:call, nil, :a).line(2)).line(2),
4457
+ s(:call, nil, :c).line(3)).line(1)
4458
+
4459
+ assert_parse_line rb, pt, 1
4460
+ end
4461
+
4462
+ def test_bdot3
4463
+ rb = "...10\n; ...a\n; c"
4464
+ pt = s(:block,
4465
+ s(:dot3, nil, s(:lit, 10).line(1)).line(1),
4466
+ s(:dot3, nil, s(:call, nil, :a).line(2)).line(2),
4467
+ s(:call, nil, :c).line(3)).line(1)
4468
+
4469
+ assert_parse_line rb, pt, 1
4470
+ end
4443
4471
  end
4444
4472
 
4473
+ class TestRubyParserV30 < RubyParserTestCase
4474
+ include TestRubyParserShared30Plus
4475
+
4476
+ def setup
4477
+ super
4478
+
4479
+ self.processor = RubyParser::V30.new
4480
+ end
4481
+ end
4445
4482
 
4446
4483
  RubyParser::VERSIONS.each do |klass|
4447
4484
  v = klass.version
data/tools/munge.rb CHANGED
@@ -197,8 +197,8 @@ ARGF.each_line do |line|
197
197
  puts line.gsub("true", "1").gsub("false", "0")
198
198
  when /^lex_state: :?([\w|]+) -> :?([\w|]+)(?: (?:at|from) (.*))?/ then
199
199
  a, b, c = $1.upcase, $2.upcase, $3
200
- a.gsub! /EXPR_/, ""
201
- b.gsub! /EXPR_/, ""
200
+ a.gsub!(/EXPR_/, "")
201
+ b.gsub!(/EXPR_/, "")
202
202
  if c && $v then
203
203
  puts "lex_state: #{a} -> #{b} at #{c}"
204
204
  else
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.15.1
4
+ version: 3.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryan Davis
@@ -29,7 +29,7 @@ cert_chain:
29
29
  d/AHw/kcnU6iuMUoJEcGiJd4gVCTn1l3cDcIvxakGslCA88Jubw0Sqatan0TnC9g
30
30
  KToW560QIey7SPfHWduzFJnV
31
31
  -----END CERTIFICATE-----
32
- date: 2021-01-11 00:00:00.000000000 Z
32
+ date: 2021-05-15 00:00:00.000000000 Z
33
33
  dependencies:
34
34
  - !ruby/object:Gem::Dependency
35
35
  name: sexp_processor
@@ -37,28 +37,40 @@ dependencies:
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '4.9'
40
+ version: '4.15'
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 4.15.1
41
44
  type: :runtime
42
45
  prerelease: false
43
46
  version_requirements: !ruby/object:Gem::Requirement
44
47
  requirements:
45
48
  - - "~>"
46
49
  - !ruby/object:Gem::Version
47
- version: '4.9'
50
+ version: '4.15'
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: 4.15.1
48
54
  - !ruby/object:Gem::Dependency
49
55
  name: rake
50
56
  requirement: !ruby/object:Gem::Requirement
51
57
  requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: '10'
52
61
  - - "<"
53
62
  - !ruby/object:Gem::Version
54
- version: '11'
63
+ version: '15'
55
64
  type: :development
56
65
  prerelease: false
57
66
  version_requirements: !ruby/object:Gem::Requirement
58
67
  requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '10'
59
71
  - - "<"
60
72
  - !ruby/object:Gem::Version
61
- version: '11'
73
+ version: '15'
62
74
  - !ruby/object:Gem::Dependency
63
75
  name: oedipus_lex
64
76
  requirement: !ruby/object:Gem::Requirement
@@ -73,6 +85,20 @@ dependencies:
73
85
  - - "~>"
74
86
  - !ruby/object:Gem::Version
75
87
  version: '2.5'
88
+ - !ruby/object:Gem::Dependency
89
+ name: racc
90
+ requirement: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '1.5'
95
+ type: :development
96
+ prerelease: false
97
+ version_requirements: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '1.5'
76
102
  - !ruby/object:Gem::Dependency
77
103
  name: rdoc
78
104
  requirement: !ruby/object:Gem::Requirement
@@ -93,20 +119,6 @@ dependencies:
93
119
  - - "<"
94
120
  - !ruby/object:Gem::Version
95
121
  version: '7'
96
- - !ruby/object:Gem::Dependency
97
- name: racc
98
- requirement: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: 1.4.6
103
- type: :development
104
- prerelease: false
105
- version_requirements: !ruby/object:Gem::Requirement
106
- requirements:
107
- - - "~>"
108
- - !ruby/object:Gem::Version
109
- version: 1.4.6
110
122
  - !ruby/object:Gem::Dependency
111
123
  name: hoe
112
124
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +200,8 @@ files:
188
200
  - lib/ruby26_parser.y
189
201
  - lib/ruby27_parser.rb
190
202
  - lib/ruby27_parser.y
203
+ - lib/ruby30_parser.rb
204
+ - lib/ruby30_parser.y
191
205
  - lib/ruby_lexer.rb
192
206
  - lib/ruby_lexer.rex
193
207
  - lib/ruby_lexer.rex.rb
@@ -225,7 +239,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
239
  - !ruby/object:Gem::Version
226
240
  version: '0'
227
241
  requirements: []
228
- rubygems_version: 3.1.4
242
+ rubygems_version: 3.2.16
229
243
  signing_key:
230
244
  specification_version: 4
231
245
  summary: ruby_parser (RP) is a ruby parser written in pure ruby (utilizing racc--which
metadata.gz.sig CHANGED
Binary file