~ubuntu-branches/ubuntu/intrepid/racc/intrepid

« back to all changes in this revision

Viewing changes to packages/racc/test/testscanner.rb

  • Committer: Bazaar Package Importer
  • Author(s): akira yamada
  • Date: 2005-04-09 17:54:44 UTC
  • mfrom: (1.2.1 upstream) (2.1.1 warty)
  • Revision ID: james.westby@ubuntu.com-20050409175444-fvtir838ypkn7a58
Tags: 1.4.4-1
* new upstream version.  (closes: #301768)
* added racc2y.1 and y2racc.1.
* modified racc2y and y2racc to use optparse instead of deprecated getopts.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#
 
2
# racc scanner tester
 
3
#
 
4
 
 
5
require 'racc/raccs'
 
6
 
 
7
 
 
8
class ScanError < StandardError; end
 
9
 
 
10
def testdata( dir, argv )
 
11
  if argv.empty? then
 
12
    Dir.glob( dir + '/*' ) -
 
13
    Dir.glob( dir + '/*.swp' ) -
 
14
    [ dir + '/CVS' ]
 
15
  else
 
16
    argv.collect {|i| dir + '/' + i }
 
17
  end
 
18
end
 
19
 
 
20
 
 
21
if ARGV.delete '--print' then
 
22
  $raccs_print_type = true
 
23
  printonly = true
 
24
else
 
25
  printonly = false
 
26
end
 
27
 
 
28
testdata( File.dirname($0) + '/scandata', ARGV ).each do |file|
 
29
  $stderr.print File.basename(file) + ': '
 
30
  begin
 
31
    ok = File.read(file)
 
32
    s = Racc::GrammarFileScanner.new( ok )
 
33
    sym, (val, lineno) = s.scan
 
34
    if printonly then
 
35
      $stderr.puts
 
36
      $stderr.puts val
 
37
      next
 
38
    end
 
39
 
 
40
    val = '{' + val + "}\n"
 
41
    sym == :ACTION  or raise ScanError, 'is not action!'
 
42
    val == ok       or raise ScanError, "\n>>>\n#{ok}----\n#{val}<<<"
 
43
 
 
44
    $stderr.puts 'ok'
 
45
  rescue => err
 
46
    $stderr.puts 'fail (' + err.type.to_s + ')'
 
47
    $stderr.puts err.message
 
48
    $stderr.puts err.backtrace
 
49
    $stderr.puts
 
50
  end
 
51
end