1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/racc/testscanner.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

52 lines
1,011 B
Ruby
Raw Permalink Normal View History

2019-05-13 08:25:22 -04:00
#
# racc scanner tester
#
require 'racc/raccs'
class ScanError < StandardError; end
def testdata( dir, argv )
if argv.empty? then
Dir.glob( dir + '/*' ) -
Dir.glob( dir + '/*.swp' ) -
[ dir + '/CVS' ]
else
argv.collect {|i| dir + '/' + i }
end
end
if ARGV.delete '--print' then
$raccs_print_type = true
printonly = true
else
printonly = false
end
testdata( File.dirname($0) + '/scandata', ARGV ).each do |file|
$stderr.print File.basename(file) + ': '
begin
ok = File.read(file)
s = Racc::GrammarFileScanner.new( ok )
2019-06-30 09:48:39 -04:00
sym, (val, _lineno) = s.scan
2019-05-13 08:25:22 -04:00
if printonly then
$stderr.puts
$stderr.puts val
next
end
val = '{' + val + "}\n"
sym == :ACTION or raise ScanError, 'is not action!'
val == ok or raise ScanError, "\n>>>\n#{ok}----\n#{val}<<<"
$stderr.puts 'ok'
rescue => err
$stderr.puts 'fail (' + err.type.to_s + ')'
$stderr.puts err.message
$stderr.puts err.backtrace
$stderr.puts
end
end