Skip to content

Commit

Permalink
Merge pull request #230 from nobu/embedded-pragmas
Browse files Browse the repository at this point in the history
Clean embedded pragmas
  • Loading branch information
nobu committed Aug 10, 2023
2 parents 624159e + f7bf342 commit 5f015be
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 25 deletions.
52 changes: 28 additions & 24 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,6 @@ RDoc::Task.new(:docs) do |rd|
rd.options << "-t #{title}"
end

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
t.libs << "test/lib"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
if RUBY_VERSION >= "2.6"
t.ruby_opts << "--enable-frozen-string-literal"
t.ruby_opts << "--debug=frozen-string-literal" if RUBY_ENGINE != "truffleruby"
end
end

def java?
/java/ === RUBY_PLATFORM
end
Expand All @@ -39,12 +27,16 @@ file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb', __FILE__] do |t|
source = 'lib/racc/parser.rb'

text = File.read(source)
text.sub!(/\A# *frozen[-_]string[-_]literal:.*\n/, '')
text.gsub!(/^require '(.*)'$/) do
%[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push "\#{__dir__}/#$1.rb"\n#{File.read("lib/#{$1}.rb")}\nend\n]
lib = $1
code = File.read("lib/#{lib}.rb")
code.sub!(/\A(?:#.*\n)+/, '')
%[unless $".find {|p| p.end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
rescue
$&
end
open(t.name, 'wb') { |io|
File.open(t.name, 'wb') { |io|
io.write(<<-eorb)
module Racc
PARSER_TEXT = <<'__end_of_file__'
Expand All @@ -58,30 +50,42 @@ end
if jruby?
# JRUBY
require "rake/javaextensiontask"
Rake::JavaExtensionTask.new("cparse") do |ext|
extask = Rake::JavaExtensionTask.new("cparse") do |ext|
jruby_home = RbConfig::CONFIG['prefix']
ext.lib_dir = File.join 'lib', 'racc'
ext.ext_dir = File.join 'ext', 'racc'
ext.lib_dir = 'lib/java/racc'
ext.ext_dir = 'ext/racc'
# source/target jvm
ext.source_version = '1.8'
ext.target_version = '1.8'
jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
ext.classpath = jars.map { |x| File.expand_path x }.join( ':' )
ext.name = 'cparse-jruby'
end

task :compile => ['lib/racc/parser-text.rb']
else
# MRI
require "rake/extensiontask"
Rake::ExtensionTask.new "cparse" do |ext|
ext.lib_dir = File.join 'lib', 'racc'
ext.ext_dir = File.join 'ext', 'racc', 'cparse'
extask = Rake::ExtensionTask.new "cparse" do |ext|
ext.lib_dir << "/#{RUBY_VERSION}/#{ext.platform}/racc"
ext.ext_dir = 'ext/racc/cparse'
end

task :compile => 'lib/racc/parser-text.rb'
end

task :compile => ['lib/racc/parser-text.rb']

task :build => "lib/racc/parser-text.rb"

task :test => :compile

require 'rake/testtask'

Rake::TestTask.new(:test) do |t|
ENV["RUBYOPT"] = "-I" + [extask.lib_dir, "test/lib"].join(File::PATH_SEPARATOR)
t.libs << extask.lib_dir
t.libs << "test/lib"
t.ruby_opts << "-rhelper"
t.test_files = FileList["test/**/test_*.rb"]
if RUBY_VERSION >= "2.6"
t.ruby_opts << "--enable-frozen-string-literal"
t.ruby_opts << "--debug=frozen-string-literal" if RUBY_ENGINE != "truffleruby"
end
end
1 change: 1 addition & 0 deletions lib/racc/info.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# frozen_string_literal: true
#--
#
#
Expand Down
2 changes: 1 addition & 1 deletion lib/racc/parser.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# frozen_string_literal: false
# frozen_string_literal: true
#--
# Copyright (c) 1999-2006 Minero Aoki
#
Expand Down

0 comments on commit 5f015be

Please sign in to comment.