@@ -131,143 +131,127 @@ end
131131
132132task :isolate => :phony
133133
134- def in_compare
135- Dir . chdir "compare" do
136- yield
137- end
138- end
139-
140- def dl v
134+ def dl v , f
141135 dir = v [ /^\d +\. \d +/ ]
142136 url = "https://cache.ruby-lang.org/pub/ruby/#{ dir } /ruby-#{ v } .tar.xz"
143- path = File . basename url
144- unless File . exist? path then
145- system "curl -O #{ url } "
146- end
137+
138+ warn "Downloading ruby #{ v } "
139+ system "curl -s -o #{ f } #{ url } "
147140end
148141
142+ task :parser => :isolate
143+
144+ multitask :compare_build
145+ task :compare_build => :generate
146+ task :compare => :compare_build
147+
149148def ruby_parse version
150149 v = version [ /^\d +\. \d +/ ] . delete "."
151- rp_txt = "rp #{ v } .txt "
152- mri_txt = "mri #{ v } .txt"
153- parse_y = "parse #{ v } .y "
154- tarball = "ruby- #{ version } .tar.xz "
155- ruby_dir = "ruby-#{ version } "
156- diff = "diff #{ v } .diff "
150+ diff = "compare/diff #{ v } .diff "
151+ rp_txt = "compare/rp #{ v } .txt"
152+ mri_txt = "compare/mri #{ v } .txt "
153+ parse_y = "compare/parse #{ v } .y "
154+ tarball = "compare/ ruby-#{ version } .tar.xz "
155+ ruby_dir = "compare/ruby- #{ version } "
157156 rp_out = "lib/ruby_parser#{ v } .output"
158- _rp_y = "lib/ruby_parser#{ v } .y"
159157 rp_y_rb = "lib/ruby_parser#{ v } .rb"
160-
161- c_diff = "compare/#{ diff } "
162- c_rp_txt = "compare/#{ rp_txt } "
163- c_mri_txt = "compare/#{ mri_txt } "
164- c_parse_y = "compare/#{ parse_y } "
165- c_tarball = "compare/#{ tarball } "
166158 normalize = "compare/normalize.rb"
167159
168- file c_tarball do
169- in_compare do
170- dl version
171- end
160+ file tarball do
161+ dl version , tarball
172162 end
173163
174164 desc "fetch all tarballs"
175- task :fetch => c_tarball
176-
177- file c_parse_y => c_tarball do
178- in_compare do
179- extract_glob = case
180- when version > "3.3" then
181- "{id.h,parse.y,tool/{id2token.rb,lrama},defs/id.def}"
182- when version > "3.2" then
183- "{id.h,parse.y,tool/id2token.rb,defs/id.def}"
184- when version > "2.7" then
185- "{id.h,parse.y,tool/{id2token.rb,lib/vpath.rb}}"
186- else
187- "{id.h,parse.y,tool/{id2token.rb,vpath.rb}}"
188- end
189- system "tar xf #{ tarball } #{ ruby_dir } /#{ extract_glob } "
190-
191- # Debugging a new parse build system:
192- #
193- # Unpack the ruby tarball in question, configure, and run the following:
194- #
195- # % touch parse.y; make -n parse.c
196- # ...
197- # echo generating parse.c
198- # /Users/ryan/.rubies.current/bin/ruby --disable=gems ./tool/id2token.rb parse.y | \
199- # ruby ./tool/lrama/exe/lrama -oparse.c -Hparse.h - parse.y
200- #
201- # Then integrate these commands into the mess below:
202-
203- Dir . chdir ruby_dir do
204- cmd = if version > "3.2" then
205- "ruby tool/id2token.rb parse.y | expand > ../#{ parse_y } "
206- else
207- "ruby tool/id2token.rb --path-separator=.:./ id.h parse.y | expand | ruby -pe 'gsub(/^%pure-parser/, \" %define api.pure\" )' > ../#{ parse_y } "
208- end
209-
210- sh cmd
211-
212- if File . exist? "tool/lrama" then # UGH: this is dumb
213- rm_rf "../lrama"
214- sh "mv tool/lrama .."
215- end
216- end
217- sh "rm -rf #{ ruby_dir } "
165+ task :fetch => tarball
166+
167+ file parse_y => tarball do
168+ extract_glob = case
169+ when version > "3.3" then
170+ "{id.h,parse.y,tool/{id2token.rb,lrama},defs/id.def}"
171+ when version > "3.2" then
172+ "{id.h,parse.y,tool/id2token.rb,defs/id.def}"
173+ when version > "2.7" then
174+ "{id.h,parse.y,tool/{id2token.rb,lib/vpath.rb}}"
175+ else
176+ "{id.h,parse.y,tool/{id2token.rb,vpath.rb}}"
177+ end
178+ system "tar xf #{ tarball } -C compare #{ File . basename ruby_dir } /#{ extract_glob } "
179+
180+ # Debugging a new parse build system:
181+ #
182+ # Unpack the ruby tarball in question, configure, and run the following:
183+ #
184+ # % touch parse.y; make -n parse.c
185+ # ...
186+ # echo generating parse.c
187+ # /Users/ryan/.rubies.current/bin/ruby --disable=gems ./tool/id2token.rb parse.y | \
188+ # ruby ./tool/lrama/exe/lrama -oparse.c -Hparse.h - parse.y
189+ #
190+ # Then integrate these commands into the mess below:
191+
192+ d = ruby_dir
193+ cmd = if version > "3.2" then
194+ "ruby #{ d } /tool/id2token.rb #{ d } /parse.y | expand > #{ parse_y } "
195+ else
196+ "ruby #{ d } /tool/id2token.rb --path-separator=.:./ #{ d } /id.h #{ d } /parse.y | expand | ruby -pe 'gsub(/^%pure-parser/, \" %define api.pure\" )' > #{ parse_y } "
197+ end
198+
199+ 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"
218204 end
205+ sh "rm -rf #{ d } "
219206 end
220207
221208 bison = Dir [ "/opt/homebrew/opt/bison/bin/bison" ,
222209 "/usr/local/opt/bison/bin/bison" ,
223210 `which bison` . chomp ,
224211 ] . first
225212
226- file c_mri_txt => [ c_parse_y , normalize ] do
227- in_compare do
228- if version > "3.3" then
229- sh "./lrama/exe/lrama -r all -oparse#{ v } .tab.c #{ parse_y } "
230- else
231- sh "#{ bison } -r all #{ parse_y } "
232- end
233-
234- sh "./normalize.rb parse#{ v } .output > #{ mri_txt } "
235- rm [ "parse#{ v } .output" , "parse#{ v } .tab.c" ]
213+ file mri_txt => [ parse_y , normalize ] do
214+ if version > "3.3" then
215+ sh "./compare/lrama/exe/lrama -r all -ocompare/parse#{ v } .tab.c #{ parse_y } "
216+ else
217+ sh "#{ bison } -r all #{ parse_y } "
218+ mv Dir [ "parse#{ v } .*" ] , "compare"
236219 end
220+
221+ sh "#{ normalize } compare/parse#{ v } .output > #{ mri_txt } "
222+ rm [ "compare/parse#{ v } .output" , "compare/parse#{ v } .tab.c" ]
237223 end
238224
239225 file rp_out => rp_y_rb
240226
241- file c_rp_txt => [ rp_out , normalize ] do
242- in_compare do
243- sh "./normalize.rb ../#{ rp_out } > #{ rp_txt } "
244- end
227+ file rp_txt => [ rp_out , normalize ] do
228+ sh "#{ normalize } #{ rp_out } > #{ rp_txt } "
245229 end
246230
247231 compare = "compare#{ v } "
232+ compare_build = "compare_build#{ v } "
248233
249234 desc "Compare all grammars to MRI"
250235 task :compare => compare
236+ task :compare_build => compare_build
251237
252- file c_diff => [ c_mri_txt , c_rp_txt ] do
253- in_compare do
254- sh " diff -du #{ mri_txt } #{ rp_txt } > #{ diff } ; true"
255- end
238+ task compare_build => diff
239+
240+ file diff => [ mri_txt , rp_txt ] do
241+ sh "diff -du #{ mri_txt } #{ rp_txt } > #{ diff } ; true"
256242 end
257243
258244 desc "Compare #{ v } grammar to MRI #{ version } "
259- task compare => c_diff do
260- in_compare do
261- system "wc -l #{ diff } "
262- end
245+ task compare => diff do
246+ system "wc -l #{ diff } "
263247 end
264248
265249 task :clean do
266- rm_f Dir [ c_mri_txt , c_rp_txt ]
250+ rm_f Dir [ mri_txt , rp_txt ]
267251 end
268252
269253 task :realclean do
270- rm_f Dir [ c_parse_y , c_tarball ]
254+ rm_f Dir [ parse_y , tarball ]
271255 end
272256end
273257
0 commit comments