Skip to content

Commit

Permalink
* ruby28.y -> ruby30.y (#729)
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Sep 1, 2020
1 parent 61f5fb4 commit 7c5558d
Show file tree
Hide file tree
Showing 9 changed files with 21 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -30,5 +30,6 @@ lib/parser/ruby25.rb
lib/parser/ruby26.rb
lib/parser/ruby27.rb
lib/parser/ruby28.rb
lib/parser/ruby30.rb
lib/parser/macruby.rb
lib/parser/rubymotion.rb
2 changes: 1 addition & 1 deletion Rakefile
Expand Up @@ -32,7 +32,7 @@ GENERATED_FILES = %w(lib/parser/lexer.rb
lib/parser/ruby25.rb
lib/parser/ruby26.rb
lib/parser/ruby27.rb
lib/parser/ruby28.rb
lib/parser/ruby30.rb
lib/parser/macruby.rb
lib/parser/rubymotion.rb)

Expand Down
2 changes: 1 addition & 1 deletion lib/parser/all.rb
Expand Up @@ -10,4 +10,4 @@
require 'parser/ruby25'
require 'parser/ruby26'
require 'parser/ruby27'
require 'parser/ruby28'
require 'parser/ruby30'
10 changes: 5 additions & 5 deletions lib/parser/builders/default.rb
Expand Up @@ -103,7 +103,7 @@ class << self
##
# AST compatibility attribute; arguments forwarding initially
# didn't have support for leading arguments
# (i.e. `def m(a, ...); end` was a syntax error). However, Ruby 2.8
# (i.e. `def m(a, ...); end` was a syntax error). However, Ruby 3.0
# added support for any number of arguments in front of the `...`.
#
# If set to false (the default):
Expand All @@ -120,7 +120,7 @@ class << self
# s(:def, :m, s(:args, s(:arg, :a), s(:arg, :b), s(:forward_arg)))
#
# It does't matter that much on 2.7 (because there can't be any leading arguments),
# but on 2.8 it should be better enabled to use a single AST format.
# but on 3.0 it should be better enabled to use a single AST format.
#
# @return [Boolean]
attr_accessor :emit_forward_arg
Expand Down Expand Up @@ -1601,9 +1601,9 @@ def check_assignment_to_numparam(name, loc)
end

def check_reserved_for_numparam(name, loc)
# MRI < 2.8 accepts assignemnt to variables like _1
# if it's not a numbererd parameter. MRI 2.8 and newer throws an error.
return if @parser.version < 28
# MRI < 3.0 accepts assignemnt to variables like _1
# if it's not a numbererd parameter. MRI 3.0 and newer throws an error.
return if @parser.version < 30

if name =~ /\A_([1-9])\z/
diagnostic :error, :reserved_for_numparam, { :name => name }, loc
Expand Down
10 changes: 5 additions & 5 deletions lib/parser/current.rb
Expand Up @@ -83,14 +83,14 @@ def warn_syntax_deviation(feature, version)
require 'parser/ruby27'
CurrentRuby = Ruby27

when /^2\.8\./
current_version = '2.8.0-dev'
when /^3\.0\./
current_version = '3.0.0-dev'
if RUBY_VERSION != current_version
warn_syntax_deviation 'parser/ruby28', current_version
warn_syntax_deviation 'parser/ruby30', current_version
end

require 'parser/ruby28'
CurrentRuby = Ruby28
require 'parser/ruby30'
CurrentRuby = Ruby30

else # :nocov:
# Keep this in sync with released Ruby.
Expand Down
4 changes: 2 additions & 2 deletions lib/parser/ruby28.y → lib/parser/ruby30.y
@@ -1,4 +1,4 @@
class Parser::Ruby28
class Parser::Ruby30

token kCLASS kMODULE kDEF kUNDEF kBEGIN kRESCUE kENSURE kEND kIF kUNLESS
kTHEN kELSIF kELSE kCASE kWHEN kWHILE kUNTIL kFOR kBREAK kNEXT
Expand Down Expand Up @@ -3034,7 +3034,7 @@ require 'parser'
---- inner
def version
28
30
end
def default_encoding
Expand Down
6 changes: 3 additions & 3 deletions lib/parser/runner.rb
Expand Up @@ -113,9 +113,9 @@ def setup_option_parsing(opts)
@parser_class = Parser::Ruby27
end

opts.on '--28', 'Parse as Ruby 2.8 would' do
require 'parser/ruby28'
@parser_class = Parser::Ruby28
opts.on '--30', 'Parse as Ruby 3.0 would' do
require 'parser/ruby30'
@parser_class = Parser::Ruby30
end

opts.on '--mac', 'Parse as MacRuby 0.12 would' do
Expand Down
2 changes: 1 addition & 1 deletion test/helper.rb
Expand Up @@ -18,7 +18,7 @@
ruby25.y
ruby26.y
ruby27.y
ruby28.y
ruby30.y
),
File.expand_path('../../lib/parser', __FILE__))

Expand Down
4 changes: 2 additions & 2 deletions test/parse_helper.rb
Expand Up @@ -7,7 +7,7 @@ module ParseHelper
require 'parser/macruby'
require 'parser/rubymotion'

ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 2.8 mac ios)
ALL_VERSIONS = %w(1.8 1.9 2.0 2.1 2.2 2.3 2.4 2.5 2.6 2.7 3.0 mac ios)

def setup
@diagnostics = []
Expand All @@ -27,7 +27,7 @@ def parser_for_ruby_version(version)
when '2.5' then parser = Parser::Ruby25.new
when '2.6' then parser = Parser::Ruby26.new
when '2.7' then parser = Parser::Ruby27.new
when '2.8' then parser = Parser::Ruby28.new
when '3.0' then parser = Parser::Ruby30.new
when 'mac' then parser = Parser::MacRuby.new
when 'ios' then parser = Parser::RubyMotion.new
else raise "Unrecognized Ruby version #{version}"
Expand Down

0 comments on commit 7c5558d

Please sign in to comment.