diff options
| author | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-26 14:19:50 +0000 |
|---|---|---|
| committer | yugui <yugui@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-07-26 14:19:50 +0000 |
| commit | da0c1dd68920c0bf01917a351f98c584e903733a (patch) | |
| tree | 5285e9eb81171b42a8ae2772b1dd2166ff3443b9 /sample | |
| parent | d3101d5cbbba6ebcb4f5eb53a27d54696bee27d5 (diff) | |
| download | ruby-da0c1dd68920c0bf01917a351f98c584e903733a.tar.gz ruby-da0c1dd68920c0bf01917a351f98c584e903733a.tar.xz ruby-da0c1dd68920c0bf01917a351f98c584e903733a.zip | |
* sample/exyacc.rb: fixed NoMethodError(Kernel#sub!).
replaced use of special variables with explicit IO
operations.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18227 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample')
| -rw-r--r-- | sample/exyacc.rb | 32 |
1 files changed, 15 insertions, 17 deletions
diff --git a/sample/exyacc.rb b/sample/exyacc.rb index 5818825e2..c96ebfd67 100644 --- a/sample/exyacc.rb +++ b/sample/exyacc.rb @@ -2,21 +2,19 @@ # usage: exyacc.rb [yaccfiles] # this is coverted 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 + grammer = source[sbeg, send-sbeg] + grammer.sub!(/.*\n/, "") + grammer.gsub!(/'\{'/, "'\001'") + grammer.gsub!(/'\}'/, "'\002'") + grammer.gsub!(%r{\*/}, "\003\003") + grammer.gsub!(%r{/\*[^\003]*\003\003}, '') + while grammer.gsub!(/\{[^{}]*\}/, ''); end + grammer.gsub!(/'\001'/, "'{'") + grammer.gsub!(/'\002'/, "'}'") + while grammer.gsub!(/^[ \t]*\n(\s)/, '\1'); end + grammer.gsub!(/([:|])[ \t\n]+(\w)/, '\1 \2') + print grammer end |
