Skip to content

Commit

Permalink
Merge pull request #218 from nobu/embed-info
Browse files Browse the repository at this point in the history
Embed racc/info.rb too
  • Loading branch information
hsbt committed Jun 8, 2023
2 parents 96ded6b + b5e121f commit fc030b5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,17 @@ end
file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
source = 'lib/racc/parser.rb'

text = File.read(source)
text.gsub!(/^require '(.*)'$/) do
%[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push '#$1.rb'\n#{File.read("lib/#{$1}.rb")}\nend\n]
rescue
$&
end
open(t.name, 'wb') { |io|
io.write(<<-eorb)
module Racc
PARSER_TEXT = <<'__end_of_file__'
#{File.read(source)}
#{text}
__end_of_file__
end
eorb
Expand Down
10 changes: 10 additions & 0 deletions test/test_parser_text.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
require File.expand_path(File.join(__dir__, 'case'))

module Racc
class TestRaccParserText < TestCase
def test_parser_text_require
assert_not_match(/^require/, Racc::PARSER_TEXT)
ruby "-I#{LIB_DIR}", "-rracc/parser-text", %[-e$:.clear], %[-eeval(Racc::PARSER_TEXT)]
end
end
end

0 comments on commit fc030b5

Please sign in to comment.