home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / rbemx144.zip / ruby-1.4.4 / sample / exyacc.rb < prev    next >
Text File  |  1998-01-16  |  537b  |  23 lines

  1. #! /usr/local/bin/ruby -Kn
  2. # usage: exyacc.rb [yaccfiles]
  3. # this is coverted from exyacc.pl in the camel book
  4.  
  5. $/ = nil
  6.  
  7. while gets()
  8.   sbeg = $_.index("\n%%") + 1
  9.   send = $_.rindex("\n%%") + 1
  10.   $_ = $_[sbeg, send-sbeg]
  11.   sub!(/.*\n/, "")
  12.   gsub!(/'\{'/, "'\001'")
  13.   gsub!(/'}'/, "'\002'")
  14.   gsub!('\*/', "\003\003")
  15.   gsub!("/\\*[^\003]*\003\003", '')
  16.   while gsub!(/\{[^{}]*}/, ''); end
  17.   gsub!(/'\001'/, "'{'")
  18.   gsub!(/'\002'/, "'}'")
  19.   while gsub!(/^[ \t]*\n(\s)/, '\1'); end
  20.   gsub!(/([:|])[ \t\n]+(\w)/, '\1 \2')
  21.   print $_
  22. end
  23.