w/ fixtures, ERB gives $end unexpected. Options?

With my fixtures, I am getting:
Fixture::FormatError: a YAML error occurred parsing /home/hgs/aeg_intranet/csest
ore/config/../test/fixtures/loans.yml. Please note that YAML must be consistentl
y indented using spaces. Tabs are not allowed. Please have a look at http://www.
yaml.org/faq.html
The exact error was:
  SyntaxError: compile error
(erb):65: syntax error, unexpected $end, expecting ')'
_erbout
       ^
    /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.3/lib/active_record/fixtures.r
b:308:in `read_fixture_files'

Now there are no unmatched parentheses in the one file, but I'm
using fixture_references to make calls to pull info from other
files. I recognize this $end type message as coming from ruby
itself, rather than ERB or rails. I get this running erb on the
files manually, but if I print the output of the script out with
erb -x then there are no such parenthetical errors.

Since this is an apparently missing close bracket, it will be
difficult to get any parser to tell me where the corresponding
opening bracket is. The position of every last parenthesis is not
pushed onto the stack, at least not in normal operation, I imagine.
I've not tried any other implementations of Ruby for anything
(JRuby, Rubinius) so I don't know if is easier to trap this kind of
information in those, but failing that, are there any tools to
assist in tracking this kind of thing down? Maybe there's something
I can interpose to ensure that the strings I get back from the calls
to methods have balanced brackets?

I may be able to use Lua's "%b()" to hunt this bug, but its a while since
I've touched Lua.

        Thank you,
        Hugh

I think the error is telling you there is an extra 'end' keyword
before the closing parenthesis. Make sure that all 'end's have
matching block starting keywords.

With my fixtures, I am getting:
Fixture::FormatError: a YAML error occurred parsing /home/hgs/aeg_intranet/csest

        [...]

The exact error was:
  SyntaxError: compile error
(erb):65: syntax error, unexpected $end, expecting ')'
_erbout

        [...]

I may be able to use Lua's "%b()" to hunt this bug, but its a while since
I've touched Lua.

OK, I used lua's gsub:

text = io.read("*a")
result = string.gsub(text, "%b()", "")
print(result)

and the result (checked with grep, fgrep and visually) had no spare
parentheses for any of the yaml files piped through this.

        Thank you,
        Hugh

        Hugh

I think the error is telling you there is an extra 'end' keyword
before the closing parenthesis. Make sure that all 'end's have

Oh, I thought $end meant end of the file and that kend or Kend meant
an end keyword. Thank you. I'll have a look at that.

matching block starting keywords.

        Hugh

I think I have found out what this is due to. So for the benefit of
anyone still reading this thread and the archives:

I had a fixture, using fixture_references, of the form (not copied
and pasted):

loan_should_work:
  id: <%= id += 1 %>
  device_id: <%= devices(:still_camera1, 'id'); # expected to be 4 %>
  student_id: <%= students(:fred_bloggs, 'id'); # expected to be 6 %>
  [...]
   
The comments inside the <%=...%> don't actually work. Trailing
comments (after <%=...%>) don't work out right, and it seems they
are not legal in YAML. The only comments legal in YAML, AFAICS, are
those beginning in column 1. This is a shame because it would be
good to add supporting information to my data. I wish there had
been a better diagnostic message complaining about comments, but
since I, myself, find parsers difficult to write, I am not in a
position to be harsh with my criticism :-). Maybe someone better at
this than me can fix this? Maybe I have misdiagnosed the problem,
even though this now seems to work?

Anyway, in the hope it helps someone else...

        Thank you,
        Hugh