no, we do not have to determine where_ to put the missing ")". We can be
close to the target, but not closer, pls.
as for ((1+2)+3+4/5
the compiler just say that the first "(" has missing ")". That is all. (1+2)
pair is already valid, and therefore consumes the last ")" which leaves the
first "(" missing a partner. Of course, this may not be what the programmer
wants, but hey, the compiler was just helping. Was it helpful? Many a times,
yes..
A "missing partner foo-end on possible foo-begin in line#" message is a lot
better than just plain "syntax error".
Is that fine enough?
-botp
···
Markus [mailto:markus@reality.com] wrote:
On Thu, 2004-10-07 at 21:19, Yukihiro Matsumoto wrote:
> Hi,
>
> In message "Re: quality of error messages" > > on Fri, 8 Oct 2004 12:58:26 +0900, Jamis Buck > <jgb3@email.byu.edu> > > writes:
>
> >> We can. But how we check for missing/broken def/end pairs, more
> >> than just syntax error?
>
> >I believe what is being asked for is more than just a
"syntax error"
> >message. If the error could be more specific, like
"missing 'end' on
> >line x", it would greatly increase the usefulness of the -c option.
>
> I know what he wants. I am not refusing his idea. The
point is I'm
> not yet sure how to detect missing pairs.
>
Having spent 12 of the last 48 hours or so hacking away
on ruby's parse.y, I think I've got a pretty clear idea what
the problem is.
Unless (as some have suggested) you add a second source of
information (such as indentation or an explicit statement of
intent such as 'enddef' or 'method_delimiter') it simply
isn't possible in general to tell which end is missing. Consider:
Sorry, my example over simplified a little. To save space, I was
using an analogy between class/end and '('/')'; and I chose a example
that was too simple to really make the point.
Consider that each token is on its own line (i.e., that we really
are wanting to identify which '(' is missing its ')', not even worrying
about where it goes). Also keep in mind that nested things like '((3))'
are valid (and meaningful)*:
(((1/2)/((3/4)/5)
So, which '(' is missing its ')'?
-- Markus
* For example,
class Foo
def Bar
print "Frobaz"
end
end
···
On Thu, 2004-10-07 at 22:26, "Peña, Botp" wrote:
Markus [mailto:markus@reality.com] wrote:
> On Thu, 2004-10-07 at 21:19, Yukihiro Matsumoto wrote:
> > Hi,
> >
> > In message "Re: quality of error messages" > > > on Fri, 8 Oct 2004 12:58:26 +0900, Jamis Buck > > <jgb3@email.byu.edu> > > > writes:
> >
> > >> We can. But how we check for missing/broken def/end pairs, more
> > >> than just syntax error?
> >
> > >I believe what is being asked for is more than just a
> "syntax error"
> > >message. If the error could be more specific, like
> "missing 'end' on
> > >line x", it would greatly increase the usefulness of the -c option.
> >
> > I know what he wants. I am not refusing his idea. The
> point is I'm
> > not yet sure how to detect missing pairs.
> >
>
>
> ((1+2)+3+4/5
>
> There is clearly a ')' missing, but should it be:
>
>
> ((1)+2)+3+4/5 which equals 6.8
>
[snip informative text]
no, we do not have to determine where_ to put the missing ")". We can be
close to the target, but not closer, pls.
as for ((1+2)+3+4/5
the compiler just say that the first "(" has missing ")". That is all. (1+2)
pair is already valid, and therefore consumes the last ")" which leaves the
first "(" missing a partner. Of course, this may not be what the programmer
wants, but hey, the compiler was just helping. Was it helpful? Many a times,
yes..
A "missing partner foo-end on possible foo-begin in line#" message is a lot
better than just plain "syntax error".
I think in most cases not. For the most common missing 'end' error, the
compiler detects it at the end of the file, and the line it thinks it pairs
with is the first line of the file. Hence it localises the error to
somewhere between the first line and last line of the file, which is not
very helpful
Concrete example:
class A
def m1
end
def m2
if true
puts "hello"
end
def m3
end
end
class B
def m1
end
def m2
end
def m3
end
end
class C
end
is parsed as:
class A
def m1
end
def m2
if true
puts "hello"
end
def m3
end
end
class B
def m1
end
def m2
end
def m3
end
end
class C
end
Since class definitions can occur within other classes (very useful), and
'def' can occur within another 'def' (not so useful for me), that's how it
gets parsed.
Regards,
Brian.
···
On Fri, Oct 08, 2004 at 02:26:26PM +0900, "Pe?a, Botp" wrote:
> There is clearly a ')' missing, but should it be:
>
>
> ((1)+2)+3+4/5 which equals 6.8
>
[snip informative text]
no, we do not have to determine where_ to put the missing ")". We can be
close to the target, but not closer, pls.
as for ((1+2)+3+4/5
the compiler just say that the first "(" has missing ")". That is all. (1+2)
pair is already valid, and therefore consumes the last ")" which leaves the
first "(" missing a partner. Of course, this may not be what the programmer
wants, but hey, the compiler was just helping. Was it helpful? Many a times,
yes..