[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Another improved error message request

DaZoner

11/29/2004 5:57:00 PM


I don't know if this case has been requested yet so sorry for the noise if
it has.

It would be nice if this code:

100.times | i |
puts i
end

.... reported that the "do" is missing on line 1 rather than saying syntax
error on line 2. The error can be difficult to find when you have nested
loops and much intervening code.


7 Answers

Brian Schröder

11/29/2004 6:32:00 PM

0

On Tue, 30 Nov 2004 03:17:57 +0900
"DaZoner" <bugmenot@world.com> wrote:

>
> I don't know if this case has been requested yet so sorry for the noise if
> it has.
>
> It would be nice if this code:
>
> 100.times | i |
> puts i
> end
>
> .... reported that the "do" is missing on line 1 rather than saying syntax
> error on line 2. The error can be difficult to find when you have nested
> loops and much intervening code.
>
>

This would indeed be nice, because I catch myself making this error also often. Somehow the do seems superfluent. But I don't think it would be possible to detect this always, because the | are parsed as bitwise or's, so there is only a superfluous end. The proposed indentation heuristic would give a correct result. So the missing end patch would help here.

(If I remember the thread correctly)

Regards,

Brian


--
Brian Schröder
http://www.brian-sch...



Yukihiro Matsumoto

11/29/2004 11:32:00 PM

0

Hi,

In message "Re: Another improved error message request"
on Tue, 30 Nov 2004 03:17:57 +0900, "DaZoner" <bugmenot@world.com> writes:

|It would be nice if this code:
|
|100.times | i |
| puts i
|end

The point is that

100.times | i | puts

is totally valid syntax. It is very hard for a parser to detect this
type of error. If anyone comes up with an idea, please tell me.

matz.


Sam Roberts

11/30/2004 12:19:00 AM

0

Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:
> Hi,
>
> In message "Re: Another improved error message request"
> on Tue, 30 Nov 2004 03:17:57 +0900, "DaZoner" <bugmenot@world.com> writes:
>
> |It would be nice if this code:
> |
> |100.times | i |
> | puts i
> |end
>
> The point is that
>
> 100.times | i | puts
>
> is totally valid syntax. It is very hard for a parser to detect this
> type of error. If anyone comes up with an idea, please tell me.

It is? Well, you would know... :-) but I'm confused!

$ irb18
irb(main):001:0> 100.times | i | puts
LocalJumpError: no block given
from (irb):1:in `times'
from (irb):1

I'm building again, maybe my 1.8 is too far out of date.

Cheers,
Sam



Hal E. Fulton

11/30/2004 12:23:00 AM

0

Sam Roberts wrote:
>>The point is that
>>
>> 100.times | i | puts
>>
>>is totally valid syntax. It is very hard for a parser to detect this
>>type of error. If anyone comes up with an idea, please tell me.
>
>
> It is? Well, you would know... :-) but I'm confused!
>
> $ irb18
> irb(main):001:0> 100.times | i | puts
> LocalJumpError: no block given
> from (irb):1:in `times'
> from (irb):1
>
> I'm building again, maybe my 1.8 is too far out of date.

I think you're seeing a runtime error -- i.e., it is not one
detected by the parser.


Hal



Joel VanderWerf

11/30/2004 12:42:00 AM

0

Sam Roberts wrote:
> Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:
...
>>The point is that
>>
>> 100.times | i | puts
>>
>>is totally valid syntax. It is very hard for a parser to detect this
>>type of error. If anyone comes up with an idea, please tell me.
>
>
> It is? Well, you would know... :-) but I'm confused!
>
> $ irb18
> irb(main):001:0> 100.times | i | puts
> LocalJumpError: no block given
> from (irb):1:in `times'
> from (irb):1

This is a LocalJumpError only because times happens to need a block.

irb(main):001:0> class Fixnum; def tmies; 4; end; end
=> nil
irb(main):002:0> i = 5
=> 5
irb(main):003:0> puts = 6
=> 6
irb(main):004:0> 100.tmies | i | puts
=> 7


Florian Gross

11/30/2004 1:10:00 AM

0

Sam Roberts wrote:

> Quoteing matz@ruby-lang.org, on Tue, Nov 30, 2004 at 08:32:04AM +0900:
>>The point is that
>>
>> 100.times | i | puts
>>
>>is totally valid syntax. It is very hard for a parser to detect this
>>type of error. If anyone comes up with an idea, please tell me.
>
> It is? Well, you would know... :-) but I'm confused!
>
> $ irb18
> irb(main):001:0> 100.times | i | puts
> LocalJumpError: no block given
> from (irb):1:in `times'
> from (irb):1

Use ruby -c to check syntax:

C:\dev\ruby>ruby -c -e "100.times | i | puts"
Syntax OK

nobu.nokada

11/30/2004 8:57:00 AM

0

Hi,

At Tue, 30 Nov 2004 10:12:52 +0900,
Florian Gross wrote in [ruby-talk:121856]:
> Use ruby -c to check syntax:
>
> C:\dev\ruby>ruby -c -e "100.times | i | puts"
> Syntax OK

And -w warns for it.

$ ruby -wc -e "100.times | i | puts"
-e:1: warning: useless use of | in void context
Syntax OK

--
Nobu Nakada