From: Paul Brannan Date: 2007-10-23T06:20:36+09:00 Subject: Re: Improving 'syntax error, unexpected $end, expecting kEND'? On Fri, Oct 19, 2007 at 03:01:55AM +0900, Hugh Sasse wrote: > I've had a look at this, but can't see how to do it: When I get > syntax error, unexpected $end, expecting kEND > I know from experience that $end means "end of file" and kEND means > the lexical token "end". What I can't figure out from reading IMO this is a pretty cryptic message. It gets easier to diagnose the more you see the message, but I'd rather see a message like: Syntax error: unexpected end of file while looking for matching 'end' > parse.c is how the stack works and how the rules are stored. I think > knowing if it was expecting the 'end' from a 'class', 'def', 'begin' > 'while', 'for', 'do', 'if', 'unless' or 'case' would help me narrow > down where I've failed to have a closing "end". If there's line > number information that would be even better. Indentation has not > solved this for me. Indentation may not solve the problem, but it does help. When all else fails I comment out sections of code until the code compiles; when that happens, I know the offending code is probably in the code block I most recently commented out. I don't think that specifying which element was missing the end necessarily helps track down the problem. Consider: class Foo def foo while true end return 42 end 1+2 With your proposed change I might expect to see something like: Syntax error: unexpected end of file; expecting matching 'end' for 'class Foo' but blindly putting an 'end' after bar() might be wrong; the user might have meant either: class Foo def foo while true end return 42 end bar() end or: class Foo def foo while true end return 42 end end bar() but it's impossible to know without probing the user's brain (though analyzing indentation could possibly help). Paul