Smarter parser errors?

Hi all,

I have a large ruby project (>40 files, >10k rows), and whenever I make
a syntax error somewhere (e.g. swap an 'end' and a '}' token), I always
get the same error, dozens of files away, in an END block, that a given
constant is not defined.

Isn't it possible to detect such errors by the parser/lexer, and give a
helpful error message?

Ferenc

On Sun, Nov 14, 2004 at 08:08:17AM +0900, Ferenc Engard scribed:

Hi all,

I have a large ruby project (>40 files, >10k rows), and whenever I make
a syntax error somewhere (e.g. swap an 'end' and a '}' token), I always
get the same error, dozens of files away, in an END block, that a given
constant is not defined.

Isn't it possible to detect such errors by the parser/lexer, and give a
helpful error message?

I share your pain. The error messages are often pretty hard to
trace. Part of my problem is that emacs is better at matching
braces than it is at matching "do" "end" statements -- actually,
does anyone know of a cute way to get emacs to do something intelligent
with these as far as automatically figuring out which statement a
particular "end" matches?

The best answer I've come up with so far is the "lots of small unit
tests" one that other people will probably suggest. Just having a
test that ensures the sanity of each file, or small chunks of each
file, is often pretty helpful, even if they're not
super-in-depth-xp-like-tests (tm). I got pretty lazy with the test
cases for my database interface code, since I didn't want to bother
with a surrogate - the test file has exactly four assertions, but
it's still remarkably useful to just make sure that the file
"compiles" (er, whatever) properly.

  -Dave

ยทยทยท

--
work: dga@lcs.mit.edu me: dga@pobox.com
      MIT Laboratory for Computer Science http://www.angio.net/

Ferenc Engard wrote:

I have a large ruby project (>40 files, >10k rows), and whenever I make
a syntax error somewhere (e.g. swap an 'end' and a '}' token), I always
get the same error, dozens of files away, in an END block, that a given
constant is not defined.

Isn't it possible to detect such errors by the parser/lexer, and give a
helpful error message?

I'm not sure if this fixes specifically your error, but for a patch that makes error messages for missing "end"s more informative see [ruby-talk:115195] and [ruby-core:03486]

The patch is available at http://www.reality.com/roberts/markus/software/ruby/location_of_missing_end/missing_end_patch.0.1.diff

> I have a large ruby project (>40 files, >10k rows), and whenever I make
> a syntax error somewhere (e.g. swap an 'end' and a '}' token), I always
> get the same error, dozens of files away, in an END block, that a given
> constant is not defined.
>
> Isn't it possible to detect such errors by the parser/lexer, and give a
> helpful error message?

I'm not sure if this fixes specifically your error, but for a patch that
makes error messages for missing "end"s more informative see
[ruby-talk:115195] and [ruby-core:03486]

Hmm. So, I should not use SciTE, but an indentation-capable editor...
:-/

I only read only about half of the thread, as it is really loooong, but
there were talk about warning by the parser about blocks where the start
and end is not in the same file? I cannot imagine useful purpose of
finishing a block in a different file where I have started it, and at
least I would know which file I should inspect.

Ferenc