diff options
Diffstat (limited to 'sample/exyacc.rb')
| -rw-r--r-- | sample/exyacc.rb | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/sample/exyacc.rb b/sample/exyacc.rb index 5818825e25..cbcc18d58b 100644 --- a/sample/exyacc.rb +++ b/sample/exyacc.rb @@ -1,22 +1,20 @@ #! /usr/local/bin/ruby -Kn # usage: exyacc.rb [yaccfiles] -# this is coverted from exyacc.pl in the camel book +# this is covered from exyacc.pl in the camel book -$/ = nil - -while gets() - sbeg = $_.index("\n%%") + 1 - send = $_.rindex("\n%%") + 1 - $_ = $_[sbeg, send-sbeg] - sub!(/.*\n/, "") - gsub!(/'\{'/, "'\001'") - gsub!(/'\}'/, "'\002'") - gsub!(%r{\*/}, "\003\003") - gsub!(%r{/\*[^\003]*\003\003}, '') - while gsub!(/\{[^{}]*\}/, ''); end - gsub!(/'\001'/, "'{'") - gsub!(/'\002'/, "'}'") - while gsub!(/^[ \t]*\n(\s)/, '\1'); end - gsub!(/([:|])[ \t\n]+(\w)/, '\1 \2') - print $_ +ARGF.each(nil) do |source| + sbeg = source.index("\n%%") + 1 + send = source.rindex("\n%%") + 1 + grammar = source[sbeg, send-sbeg] + grammar.sub!(/.*\n/, "") + grammar.gsub!(/'\{'/, "'\001'") + grammar.gsub!(/["']\}["']/, "'\002'") + grammar.gsub!(%r{\*/}, "\003\003") + grammar.gsub!(%r{/\*[^\003]*\003\003}, '') + while grammar.gsub!(/\{[^{}]*\}/, ''); end + grammar.gsub!(/'\001'/, "'{'") + grammar.gsub!(/'\002'/, "'}'") + while grammar.gsub!(/^[ \t]*\n(\s)/, '\1'); end + grammar.gsub!(/([:|])[ \t\n]+(\w)/, '\1 \2') + print grammar end |
