Skip to content

Commit

Permalink
Merge pull request #221 from nobu/embedded-path
Browse files Browse the repository at this point in the history
Embedded path
  • Loading branch information
hsbt committed Jun 14, 2023
2 parents d4713af + 31ac4f0 commit 0f2588c
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 10 deletions.
4 changes: 2 additions & 2 deletions Rakefile
Expand Up @@ -35,12 +35,12 @@ def jruby?
Object.const_defined?(:RUBY_ENGINE) and 'jruby' == RUBY_ENGINE
end

file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb'] do |t|
file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb', __FILE__] 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]
%[unless $".find {|p| p.end_with?('/#$1.rb')}\n$".push "\#{__dir__}/#$1.rb"\n#{File.read("lib/#{$1}.rb")}\nend\n]
rescue
$&
end
Expand Down
4 changes: 2 additions & 2 deletions lib/racc/parserfilegenerator.rb
Expand Up @@ -135,8 +135,8 @@ def runtime_source

def embed_library(src)
line %[###### #{src.filename} begin]
line %[unless $".index '#{src.filename}']
line %[$".push '#{src.filename}']
line %[unless $".find {|p| p.end_with?('/#{src.filename}')}]
line %[$".push "\#{__dir__}/#{src.filename}"]
put src, @params.convert_line?
line %[end]
line %[###### #{src.filename} end]
Expand Down
12 changes: 8 additions & 4 deletions test/case.rb
Expand Up @@ -75,9 +75,9 @@ def assert_debugfile(asset, ok)
end
end

def assert_exec(asset)
def assert_exec(asset, **opts)
file = File.basename(asset, '.y')
ruby "-I#{LIB_DIR}", "#{@TAB_DIR}/#{file}"
ruby "-I#{LIB_DIR}", "-rracc/parser", "#{@TAB_DIR}/#{file}", **opts
end

def strip_version(source)
Expand All @@ -101,8 +101,12 @@ def racc(*arg, **opt)
ruby "-I#{LIB_DIR}", "-S", RACC, *arg, **opt
end

def ruby(*arg, **opt)
assert_ruby_status(["-C", @TEMP_DIR, *arg], **opt)
def ruby(*arg, quiet: false, **opt)
if quiet
assert_in_out_err(["-C", @TEMP_DIR, *arg], **opt)
else
assert_ruby_status(["-C", @TEMP_DIR, *arg], **opt)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_parser_text.rb
Expand Up @@ -4,7 +4,7 @@ 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)]
assert_in_out_err(%W[-I#{LIB_DIR} -rracc/parser-text -e$:.clear -eeval(Racc::PARSER_TEXT)])
end
end
end
2 changes: 1 addition & 1 deletion test/test_racc_command.rb
Expand Up @@ -45,7 +45,7 @@ def test_chk_y
def test_echk_y
assert_compile 'echk.y', '-E'
assert_debugfile 'echk.y', []
assert_exec 'echk.y'
assert_exec 'echk.y', quiet: true
end

def test_err_y
Expand Down

0 comments on commit 0f2588c

Please sign in to comment.