Skip to content

Commit 3957ec2

Browse files
committed
Fix embedded parser redefinition warnings
1 parent bf9d9a7 commit 3957ec2

4 files changed

Lines changed: 24 additions & 3 deletions

File tree

Rakefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ file 'lib/racc/parser-text.rb' => ['lib/racc/parser.rb', 'lib/racc/info.rb', __F
3434
lib = $1
3535
code = File.read("lib/#{lib}.rb")
3636
code.sub!(/\A(?:#.*\n)+/, '')
37-
%[unless $".find {|p| p.end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
37+
%[unless $".find {|p| p.tr('\\\\', '/').end_with?('/#{lib}.rb')}\n$".push "\#{__dir__}/#{lib}.rb"\n#{code}\nend\n]
3838
rescue
3939
$&
4040
end

lib/racc/parserfilegenerator.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ def runtime_source
138138

139139
def embed_library(src)
140140
line %[###### #{src.filename} begin]
141-
line %[unless $".find {|p| p.end_with?('/#{src.filename}')}]
141+
line %[unless $".find {|p| p.tr('\\\\', '/').end_with?('/#{src.filename}')}]
142142
line %[$".push "\#{__dir__}/#{src.filename}"]
143143
put src, @params.convert_line?
144144
line %[end]

test/test_parser_text.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@ module Racc
44
class TestRaccParserText < TestCase
55
def test_parser_text_require
66
assert_not_match(/^require/, Racc::PARSER_TEXT)
7-
assert_in_out_err(%W[-I#{LIB_DIR} -rracc/parser-text -e$:.clear -eeval(Racc::PARSER_TEXT)])
7+
ruby "-I#{LIB_DIR}", "-rracc/parser-text", "-e", "$:.clear", "-e", "eval(Racc::PARSER_TEXT)", quiet: true
8+
end
9+
10+
def test_parser_text_require_with_backslash_loaded_feature
11+
ruby "-I#{LIB_DIR}", "-rracc/parser-text", "-e", <<~'RUBY', quiet: true
12+
require 'racc/info'
13+
$".map! do |feature|
14+
feature.end_with?('/racc/info.rb') ? 'C:\\tmp\\racc\\info.rb' : feature
15+
end
16+
eval(Racc::PARSER_TEXT)
17+
RUBY
818
end
919
end
1020
end

test/test_racc_command.rb

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,17 @@ def test_echk_y
4848
assert_exec 'echk.y', quiet: true
4949
end
5050

51+
def test_echk_y_with_backslash_loaded_feature
52+
assert_compile 'echk.y', '-E'
53+
assert_debugfile 'echk.y', []
54+
ruby "-I#{LIB_DIR}", "-rracc/parser", "-e", <<~'RUBY', "#{@TAB_DIR}/echk", quiet: true
55+
$".map! do |feature|
56+
feature.end_with?('/racc/parser.rb') ? 'C:\\tmp\\racc\\parser.rb' : feature
57+
end
58+
load ARGV.shift
59+
RUBY
60+
end
61+
5162
def test_err_y
5263
assert_compile 'err.y'
5364
assert_debugfile 'err.y', []

0 commit comments

Comments
 (0)