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