From: Stefano Crocco Date: 2008-03-03T17:42:19+09:00 Subject: Re: Patterns for error messages Alle Monday 03 March 2008, Victor 'Zverok' Shepelev ha scritto: > >From: Stefano Crocco [mailto:stefano.crocco@alice.it] > > > >Alle Saturday 01 March 2008, Victor 'Zverok' Shepelev ha scritto: > >> Hello all. > >> > >> It seems that the question relates to interpreter "internals", but I'm > >> afraid of ask silly questions in ruby-core. > >> > >> The question is: why error messages of interpreter has inconsistent > >> addressing system of file and line? > >> > >> There are at many slightly different schemes (and all of them can be > >> present in the same error backtrace): > >> > >> path/file.rb:10: error text > >> path/file.rb:1:in `require': other-path/other-file.rb:31: error text > >> path/file.rb:7:in `method' error text > >> ^ from path/file.rb:12 > >> > >> And so on. I can't invent one regexp for my output-capturing text editor > >> (EditPlus on Windows) for catch all cases and automatically extract file > >> and path for navigate me to this path. > >> > >> Thanks for the answers. > >> > >> v. > > > >I can't find the differences. If you want a regexp which gives the name of > >the > >file, I think you can simply use something like: > > > >/^.*(?=:\d+:)/ > > For 4 of my cases it would find, respectively: > 1. path/file.rb:10: - OK > 2. path/file.rb:1: - when I wanted "the real error" address - > "other-path/other-file.rb:31:" > 3. path/file.rb:7: - OK > 4. nothing, because of there's no last ":" in the string with "^ from". > Even if you delete last ":" from regexp, the result will be unsatisfactory: > " ^ from path/file.rb:12" (There would be even more spaces, but you > understand the idea) > > It's a pain. > > V. Yes, now I see what you mean. Well, for the second case, it depends on how your editor works exactly. If it has support for regexp groups, you can use the following regexp: /^(?:.*:\d+:in\s+`require':\s+)?(.*)(?=:\d+:)/ The name of the file is in the first group (this works also for the first case) 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. Stefano