[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Re: Patterns for error messages

Victor 'Zverok' Shepelev

3/3/2008 9:51:00 AM

From: Stefano Crocco [mailto:stefano.crocco@alice.it]
Sent: Monday, March 03, 2008 11:41 AM
>
>Alle Monday 03 March 2008, Victor 'Zverok' Shepelev ha scritto:
>> OK, but this regexp works for the second case ONLY (unfortunately, I have
>> only one "output pattern" setting, so, I am trying to invent the
>universal
>> one).
>
>It should work for all the first three cases (at least, it does in ruby,
>which
>I'm using to test it).
>
>>
>> >Regarding the last case, I think (but I may be wrong) that the third and
>> >last
>> >one are a single message, split in two lines for some reason. You should
>> >try
>> >to understand why this happens and act consequently. If you post the
>full
>> >error messages, maybe with a piece of code which generates them, I can
>try
>> >to
>> >help you more.
>>
>> Yes, it is like call stack: first line has something like case1-case3,
>other
>> lines has something like case4.
>>
>> For ex:
>>
>> D:/!work/home/!stuff/ruby-tricks/test.rb:1:in `require': ./tricks.rb:31:
>> syntax error, unexpected ']', expecting $end (SyntaxError)
>> p 1,2,3].inject(0){|sum, n| sum + n}
>> ^ from D:/!work/home/!stuff/ruby-tricks/test.rb:1
>>
>
>This should take care of all the four patterns:
>
>/^(?:.*:\d+:in\s+`require':\s+|\s+\^\s+from\s+)?(.*)(?=:\d+)/
>

But not this one:

"./../app/models/teachers.rb:7:in `initialize': undefined local variable"

(not saying about that most of regexp engines too dumb for doing ?: and ?=
groups).

Maybe somebody from core team can comment on the question phrased as: Can
the error messages form be more consistend? (Hmmm... Even I'm ready for
trying to contribute, I think). Or this kind of questions should be asked in
ruby-core?

V.


1 Answer

Stefano Crocco

3/3/2008 10:18:00 AM

0

Alle Monday 03 March 2008, Victor 'Zverok' Shepelev ha scritto:
> >This should take care of all the four patterns:
> >
> >/^(?:.*:\d+:in\s+`require':\s+|\s+\^\s+from\s+)?(.*)(?=:\d+)/
>
> But not this one:
>
> "./../app/models/teachers.rb:7:in `initialize': undefined local variable"

I think this is a different matter: here, we're in the first case (the
simplest) and the regexp correctly gives:

"./../app/models/teachers.rb"

This is the path of the file where the error occurs, relative to the directory
where ruby was started. What would you like to get here?

> (not saying about that most of regexp engines too dumb for doing ?: and ?=
> groups).

Are they? I didn't try many editors (in particular, kate and vim on linux),
but they all support them. At any rate, I think you can do without them. If
you replace the initial (?: with a simple (, you'll get the name of the file
in the second group instead of the first. The look-ahead at the end can be
removed by replacing (.*) with [^:]*. which matche any character except the
column. This has the side effect of not working with filenames containing ':'
(this is the reason I used the look-ahead).

Stefano