smarter parser errors?

F

Ferenc Engard

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
 
D

David G. Andersen

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
 
F

Florian Gross

Ferenc said:
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/mark...ion_of_missing_end/missing_end_patch.0.1.diff
 
F

Ferenc Engard

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,161
Messages
2,570,892
Members
47,427
Latest member
HildredDic

Latest Threads

Top