Skip to content

Commit b0bfcbc

Browse files
committed
+ Added tentative 3.4 support.
+ Restructured comparison rake tasks and normalization to deal with lrama changes. + Updated compare versions and added 3.4. [git-p4: depot-paths = "//src/ruby_parser/dev/": change = 14472]
1 parent 718e13e commit b0bfcbc

File tree

6 files changed

+50
-18
lines changed

6 files changed

+50
-18
lines changed

Manifest.txt

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ lib/ruby_parser30.rb
3030
lib/ruby_parser31.rb
3131
lib/ruby_parser32.rb
3232
lib/ruby_parser33.rb
33+
lib/ruby_parser34.rb
3334
lib/ruby_parser_extras.rb
3435
test/test_ruby_lexer.rb
3536
test/test_ruby_parser.rb

Rakefile

+16-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Hoe.add_include_dirs "../../oedipus_lex/dev/lib"
1414
Hoe.add_include_dirs "../../ruby2ruby/dev/lib"
1515

1616
V2 = %w[20 21 22 23 24 25 26 27]
17-
V3 = %w[30 31 32 33]
17+
V3 = %w[30 31 32 33 34]
1818

1919
VERS = V2 + V3
2020

@@ -164,7 +164,7 @@ def ruby_parse version
164164
desc "fetch all tarballs"
165165
task :fetch => tarball
166166

167-
file parse_y => tarball do
167+
file ruby_dir => tarball do
168168
extract_glob = case
169169
when version > "3.3" then
170170
"{id.h,parse.y,tool/{id2token.rb,lrama},defs/id.def}"
@@ -176,15 +176,20 @@ def ruby_parse version
176176
"{id.h,parse.y,tool/{id2token.rb,vpath.rb}}"
177177
end
178178
system "tar xf #{tarball} -C compare #{File.basename ruby_dir}/#{extract_glob}"
179+
end
180+
181+
file parse_y => ruby_dir do
182+
# env -u RUBYOPT rake compare/parse33.y
183+
warn "Warning: RUBYOPT is set! Use 'env -u RUBYOPT rake'" if ENV["RUBYOPT"]
179184

180185
# Debugging a new parse build system:
181186
#
182187
# Unpack the ruby tarball in question, configure, and run the following:
183188
#
184-
# % touch parse.y; make -n parse.c
189+
# % [ -e Makefile ] || ./configure ; make -n -W parse.y parse.c
185190
# ...
186191
# echo generating parse.c
187-
# /Users/ryan/.rubies.current/bin/ruby --disable=gems ./tool/id2token.rb parse.y | \
192+
# ruby --disable=gems ./tool/id2token.rb parse.y | \
188193
# ruby ./tool/lrama/exe/lrama -oparse.c -Hparse.h - parse.y
189194
#
190195
# Then integrate these commands into the mess below:
@@ -197,12 +202,6 @@ def ruby_parse version
197202
end
198203

199204
sh cmd
200-
201-
if File.exist? "#{d}/tool/lrama" then # UGH: this is dumb
202-
rm_rf "compare/lrama"
203-
sh "mv #{d}/tool/lrama compare"
204-
end
205-
sh "rm -rf #{d}"
206205
end
207206

208207
bison = Dir["/opt/homebrew/opt/bison/bin/bison",
@@ -211,8 +210,9 @@ def ruby_parse version
211210
].first
212211

213212
file mri_txt => [parse_y, normalize] do
213+
d = ruby_dir
214214
if version > "3.3" then
215-
sh "./compare/lrama/exe/lrama -r all -ocompare/parse#{v}.tab.c #{parse_y}"
215+
sh "./#{d}/tool/lrama/exe/lrama -r states --report-file=compare/parse#{v}.output -ocompare/parse#{v}.tab.c #{parse_y}"
216216
else
217217
sh "#{bison} -r all #{parse_y}"
218218
mv Dir["parse#{v}.*"], "compare"
@@ -247,7 +247,7 @@ def ruby_parse version
247247
end
248248

249249
task :clean do
250-
rm_f Dir[mri_txt, rp_txt]
250+
rm_f Dir[mri_txt, rp_txt, ruby_dir]
251251
end
252252

253253
task :realclean do
@@ -296,9 +296,10 @@ ruby_parse "2.5.9"
296296
ruby_parse "2.6.10"
297297
ruby_parse "2.7.8"
298298
ruby_parse "3.0.6"
299-
ruby_parse "3.1.4"
300-
ruby_parse "3.2.2"
301-
ruby_parse "3.3.0"
299+
ruby_parse "3.1.7"
300+
ruby_parse "3.2.8"
301+
ruby_parse "3.3.7"
302+
ruby_parse "3.4.2"
302303

303304
task :debug => :isolate do
304305
ENV["V"] ||= VERS.last

compare/normalize.rb

+15-3
Original file line numberDiff line numberDiff line change
@@ -153,13 +153,21 @@ def munge s
153153

154154
'"do (for condition)"', "kDO_COND",
155155
'"do (for lambda)"', "kDO_LAMBDA",
156-
'"do (for block)"', "kDO_BLOCK",
156+
%("'do' for block"), "kDO_BLOCK", # 3.4
157+
%("'do' for lambda"), "kDO_LAMBDA", # 3.4
158+
%("'do' for condition"),"kDO_COND", # 3.4
159+
%q("#{"), "tSTRING_DBEG", # 3.4
160+
'"do (for block)"', "kDO_BLOCK", # 3.4
157161

162+
/\"'(\w+)' \(?modifier\)?\"/, proc { |x| "k#{$1.upcase}_MOD" }, # 3.4
158163
/\"(\w+) \(?modifier\)?\"/, proc { |x| "k#{$1.upcase}_MOD" },
159-
/\"(\w+)\"/, proc { |x| "k#{$1.upcase}" },
164+
/\"((?!k)\w+)\"/, proc { |x| "k#{$1.upcase}" },
160165

161166
/\$?@(\d+)(\s+|$)/, "", # newer bison
162167

168+
# 3.4(ish?) changes:
169+
"option_tNL", "opt_nl", # ruby 3.4
170+
163171
# TODO: remove for 3.0 work:
164172
"lex_ctxt ", "" # 3.0 production that's mostly noise right now
165173
]
@@ -178,12 +186,16 @@ def munge s
178186
ARGF.each_line do |line|
179187
next unless good or line =~ /^-* ?Grammar|\$accept : /
180188

181-
case line.strip
189+
case line.strip # TODO: .delete %q["'()]
182190
when /^$/ then
183191
when /^(\d+) (\$?[@\w]+): (.*)/ then # yacc
184192
rule = $2
185193
order << rule unless rules.has_key? rule
186194
rules[rule] << munge($3)
195+
when /^(\d+) (\$?[@\w]+'(?: |\\n)'): (.*)/ then # munges both sides
196+
rule = $2
197+
order << rule unless rules.has_key? rule
198+
rules[munge(rule)] << munge($3)
187199
when /^(\d+) \s+\| (.*)/ then # yacc
188200
rules[rule] << munge($2)
189201
when /^(\d+) (@\d+): (.*)/ then # yacc

lib/ruby_parser.rb

+2
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ class SyntaxError < RuntimeError; end
8383
require "ruby_parser31"
8484
require "ruby_parser32"
8585
require "ruby_parser33"
86+
require "ruby_parser34"
8687

8788
class RubyParser # HACK
8889
VERSIONS.clear # also a HACK caused by racc namespace issues
8990

91+
class V34 < ::Ruby33Parser; end
9092
class V33 < ::Ruby33Parser; end
9193
class V32 < ::Ruby32Parser; end
9294
class V31 < ::Ruby31Parser; end

lib/ruby_parser3.yy

+2
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ class Ruby31Parser
88
class Ruby32Parser
99
#elif V == 33
1010
class Ruby33Parser
11+
#elif V == 34
12+
class Ruby34Parser
1113
#else
1214
fail "version not specified or supported on code generation"
1315
#endif

test/test_ruby_parser.rb

+14
Original file line numberDiff line numberDiff line change
@@ -5681,6 +5681,10 @@ module TestRubyParserShared33Plus
56815681
include TestRubyParserShared32Plus
56825682
end
56835683

5684+
module TestRubyParserShared34Plus
5685+
include TestRubyParserShared33Plus
5686+
end
5687+
56845688
class Minitest::Test
56855689
def skip s = "blah"
56865690
warn "ignoring skip for %s: %s" % [name, s]
@@ -6039,6 +6043,16 @@ def setup
60396043
end
60406044
end
60416045

6046+
class TestRubyParserV34 < RubyParserTestCase
6047+
include TestRubyParserShared34Plus
6048+
6049+
def setup
6050+
super
6051+
6052+
self.processor = RubyParser::V34.new
6053+
end
6054+
end
6055+
60426056
RubyParser::VERSIONS.each do |klass|
60436057
v = klass.version
60446058
describe "block args arity #{v}" do

0 commit comments

Comments
 (0)