Mismatched-End: README.txt

Release: 1.0.0

copyright(c) 2008 kuwata-lab.com all rights reserved.

http://rubyforge.org/projects/mismatched-end/

About

This is a patch for Ruby to extend and add new keywords to parser. With this patch, the following keywords are available.

Advantage

This patch solves Ruby's `mistached-end' problem.

The following is an example that contains mismatched-end problem because 'end' at line 10 is wrong.

test1.rb:

001:  module Foo
002:    class Bar
003:      def example(arg)
004:        i = 0
005:        for item in arg
006:          if item
007:            p item
008:          end
009:        end
010:      enb        # error
011:    end
012:  end

You'll got the following error message if you try to run this script, but you can't get where the true error is in.

$ ruby test1.rb
test1.rb:12: syntax error, unexpected $end, expecting kEND

Applying this patch, you can use new keywords 'endif', 'endfor', and so on. To replace 'end' to these keywords helps you to detect where the true error is happened.

test2.rb:

001:  module Foo
002:    class Bar
003:      def example(arg)
004:        i = 0
005:        for item in arg
006:          if item
007:            p item
008:          end
009:        endfor   # use 'endfor' instead of 'end'
010:      enb        # error
011:    endclass     # use 'endclass' instead of 'end'
012:  end

You'll got the following error message and you'll get that the error is on 'enddef' (or 'end' of 'def').

$ myruby test2.rb
test2.rb:11: syntax error, unexpected kENDCLASS, expecting kEND or kENDDEF

This is also useful especially for complex eRuby file, because it is very often that HTML is very long between <% for item in list %> and <% end %> or between <% if condition %> and <% end %>, and it is more difficult to match 'if' and 'end' or 'for' and 'end' as HTML is more complex.

<% if @list %>
<table>
<% for item in @list %>
  <tr>
<%   if !item.name %>
    <td cols="2">-</td>
<%   elsif item.email %>
    <td><a href="mailto:<%=item.email%>"><%=h item.name %></a></td>
    <td><a href="mailto:<%=item.email%>"><%=h item.email %></a></td>
<%   else %>
    <td><%= item.name %></td>
    <td>-</td>
<%   endif %>
  </tr>
<% endfor %>
</table>
<% else %>
<p>Not found.</p>
<% endif %>

Install

  1. Apply 'patch.diff' to Ruby's source code by patch command.
  2. Compile and install Ruby.

Notice that gpref is required to generate lex.c from keywords file, and bison is required to generate parser.c from parser.y.

$ tar xzf ruby-1.8.6-p114.tar.gz
$ cd ruby-1.8.6-p114/
$ patch -p1 < /tmp/end-mismatch-patch/ruby-1.8.6/patch.diff
$ ./configure --prefix=/usr/local
$ make
$ make test
$ sudo cp ruby /usr/local/bin/myruby

License

Ruby's

Author

Makoto Kuwata <kwa.at.kuwata-lab.com>

Bug reports

If you have bugs or questions, report them to kwa.at.kuwata-lab.com.