--000e0cd2c0d02ac8b6047461364e
Content-Type: text/plain; charset=ISO-8859-1

On Fri, Sep 25, 2009 at 12:54 AM, Ahmet Kilic <ahmedkilic / gmail.com> wrote:

>  Thank you very much,
> I am making customize the code but when I change this part from
> > str.scan(/^\s*function\s*([^(]+)\(([^)]+)/).map do |name,args|
> to
>
> /procedure|function\s+(\w+)([^\s(]+)\s*\(([^)]+)\)\s*:\s*(\S+)\s*;\s*^\s*var\s*$(.*?)^begin/xm
>
>
I don't know what you are looking for exactly, but it looks like
procedure|functions should be grouped. Also, all your capture groups are
going to get passed into the block, so for each of them, you need a
variable. Any groups that you don't want passed in, you should make into a
non capture group by placing ?: after the opening of the group, like this
(?:)

To see what is going on, you can have the block accept a variable list of
arguments, then print that out to see what was passed in, something like
this:

"ab  cdef".scan(/(b)(\s*)(?:c)de(f)/).each do |*args|
  p *args
end

Which would print out ["b", "  ", "f"] Then you can go and change your
groups around, and see how that affects it.


On Fri, Sep 25, 2009 at 1:05 AM, Robert Klemme
<shortcutter / googlemail.com>wrote:

> On 09/25/2009 06:15 AM, Josh Cheek wrote:
>
>>
>> On Thu, Sep 24, 2009 at 9:17 PM, Ahmet Kilic <ahmedkilic / gmail.com>
>> wrote:
>>
>>
>  functs  rray.new
>>
>> str.scan(/^\s*function\s*([^(]+)\(([^)]+)/).map do |name,args|
>>  name.gsub!(/\s/,'')
>>  args.gsub!(/\s/,'')
>>  functs << ParsedFunction.new( name , args.split(/;/).map{|arg|
>> arg.split(/:/) } )
>> end
>>
>
> Either you should not be using #map above or assign the result of #map to
> functs.  A #map without using the result is pretty useless.
>
> But definitively #scan is the right tool for the job.  If only printing of
> function names and arguments is interesting that could be done inside the
> #scan body as well avoiding a second pass.
>
> Kind regards
>
>        robert
>
> --
> remember.guy do |as, often| as.you_can - without end
> http://blog.rubybestpractices.com/
>
>
Yes, that should be replaced with "each". I initially had it like this

functs  tr.scan(/^\s*function\s*([^(]+)\(([^)]+)/).map do |name,args|
  name.gsub!(/\s/,'')
  args.gsub!(/\s/,'')
  ParsedFunction.new( name , args.split(/;/).map{|arg| arg.split(/:/) } )
end

But I thought it might be easier to follow if I separated the functs
variable. When I did that, I should have also switched map to each.

--000e0cd2c0d02ac8b6047461364e--